• Sean Christopherson's avatar
    KVM: SVM: Simplify and harden helper to flush SEV guest page(s) · 4bbef7e8
    Sean Christopherson authored
    
    
    Rework sev_flush_guest_memory() to explicitly handle only a single page,
    and harden it to fall back to WBINVD if VM_PAGE_FLUSH fails.  Per-page
    flushing is currently used only to flush the VMSA, and in its current
    form, the helper is completely broken with respect to flushing actual
    guest memory, i.e. won't work correctly for an arbitrary memory range.
    
    VM_PAGE_FLUSH takes a host virtual address, and is subject to normal page
    walks, i.e. will fault if the address is not present in the host page
    tables or does not have the correct permissions.  Current AMD CPUs also
    do not honor SMAP overrides (undocumented in kernel versions of the APM),
    so passing in a userspace address is completely out of the question.  In
    other words, KVM would need to manually walk the host page tables to get
    the pfn, ensure the pfn is stable, and then use the direct map to invoke
    VM_PAGE_FLUSH.  And the latter might not even work, e.g. if userspace is
    particularly evil/clever and backs the guest with Secret Memory (which
    unmaps memory from the direct map).
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    
    Fixes: add5e2f0
    
     ("KVM: SVM: Add support for the SEV-ES VMSA")
    Reported-by: default avatarMingwei Zhang <mizhang@google.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarMingwei Zhang <mizhang@google.com>
    Message-Id: <20220421031407.2516575-2-mizhang@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    4bbef7e8
sev.c 74.1 KB