x86/sev: Register tpm-svsm platform device
authorStefano Garzarella <sgarzare@redhat.com>
Thu, 10 Apr 2025 13:51:16 +0000 (15:51 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Thu, 10 Apr 2025 14:25:33 +0000 (16:25 +0200)
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@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/20250410135118.133240-5-sgarzare@redhat.com
arch/x86/coco/sev/core.c

index ecd09dad87f244c4bfb47347f88ed4138a57ce2b..654a4cc06b3fa592ee98c0f864ea8ce551b9fae9 100644 (file)
@@ -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);