• Brijesh Singh's avatar
    KVM: SEV: Provide support for SNP_GUEST_REQUEST NAE event · 88caf544
    Brijesh Singh authored
    Version 2 of GHCB specification added support for the SNP Guest Request
    Message NAE event. The event allows for an SEV-SNP guest to make
    requests to the SEV-SNP firmware through the hypervisor using the
    SNP_GUEST_REQUEST API defined in the SEV-SNP firmware specification.
    
    This is used by guests primarily to request attestation reports from
    firmware. There are other request types are available as well, but the
    specifics of what guest requests are being made generally does not
    affect how they are handled by the hypervisor, which only serves as a
    proxy for the guest requests and firmware responses.
    
    Implement handling for these events.
    
    When an SNP Guest Request is issued, the guest will provide its own
    request/response pages, which could in theory be passed along directly
    to firmware. However, these pages would need special care:
    
      - Both pages are from shared guest memory, so they need to be
        protected from migration/etc. occurring while firmware reads/writes
        to them. At a minimum, this requires elevating the ref counts and
        potentially needing an explicit pinning of the memory. This places
        additional restrictions on what type of memory backends userspace
        can use for shared guest memory since there would be some reliance
        on using refcounted pages.
    
      - The response page needs to be switched to Firmware-owned state
        before the firmware can write to it, which can lead to potential
        host RMP #PFs if the guest is misbehaved and hands the host a
        guest page that KVM is writing to for other reasons (e.g. virtio
        buffers).
    
    Both of these issues can be avoided completely by using
    separately-allocated bounce pages for both the request/response pages
    and passing those to firmware instead. So that's the approach taken
    here.
    Signed-off-by: default avatarBrijesh Singh <brijesh.singh@amd.com>
    Co-developed-by: default avatarAlexey Kardashevskiy <aik@amd.com>
    Signed-off-by: default avatarAlexey Kardashevskiy <aik@amd.com>
    Co-developed-by: default avatarAshish Kalra <ashish.kalra@amd.com>
    Signed-off-by: default avatarAshish Kalra <ashish.kalra@amd.com>
    Reviewed-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
    Reviewed-by: default avatarLiam Merwick <liam.merwick@oracle.com>
    [mdr: ensure FW command failures are indicated to guest, drop extended
     request handling to be re-written as separate patch, massage commit]
    Signed-off-by: default avatarMichael Roth <michael.roth@amd.com>
    Message-ID: <20240701223148.3798365-2-michael.roth@amd.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    88caf544
svm.h 22.5 KB