[tip: x86/sev] x86/sev: Register tpm-svsm platform device

From: tip-bot2 for Stefano Garzarella
Date: Fri Apr 11 2025 - 06:17:45 EST


The following commit has been merged into the x86/sev branch of tip:

Commit-ID: e396dd85172c6098e3b70b17e91424edc7bb2d8f
Gitweb: https://git.kernel.org/tip/e396dd85172c6098e3b70b17e91424edc7bb2d8f
Author: Stefano Garzarella <sgarzare@xxxxxxxxxx>
AuthorDate: Thu, 10 Apr 2025 15:51:16 +02:00
Committer: Borislav Petkov (AMD) <bp@xxxxxxxxx>
CommitterDate: Thu, 10 Apr 2025 16:25:33 +02:00

x86/sev: Register tpm-svsm platform device

SNP platform can provide a vTPM device emulated by SVSM.

The "tpm-svsm" device can be handled by the platform driver registered by the
x86/sev core code.

Register the platform device only when SVSM is available and it supports vTPM
commands as checked by snp_svsm_vtpm_probe().

[ bp: Massage commit message. ]

Signed-off-by: Stefano Garzarella <sgarzare@xxxxxxxxxx>
Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
Reviewed-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
Link: https://lore.kernel.org/r/20250410135118.133240-5-sgarzare@xxxxxxxxxx
---
arch/x86/coco/sev/core.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index ecd09da..654a4cc 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -2688,6 +2688,11 @@ static struct platform_device sev_guest_device = {
.id = -1,
};

+static struct platform_device tpm_svsm_device = {
+ .name = "tpm-svsm",
+ .id = -1,
+};
+
static int __init snp_init_platform_device(void)
{
if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
@@ -2696,7 +2701,11 @@ static int __init snp_init_platform_device(void)
if (platform_device_register(&sev_guest_device))
return -ENODEV;

- pr_info("SNP guest platform device initialized.\n");
+ if (snp_svsm_vtpm_probe() &&
+ platform_device_register(&tpm_svsm_device))
+ return -ENODEV;
+
+ pr_info("SNP guest platform devices initialized.\n");
return 0;
}
device_initcall(snp_init_platform_device);