From: Roy Hopkins <roy.hopkins@randomman.co.uk>
To: Ani Sinha <anisinha@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Daniel Berrange <berrange@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Michael Tsirkin <mst@redhat.com>,
Cornelia Huck <cohuck@redhat.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>,
Joerg Roedel <joro@8bytes.org>
Subject: Re: [PATCH v7 15/16] i386/sev: Add implementation of CGS set_guest_policy()
Date: Fri, 13 Jun 2025 13:20:34 +0100 [thread overview]
Message-ID: <07f6c5d67b439acc49b96b0aefdafe602488585d.camel@randomman.co.uk> (raw)
In-Reply-To: <18D52538-820A-44BE-82CB-FF960882A414@redhat.com>
On Fri, 2025-06-13 at 17:41 +0530, Ani Sinha wrote:
>
>
> > On 27 Feb 2025, at 7:59 PM, Roy Hopkins <roy.hopkins@randomman.co.uk> wrote:
> >
> > The new cgs_set_guest_policy() function is provided to receive the guest
> > policy flags, SNP ID block and SNP ID authentication from guest
> > configuration such as an IGVM file and apply it to the platform prior to
> > launching the guest.
> >
> > The policy is used to populate values for the existing 'policy',
> > 'id_block' and 'id_auth' parameters. When provided, the guest policy is
> > applied and the ID block configuration is used to verify the launch
> > measurement and signatures. The guest is only successfully started if
> > the expected launch measurements match the actual measurements and the
> > signatures are valid.
> >
> > Signed-off-by: Roy Hopkins <roy.hopkins@randomman.co.uk>
> > Acked-by: Michael S. Tsirkin <mst@redhat.com>
> > Acked-by: Stefano Garzarella <sgarzare@redhat.com>
> > ---
> > target/i386/sev.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++
> > target/i386/sev.h | 12 +++++++
> > 2 files changed, 95 insertions(+)
> >
> > diff --git a/target/i386/sev.c b/target/i386/sev.c
> > index 31b29695bf..fa9b4bcad6 100644
> > --- a/target/i386/sev.c
> > +++ b/target/i386/sev.c
> > @@ -2526,6 +2526,88 @@ 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)
> > +{
> > + if (policy_type != GUEST_POLICY_SEV) {
> > + error_setg(errp, "%s: Invalid guest policy type provided for SEV: %d",
> > + __func__, policy_type);
> > + 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, "%s: Invalid SEV-SNP ID block: incorrect size",
> > + __func__);
> > + return -1;
> > + }
> > + if (policy_data2_size != KVM_SEV_SNP_ID_AUTH_SIZE) {
> > + error_setg(errp,
> > + "%s: Invalid SEV-SNP ID auth block: incorrect size",
> > + __func__);
> > + return -1;
> > + }
> > + assert(policy_data1 != NULL);
> > + assert(policy_data2 != NULL);
> > +
> > + 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);
> > +
> > + /*
> > + * 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;
> > + }
> > + sev_snp_guest->kvm_start_conf.policy = policy;
> > + } else {
>
> I do not see how this “else” part (sev and sev-es) will ever be executed since qigvm_handle_policy() in patch #14 only calls set_guest_policy() if its SEV-
> SNP.
>
You're correct. There is currently no way for this code to be be called. But as it is
an interface function on confidential-guest-support, it could be called erroneously
in the future so I don't see any harm in leaving the error check there.
Thanks,
Roy
prev parent reply other threads:[~2025-06-13 12:22 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
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 [this message]
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=07f6c5d67b439acc49b96b0aefdafe602488585d.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=joro@8bytes.org \
--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).