mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/sev: Do not fail SNP platform init if the vTPM cannot be registered
@ 2026-08-21  5:34 Gokul K
  2026-09-10  8:24 ` Stefano Garzarella
  0 siblings, 1 reply; 3+ messages in thread
From: Gokul K @ 2026-08-21  5:34 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H. Peter Anvin, Stefano Garzarella, Tom Lendacky,
	Jarkko Sakkinen, linux-coco, linux-kernel

The SVSM vTPM is optional: snp_svsm_vtpm_probe() returns false when no
SVSM is present or when it does not implement TPM_SEND_COMMAND, and
snp_init_platform_device() happily returns success in that case.

When the vTPM *is* available but registering its platform device fails,
the same function instead returns -ENODEV, after sev_guest_device has
already been registered.  That is worse than the absent-vTPM case in two
ways: the sev-guest device is left registered while the initcall reports
failure, and the error tells nobody anything, because the return value of
a device_initcall is only ever traced, never acted upon.

Log the failure and carry on, so an optional device that could not be
registered no longer determines the fate of an unrelated one.  The vTPM
is simply absent, which is a state the guest already has to cope with.

Fixes: e396dd85172c ("x86/sev: Register tpm-svsm platform device")
Signed-off-by: Gokul K <gokul02k@gmail.com>
---
Compile-tested only.  Reaching the failure path needs an SNP guest under an
SVSM whose vTPM platform device fails to register, which in practice means
-ENOMEM during initcalls; I have no way to reproduce that.  Built at W=1 with
CONFIG_AMD_MEM_ENCRYPT=y, and confirmed the file is not built with it =n.

 arch/x86/coco/sev/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index ecd77d3217f3..6501b6f7469a 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -1401,7 +1401,7 @@ static int __init snp_init_platform_device(void)
 
 	if (snp_svsm_vtpm_probe() &&
 	    platform_device_register(&tpm_svsm_device))
-		return -ENODEV;
+		pr_err("Failed to register the SVSM vTPM device\n");
 
 	pr_info("SNP guest platform devices initialized.\n");
 	return 0;
-- 
2.54.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/sev: Do not fail SNP platform init if the vTPM cannot be registered
  2026-08-21  5:34 [PATCH] x86/sev: Do not fail SNP platform init if the vTPM cannot be registered Gokul K
@ 2026-09-10  8:24 ` Stefano Garzarella
  2026-09-12 18:24   ` Gokul K
  0 siblings, 1 reply; 3+ messages in thread
From: Stefano Garzarella @ 2026-09-10  8:24 UTC (permalink / raw)
  To: Gokul K
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Tom Lendacky, Jarkko Sakkinen, linux-coco,
	linux-kernel

On Fri, Aug 21, 2026 at 11:04:11AM +0530, Gokul K wrote:
>The SVSM vTPM is optional: snp_svsm_vtpm_probe() returns false when no
>SVSM is present or when it does not implement TPM_SEND_COMMAND, and
>snp_init_platform_device() happily returns success in that case.
>
>When the vTPM *is* available but registering its platform device fails,
>the same function instead returns -ENODEV, after sev_guest_device has
>already been registered.  That is worse than the absent-vTPM case in two
>ways: the sev-guest device is left registered while the initcall reports
>failure, and the error tells nobody anything, because the return value of
>a device_initcall is only ever traced, never acted upon.
>
>Log the failure and carry on, so an optional device that could not be
>registered no longer determines the fate of an unrelated one.  The vTPM
>is simply absent, which is a state the guest already has to cope with.
>
>Fixes: e396dd85172c ("x86/sev: Register tpm-svsm platform device")
>Signed-off-by: Gokul K <gokul02k@gmail.com>
>---
>Compile-tested only.  Reaching the failure path needs an SNP guest under an
>SVSM whose vTPM platform device fails to register, which in practice means
>-ENOMEM during initcalls; I have no way to reproduce that.  Built at W=1 with
>CONFIG_AMD_MEM_ENCRYPT=y, and confirmed the file is not built with it =n.
>
> arch/x86/coco/sev/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
>index ecd77d3217f3..6501b6f7469a 100644
>--- a/arch/x86/coco/sev/core.c
>+++ b/arch/x86/coco/sev/core.c
>@@ -1401,7 +1401,7 @@ static int __init snp_init_platform_device(void)
>
> 	if (snp_svsm_vtpm_probe() &&
> 	    platform_device_register(&tpm_svsm_device))
>-		return -ENODEV;
>+		pr_err("Failed to register the SVSM vTPM device\n");

IIUC platform_device_register() fails only if something is really bad, 
no memory, device already registered, etc. so IMO this should never 
happen.

I'm opposed convert to an error message, but honestly I don't understand 
which problem we are fixing.

Stefano

>
> 	pr_info("SNP guest platform devices initialized.\n");
> 	return 0;
>-- 
>2.54.0
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/sev: Do not fail SNP platform init if the vTPM cannot be registered
  2026-09-10  8:24 ` Stefano Garzarella
@ 2026-09-12 18:24   ` Gokul K
  0 siblings, 0 replies; 3+ messages in thread
From: Gokul K @ 2026-09-12 18:24 UTC (permalink / raw)
  To: Borislav Petkov, Dave Hansen, H. Peter Anvin, Ingo Molnar,
	Jarkko Sakkinen, linux-coco, linux-kernel, Stefano Garzarella,
	Thomas Gleixner, Tom Lendacky, x86

> I'm opposed convert to an error message, but honestly I don't understand
> which problem we are fixing.

Only an inconsistency: no vTPM returns 0, a failed registration returns
-ENODEV, both leave sev-guest registered, and nothing reads the return
value.  The failure itself should not happen in practice and I am not
arguing otherwise.

Happy to drop this if you would rather keep the -ENODEV.

Thanks,
Gokul


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-12 18:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-21  5:34 [PATCH] x86/sev: Do not fail SNP platform init if the vTPM cannot be registered Gokul K
2026-09-10  8:24 ` Stefano Garzarella
2026-09-12 18:24   ` Gokul K

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®