From: Roy Hopkins <roy.hopkins@randomman.co.uk>
To: Stefano Garzarella <sgarzare@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org,
"Daniel P . Berrange" <berrange@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Sergio Lopez <slp@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>,
Alistair Francis <alistair@alistair23.me>,
Peter Xu <peterx@redhat.com>,
David Hildenbrand <david@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Michael Roth <michael.roth@amd.com>,
Ani Sinha <anisinha@redhat.com>, Joerg Roedel <jroedel@suse.com>
Subject: Re: [PATCH v7 00/16] Introduce support for IGVM files
Date: Thu, 06 Mar 2025 11:48:29 +0000 [thread overview]
Message-ID: <3bc8c923df287519b552a1b67c2f01b557adbf02.camel@randomman.co.uk> (raw)
In-Reply-To: <CAGxU2F4pq3Y7QnQBCEPQ35kQ2hxrwU5nVA9FmR=J6id+EJXAtA@mail.gmail.com>
On Wed, 2025-03-05 at 16:47 +0100, Stefano Garzarella wrote:
> Hi Roy,
>
> I was testing this series with the IGVM file generated by COCONUT SVSM,
> but QEMU was failing in this way:
>
> qemu-system-x86_64: KVM does not support guest_memfd
> qemu-system-x86_64: failed to initialize kvm: Operation not permitted
>
> After spending some time debugging, I found that IGVM is parsed in
> kvm_arch_init(). One of the handler called during the parsing is
> qigvm_prepare_memory(), which adds a new memory region calling
> memory_region_init_ram_guest_memfd(), but it fails:
>
> kvm_arch_init()
> -> qigvm_prepare_memory()
> -> memory_region_init_ram_guest_memfd()
> -> kvm_create_guest_memfd()
> ...
> if (!kvm_guest_memfd_supported) {
> error_setg(errp, "KVM does not support guest_memfd");
> return -1;
> }
>
> So, I applied the following change and SVSM booted!
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index f89568bfa3..840f36675e 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -2722,17 +2722,17 @@ static int kvm_init(MachineState *ms)
>
> kvm_state = s;
>
> - ret = kvm_arch_init(ms, s);
> - if (ret < 0) {
> - goto err;
> - }
> -
> kvm_supported_memory_attributes = kvm_vm_check_extension(s, KVM_CAP_MEMORY_ATTRIBUTES);
> kvm_guest_memfd_supported =
> kvm_check_extension(s, KVM_CAP_GUEST_MEMFD) &&
> kvm_check_extension(s, KVM_CAP_USER_MEMORY2) &&
> (kvm_supported_memory_attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE);
>
> + ret = kvm_arch_init(ms, s);
> + if (ret < 0) {
> + goto err;
> + }
> +
> if (s->kernel_irqchip_split == ON_OFF_AUTO_AUTO) {
> s->kernel_irqchip_split = mc->default_kernel_irqchip_split ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
> }
>
> Checking, I discovered that it was done on purpose by Paolo, so not sure
> if my fix is valid:
>
> commit 586d708c1e3e5e29a0b3c05c347290aed9478854
> Author: Paolo Bonzini <pbonzini@redhat.com>
> Date: Fri Oct 11 10:39:58 2024 +0200
>
> accel/kvm: check for KVM_CAP_MEMORY_ATTRIBUTES on vm
>
> The exact set of available memory attributes can vary by VM. In the
> future it might vary depending on enabled capabilities, too. Query the
> extension on the VM level instead of on the KVM level, and only after
> architecture-specific initialization.
>
> Inspired by an analogous patch by Tom Dohrmann.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> @Paolo any suggestion?
>
> Thanks,
> Stefano
>
Hi Stefano,
Thanks for testing this. The problem seems to be down to the fact that I
had to introduce an initial parsing of the IGVM file during initialization
to extract sev_features. I was parsing all directives in the file but it
appears this has some unwanted side effects.
Please could you try the patch below to see if it fixes the issue? If it
does I'll incorporate it into the patch series and resubmit.
From 3590460ec3945b02a679ad79735681a642596d60 Mon Sep 17 00:00:00 2001
From: Roy Hopkins <roy.hopkins@randomman.co.uk>
Date: Thu, 6 Mar 2025 11:25:07 +0000
Subject: [PATCH 1/1] backends/igvm: Add function to process only VP context
When initializing kvm for SEV, the sev_features need to be
passed to the initialization function. When using IGVM files,
sev_features is provided in the VP context definintions in
the file. Currently this is handled in sev.c by processing
the entire file to extract the VP context, however this has
unwanted side-effects. Therefore this commit adds a new
function that allows only the VP context definitions to
be parsed in the IGVM file.
Signed-off-by: Roy Hopkins <roy.hopkins@randomman.co.uk>
---
backends/igvm-cfg.c | 1 +
backends/igvm.c | 51 +++++++++++++++++++++++++++++++++++++++
backends/igvm.h | 3 +++
include/system/igvm-cfg.h | 10 ++++++++
target/i386/sev.c | 10 ++++----
5 files changed, 70 insertions(+), 5 deletions(-)
diff --git a/backends/igvm-cfg.c b/backends/igvm-cfg.c
index 38f17dae44..25c4469768 100644
--- a/backends/igvm-cfg.c
+++ b/backends/igvm-cfg.c
@@ -41,6 +41,7 @@ static void igvm_cfg_class_init(ObjectClass *oc, void *data)
"Set the IGVM filename to use");
igvmc->process = qigvm_process_file;
+ igvmc->process_vp_context = qigvm_process_vp_context;
}
static void igvm_cfg_init(Object *obj)
diff --git a/backends/igvm.c b/backends/igvm.c
index 7673e4a882..aae83f8a77 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -965,3 +965,54 @@ cleanup:
return retval;
}
+
+int qigvm_process_vp_context(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
+ Error **errp)
+{
+ int32_t header_count;
+ int retval = -1;
+ QIgvm ctx;
+
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.file = qigvm_file_init(cfg->filename, errp);
+ if (ctx.file < 0) {
+ return -1;
+ }
+
+ ctx.cgs = cgs;
+ ctx.cgsc = cgs ? CONFIDENTIAL_GUEST_SUPPORT_GET_CLASS(cgs) : NULL;
+
+ /*
+ * Check that the IGVM file provides configuration for the current
+ * platform
+ */
+ if (qigvm_supported_platform_compat_mask(&ctx, errp) < 0) {
+ goto cleanup;
+ }
+
+ header_count = igvm_header_count(ctx.file, IGVM_HEADER_SECTION_DIRECTIVE);
+ if (header_count <= 0) {
+ error_setg(
+ errp, "Invalid directive header count in IGVM file. Error code: %X",
+ header_count);
+ goto cleanup;
+ }
+
+ for (ctx.current_header_index = 0;
+ ctx.current_header_index < (unsigned)header_count;
+ ctx.current_header_index++) {
+ IgvmVariableHeaderType type = igvm_get_header_type(
+ ctx.file, IGVM_HEADER_SECTION_DIRECTIVE, ctx.current_header_index);
+ if (type == IGVM_VHT_VP_CONTEXT) {
+ if (qigvm_handler(&ctx, type, errp) < 0) {
+ goto cleanup;
+ }
+ }
+ }
+ retval = 0;
+
+cleanup:
+ igvm_free(ctx.file);
+
+ return retval;
+}
diff --git a/backends/igvm.h b/backends/igvm.h
index 269eb3a10e..a43b029d56 100644
--- a/backends/igvm.h
+++ b/backends/igvm.h
@@ -20,4 +20,7 @@
int qigvm_process_file(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
Error **errp);
+int qigvm_process_vp_context(IgvmCfg *igvm, ConfidentialGuestSupport *cgs,
+ Error **errp);
+
#endif
diff --git a/include/system/igvm-cfg.h b/include/system/igvm-cfg.h
index 21fadfe5b7..0c1a7ef309 100644
--- a/include/system/igvm-cfg.h
+++ b/include/system/igvm-cfg.h
@@ -38,6 +38,16 @@ typedef struct IgvmCfgClass {
int (*process)(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
Error **errp);
+ /*
+ * If an IGVM filename has been specified then only process
+ * the VMSA sections in the IGVM file.
+ * Performs a no-op if no filename has been specified.
+ *
+ * Returns 0 for ok and -1 on error.
+ */
+ int (*process_vp_context)(IgvmCfg *cfg, ConfidentialGuestSupport *cgs,
+ Error **errp);
+
} IgvmCfgClass;
#define TYPE_IGVM_CFG "igvm-cfg"
diff --git a/target/i386/sev.c b/target/i386/sev.c
index ef25e64b14..d22e9870ea 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -1893,14 +1893,14 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
* each vcpu.
*
* The IGVM file is normally processed after initialization. Therefore
- * we need to pre-process it here to extract sev_features in order to
- * provide it to KVM_SEV_INIT2. Each cgs_* function that is called by
- * the IGVM processor detects this pre-process by observing the state
- * as SEV_STATE_UNINIT.
+ * we need to pre-process it here, just looking for the vp_context to
+ * extract sev_features in order to provide it to KVM_SEV_INIT2. Each
+ * cgs_* function that is called by the IGVM processor detects this
+ * pre-process by observing the state as SEV_STATE_UNINIT.
*/
if (x86machine->igvm) {
if (IGVM_CFG_GET_CLASS(x86machine->igvm)
- ->process(x86machine->igvm, machine->cgs, errp) == -1) {
+ ->process_vp_context(x86machine->igvm, machine->cgs, errp) == -1) {
return -1;
}
/*
--
2.43.0
next prev parent reply other threads:[~2025-03-06 11:50 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 13:38 [PATCH v7 00/16] Introduce support for IGVM files Roy Hopkins
2025-02-27 13:38 ` [PATCH v7 01/16] meson: Add optional dependency on IGVM library Roy Hopkins
2025-02-27 13:44 ` [PATCH v7 02/16] backends/confidential-guest-support: Add functions to support IGVM Roy Hopkins
2025-02-27 13:44 ` [PATCH v7 03/16] backends/igvm: Add IGVM loader and configuration Roy Hopkins
2025-02-28 13:13 ` Gerd Hoffmann
2025-06-13 10:54 ` Roy Hopkins
2025-03-03 9:03 ` David Hildenbrand
2025-02-27 13:49 ` [PATCH v7 04/16] hw/i386: Add igvm-cfg object and processing for IGVM files Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 05/16] i386/pc_sysfw: Ensure sysfw flash configuration does not conflict with IGVM Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 06/16] sev: Update launch_update_data functions to use Error handling Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 07/16] target/i386: Allow setting of R_LDTR and R_TR with cpu_x86_load_seg_cache() Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 08/16] i386/sev: Refactor setting of reset vector and initial CPU state Roy Hopkins
2025-02-27 17:06 ` Gupta, Pankaj
2025-02-27 14:29 ` [PATCH v7 09/16] i386/sev: Implement ConfidentialGuestSupport functions for SEV Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 10/16] docs/system: Add documentation on support for IGVM Roy Hopkins
2025-02-27 17:12 ` Gupta, Pankaj
2025-02-27 14:29 ` [PATCH v7 11/16] docs/interop/firmware.json: Add igvm to FirmwareDevice Roy Hopkins
2025-02-28 13:15 ` Gerd Hoffmann
2025-02-27 14:29 ` [PATCH v7 12/16] backends/confidential-guest-support: Add set_guest_policy() function Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 13/16] backends/igvm: Process initialization sections in IGVM file Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 14/16] backends/igvm: Handle policy for SEV guests Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 15/16] i386/sev: Add implementation of CGS set_guest_policy() Roy Hopkins
2025-02-27 14:29 ` [PATCH v7 16/16] sev: Provide sev_features flags from IGVM VMSA to KVM_SEV_INIT2 Roy Hopkins
2025-02-27 15:32 ` [PATCH v7 00/16] Introduce support for IGVM files Stefano Garzarella
2025-02-27 16:12 ` Roy Hopkins
2025-02-28 9:26 ` Stefano Garzarella
2025-02-27 15:35 ` [PATCH v7 16/16] sev: Provide sev_features flags from IGVM VMSA to KVM_SEV_INIT2 Roy Hopkins
2025-02-27 15:47 ` Roy Hopkins
2025-02-27 15:56 ` Roy Hopkins
2025-02-28 13:18 ` [PATCH v7 00/16] Introduce support for IGVM files Gerd Hoffmann
2025-03-05 15:47 ` Stefano Garzarella
2025-03-06 11:48 ` Roy Hopkins [this message]
2025-03-06 13:09 ` Stefano Garzarella
2025-05-20 10:01 ` Ani Sinha
[not found] ` <b43aa3fa.AUoAAGOlyUYAAAAAAAAAA9cBm3AAAYKJZwAAAAAAAC5ATwBnwHdy@mailjet.com>
2025-06-12 12:03 ` [PATCH v7 08/16] i386/sev: Refactor setting of reset vector and initial CPU state Ani Sinha
2025-06-16 8:39 ` Ani Sinha
[not found] ` <ec4fb8e4.AUUAAGN5T_UAAAAAAAAAA9cBm3AAAYKJZwAAAAAAAC5ATwBnwULW@mailjet.com>
2025-06-13 12:11 ` [PATCH v7 15/16] i386/sev: Add implementation of CGS set_guest_policy() Ani Sinha
2025-06-13 12:20 ` Roy Hopkins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3bc8c923df287519b552a1b67c2f01b557adbf02.camel@randomman.co.uk \
--to=roy.hopkins@randomman.co.uk \
--cc=alistair@alistair23.me \
--cc=anisinha@redhat.com \
--cc=berrange@redhat.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=eduardo@habkost.net \
--cc=imammedo@redhat.com \
--cc=jroedel@suse.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=michael.roth@amd.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=slp@redhat.com \
--cc=thomas.lendacky@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).