From: Breno Leitao <leitao@debian.org>
To: Peter Huewe <peterhuewe@gmx.de>,
Jarkko Sakkinen <jarkko@kernel.org>,
Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
surenkj@amazon.com, noodles@meta.com,
Breno Leitao <leitao@debian.org>,
kernel-team@meta.com
Subject: [PATCH 2/2] tpm: Disable a TPM whose hwrng reads keep failing
Date: Wed, 11 Nov 2026 01:57:34 -0800 [thread overview]
Message-ID: <20261111-tpm_unresponsive-v1-2-42ac1b965eb9@debian.org> (raw)
In-Reply-To: <20261111-tpm_unresponsive-v1-0-42ac1b965eb9@debian.org>
The hwrng core retries a failed read every 10 seconds, forever. When the
TPM keeps answering GetRandom with an error, each retry logs a line:
tpm tpm0: A TPM error (256) occurred attempting get random
tpm tpm0: A TPM error (256) occurred attempting get random
...
Neither clears on its own, and the TPM does answer, so the timeout check
in tpm_transmit() never fires.
After 60 failed reads in a row, ~ten minutes of retries on my system,
set TPM_CHIP_FLAG_DISABLE as tpm_transmit() does for a TPM that stopped
responding. Later reads then fail in tpm_try_get_ops() without sending
the TPM a command. A successful read resets the count. A handful of
failures is not enough, since some TPMs stall for half a minute and then
recover.
This also takes the TPM away from userspace, which could otherwise
still send TPM2_Startup or query the failure mode. Rebinding the driver
brings it back.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
drivers/char/tpm/tpm-chip.c | 20 +++++++++++++++++++-
include/linux/tpm.h | 1 +
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 0be5dbfaa72ebf..d94ea462a5ef0c 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -466,11 +466,29 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
return 0;
}
+#define TPM_HWRNG_MAX_FAILURES 60 /* ~10 minutes of retries */
+
static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
{
struct tpm_chip *chip = container_of(rng, struct tpm_chip, hwrng);
+ int rc;
+
+ rc = tpm_get_random(chip, data, max);
+ if (rc > 0) {
+ chip->hwrng_failures = 0;
+ return rc;
+ }
+
+ if (++chip->hwrng_failures == TPM_HWRNG_MAX_FAILURES &&
+ !(chip->flags & TPM_CHIP_FLAG_DISABLE)) {
+ dev_err(&chip->dev, "hwrng: %u reads failed in a row, disabling the TPM\n",
+ chip->hwrng_failures);
+ mutex_lock(&chip->tpm_mutex);
+ chip->flags |= TPM_CHIP_FLAG_DISABLE;
+ mutex_unlock(&chip->tpm_mutex);
+ }
- return tpm_get_random(chip, data, max);
+ return rc;
}
static bool tpm_is_hwrng_enabled(struct tpm_chip *chip)
diff --git a/include/linux/tpm.h b/include/linux/tpm.h
index 4264c87a04d98c..402b5160db962c 100644
--- a/include/linux/tpm.h
+++ b/include/linux/tpm.h
@@ -129,6 +129,7 @@ struct tpm_chip {
char hwrng_name[64];
struct hwrng hwrng;
+ unsigned int hwrng_failures; /* consecutive failed reads */
struct mutex tpm_mutex; /* tpm is processing */
unsigned int nr_timeouts; /* consecutive command timeouts */
--
2.53.0-Meta
prev parent reply other threads:[~2026-11-11 9:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 9:57 [PATCH 0/2] tpm: Stop retrying TPMs that have stopped working Breno Leitao
2026-11-11 9:57 ` [PATCH 1/2] tpm: Disable a TPM that stops responding Breno Leitao
2026-11-11 9:57 ` Breno Leitao [this message]
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=20261111-tpm_unresponsive-v1-2-42ac1b965eb9@debian.org \
--to=leitao@debian.org \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=kernel-team@meta.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noodles@meta.com \
--cc=peterhuewe@gmx.de \
--cc=surenkj@amazon.com \
/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
all inboxes | Powered by JetHome®