From: Jarkko Sakkinen <jarkko@kernel.org>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Peter Huewe <peterhuewe@gmx.de>,
Tom Lendacky <thomas.lendacky@amd.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Borislav Petkov <bp@alien8.de>,
linux-integrity@vger.kernel.org,
Dov Murik <dovmurik@linux.ibm.com>,
Dionna Glaze <dionnaglaze@google.com>,
linux-coco@lists.linux.dev,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Claudio Carvalho <cclaudio@linux.ibm.com>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Joerg Roedel <jroedel@suse.de>
Subject: Re: [PATCH v3 1/4] x86/sev: add SVSM vTPM probe/send_command functions
Date: Fri, 14 Mar 2025 17:04:00 +0200 [thread overview]
Message-ID: <Z9RFYCAGEZTVfqjb@kernel.org> (raw)
In-Reply-To: <2of2zhxi2c735fgvjxug2bxjfpz2zk25adf3h2ps5byau3rj3k@pgbxmpbskezi>
On Wed, Mar 12, 2025 at 11:56:06AM +0100, Stefano Garzarella wrote:
> On Tue, Mar 11, 2025 at 11:56:23AM +0200, Jarkko Sakkinen wrote:
> > On Tue, Mar 11, 2025 at 10:42:22AM +0100, Stefano Garzarella wrote:
> > > Add two new functions to probe and send commands to the SVSM vTPM.
> > > They leverage the two calls defined by the AMD SVSM specification [1]
> > > for the vTPM protocol: SVSM_VTPM_QUERY and SVSM_VTPM_CMD.
> > >
> > > Expose these functions to be used by other modules such as a tpm
> > > driver.
> > >
> > > [1] "Secure VM Service Module for SEV-SNP Guests"
> > > Publication # 58019 Revision: 1.00
> > >
> > > Co-developed-by: James Bottomley <James.Bottomley@HansenPartnership.com>
> > > Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
> > > Co-developed-by: Claudio Carvalho <cclaudio@linux.ibm.com>
> > > Signed-off-by: Claudio Carvalho <cclaudio@linux.ibm.com>
> > > Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> > > ---
> > > v3:
> > > - removed link to the spec because those URLs are unstable [Borislav]
> > > - squashed "x86/sev: add SVSM call macros for the vTPM protocol" patch
> > > in this one [Borislav]
> > > - slimmed down snp_svsm_vtpm_probe() [Borislav]
> > > - removed features check and any print related [Tom]
> > > ---
> > > arch/x86/include/asm/sev.h | 7 +++++++
> > > arch/x86/coco/sev/core.c | 31 +++++++++++++++++++++++++++++++
> > > 2 files changed, 38 insertions(+)
> > >
> > > diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
> > > index ba7999f66abe..09471d058ce5 100644
> > > --- a/arch/x86/include/asm/sev.h
> > > +++ b/arch/x86/include/asm/sev.h
> > > @@ -384,6 +384,10 @@ struct svsm_call {
> > > #define SVSM_ATTEST_SERVICES 0
> > > #define SVSM_ATTEST_SINGLE_SERVICE 1
> > >
> > > +#define SVSM_VTPM_CALL(x) ((2ULL << 32) | (x))
> > > +#define SVSM_VTPM_QUERY 0
> > > +#define SVSM_VTPM_CMD 1
> > > +
> > > #ifdef CONFIG_AMD_MEM_ENCRYPT
> > >
> > > extern u8 snp_vmpl;
> > > @@ -481,6 +485,9 @@ void snp_msg_free(struct snp_msg_desc *mdesc);
> > > int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req,
> > > struct snp_guest_request_ioctl *rio);
> > >
> > > +bool snp_svsm_vtpm_probe(void);
> > > +int snp_svsm_vtpm_send_command(u8 *buffer);
> > > +
> > > void __init snp_secure_tsc_prepare(void);
> > > void __init snp_secure_tsc_init(void);
> > >
> > > diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
> > > index 96c7bc698e6b..2166bdff88b7 100644
> > > --- a/arch/x86/coco/sev/core.c
> > > +++ b/arch/x86/coco/sev/core.c
> > > @@ -2628,6 +2628,37 @@ static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_dat
> > > return ret;
> > > }
> > >
> >
> > Since this is an exported symbol, it'd be a good practice document
> > snp_svsm_vtpm_probe().
>
> Yes, you are right, since the others were not documented, I had not added
> it, but I agree with you, I'll do in v4.
>
> >
> > > +bool snp_svsm_vtpm_probe(void)
> > > +{
> > > + struct svsm_call call = {};
> > > +
> > > + /* The vTPM device is available only if a SVSM is present */
> > > + if (!snp_vmpl)
> > > + return false;
> > > +
> > > + call.caa = svsm_get_caa();
> > > + call.rax = SVSM_VTPM_CALL(SVSM_VTPM_QUERY);
> >
> > I supposed CAA is some kind of shared memory area for host and VM?
>
> Not with the host, but with SVSM, which is the firmware running in the
> guest, but at a higher privilege level (VMPL) than the kernel, where, for
> example, the vTPM is emulated.
>
> BTW, yep it is a shared memory defined by the SVSM calling convention.
> From AMD SVSM specification:
>
> 5 Calling Convention
>
> Each call to the SVSM conveys data through a combination of the
> SVSM Calling Area (whose address was first configured through the
> SVSM_CAA field of the secrets page) and registers. Use of the
> Calling Area is necessary for the SVSM to detect the difference
> between a call that was issued by the guest and a spurious
> invocation by a poorly behaved host. Registers are used for all
> other parameters.
> The initially configured SVSM Calling Area is a page of memory that
> lies outside the initial SVSM memory range and has not had its VMPL
> permissions restricted in any way. The address is guaranteed to be
> aligned to a 4 KB boundary, so the remainder of the page may be used
> by the guest for memory-based parameter passing if desired.
> The contents of the Calling Area are described in the following
> table:
>
> Table 2: Calling Area
> Byte Size Name Description
> Offset
>
> 0x000 1 byte SVSM_CALL_PENDING Indicates whether a call has
> been requested by the guest
> (0=no call requested, 1=call
> requested).
> 0x001 1 byte SVSM_MEM_AVAILABLE Free memory is available to
> be withdrawn.
> 0x002 6 byte Reserved. The SVSM is not
> required to verify that
> these bytes are 0.
>
> >
> > > +
> > > + if (svsm_perform_call_protocol(&call))
> > > + return false;
> > > +
> > > + /* Check platform commands contains TPM_SEND_COMMAND - platform command 8 */
> > > + return (call.rcx_out & BIT_ULL(8)) == BIT_ULL(8);
> > > +}
> > > +EXPORT_SYMBOL_GPL(snp_svsm_vtpm_probe);
> > > +
> >
> > Ditto.
>
> Ack.
>
> >
> > > +int snp_svsm_vtpm_send_command(u8 *buffer)
> > > +{
> > > + struct svsm_call call = {};
> > > +
> > > + call.caa = svsm_get_caa();
> > > + call.rax = SVSM_VTPM_CALL(SVSM_VTPM_CMD);
> > > + call.rcx = __pa(buffer);
> > > +
> > > + return svsm_perform_call_protocol(&call);
> > > +}
> > > +EXPORT_SYMBOL_GPL(snp_svsm_vtpm_send_command);
> > > +
> > > static struct platform_device sev_guest_device = {
> > > .name = "sev-guest",
> > > .id = -1,
> > > --
> > > 2.48.1
> > >
> >
> > That said, these are rather self-documenting (i.e, nice and clean).
>
> Thanks for the review!
Sure, don't worry about it! Let's just cycle this enough rounds that
it fits well...
> Stefano
BR, Jarkko
next prev parent reply other threads:[~2025-03-14 15:04 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-11 9:42 [PATCH v3 0/4] Enlightened vTPM support for SVSM on SEV-SNP Stefano Garzarella
2025-03-11 9:42 ` [PATCH v3 1/4] x86/sev: add SVSM vTPM probe/send_command functions Stefano Garzarella
2025-03-11 9:56 ` Jarkko Sakkinen
2025-03-12 10:56 ` Stefano Garzarella
2025-03-14 15:04 ` Jarkko Sakkinen [this message]
2025-03-14 15:27 ` Tom Lendacky
2025-03-17 13:36 ` Jarkko Sakkinen
2025-03-18 10:07 ` Stefano Garzarella
2025-03-20 15:03 ` Jarkko Sakkinen
2025-03-20 17:16 ` Borislav Petkov
2025-03-20 17:30 ` Jarkko Sakkinen
2025-03-21 9:01 ` Stefano Garzarella
2025-03-21 22:05 ` Borislav Petkov
2025-03-22 20:17 ` Jarkko Sakkinen
2025-03-24 9:00 ` Stefano Garzarella
2025-03-11 9:42 ` [PATCH v3 2/4] svsm: add header with SVSM_VTPM_CMD helpers Stefano Garzarella
2025-03-11 10:07 ` Jarkko Sakkinen
2025-03-12 11:47 ` Stefano Garzarella
2025-03-11 9:42 ` [PATCH v3 3/4] tpm: add SNP SVSM vTPM driver Stefano Garzarella
2025-03-14 16:48 ` Tom Lendacky
2025-03-17 13:43 ` Jarkko Sakkinen
2025-03-18 10:38 ` Stefano Garzarella
2025-03-18 14:54 ` Tom Lendacky
2025-03-18 16:18 ` Stefano Garzarella
2025-03-19 23:44 ` Jason Gunthorpe
2025-03-20 11:18 ` Stefano Garzarella
2025-03-20 15:00 ` Jarkko Sakkinen
2025-03-20 14:56 ` Jarkko Sakkinen
2025-03-11 9:42 ` [PATCH v3 4/4] x86/sev: register tpm-svsm platform device Stefano Garzarella
2025-03-14 16:56 ` Tom Lendacky
2025-03-17 13:34 ` Jarkko Sakkinen
2025-03-18 10:44 ` Stefano Garzarella
2025-03-20 15:02 ` Jarkko Sakkinen
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=Z9RFYCAGEZTVfqjb@kernel.org \
--to=jarkko@kernel.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=bp@alien8.de \
--cc=cclaudio@linux.ibm.com \
--cc=dave.hansen@linux.intel.com \
--cc=dionnaglaze@google.com \
--cc=dovmurik@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=jgg@ziepe.ca \
--cc=jroedel@suse.de \
--cc=linux-coco@lists.linux.dev \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterhuewe@gmx.de \
--cc=sgarzare@redhat.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/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).