linux-coco.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: James Bottomley <jejb@linux.ibm.com>
To: linux-coco@lists.linux.dev
Subject: [RFC 2/2] x86/sev: add a SVSM vTPM platform device
Date: Tue, 03 Jan 2023 16:04:00 -0500	[thread overview]
Message-ID: <83bcfc398d885f9e42d5aae42359fe02ab12d306.camel@linux.ibm.com> (raw)
In-Reply-To: <acb06bc7f329dfee21afa1b2ff080fe29b799021.camel@linux.ibm.com>

From: James Bottomley <James.Bottomley@HansenPartnership.com>

If the SNP boot has a SVSM, probe for the vTPM device by sending a
call to SVSM function 8 with no arguments.  If this returns
successfully, the vTPM is present in the SVSM (If the SVSM doesn't
have a vTPM, this call should return SVSM_ERR_UNSUPPORTED_CALLID).

If a vTPM is found, register a platform device as "platform:tpm" so it
can be attached to the tpm_platform.c driver.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 arch/x86/kernel/sev.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c
index 0297077f7602..276568b1f01a 100644
--- a/arch/x86/kernel/sev.c
+++ b/arch/x86/kernel/sev.c
@@ -21,6 +21,7 @@
 #include <linux/cpumask.h>
 #include <linux/efi.h>
 #include <linux/platform_device.h>
+#include <linux/tpm_platform.h>
 #include <linux/io.h>
 
 #include <asm/cpu_entry_area.h>
@@ -2426,6 +2427,11 @@ static struct platform_device guest_req_device = {
 	.id		= -1,
 };
 
+static struct platform_device tpm_device = {
+	.name		= "tpm",
+	.id		= -1,
+};
+
 static u64 get_secrets_page(void)
 {
 	u64 pa_data = boot_params.cc_blob_address;
@@ -2450,10 +2456,19 @@ static u64 get_secrets_page(void)
 	return info.secrets_phys;
 }
 
+static int tpm_send_buffer(u8 *buffer)
+{
+	struct svsm_caa *caa;
+
+	caa = this_cpu_read(svsm_caa);
+	return __svsm_msr_protocol(caa, 8, __pa(buffer), 0, 0, 0);
+}
+
 static int __init snp_init_platform_device(void)
 {
 	struct snp_guest_platform_data data;
 	u64 gpa;
+	struct svsm_caa *caa = this_cpu_read(svsm_caa);
 
 	if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
 		return -ENODEV;
@@ -2470,6 +2485,24 @@ static int __init snp_init_platform_device(void)
 		return -ENODEV;
 
 	pr_info("SNP guest platform device initialized.\n");
+
+	/* 
+	 * The VTPM device is available only if we have a SVSM and it
+	 * probes correctly (probe is to send a call with no arguments
+	 * to function 8 and see it comes back as OK)
+	 */
+	if (IS_ENABLED(CONFIG_TCG_PLATFORM) && svsm_vmpl &&
+	    __svsm_msr_protocol(caa, 8, 0, 0, 0, 0) == 0) {
+		struct tpm_platform_ops pops = {
+			.sendrcv = tpm_send_buffer,
+		};
+
+		if (platform_device_add_data(&tpm_device, &pops, sizeof(pops)))
+			return -ENODEV;
+		if (platform_device_register(&tpm_device))
+			return -ENODEV;
+		pr_info("SNP SVSM VTPM platform device initialized\n");
+	}
 	return 0;
 }
 device_initcall(snp_init_platform_device);
-- 
2.35.3



  parent reply	other threads:[~2023-01-03 21:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-03 21:01 [RFC 0/3] Enlightened vTPM support for SVSM on SEV-SNP James Bottomley
2023-01-03 21:02 ` [RFC 1/3] tpm: add generic platform device James Bottomley
2023-01-05  8:08   ` Dov Murik
2023-01-05 12:28     ` James Bottomley
2023-01-03 21:04 ` James Bottomley [this message]
2023-01-03 21:05 ` [RFC 3/3] edk2: Add SVSM based vTPM James Bottomley
2023-01-04 22:44 ` [RFC 0/3] Enlightened vTPM support for SVSM on SEV-SNP Tom Lendacky
2023-01-04 22:59   ` James Bottomley
2024-11-06 11:19 ` Stefano Garzarella
2024-11-06 14:54   ` James Bottomley
2024-11-06 15:33     ` 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=83bcfc398d885f9e42d5aae42359fe02ab12d306.camel@linux.ibm.com \
    --to=jejb@linux.ibm.com \
    --cc=linux-coco@lists.linux.dev \
    /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).