[PATCH 0/2] tpm: Stop retrying TPMs that have stopped working

Breno Leitao posted 2 patches 1 week, 6 days ago
There is a newer version of this series
drivers/char/tpm/tpm-chip.c      | 20 +++++++++++++++++++-
drivers/char/tpm/tpm-interface.c | 29 +++++++++++++++++++++++++++++
include/linux/tpm.h              |  3 +++
3 files changed, 51 insertions(+), 1 deletion(-)
[PATCH 0/2] tpm: Stop retrying TPMs that have stopped working
Posted by Breno Leitao 1 week, 6 days ago
On Meta's datacenter, given the size, TPMs that stop working write about
54 million lines a day to the kernel log, because nothing in the kernel
gives up on them.

Two cases make up nearly all of it.

Some TPMs stop responding. Every command then fails only after the
transport timeout, while the hwrng thread and userspace keep sending
more.

The goal is to retire TPM that are not properly working, similarly to
what was done for EFI in commit 4b2c033b5bc971 ("efi/runtime-wrappers:
retire the worker if a wedged call ever returns")

This feature aim to disable the chip once its commands have kept timing,
instead of keeping it in this desolate state.

Disabling the chip makes the failure explicit: the log gets one line
saying the TPM is disabled, and every later command fails at once
instead of timing out. 

A health-check daemon, such as machine checker, can then detect
the broken hardware and send the machine to repair.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
Breno Leitao (2):
      tpm: Disable a TPM that stops responding
      tpm: Disable a TPM whose hwrng reads keep failing

 drivers/char/tpm/tpm-chip.c      | 20 +++++++++++++++++++-
 drivers/char/tpm/tpm-interface.c | 29 +++++++++++++++++++++++++++++
 include/linux/tpm.h              |  3 +++
 3 files changed, 51 insertions(+), 1 deletion(-)
---
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
change-id: 20261110-tpm_unresponsive-a5f71c1db026

Best regards,
--  
Breno Leitao <leitao@debian.org>
Re: [PATCH 0/2] tpm: Stop retrying TPMs that have stopped working
Posted by Jarkko Sakkinen 1 week, 5 days ago
On Wed, Nov 11, 2026 at 01:57:32AM -0800, Breno Leitao wrote:
> On Meta's datacenter, given the size, TPMs that stop working write about
> 54 million lines a day to the kernel log, because nothing in the kernel
> gives up on them.
> 
> Two cases make up nearly all of it.
> 
> Some TPMs stop responding. Every command then fails only after the
> transport timeout, while the hwrng thread and userspace keep sending
> more.
> 
> The goal is to retire TPM that are not properly working, similarly to
> what was done for EFI in commit 4b2c033b5bc971 ("efi/runtime-wrappers:
> retire the worker if a wedged call ever returns")
> 
> This feature aim to disable the chip once its commands have kept timing,
> instead of keeping it in this desolate state.
> 
> Disabling the chip makes the failure explicit: the log gets one line
> saying the TPM is disabled, and every later command fails at once
> instead of timing out. 
> 
> A health-check daemon, such as machine checker, can then detect
> the broken hardware and send the machine to repair.
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
> Breno Leitao (2):
>       tpm: Disable a TPM that stops responding
>       tpm: Disable a TPM whose hwrng reads keep failing
> 
>  drivers/char/tpm/tpm-chip.c      | 20 +++++++++++++++++++-
>  drivers/char/tpm/tpm-interface.c | 29 +++++++++++++++++++++++++++++
>  include/linux/tpm.h              |  3 +++
>  3 files changed, 51 insertions(+), 1 deletion(-)
> ---
> base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
> change-id: 20261110-tpm_unresponsive-a5f71c1db026
> 
> Best regards,
> --  
> Breno Leitao <leitao@debian.org>
> 

I think this good stuff so existential condition for having some changes
to address these issues is fulfilled.

I.e. debating the details through will likely lead to productive results
:-)

Br, Jarkko
Re: [PATCH 0/2] tpm: Stop retrying TPMs that have stopped working
Posted by Jarkko Sakkinen 1 week, 5 days ago
On Thu, Nov 12, 2026 at 12:30:35AM +0200, Jarkko Sakkinen wrote:
> On Wed, Nov 11, 2026 at 01:57:32AM -0800, Breno Leitao wrote:
> > On Meta's datacenter, given the size, TPMs that stop working write about
> > 54 million lines a day to the kernel log, because nothing in the kernel
> > gives up on them.
> > 
> > Two cases make up nearly all of it.
> > 
> > Some TPMs stop responding. Every command then fails only after the
> > transport timeout, while the hwrng thread and userspace keep sending
> > more.
> > 
> > The goal is to retire TPM that are not properly working, similarly to
> > what was done for EFI in commit 4b2c033b5bc971 ("efi/runtime-wrappers:
> > retire the worker if a wedged call ever returns")
> > 
> > This feature aim to disable the chip once its commands have kept timing,
> > instead of keeping it in this desolate state.
> > 
> > Disabling the chip makes the failure explicit: the log gets one line
> > saying the TPM is disabled, and every later command fails at once
> > instead of timing out. 
> > 
> > A health-check daemon, such as machine checker, can then detect
> > the broken hardware and send the machine to repair.
> > 
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> > ---
> > Breno Leitao (2):
> >       tpm: Disable a TPM that stops responding
> >       tpm: Disable a TPM whose hwrng reads keep failing
> > 
> >  drivers/char/tpm/tpm-chip.c      | 20 +++++++++++++++++++-
> >  drivers/char/tpm/tpm-interface.c | 29 +++++++++++++++++++++++++++++
> >  include/linux/tpm.h              |  3 +++
> >  3 files changed, 51 insertions(+), 1 deletion(-)
> > ---
> > base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
> > change-id: 20261110-tpm_unresponsive-a5f71c1db026
> > 
> > Best regards,
> > --  
> > Breno Leitao <leitao@debian.org>
> > 
> 
> I think this good stuff so existential condition for having some changes
> to address these issues is fulfilled.
> 
> I.e. debating the details through will likely lead to productive results
> :-)

$ tpm2sh return-code 256
TPM_RC_INITIALIZE

I.e. TPM has not been properly initialized by TPM2_Startup().

I.e. TPM is also saying that it is *disabled*.

So acting on this proven fact  makes most sense to me.

Br, Jarkko
Re: [PATCH 0/2] tpm: Stop retrying TPMs that have stopped working
Posted by Jarkko Sakkinen 1 week, 5 days ago
On Thu, Nov 12, 2026 at 12:43:59AM +0200, Jarkko Sakkinen wrote:
> $ tpm2sh return-code 256
> TPM_RC_INITIALIZE
> 
> I.e. TPM has not been properly initialized by TPM2_Startup().
> 
> I.e. TPM is also saying that it is *disabled*.
> 
> So acting on this proven fact  makes most sense to me.


Actually, should we even disable TPM if it returns this error code
already at the level of tpm_transmit(). It is a guaranteed dead-end
to any possible TPM operation.

I.e. while this fixes hwrng issue I think it might be addressing the
issue at a wrong level.

Br, Jarkko
Re: [PATCH 0/2] tpm: Stop retrying TPMs that have stopped working
Posted by Jarkko Sakkinen 1 week, 5 days ago
On Thu, Nov 12, 2026 at 12:46:57AM +0200, Jarkko Sakkinen wrote:
> On Thu, Nov 12, 2026 at 12:43:59AM +0200, Jarkko Sakkinen wrote:
> > $ tpm2sh return-code 256
> > TPM_RC_INITIALIZE
> > 
> > I.e. TPM has not been properly initialized by TPM2_Startup().
> > 
> > I.e. TPM is also saying that it is *disabled*.
> > 
> > So acting on this proven fact  makes most sense to me.
> 
> 
> Actually, should we even disable TPM if it returns this error code
> already at the level of tpm_transmit(). It is a guaranteed dead-end
> to any possible TPM operation.
> 
> I.e. while this fixes hwrng issue I think it might be addressing the
> issue at a wrong level.

I leave room for figuring out 1/2 but for the second issue I would just
do what the attached patch does and call it a day.

Br, Jarkko
Re: [PATCH 0/2] tpm: Stop retrying TPMs that have stopped working
Posted by Jarkko Sakkinen 1 week, 5 days ago
On Thu, Nov 12, 2026 at 03:57:29AM +0200, Jarkko Sakkinen wrote:
> On Thu, Nov 12, 2026 at 12:46:57AM +0200, Jarkko Sakkinen wrote:
> > On Thu, Nov 12, 2026 at 12:43:59AM +0200, Jarkko Sakkinen wrote:
> > > $ tpm2sh return-code 256
> > > TPM_RC_INITIALIZE
> > > 
> > > I.e. TPM has not been properly initialized by TPM2_Startup().
> > > 
> > > I.e. TPM is also saying that it is *disabled*.
> > > 
> > > So acting on this proven fact  makes most sense to me.
> > 
> > 
> > Actually, should we even disable TPM if it returns this error code
> > already at the level of tpm_transmit(). It is a guaranteed dead-end
> > to any possible TPM operation.
> > 
> > I.e. while this fixes hwrng issue I think it might be addressing the
> > issue at a wrong level.
> 
> I leave room for figuring out 1/2 but for the second issue I would just
> do what the attached patch does and call it a day.
> 
> Br, Jarkko

> From 093124e51a26de8191e21ce41988532ea7e0bc8a Mon Sep 17 00:00:00 2001
> From: Jarkko Sakkinen <jarkko@kernel.org>
> Date: Thu, 12 Nov 2026 03:55:00 +0200
> Subject: [PATCH] tpm: Disable TPM on TPM_RC_INITIALIZE
> 
> If the TPM has been spuriously disabled, the game is over. Let's reflect
> this truth with TPM_CHIP_FLAG_DISABLE.
> 
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> ---
>  drivers/char/tpm/tpm-interface.c | 5 +++++
>  drivers/char/tpm/tpm2-cmd.c      | 2 ++
>  2 files changed, 7 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 470b2da3234e..1f1e22341155 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -256,6 +256,11 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz)
>  		if (rc == TPM2_RC_TESTING && cc == TPM2_CC_SELF_TEST)
>  			break;
>  
> +		if (rc == TPM_RC_INITIALIZE) {
> +			chip->flag |= TPM_CHIP_FLAG_DISABLE;
> +			break;
> +		}
> +

Sorry, should be TPM2_RC_INITIALIZE. 

Br, Jarkko
Re: [PATCH 0/2] tpm: Stop retrying TPMs that have stopped working
Posted by Breno Leitao 1 week, 4 days ago
On Thu, Nov 12, 2026 at 04:01:47AM +0200, Jarkko Sakkinen wrote:
> On Thu, Nov 12, 2026 at 03:57:29AM +0200, Jarkko Sakkinen wrote:
> > On Thu, Nov 12, 2026 at 12:46:57AM +0200, Jarkko Sakkinen wrote:
> > > On Thu, Nov 12, 2026 at 12:43:59AM +0200, Jarkko Sakkinen wrote:
> > > > $ tpm2sh return-code 256
> > > > TPM_RC_INITIALIZE
> > > > 
> > > > I.e. TPM has not been properly initialized by TPM2_Startup().
> > > > 
> > > > I.e. TPM is also saying that it is *disabled*.
> > > > 
> > > > So acting on this proven fact  makes most sense to me.
> > > 
> > > 
> > > Actually, should we even disable TPM if it returns this error code
> > > already at the level of tpm_transmit(). It is a guaranteed dead-end
> > > to any possible TPM operation.
> > > 
> > > I.e. while this fixes hwrng issue I think it might be addressing the
> > > issue at a wrong level.
> > 
> > I leave room for figuring out 1/2 but for the second issue I would just
> > do what the attached patch does and call it a day.
> > 
> > Br, Jarkko
> 
> > From 093124e51a26de8191e21ce41988532ea7e0bc8a Mon Sep 17 00:00:00 2001
> > From: Jarkko Sakkinen <jarkko@kernel.org>
> > Date: Thu, 12 Nov 2026 03:55:00 +0200
> > Subject: [PATCH] tpm: Disable TPM on TPM_RC_INITIALIZE
> > 
> > If the TPM has been spuriously disabled, the game is over. Let's reflect
> > this truth with TPM_CHIP_FLAG_DISABLE.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > ---
> >  drivers/char/tpm/tpm-interface.c | 5 +++++
> >  drivers/char/tpm/tpm2-cmd.c      | 2 ++
> >  2 files changed, 7 insertions(+)
> > 
> > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> > index 470b2da3234e..1f1e22341155 100644
> > --- a/drivers/char/tpm/tpm-interface.c
> > +++ b/drivers/char/tpm/tpm-interface.c
> > @@ -256,6 +256,11 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz)
> >  		if (rc == TPM2_RC_TESTING && cc == TPM2_CC_SELF_TEST)
> >  			break;
> >  
> > +		if (rc == TPM_RC_INITIALIZE) {
> > +			chip->flag |= TPM_CHIP_FLAG_DISABLE;
> > +			break;
> > +		}
> > +
> 
> Sorry, should be TPM2_RC_INITIALIZE. 

Ack. Thanks for the suggestion, I will include it on my v2 then, but,
while testing, I needed to change a few things:

1) The check needs to go before the RETRY/TESTING break, otherwise an
   RC_INITIALIZE reply leaves the loop before reaching it.

2) It needs to skip TPM2_Startup:
          if (rc == TPM2_RC_INITIALIZE && cc != TPM2_CC_STARTUP) {

A TPM that is already started answers TPM2_Startup with
TPM_RC_INITIALIZE as well, so without the cc check a redundant
TPM2_Startup disables a healthy TPM. I hit it with swtpm's vTPM proxy,
which sends its own TPM2_Startup right after the one from
tpm2_auto_startup().

Let me respin a v2 with these changes I have been testing, and we can
continue on that thread.

Thanks for the review and suggestion,
--breno