From: "tip-bot2 for Stefano Garzarella" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
Claudio Carvalho <cclaudio@linux.ibm.com>,
Stefano Garzarella <sgarzare@redhat.com>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
Tom Lendacky <thomas.lendacky@amd.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/sev] x86/sev: Add SVSM vTPM probe/send_command functions
Date: Fri, 11 Apr 2025 10:15:43 -0000 [thread overview]
Message-ID: <174436654323.31282.652380775473462628.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250403100943.120738-2-sgarzare@redhat.com>
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: 770de678bc281f6b0be339c29c1ad74dfb0e9325
Gitweb: https://git.kernel.org/tip/770de678bc281f6b0be339c29c1ad74dfb0e9325
Author: Stefano Garzarella <sgarzare@redhat.com>
AuthorDate: Thu, 03 Apr 2025 12:09:39 +02:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Thu, 10 Apr 2025 16:15:41 +02:00
x86/sev: Add SVSM vTPM probe/send_command functions
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 snp_svsm_vtpm_send_command() to be used by a TPM driver.
[1] "Secure VM Service Module for SEV-SNP Guests"
Publication # 58019 Revision: 1.00
[ bp: Some doc touchups. ]
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>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lore.kernel.org/r/20250403100943.120738-2-sgarzare@redhat.com
---
arch/x86/coco/sev/core.c | 58 +++++++++++++++++++++++++++++++++++++-
arch/x86/include/asm/sev.h | 7 ++++-
2 files changed, 65 insertions(+)
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index b0c1a7a..ecd09da 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -2625,6 +2625,64 @@ e_restore_irq:
return ret;
}
+/**
+ * snp_svsm_vtpm_probe() - Probe if SVSM provides a vTPM device
+ *
+ * Check that there is SVSM and that it supports at least TPM_SEND_COMMAND
+ * which is the only request used so far.
+ *
+ * Return: true if the platform provides a vTPM SVSM device, false otherwise.
+ */
+static 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);
+
+ 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);
+}
+
+/**
+ * snp_svsm_vtpm_send_command() - Execute a vTPM operation on SVSM
+ * @buffer: A buffer used to both send the command and receive the response.
+ *
+ * Execute a SVSM_VTPM_CMD call as defined by
+ * "Secure VM Service Module for SEV-SNP Guests" Publication # 58019 Revision: 1.00
+ *
+ * All command request/response buffers have a common structure as specified by
+ * the following table:
+ * Byte Size In/Out Description
+ * Offset (Bytes)
+ * 0x000 4 In Platform command
+ * Out Platform command response size
+ *
+ * Each command can build upon this common request/response structure to create
+ * a structure specific to the command. See include/linux/tpm_svsm.h for more
+ * details.
+ *
+ * Return: 0 on success, -errno on failure
+ */
+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,
diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index ba7999f..d9ba035 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,8 @@ 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);
+int snp_svsm_vtpm_send_command(u8 *buffer);
+
void __init snp_secure_tsc_prepare(void);
void __init snp_secure_tsc_init(void);
@@ -524,6 +530,7 @@ static inline struct snp_msg_desc *snp_msg_alloc(void) { return NULL; }
static inline void snp_msg_free(struct snp_msg_desc *mdesc) { }
static inline int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req,
struct snp_guest_request_ioctl *rio) { return -ENODEV; }
+static inline int snp_svsm_vtpm_send_command(u8 *buffer) { return -ENODEV; }
static inline void __init snp_secure_tsc_prepare(void) { }
static inline void __init snp_secure_tsc_init(void) { }
next prev parent reply other threads:[~2025-04-11 10:15 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-03 10:09 [PATCH v6 0/4] Enlightened vTPM support for SVSM on SEV-SNP Stefano Garzarella
2025-04-03 10:09 ` [PATCH v6 1/4] x86/sev: add SVSM vTPM probe/send_command functions Stefano Garzarella
2025-04-11 10:15 ` tip-bot2 for Stefano Garzarella [this message]
2025-04-03 10:09 ` [PATCH v6 2/4] svsm: add header with SVSM_VTPM_CMD helpers Stefano Garzarella
2025-04-11 10:15 ` [tip: x86/sev] svsm: Add " tip-bot2 for Stefano Garzarella
2025-04-03 10:09 ` [PATCH v6 3/4] tpm: add SNP SVSM vTPM driver Stefano Garzarella
2025-04-03 19:05 ` Jarkko Sakkinen
2025-04-09 9:43 ` Stefano Garzarella
2025-04-09 14:21 ` Jarkko Sakkinen
2025-04-04 17:31 ` Dionna Amalie Glaze
2025-04-04 18:37 ` Stefano Garzarella
2025-04-04 18:58 ` Dionna Amalie Glaze
2025-04-09 9:45 ` Stefano Garzarella
2025-04-03 10:09 ` [PATCH v6 4/4] x86/sev: register tpm-svsm platform device Stefano Garzarella
2025-04-03 19:06 ` Jarkko Sakkinen
2025-04-08 11:00 ` Borislav Petkov
2025-04-08 11:08 ` Stefano Garzarella
2025-04-08 11:28 ` Borislav Petkov
2025-04-08 11:54 ` Stefano Garzarella
2025-04-09 10:21 ` Borislav Petkov
2025-04-09 10:43 ` Stefano Garzarella
2025-04-09 11:31 ` Borislav Petkov
2025-04-09 12:22 ` James Bottomley
2025-04-09 15:09 ` Stefano Garzarella
2025-04-09 18:38 ` Borislav Petkov
2025-04-09 16:07 ` Tom Lendacky
2025-04-09 16:51 ` Stefano Garzarella
2025-04-09 18:45 ` Borislav Petkov
2025-04-09 19:16 ` Tom Lendacky
2025-04-10 8:15 ` Stefano Garzarella
2025-04-07 13:46 ` [PATCH v6 0/4] Enlightened vTPM support for SVSM on SEV-SNP Borislav Petkov
2025-04-07 18:14 ` 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=174436654323.31282.652380775473462628.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=James.Bottomley@HansenPartnership.com \
--cc=bp@alien8.de \
--cc=cclaudio@linux.ibm.com \
--cc=jarkko@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=sgarzare@redhat.com \
--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
all inboxes | Powered by JetHome®