• David Matlack's avatar
    KVM: x86/mmu: Cache the access bits of shadowed translations · 6a97575d
    David Matlack authored
    Splitting huge pages requires allocating/finding shadow pages to replace
    the huge page. Shadow pages are keyed, in part, off the guest access
    permissions they are shadowing. For fully direct MMUs, there is no
    shadowing so the access bits in the shadow page role are always ACC_ALL.
    But during shadow paging, the guest can enforce whatever access
    permissions it wants.
    
    In particular, eager page splitting needs to know the permissions to use
    for the subpages, but KVM cannot retrieve them from the guest page
    tables because eager page splitting does not have a vCPU.  Fortunately,
    the guest access permissions are easy to cache whenever page faults or
    FNAME(sync_page) update the shadow page tables; this is an extension of
    the existing cache of the shadowed GFNs in the gfns array of the shadow
    page.  The access bits only take up 3 bits, which leaves 61 bits left
    over for gfns, which is more than enough.
    
    Now that the gfns array caches more information than just GFNs, rename
    it to shadowed_translation.
    
    While here, preemptively fix up the WARN_ON() that detects gfn
    mismatches in direct SPs. The WARN_ON() was paired with a
    pr_err_ratelimited(), which means that users could sometimes see the
    WARN without the accompanying error message. Fix this by outputting the
    error message as part of the WARN splat, and opportunistically make
    them WARN_ONCE() because if these ever fire, they are all but guaranteed
    to fire a lot and will bring down the kernel.
    Signed-off-by: default avatarDavid Matlack <dmatlack@google.com>
    Message-Id: <20220516232138.1783324-18-dmatlack@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    6a97575d
mmu_internal.h 9.62 KB