i386/sev: Support measured direct kernel boot on SNP
v2 cover i386/sev: Support measured direct kernel boot on SNP
This RFC patch series is based on AMD's RFC upmv10-snpv3 tree [1].
In order to enable measured direct kernel boot on SNP, QEMU needs to fill the hashes page when kernel-hashes=on. This relies on several changes to the SNP metadata published by OVMF (See [2] for proposed OVMF patches).
Patch 1 pulls the 'kernel-hashes' property from the SEV guest settings to the common settings to make it available for both SEV and SNP.
Patch 2 adds the hashes table for SNP guests (or validates the page as a zero page if kernel-hashes=off).
This patch series is also available at [3].
[1] https://github.com/mdroth/qemu/commits/upmv10-snpv3
[2] https://edk2.groups.io/g/devel/message/100286
[3] https://github.com/confidential-containers-demo/qemu/tree/snp-kernel-hashes-v2
v2 changes:
* Rebase on top of upmv10-snpv3 which includes kernel-hashes.
v1: https://lore.kernel.org/qemu-devel/20220329064038.96006-1-dovmurik%40linux.ibm.com/
Dov Murik (2):
qapi, i386: Move kernel-hashes to SevCommonProperties i386/sev: Allow measured direct kernel boot on SNP
qapi/qom.json | 12 +++--- target/i386/sev.c | 95 +++++++++++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 42 deletions(-)
Signature · 1 line
2.25.1
RFC PATCH v2 1/2 qapi, i386: Move kernel-hashes to SevCommonProperties
In order to enable kernel-hashes for SNP, pull it from SevGuestProperties to its parent SevCommonProperties so it will be available for both SEV and SNP.
--- qapi/qom.json | 12 ++++++------ target/i386/sev.c | 44 ++++++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 32 deletions(-)
qapi/qom.json +6 -6
@@ -836,6 +836,10 @@ # @reduced-phys-bits: number of bits in physical addresses that become # unavailable when SEV is enabled # +# @kernel-hashes: if true, add hashes of kernel/initrd/cmdline to a +# designated guest firmware page for measured boot +# with -kernel (default: false) (since 6.2) +# # @upm-mode: configure Unmapped Private Memory mode # # @discard: configure how discarding is handled for memory after
@@ -848,6 +852,7 @@ 'data': { '*sev-device': 'str', '*cbitpos': 'uint32', 'reduced-phys-bits': 'uint32', + '*kernel-hashes': 'bool', '*upm-mode': 'bool', '*discard': 'str' } }
@@ -864,10 +869,6 @@ # # @handle: SEV firmware handle (default: 0) # -# @kernel-hashes: if true, add hashes of kernel/initrd/cmdline to a -# designated guest firmware page for measured boot -# with -kernel (default: false) (since 6.2) -# # Since: 2.12 ## { 'struct': 'SevGuestProperties',
@@ -875,8 +876,7 @@ 'data': { '*dh-cert-file': 'str', '*session-file': 'str', '*policy': 'uint32', - '*handle': 'uint32', - '*kernel-hashes': 'bool' } } + '*handle': 'uint32' } } ## # @SevSnpGuestProperties:
target/i386/sev.c +18 -26
90 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [RFC PATCH v2 1/2] qapi, i386: Move kernel-hashes to SevCommonProperties
Quoted 3 lines · Dov Murik
In order to enable kernel-hashes for SNP, pull it from SevGuestProperties to its parent SevCommonProperties so it will be available for both SEV and SNP.
Missing
Patch does not apply for me.
Re: [RFC PATCH v2 1/2] qapi, i386: Move kernel-hashes to SevCommonProperties
Hello Markus,
Quoted 10 lines · Markus Armbruster
Quoted 3 lines · Dov Murik
In order to enable kernel-hashes for SNP, pull it from SevGuestProperties to its parent SevCommonProperties so it will be available for both SEV and SNP.
Missing
Signed-off-by Dov Murik <[email protected]>
Oops, thanks. I'll fix.
Quoted 2 lines
Patch does not apply for me.
This patch series is based on AMD's upmv10-snpv3 tree:
https://github.com/mdroth/qemu/tree/upmv10-snpv3
Have you tried to apply it on top of that tree?
-Dov
Re: [RFC PATCH v2 1/2] qapi, i386: Move kernel-hashes to SevCommonProperties
Quoted 16 lines · Dov Murik
Hello Markus,
Quoted 10 lines · Markus Armbruster
Quoted 3 lines · Dov Murik
In order to enable kernel-hashes for SNP, pull it from SevGuestProperties to its parent SevCommonProperties so it will be available for both SEV and SNP.
Missing
Signed-off-by Dov Murik <[email protected]>Oops, thanks. I'll fix.
Quoted 8 lines
Quoted 2 lines
Patch does not apply for me.
This patch series is based on AMD's upmv10-snpv3 tree:
https://github.com/mdroth/qemu/tree/upmv10-snpv3
Have you tried to apply it on top of that tree?
Missed that part in the cover letter, oops :)
Recommend to also express it like
Based-on: <message-id>
so machines like Patchew can apply it correctly.
However, that upmv10-snpv3 branch is a bit over 1700 commits behind upstream master. I'm afraid you guys need to rebase :)
RFC PATCH v2 2/2 i386/sev: Allow measured direct kernel boot on SNP
In reply to Dov MurikIn SNP, the hashes page is not included in the ranges to pre-validate that appear in the SNP metadata published by AmdSev OVMF.
Therefore, if the user enabled kernel hashes (for measured direct boot), QEMU should fill hashes table and encrypt the page. Note that in SNP (unlike SEV and SEV-ES) the measurements is done in whole 4KB pages. Therefore QEMU zeros the whole page that includes the hashes table, and fills in the kernel hashes area in that page, and then encrypts the whole page. The rest of the page is reserved for SEV launch secrets which are not usable anyway on SNP.
If the user disabled kernel hashes, QEMU pre-validates the page as a zero page.
--- target/i386/sev.c | 51 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-)
target/i386/sev.c +41 -10
@@ -2079,8 +2079,11 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)uint8_t initrd_hash[HASH_SIZE ];uint8_t kernel_hash[HASH_SIZE ];uint8_t *hashp; +hwaddr mapped_gpa, mapped_offset, mapped_len, expected_mapped_len; +uint8_t *mapped_area =NULL ; +MemoryRegion *mr =NULL ; +void *hva;size_t hash_len =HASH_SIZE ; -hwaddr mapped_len =sizeof (*padded_ht);MemTxAttrs attrs = {0 };bool ret = true;SevCommonState *sev_common =SEV_COMMON (MACHINE (qdev_get_machine ())->cgs);
@@ -2090,6 +2093,25 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)* stated kernel-hashes=on. */ if (!sev_common->kernel_hashes) { +if (sev_snp_enabled ()) { +/* Mark the hashes page (if defined) as a zero page */ +if (!pc_system_ovmf_table_find (SEV_HASH_TABLE_RV_GUID , &data,NULL )) { +return false; + } + + area = (SevHashTableDescriptor *)data; +if (!area->base || area->size <sizeof (PaddedSevHashTable)) { +return false; + } + + mapped_gpa = area->base &TARGET_PAGE_MASK ; + hva =gpa2hva (&mr, mapped_gpa,TARGET_PAGE_SIZE ,NULL ); +if (sev_snp_launch_update (SEV_SNP_GUEST (sev_common), mapped_gpa, hva, +TARGET_PAGE_SIZE ,KVM_SEV_SNP_PAGE_TYPE_ZERO )) { +error_setg (errp,"SEV: error marking kernel hashes page as zero" ); + } +return false; + }return false; }
@@ -2099,10 +2121,6 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)return false; } -if (sev_snp_enabled ()) { -return false; - } - area = (SevHashTableDescriptor *)data;if (!area->base || area->size <sizeof (PaddedSevHashTable)) { error_setg(errp, "SEV: guest firmware hashes table area is invalid "
@@ -2149,12 +2167,25 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)* Populate the hashes table in the guest's memory at the OVMF-designated * area for the SEV hashes table */ - padded_ht =address_space_map (&address_space_memory, area->base, - &mapped_len, true, attrs); -if (!padded_ht || mapped_len !=sizeof (*padded_ht)) { +if (sev_snp_enabled ()) { +/* SNP encrypts and measures memory in whole pages */ + mapped_gpa = area->base &TARGET_PAGE_MASK ; + mapped_offset = area->base & ~TARGET_PAGE_MASK ; + mapped_len =TARGET_PAGE_SIZE ; + }else { + mapped_gpa = area->base; + mapped_offset =0 ; + mapped_len =sizeof (*padded_ht); + } + expected_mapped_len = mapped_len; + mapped_area =address_space_map (&address_space_memory, mapped_gpa, + &mapped_len, true, attrs); +if (!mapped_area || mapped_len != expected_mapped_len) {error_setg (errp,"SEV: cannot map hashes table guest memory area" );return false; } +memset (mapped_area,0 , mapped_len); + padded_ht = (PaddedSevHashTable *)(mapped_area + mapped_offset); ht = &padded_ht->ht; ht->guid = sev_hash_table_header_guid;
@@ -2175,11 +2206,11 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)/* zero the excess data so the measurement can be reliably calculated */ memset (padded_ht->padding,0 ,sizeof (padded_ht->padding)); -if (sev_encrypt_flash (area->base, (uint8_t *)padded_ht,sizeof (*padded_ht), errp) <0 ) { +if (sev_encrypt_flash (mapped_gpa, mapped_area, mapped_len, errp) <0 ) { ret = false; } -address_space_unmap (&address_space_memory, padded_ht, +address_space_unmap (&address_space_memory, mapped_area, mapped_len, true, mapped_len);return ret;
Signature · 1 line
2.25.1
Quoted 2 lines · Dov Murik
This RFC patch series is based on AMD's RFC upmv10-snpv3 tree [1].
Note that in order to test this you must use '-machine pc-q35-7.1' to circumvent the SETUP_RNG_SEED bug [1] that interferes with the measured kernel.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
-Dov
Quoted 47 lines
In order to enable measured direct kernel boot on SNP, QEMU needs to fill the hashes page when kernel-hashes=on. This relies on several changes to the SNP metadata published by OVMF (See [2] for proposed OVMF patches).
Patch 1 pulls the 'kernel-hashes' property from the SEV guest settings to the common settings to make it available for both SEV and SNP.
Patch 2 adds the hashes table for SNP guests (or validates the page as a zero page if kernel-hashes=off).
This patch series is also available at [3].
[1] https://github.com/mdroth/qemu/commits/upmv10-snpv3
[2] https://edk2.groups.io/g/devel/message/100286
[3] https://github.com/confidential-containers-demo/qemu/tree/snp-kernel-hashes-v2v2 changes:
* Rebase on top of upmv10-snpv3 which includes kernel-hashes.v1: https://lore.kernel.org/qemu-devel/20220329064038.96006-1-dovmurik%40linux.ibm.com/
Cc Paolo Bonzini <[email protected]>Cc Daniel P. Berrangé <[email protected]>Cc Dr. David Alan Gilbert <[email protected]>Cc Eduardo Habkost <[email protected]>Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Cc Marcelo Tosatti <[email protected]>Cc Gerd Hoffmann <[email protected]>Cc James Bottomley <[email protected]>Cc Tom Lendacky <[email protected]>Cc Michael Roth <[email protected]>Cc Ashish Kalra <[email protected]>Cc Mario Smarduch <[email protected]>Cc Tobin Feldman-Fitzthum <[email protected]>Dov Murik (2):
qapi, i386: Move kernel-hashes to SevCommonProperties i386/sev: Allow measured direct kernel boot on SNPqapi/qom.json | 12 +++--- target/i386/sev.c | 95 +++++++++++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 42 deletions(-)
Quoted 1 line · Dov Murik
This RFC patch series is based on AMD's RFC upmv10-snpv3 tree [1].
I've seen postings of the kernel patches for SNP using the kernel UPM support, but I don't recall ever seeing these QEMU pieces posted for review. The code in that QEMU branch looks different from the last posting of SNP to qemu-devel years ago.
IMHO it would be very desirable if that QEMU UPM tree was submitted to qemu-devel for review feedback, before requesting review of patches that build on top of it.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 10 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 1 line · Dov Murik
This RFC patch series is based on AMD's RFC upmv10-snpv3 tree [1].
I've seen postings of the kernel patches for SNP using the kernel UPM support, but I don't recall ever seeing these QEMU pieces posted for review. The code in that QEMU branch looks different from the last posting of SNP to qemu-devel years ago.
IMHO it would be very desirable if that QEMU UPM tree was submitted to qemu-devel for review feedback
Some of the patches in there look like they're not dependent on SNP or the UPM interface; (eg some CPU model updates). It's probably worth posting those separately so that they can be reviewed and merged and out of the way.
Quoted 2 lines
before requesting review of patches
that build on top of it.
But at the same time it seems right for Dov to send these patches for review.
Dave
Quoted 8 lines
With regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK