From: Stefano Garzarella <sgarzare@redhat.com>
To: Luigi Leonardi <leonardi@redhat.com>
Cc: qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
Ani Sinha <anisinha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Zhao Liu <zhao1.liu@intel.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
kvm@vger.kernel.org
Subject: Re: [PATCH 1/4] sev: rename set_guest_policy to set_id_block and remove dead policy code
Date: Thu, 3 Sep 2026 12:32:21 +0200 [thread overview]
Message-ID: <aplMPpjG6X__JZeM@sgarzare-redhat> (raw)
In-Reply-To: <20260901-fix_igvm_policy-v1-1-e93a6cf8c5ac@redhat.com>
On Tue, Sep 01, 2026 at 12:09:18PM +0200, Luigi Leonardi wrote:
>The guest policy must be provided at guest launch start: LAUNCH_START for
>SEV/SEV-ES and SNP_LAUNCH_START for SEV-SNP. See the SEV API
>specification, chapter 3 (Guest Policy), and the SEV-SNP firmware ABI
>specification, section 4.3 (Guest Policy).
>
>The policy parameter in set_guest_policy was never effective: by the
>time this callback runs, LAUNCH_START has already been issued for both
>SEV/SEV-ES and SEV-SNP, so writing to kvm_start_conf.policy or
>sev_guest->policy has no effect. In practice the only thing this
>callback actually does is set the ID block and ID auth for SNP's
>LAUNCH_FINISH, so rename it to set_id_block to reflect its real
>purpose, remove the unused policy parameter, and drop the non-SNP code
>path which was entirely dead.
>
>This is preliminary work: actually forwarding the guest policy to the
>platform before LAUNCH_START is added in a later commit.
IIUC the behaviour is the same after this patch, but IMO better to
clarify.
>
>Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
>---
> backends/confidential-guest-support.c | 12 ++-
> backends/igvm.c | 6 +-
> include/system/confidential-guest-support.h | 28 ++++---
> target/i386/sev.c | 118 +++++++++++-----------------
> 4 files changed, 67 insertions(+), 97 deletions(-)
>
>diff --git a/backends/confidential-guest-support.c b/backends/confidential-guest-support.c
>index 156dd15e66..a0b36d2da5 100644
>--- a/backends/confidential-guest-support.c
>+++ b/backends/confidential-guest-support.c
>@@ -38,14 +38,12 @@ static int set_guest_state(hwaddr gpa, uint8_t *ptr, uint64_t len,
> return -1;
> }
>
>-static int set_guest_policy(ConfidentialGuestPolicyType policy_type,
>- uint64_t policy,
>- void *policy_data1, uint32_t policy_data1_size,
>- void *policy_data2, uint32_t policy_data2_size,
>- Error **errp)
>+static int set_id_block(void *id_block, uint32_t id_block_size,
>+ void *id_auth, uint32_t id_auth_size,
>+ Error **errp)
> {
> error_setg(errp,
>- "Setting confidential guest policy is not supported for this platform");
>+ "Setting ID block is not supported for this platform");
> return -1;
> }
>
>@@ -64,7 +62,7 @@ static void confidential_guest_support_class_init(ObjectClass *oc,
> ConfidentialGuestSupportClass *cgsc = CONFIDENTIAL_GUEST_SUPPORT_CLASS(oc);
> cgsc->check_support = check_support;
> cgsc->set_guest_state = set_guest_state;
>- cgsc->set_guest_policy = set_guest_policy;
>+ cgsc->set_id_block = set_id_block;
> cgsc->get_mem_map_entry = get_mem_map_entry;
> }
>
>diff --git a/backends/igvm.c b/backends/igvm.c
>index 7b7bdc72b7..85de0d54ec 100644
>--- a/backends/igvm.c
>+++ b/backends/igvm.c
>@@ -968,9 +968,9 @@ static int qigvm_handle_policy(QIgvm *ctx, Error **errp)
> id_block_len = sizeof(struct sev_id_block);
> id_auth_len = sizeof(struct sev_id_authentication);
> }
>- return ctx->cgsc->set_guest_policy(GUEST_POLICY_SEV,
>ctx->sev_policy,
>- ctx->id_block, id_block_len,
>- ctx->id_auth, id_auth_len, errp);
>+
>+ return ctx->cgsc->set_id_block(ctx->id_block, id_block_len,
>+ ctx->id_auth, id_auth_len, errp);
> }
> return 0;
> }
>diff --git a/include/system/confidential-guest-support.h b/include/system/confidential-guest-support.h
>index 5dca717308..6d35ddb97a 100644
>--- a/include/system/confidential-guest-support.h
>+++ b/include/system/confidential-guest-support.h
>@@ -128,21 +128,23 @@ typedef struct ConfidentialGuestSupportClass {
> uint16_t cpu_index, Error **errp);
>
> /*
>- * Set the guest policy. The policy can be used to configure the
>- * confidential platform, such as if debug is enabled or not and can contain
>- * information about expected launch measurements, signed verification of
>- * guest configuration and other platform data.
>- *
>- * The format of the policy data is specific to each platform. For example,
>- * SEV-SNP uses a policy bitfield in the 'policy' argument and provides an
>- * ID block and ID authentication in the 'policy_data' parameters. The type
>- * of policy data is identified by the 'policy_type' argument.
>+ * Set the guest policy for the confidential platform. The policy
>+ * configures properties of the guest, such as whether debug is
>+ * enabled. Its format is platform-specific; for SEV/SEV-ES and
>+ * SEV-SNP it is a policy bitfield. Must be called before LAUNCH_START
>+ * so the policy is in effect for launch.
> */
> int (*set_guest_policy)(ConfidentialGuestPolicyType policy_type,
I'm confused, this commit says "rename set_guest_policy to set_id_block"
so why this callback is still here?
>- uint64_t policy,
>- void *policy_data1, uint32_t policy_data1_size,
>- void *policy_data2, uint32_t policy_data2_size,
>- Error **errp);
>+ uint64_t policy, Error **errp);
>+
>+ /*
>+ * Set the SEV-SNP ID block and ID authentication block. These are
>+ * passed to SNP_LAUNCH_FINISH to provide signed verification of the
>+ * guest configuration.
>+ */
>+ int (*set_id_block)(void *id_block, uint32_t id_block_size,
>+ void *id_auth, uint32_t id_auth_size,
>+ Error **errp);
>
> /*
> * Iterate the system memory map, getting the entry with the given index
>diff --git a/target/i386/sev.c b/target/i386/sev.c
>index 4d875d10ff..465415c535 100644
>--- a/target/i386/sev.c
>+++ b/target/i386/sev.c
>@@ -2723,10 +2723,9 @@ static int cgs_get_mem_map_entry(int index,
> return 0;
> }
>
>-static int cgs_set_guest_policy(ConfidentialGuestPolicyType policy_type,
>- uint64_t policy, void *policy_data1,
>- uint32_t policy_data1_size, void *policy_data2,
>- uint32_t policy_data2_size, Error **errp)
>+static int cgs_set_id_block(void *id_block, uint32_t id_block_size,
>+ void *id_auth, uint32_t id_auth_size,
>+ Error **errp)
> {
> SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs);
> if (sev_common->state == SEV_STATE_UNINIT) {
>@@ -2734,86 +2733,57 @@ static int cgs_set_guest_policy(ConfidentialGuestPolicyType policy_type,
> return 0;
> }
>
>- if (policy_type != GUEST_POLICY_SEV) {
>- error_setg(errp, "SEV: Invalid guest policy type provided for SEV: %d",
>- policy_type);
>+ if (!sev_snp_enabled()) {
>+ error_setg(errp, "SEV: ID block is only supported for SEV-SNP");
> return -1;
> }
>- /*
>- * SEV-SNP handles policy differently. The policy flags are defined in
>- * kvm_start_conf.policy and an ID block and ID auth can be provided.
>- */
>- if (sev_snp_enabled()) {
>- SevSnpGuestState *sev_snp_guest =
>- SEV_SNP_GUEST(MACHINE(qdev_get_machine())->cgs);
>- struct kvm_sev_snp_launch_finish *finish =
>- &sev_snp_guest->kvm_finish_conf;
>
>- /*
>- * The policy consists of flags in 'policy' and optionally an ID block
>- * and ID auth in policy_data1 and policy_data2 respectively. The ID
>- * block and auth are optional so clear any previous ID block and auth
>- * and set them if provided, but always set the policy flags.
>- */
>- g_free(sev_snp_guest->id_block);
>- g_free((guchar *)finish->id_block_uaddr);
>- g_free(sev_snp_guest->id_auth);
>- g_free((guchar *)finish->id_auth_uaddr);
>- sev_snp_guest->id_block = NULL;
>- finish->id_block_uaddr = 0;
>- sev_snp_guest->id_auth = NULL;
>- finish->id_auth_uaddr = 0;
>-
>- if (policy_data1_size > 0) {
>- struct sev_snp_id_authentication *id_auth =
>- (struct sev_snp_id_authentication *)policy_data2;
>-
>- if (policy_data1_size != KVM_SEV_SNP_ID_BLOCK_SIZE) {
>- error_setg(errp, "SEV: Invalid SEV-SNP ID block: incorrect size");
>- return -1;
>- }
>- if (policy_data2_size != KVM_SEV_SNP_ID_AUTH_SIZE) {
>- error_setg(errp,
>- "SEV: Invalid SEV-SNP ID auth block: incorrect size");
>- return -1;
>- }
>- assert(policy_data1 != NULL);
>- assert(policy_data2 != NULL);
>+ SevSnpGuestState *sev_snp_guest =
>+ SEV_SNP_GUEST(MACHINE(qdev_get_machine())->cgs);
>+ struct kvm_sev_snp_launch_finish *finish =
>+ &sev_snp_guest->kvm_finish_conf;
>
>- finish->id_block_uaddr =
>- (__u64)g_memdup2(policy_data1, KVM_SEV_SNP_ID_BLOCK_SIZE);
>- finish->id_auth_uaddr =
>- (__u64)g_memdup2(policy_data2, KVM_SEV_SNP_ID_AUTH_SIZE);
>+ g_free(sev_snp_guest->id_block);
>+ g_free((guchar *)finish->id_block_uaddr);
>+ g_free(sev_snp_guest->id_auth);
>+ g_free((guchar *)finish->id_auth_uaddr);
>+ sev_snp_guest->id_block = NULL;
>+ finish->id_block_uaddr = 0;
>+ sev_snp_guest->id_auth = NULL;
>+ finish->id_auth_uaddr = 0;
>
>- /*
>- * Check if an author key has been provided and use that to flag
>- * whether the author key is enabled. The first of the author key
>- * must be non-zero to indicate the key type, which will currently
>- * always be 2.
>- */
>- sev_snp_guest->kvm_finish_conf.auth_key_en =
>- id_auth->author_key[0] ? 1 : 0;
>- finish->id_block_en = 1;
>- }
>+ if (id_block_size > 0) {
>+ struct sev_snp_id_authentication *auth =
>+ (struct sev_snp_id_authentication *)id_auth;
>
>- /* do not reset existing policy if policy was not set in IGVM */
>- if (policy != 0) {
>- sev_snp_guest->kvm_start_conf.policy = policy;
>+ if (id_block_size != KVM_SEV_SNP_ID_BLOCK_SIZE) {
>+ error_setg(errp, "SEV: Invalid SEV-SNP ID block: incorrect size");
>+ return -1;
> }
>- } else {
>- SevGuestState *sev_guest = SEV_GUEST(MACHINE(qdev_get_machine())->cgs);
>- /* Only the policy flags are supported for SEV and SEV-ES */
>- if ((policy_data1_size > 0) || (policy_data2_size > 0) || !sev_guest) {
>- error_setg(errp, "SEV: An ID block/ID auth block has been provided "
>- "but SEV-SNP is not enabled");
>+ if (id_auth_size != KVM_SEV_SNP_ID_AUTH_SIZE) {
>+ error_setg(errp,
>+ "SEV: Invalid SEV-SNP ID auth block: incorrect size");
> return -1;
> }
>+ assert(id_block != NULL);
>+ assert(id_auth != NULL);
>
>- /* do not reset existing policy if policy was not set in IGVM */
>- if (policy != 0) {
>- sev_guest->policy = policy;
>- }
>+ finish->id_block_uaddr =
>+ (__u64)g_memdup2(id_block, KVM_SEV_SNP_ID_BLOCK_SIZE);
>+ finish->id_auth_uaddr =
>+ (__u64)g_memdup2(id_auth, KVM_SEV_SNP_ID_AUTH_SIZE);
>+
>+ /*
>+ * Check if an author key has been provided and use that to flag
>+ * whether the author key is enabled. The first of the author key
>+ * must be non-zero to indicate the key type, which will currently
>+ * always be 2.
>+ */
>+ sev_snp_guest->kvm_finish_conf.auth_key_en =
>+ auth->author_key[0] ? 1 : 0;
>+ finish->id_block_en = 1;
> }
>+
> return 0;
> }
>
>@@ -2878,7 +2848,7 @@ sev_common_instance_init(Object *obj)
> cgs->check_support = cgs_check_support;
> cgs->set_guest_state = cgs_set_guest_state;
> cgs->get_mem_map_entry = cgs_get_mem_map_entry;
>- cgs->set_guest_policy = cgs_set_guest_policy;
>+ cgs->set_id_block = cgs_set_id_block;
> cgs->can_rebuild_guest_state = true;
>
> QTAILQ_INIT(&sev_common->launch_vmsa);
>
>--
>2.55.0
>
next prev parent reply other threads:[~2026-09-03 10:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 10:09 [PATCH 0/4] igvm/sev: apply the IGVM guest policy before launch Luigi Leonardi
2026-09-01 10:09 ` [PATCH 1/4] sev: rename set_guest_policy to set_id_block and remove dead policy code Luigi Leonardi
2026-09-03 8:47 ` Ani Sinha
2026-09-03 10:32 ` Stefano Garzarella [this message]
2026-09-03 10:47 ` Luigi Leonardi
2026-09-03 13:55 ` Stefano Garzarella
2026-09-04 5:29 ` Gerd Hoffmann
2026-09-01 10:09 ` [PATCH 2/4] igvm: move set_id_block call into the SNP ID block directive handler Luigi Leonardi
2026-09-03 12:57 ` Stefano Garzarella
2026-09-03 13:29 ` Luigi Leonardi
2026-09-03 15:53 ` Stefano Garzarella
2026-09-01 10:09 ` [PATCH 3/4] i386/sev: convert the guest policy properties to custom accessors Luigi Leonardi
2026-09-03 8:46 ` Ani Sinha
2026-09-01 10:09 ` [PATCH 4/4] igvm/sev: forward the IGVM guest policy to the platform before launch Luigi Leonardi
2026-09-03 8:46 ` Ani Sinha
2026-09-03 9:01 ` Luigi Leonardi
2026-09-03 10:03 ` Ani Sinha
2026-09-03 11:02 ` Luigi Leonardi
2026-09-03 11:34 ` Ani Sinha
2026-09-03 11:50 ` Daniel P. Berrangé
2026-09-03 13:28 ` Stefano Garzarella
2026-09-03 13:40 ` Luigi Leonardi
2026-09-04 5:45 ` Gerd Hoffmann
2026-09-03 13:14 ` Stefano Garzarella
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=aplMPpjG6X__JZeM@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=anisinha@redhat.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=leonardi@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhao1.liu@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.