SEV-SNP: Add support for SNP certificate fetching
v4 cover SEV-SNP: Add support for SNP certificate fetching
This patchset is also available at:
https://github.com/amdese/qemu/commits/snp-certs-v4
and is based on top of qemu master (b574eaf640)
v1: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v3: https://lore.kernel.org/qemu-devel/[email protected]/
v4:
- Use 'int' for 'certs-timeout' in QAPI schema and avoid subtle upcasting of uint32 (Markus)
- Fix up comments/documentation for readability/grammar/spelling.
Overview
--------
The GHCB 2.0 specification defines 2 GHCB request types to allow SNP guests to send encrypted messages/requests to firmware: SNP Guest Requests and SNP Extended Guest Requests. These encrypted messages are used for things like servicing attestation requests issued by the guest. Implementing support for these is required to be fully GHCB-compliant.
For the most part, KVM only needs to handle forwarding these requests to firmware (to be issued via the SNP_GUEST_REQUEST firmware command defined in the SEV-SNP Firmware ABI), and then forwarding the encrypted response to the guest.
However, in the case of SNP Extended Guest Requests, the host is also able to provide the certificate data corresponding to the endorsement key used by firmware to sign attestation report requests. This certificate data is provided by userspace because:
1) It allows for different keys/key types to be used for each particular guest with requiring any sort of KVM API to configure the certificate table in advance on a per-guest basis.
2) It provides additional flexibility with how attestation requests might be handled during live migration where the certificate data for source/dest might be different.
3) It allows all synchronization between certificates and firmware/signing key updates to be handled purely by userspace rather than requiring some in-kernel mechanism to facilitate it. [1]
To support fetching certificate data from userspace, a new KVM KVM_EXIT_SNP_REQ_CERTS exit type is used to fetch the data similarly to KVM_EXIT_MMIO/etc, with an associate KVM capability to detect/enable the exits depending on whether userspace has been configured to provide certificate data.
Add support for this exit in QEMU. Additionally, because some of the locking behavior relies on kvm_immediate_exit, add an some infrastructure to allow for callbacks to be registered and executed upon a kvm_immediate_exit-induced exit from KVM.
See the documentation included in the patches for more details on the expected usage and kvm_immediate_exit handling:
[1] https://lore.kernel.org/kvm/[email protected]/
Testing
-------
For testing this, use a recent host kernel (7.0 or newer should suffice).
For the guest, any 5.19 or newer kernel will do.
A basic command-line invocation for an SNP guest with certificate data supplied would be:
qemu-system-x86_64 -smp 32,maxcpus=255 -cpu EPYC-Milan-v2
-machine q35,confidential-guest-support=sev0,memory-backend=ram1
-object memory-backend-memfd,id=ram1,size=4G,share=true,reserve=false
-object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,id-auth=,certs-path=/home/mroth/cert.blob -bios OVMF.fd
Something like the following simple example can be used to simulate an exclusive lock being held on the certificate by management tools performing an update:
#include <stdlib.h>
#include <stdio.h>
#define __USE_GNU
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, void **argv)
{
int ret, fd, i = 0;
char *path = argv[1]; struct flock fl = {
.l_whence = SEEK_SET,
.l_start = 0,
.l_len = 0,
.l_type = F_WRLCK
};
fd = open(path, O_RDWR);
ret = fcntl(fd, F_OFD_SETLK, &fl);
if (ret) {
printf("error locking file, ret %d errno %d\n", ret, errno);
return ret;
}
while (true) {
i++;
printf("now holding lock (%d seconds elapsed)...\n", i);
usleep(1000 * 1000);
}
return 0;}
For requesting attestation with certificate data attached, you can use something like the following tool/workflow:
https://github.com/virtee/snpguest?tab=readme-ov-file#extended-attestation-workflow
The format of the certificate blob is defined in the GHCB 2.0 specification, but if it's not being parsed on the guest-side then random data will suffice for testing the KVM bits.
Any feedback/review is appreciated.
Thanks!
-Mike
----------------------------------------------------------------
Michael Roth (3):
hw/cpu: Add async_run_on_cpu_after_accel()
accel/kvm: Add kvm_immediate_exit callback infrastructure i386/sev: Add KVM_EXIT_SNP_REQ_CERTS support for certificate-fetching
accel/kvm/kvm-all.c | 21 ++ cpu-common.c | 66 ++++++ docs/system/i386/amd-memory-encryption.rst | 77 ++++++ hw/core/cpu-common.c | 2 + include/hw/core/cpu.h | 33 +++ include/system/kvm.h | 11 + qapi/qom.json | 23 +- target/i386/kvm/kvm.c | 10 + target/i386/sev-system-stub.c | 5 + target/i386/sev.c | 363 +++++++++++++++++++++++++++++ target/i386/sev.h | 3 +- 11 files changed, 612 insertions(+), 2 deletions(-)
PATCH v4 1/3 hw/cpu: Add async_run_on_cpu_after_accel()
For some operations, hypervisors/accelerators like KVM might require calling back into the accelerator code prior to userspace being able to complete handling of certain operations. One common example is I/O emulation where the accelerator call may be necessary to complete pending work on the accelerator side, which then signals completion to userspace via another CPU exit, such is the case with KVM via the existing 'immediate_exit' machinery.
In some cases however, userspace may need to perform additional work on behalf of the vCPU after the accelerator exits, requiring some kind of per-vCPU callback mechanism. async_run_on_cpu() already provides something very similar, but it forces an exit from the inner loop, and is processed at the start of the outer loop, so those callbacks might be issued before the accelerator has a chance to get called again.
Introduce a new variant, async_run_on_cpu_after_accel(), that is designed to queue up work to be processed after the next accelerator exit, and without unnecessarily forcing an exit from the inner loop. The handling is via process_queued_cpu_accel_work(), which is left to accelerator/arch-specific code to implement in their inner loops where appropriate.
KVM will use this general per-vCPU infrastructure to handle callbacks for these cases. Other accelerators may have other uses in the future.
--- cpu-common.c | 66 +++++++++++++++++++++++++++++++++++++++++++ hw/core/cpu-common.c | 2 ++ include/hw/core/cpu.h | 33 ++++++++++++++++++++++ 3 files changed, 101 insertions(+)
cpu-common.c +66 -0
@@ -141,6 +141,23 @@ static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi)cpu_exit (cpu); } +/* +* Queue work on a CPU to run after the next accelerator exit. +* +* This helper intentionally leaves the inner loop running rather than forcing +* an exit via cpu_exit(), since the intention is to immediately call back into +* the accelerator to process pending events, and then upon exiting issue +* callbacks/notifications to any CPUs that need to complete any work that is +* pending on that accelerator call/exit. +*/ +static void queue_accel_work_on_cpu (CPUState *cpu,struct qemu_work_item *wi) +{ +assert (wi->free); +qemu_mutex_lock (&cpu->work_mutex); +QSIMPLEQ_INSERT_TAIL (&cpu->accel_work_list, wi, node); +qemu_mutex_unlock (&cpu->work_mutex); +} +void do_run_on_cpu (CPUState *cpu,run_on_cpu_func func,run_on_cpu_data data,QemuMutex *mutex) {
@@ -178,6 +195,24 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)queue_work_on_cpu (cpu, wi); } +void async_run_on_cpu_after_accel (CPUState *cpu,run_on_cpu_func func, +run_on_cpu_data data) +{ +struct qemu_work_item *wi; + + wi = g_new0(struct qemu_work_item, 1); + +/* +* Only asynchronous accelerator work items are allowed. I.e. wi->free +* must be true. Subsequent code will assert this. +*/ + wi->func = func; + wi->data = data; + wi->free = true; + +queue_accel_work_on_cpu (cpu, wi); +} +/* Wait for pending exclusive operations to complete. The CPU list lock must be held. */ static inline void exclusive_idle (void )
@@ -349,6 +384,37 @@ void free_queued_cpu_work(CPUState *cpu) } } +void free_queued_cpu_accel_work (CPUState *cpu) +{ +while (!QSIMPLEQ_EMPTY (&cpu->accel_work_list)) { +struct qemu_work_item *wi =QSIMPLEQ_FIRST (&cpu->accel_work_list); +QSIMPLEQ_REMOVE_HEAD (&cpu->accel_work_list, node); +assert (wi->free); +g_free (wi); + } +} + +void process_queued_cpu_accel_work (CPUState *cpu) +{ +struct qemu_work_item *wi; + +qemu_mutex_lock (&cpu->work_mutex); + +while (!QSIMPLEQ_EMPTY (&cpu->accel_work_list)) { + wi =QSIMPLEQ_FIRST (&cpu->accel_work_list); +QSIMPLEQ_REMOVE_HEAD (&cpu->accel_work_list, node); + +qemu_mutex_unlock (&cpu->work_mutex); + wi->func (cpu, wi->data); +qemu_mutex_lock (&cpu->work_mutex); + +assert (wi->free); +g_free (wi); + } + +qemu_mutex_unlock (&cpu->work_mutex); +} +void process_queued_cpu_work (CPUState *cpu) {struct qemu_work_item *wi;
hw/core/cpu-common.c +2 -0
@@ -304,6 +304,7 @@ static void cpu_common_initfn(Object *obj)qemu_mutex_init (&cpu->work_mutex);qemu_lockcnt_init (&cpu->in_ioctl_lock);QSIMPLEQ_INIT (&cpu->work_list); +QSIMPLEQ_INIT (&cpu->accel_work_list);QTAILQ_INIT (&cpu->breakpoints);QTAILQ_INIT (&cpu->watchpoints);
@@ -332,6 +333,7 @@ static void cpu_common_finalize(Object *obj) }#endif free_queued_cpu_work (cpu); +free_queued_cpu_accel_work (cpu);/* If cleanup didn't happen in context to gdb_unregister_coprocessor_all */ if (cpu->gdb_regs) {g_array_free (cpu->gdb_regs, TRUE);
include/hw/core/cpu.h +33 -0
@@ -523,6 +523,7 @@ struct CPUState {QemuMutex work_mutex; QSIMPLEQ_HEAD(, qemu_work_item) work_list; + QSIMPLEQ_HEAD(, qemu_work_item) accel_work_list;struct CPUAddressSpace *cpu_ases;AddressSpace *as;
@@ -968,6 +969,24 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);*/ void async_run_on_cpu (CPUState *cpu,run_on_cpu_func func,run_on_cpu_data data); +/** +* async_run_on_cpu_after_accel: +* @cpu: The vCPU to run on. +* @func: The function to be executed. +* @data: Data to pass to the function. +* +* Schedules the function @func for execution on the vCPU @cpu asynchronously, +* to be handled only after the next invocation of the configured accelerator. +* Unlike async_run_on_cpu(), @func will not be run with the BQL held; taking +* the lock is instead left to @func to handle if needed. +* +* This does not guarantee any sort of expedited exiting from the accelerator +* or the inner loop; this aspect is instead left up to +* accelerator/arch-specific code. +*/ +void async_run_on_cpu_after_accel (CPUState *cpu,run_on_cpu_func func, +run_on_cpu_data data); +/** * async_safe_run_on_cpu: * @cpu: The vCPU to run on.
@@ -1115,12 +1134,26 @@ void cpu_remove_sync(CPUState *cpu);*/ void free_queued_cpu_work (CPUState *cpu); +/** +* free_queued_cpu_accel_work() - free all items on CPU accel work queue +* @cpu: The CPU which accel work queue to free. +*/ +void free_queued_cpu_accel_work (CPUState *cpu); +/** * process_queued_cpu_work() - process all items on CPU work queue * @cpu: The CPU which work queue to process. */ void process_queued_cpu_work (CPUState *cpu); +/** +* process_queued_cpu_accel_work() - process all items on CPU accel work queue +* @cpu: The CPU which work queue to process. +* +* Must be called without the BQL held. +*/ +void process_queued_cpu_accel_work (CPUState *cpu); +/** * cpu_exec_start: * @cpu: The CPU for the current thread.
Signature · 1 line
2.43.0
PATCH v4 2/3 accel/kvm: Add kvm_immediate_exit callback infrastructure
In reply to Michael RothProvide a generic mechanism so that users of struct kvm_run's 'immediate_exit' flag can register a callback that can be issued after returning from KVM. Utilize the recently-added async_run_on_cpu_after_accel() interface, with a small wrapper to set the 'immediate_exit' flag upon queuing of any new callbacks.
As with async_run_on_cpu_after_accel(), these callbacks are not run with the BQL held; that is left to individual callback implementations when needed.
--- accel/kvm/kvm-all.c | 21 +++++++++++++++++++++ include/system/kvm.h | 11 +++++++++++ 2 files changed, 32 insertions(+)
accel/kvm/kvm-all.c +21 -0
@@ -3449,6 +3449,19 @@ out_unref:return ret; } +/* +* Queue up CPU work to run after the next call to KVM_RUN. +* +* Requires KVM_CAP_IMMEDIATE_EXIT. +*/ +void kvm_add_immediate_exit_callback (CPUState *cpu,run_on_cpu_func cb, +run_on_cpu_data data) +{ +assert (kvm_immediate_exit); +async_run_on_cpu_after_accel (cpu, cb, data); +kvm_cpu_kick (cpu); +} +int kvm_cpu_exec (CPUState *cpu) {struct kvm_run *run = cpu->kvm_run;
@@ -3511,6 +3524,14 @@ int kvm_cpu_exec(CPUState *cpu)if (run_ret == -EINTR || run_ret == -EAGAIN ) {trace_kvm_io_window_exit ();kvm_eat_signals (cpu); +/* +* This will process any events queued by +* kvm_add_immediate_exit_callback(). This is intentionally run +* after the 'immediate_exit' field is cleared by +* kvm_eat_signals() so that queued accel work can requeue +* itself if needed. +*/ +process_queued_cpu_accel_work (cpu); ret =EXCP_INTERRUPT ;break ; }
include/system/kvm.h +11 -0
@@ -21,6 +21,7 @@#include "qemu/accel.h" #include "accel/accel-route.h" #include "qom/object.h" +#include "hw/core/cpu.h" #ifdef COMPILING_PER_TARGET # ifdef CONFIG_KVM
@@ -594,4 +595,14 @@ void kvm_vcpufd_add_change_notifier(NotifierWithReturn *n);*/ void kvm_vcpufd_remove_change_notifier (NotifierWithReturn *n); +/** +* kvm_add_immediate_exit_callback - register a callback to be performed after +* the next call to KVM_RUN (with immediate_exit set via kvm_cpu_kick()). +* @cpu: CPU to run the callback on. +* @cb: The callback to run. +* @data: The data to pass to the callback. +*/ +void kvm_add_immediate_exit_callback (CPUState *cpu,run_on_cpu_func cb, +run_on_cpu_data data); +#endif
Signature · 1 line
2.43.0
PATCH v4 3/3 i386/sev: Add KVM_EXIT_SNP_REQ_CERTS support for certificate-fetching
In reply to Michael RothThe GHCB specification[1] defines a VMGEXIT-based Guest Request hypercall to allow an SNP guest to issue encrypted requests directly to SNP firmware to do things like query the attestation report for the guest. These are generally handled purely in the kernel.
In some cases, it's useful for the host to be able to additionally supply the certificate chain for the signing key that SNP firmware uses to sign these attestation reports. To allow for this, the GHCB specification defines an Extended Guest Request where this certificate data (along with other accompanying data) can be provided in a special format described in the GHCB spec. This certificate data may be global or guest-specific depending on how the guest was configured. Rather than providing interfaces to manage these within the kernel, KVM provides a new KVM_EXIT_SNP_REQ_CERTS exit to request the certificate contents from userspace. Implement support for that in QEMU.
To synchronize delivery of the certificates to the guest in a way where they will not be rendered invalid by updates to SNP firmware or attestation signing/endorsement keys by management tools outside the purview of QEMU, it is expected by users of KVM_EXIT_SNP_REQ_CERTS to obtain a shared/read lock on the certificate file prior to delivering them back to KVM. Only after this will the attestation report be retrieved from firmware and bundled with the certificate data, so QEMU must continue to hold the file lock until KVM confirms that the attestation report has been retrieved/bundled.
This confirmation is done by way of the kvm_immediate_exit callback infrastructure that was introduced in a prior commit. Once the callback is issued (after the next KVM_RUN), the attestation report will have been fetched, so the report and certificate data fetched by QEMU should be consistent with one another, and the certificate lock can then be released. The included documentation updates have more details on how this is handled.
[1] "Guest Hypervisor Communication Block (GHCB) Standardization",
https://www.amd.com/en/developer/sev.html
--- docs/system/i386/amd-memory-encryption.rst | 77 +++++ qapi/qom.json | 23 +- target/i386/kvm/kvm.c | 10 + target/i386/sev-system-stub.c | 5 + target/i386/sev.c | 363 +++++++++++++++++++++ target/i386/sev.h | 3 +- 6 files changed, 479 insertions(+), 2 deletions(-)
docs/system/i386/amd-memory-encryption.rst +77 -0
@@ -228,6 +228,83 @@ schema for the 'sev-snp-guest' object):: -machine ...,confidential-guest-support=sev0 \ -object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1 +Certificate-fetching (SEV-SNP) +------------------------------ + +When an SEV-SNP guest requests an attestation report from the host, it may +optionally request that the host also deliver the certificates (and +potentially other accompanying data) as part of the response. + +QEMU can be configured to provide this certificate data in the following +manner:: + + # ${QEMU} \ + -machine ...,confidential-guest-support=sev0 \ + -object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,certs-filename=<certs> + +where the format of the file is defined in the SEV-ES Guest-Hypervisor +Communication Block Standardization (GHCB) v2.04, section 4.1.8.1, as:: + + Returned certificates are identified in a table starting at offset 0x0 of + [the file]. Each entry consists of a 16-byte GUID, a 4-byte offset from + [the file] to where the certificate data starts and a 4-byte length + representing the length of the certificate data. The table is terminated + with an entry containing all zeroes for the GUID, offset and length. + + struct cert_table { + struct { + unsigned char guid[16]; + uint32 offset; + uint32 length; + } cert_table_entry[]; + }; + +Because QEMU supplies the certificate to the hypervisor prior to the +hypervisor actually issuing an attestation request, there is potential for +the certificate data to become stale due to a firmware upgrade or other +host management activities. The ioctl which enables certificate-fetching +support via the KVM hypervisor, KVM_SEV_SNP_ENABLE_REQ_CERTS, documents +the following suggested scheme as part of its Linux documentation (v7.3 +at the time of this writing), and it is highly recommended that all software +interacting with these certificates, or performing operations that may +affect their validity, adopt this same scheme for interoperability:: + + The recommended scheme to do this is to use file locking (e.g. via + fcntl()'s F_OFD_SETLK) in the following manner: + + - Prior to obtaining/providing certificate data as part of servicing an + exit type of ``KVM_EXIT_SNP_REQ_CERTS``, the VMM should obtain a + shared/read or exclusive/write lock on the certificate blob file before + reading it and returning it to KVM, and continue to hold the lock until + the attestation request is actually sent to firmware. To facilitate + this, the VMM can set the ``immediate_exit`` flag of kvm_run just after + supplying the certificate data, and just before resuming the vCPU. + This will ensure the vCPU will exit again to userspace with ``-EINTR`` + after it finishes fetching the attestation request from firmware, at + which point the VMM can safely drop the file lock. + + - Tools/libraries that perform updates to SNP firmware TCB values or + endorsement keys (e.g. via /dev/sev interfaces such as ``SNP_COMMIT``, + ``SNP_SET_CONFIG``, or ``SNP_VLEK_LOAD``, see + Documentation/virt/coco/sev-guest.rst for more details) in such a way + that the certificate blob needs to be updated, should similarly take an + exclusive lock on the certificate blob for the duration of any updates + to endorsement keys or the certificate blob contents to ensure that + VMMs using the above scheme will not return certificate blob data that + is out of sync with the endorsement key used by firmware at the time + the attestation request is actually issued. + + This scheme is recommended so that tools can use a fairly generic/natural + approach to synchronizing firmware/certificate updates via file-locking, + which should make it easier to maintain interoperability across + tools/VMMs/vendors. + +As such, QEMU implements this same scheme by waiting for a read-lock on the +file containing the certificate data before supplying any data it contains. +In order to ensure that the lock is not released until after the hypervisor +is finished fetching the attestation report for the guest, the lock is held +until a subsequent exit from the hypervisor that indicates the attestation +report has already been fetched, at which point QEMU will drop the lock. Debugging ---------
qapi/qom.json +22 -1
@@ -1104,6 +1104,25 @@ # @tsc-frequency: set secure TSC frequency. Only valid if Secure TSC # is enabled (default: zero) (since 11.1) # +# @certs-filename: Certificate data that can be passed to guests as +# part of an attestation request. See the +# :doc:`/system/i386/amd-memory-encryption` documentation for more +# details on the usage and file format. +# (default: none) (since: 11.2) +# +# @certs-timeout: Maximum time in milliseconds to wait to obtain a +# read lock on the certificate file specified by @certs-filename. +# This is not a cumulative value and only affects how long QEMU +# waits before returning execution to the vCPU and informing the +# guest of the timeout, so the guest can still continue retrying +# for as long as it likes, which for Linux guests at the time of +# this writing will be about 60 seconds before the guest gives +# up and disables further requests. If this guest-side timeout is +# insufficient, set this higher to allow more time to fetch the +# certificate. If the guest-side timeout is sufficient, +# set this lower to reduce the likelihood of soft lockups in the +# guest. (default: 100) (since: 11.2) +# # Since: 9.1 ## { 'struct': 'SevSnpGuestProperties',
@@ -1117,7 +1136,9 @@ '*host-data': 'str', '*vcek-disabled': 'bool', '*secure-tsc': 'bool', - '*tsc-frequency': 'uint32' } } + '*tsc-frequency': 'uint32', + '*certs-filename': 'str', + '*certs-timeout': 'int' } } ## # @TdxGuestProperties:
target/i386/kvm/kvm.c +10 -0
@@ -6651,6 +6651,16 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)break ; } ret =0 ; +break ; +case KVM_EXIT_SNP_REQ_CERTS : +if (!sev_snp_enabled ()) { +error_report ("KVM: Encountered a certificate request exit for a " +"non-SEV-SNP guest." ); + ret =-1 ; + }else { + ret =kvm_handle_snp_req_certs (cs, run); + } +break ;default :fprintf (stderr,"KVM: unknown exit reason %d\n" , run->exit_reason);
target/i386/sev-system-stub.c +5 -0
@@ -34,3 +34,8 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size)void pc_system_parse_sev_metadata (uint8_t *flash_ptr,size_t flash_size) { } + +int kvm_handle_snp_req_certs (CPUState *cpu,struct kvm_run *run) +{ +g_assert_not_reached (); +}
target/i386/sev.c +363 -0
405 lines not on this page · raw message
target/i386/sev.h +2 -1
@@ -15,6 +15,7 @@#define I386_SEV_H #include "target/i386/svm.h" +#include "system/kvm.h" #ifndef CONFIG_USER_ONLY #include CONFIG_DEVICES /* CONFIG_SEV */
@@ -198,5 +199,5 @@ void pc_system_parse_sev_metadata(uint8_t *flash_ptr, size_t flash_size);uint32_t sev_get_cbit_position (void );uint32_t sev_get_reduced_phys_bits (void ); - +int kvm_handle_snp_req_certs (CPUState *cpu,struct kvm_run *run);#endif
Signature · 1 line
2.43.0
Re: [PATCH v4 3/3] i386/sev: Add KVM_EXIT_SNP_REQ_CERTS support for certificate-fetching
Quoted 34 lines · Michael Roth
The GHCB specification[1] defines a VMGEXIT-based Guest Request hypercall to allow an SNP guest to issue encrypted requests directly to SNP firmware to do things like query the attestation report for the guest. These are generally handled purely in the kernel.
In some cases, it's useful for the host to be able to additionally supply the certificate chain for the signing key that SNP firmware uses to sign these attestation reports. To allow for this, the GHCB specification defines an Extended Guest Request where this certificate data (along with other accompanying data) can be provided in a special format described in the GHCB spec. This certificate data may be global or guest-specific depending on how the guest was configured. Rather than providing interfaces to manage these within the kernel, KVM provides a new
KVM_EXIT_SNP_REQ_CERTSexit to request the certificate contents from userspace. Implement support for that in QEMU.To synchronize delivery of the certificates to the guest in a way where they will not be rendered invalid by updates to SNP firmware or attestation signing/endorsement keys by management tools outside the purview of QEMU, it is expected by users of
KVM_EXIT_SNP_REQ_CERTSto obtain a shared/read lock on the certificate file prior to delivering them back to KVM. Only after this will the attestation report be retrieved from firmware and bundled with the certificate data, so QEMU must continue to hold the file lock until KVM confirms that the attestation report has been retrieved/bundled.This confirmation is done by way of the
kvm_immediate_exitcallback infrastructure that was introduced in a prior commit. Once the callback is issued (after the nextKVM_RUN), the attestation report will have been fetched, so the report and certificate data fetched by QEMU should be consistent with one another, and the certificate lock can then be released. The included documentation updates have more details on how this is handled.
Quoted 6 lines
[1] "Guest Hypervisor Communication Block (GHCB) Standardization",
https://www.amd.com/en/developer/sev.htmlCo-developed-by Melody Wang <[email protected]>Signed-off-by Melody Wang <[email protected]>Signed-off-by Michael Roth <[email protected]>
QAPI schema