All of lore.kernel.org
 help / color / mirror / Atom feed
From: Surendran Kanagaraj <surenkj@amazon.com>
To: Jarkko Sakkinen <jarkko@kernel.org>, Peter Huewe <peterhuewe@gmx.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, <linux-integrity@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>, <linux-doc@vger.kernel.org>,
	Jonathan McDowell <noodles@earth.li>,
	"Breno Leitao" <leitao@debian.org>, <nh-open-source@amazon.com>,
	Alexander Graf <graf@amazon.de>,
	Gunnar Kudrjavets <gunnarku@amazon.com>,
	Josh Levinson <joshlev@amazon.com>
Subject: [RFC PATCH v4 7/8] tpm: Show timeouts and durations for TPM 2.0 chips
Date: Wed, 18 Nov 2026 07:49:03 +0000	[thread overview]
Message-ID: <20261118074904.60624-3-surenkj@amazon.com> (raw)
In-Reply-To: <20261118073852.81107-1-surenkj@amazon.com>

The timeouts and durations files exist only for TPM 1.x chips, so a
TPM 2.0 chip exposes none of its wait limits, even when tpm.limits= or
a driver's ->adjust_limits() hook changes them.

Both files read the limits table, so add them to the TPM 2.0 attributes
too. A TPM 2.0 chip reports none of these values, so for it "[adjusted]"
means that tpm.limits= or a driver's ->adjust_limits() hook set one of
the shown values, or that validation changed one. TPM 2.0 chips get no
device/ links, so the files are /sys/class/tpm/tpmX/timeouts and
durations. Document both paths in sysfs-class-tpm.

Signed-off-by: Surendran Kanagaraj <surenkj@amazon.com>
---
 Documentation/ABI/stable/sysfs-class-tpm | 26 ++++++++++++++++++++++++
 drivers/char/tpm/tpm-sysfs.c             |  2 ++
 drivers/char/tpm/tpm2-cmd.c              | 17 ++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-class-tpm b/Documentation/ABI/stable/sysfs-class-tpm
index 73b69f63b298..ada59d147d14 100644
--- a/Documentation/ABI/stable/sysfs-class-tpm
+++ b/Documentation/ABI/stable/sysfs-class-tpm
@@ -184,6 +184,32 @@ Description:	The "timeouts" property shows the 4 vendor-specific values
 		"[adjusted]" if any value differs from what the chip
 		reported, and "[original]" otherwise.
 
+What:		/sys/class/tpm/tpmX/durations
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	linux-integrity@vger.kernel.org
+Description:	The "durations" property, in the same format as
+		/sys/class/tpm/tpmX/device/durations. On a TPM 1.x chip,
+		device/durations is a compatibility link to this file. A
+		TPM 2.0 chip has only this path. TPM 2.0 has no command
+		that returns these values, so for a TPM 2.0 chip
+		"[adjusted]" is displayed when the tpm.limits= parameter
+		or the driver set one of the values, or the bounds check
+		changed one.
+
+What:		/sys/class/tpm/tpmX/timeouts
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	linux-integrity@vger.kernel.org
+Description:	The "timeouts" property, in the same format as
+		/sys/class/tpm/tpmX/device/timeouts. On a TPM 1.x chip,
+		device/timeouts is a compatibility link to this file. A
+		TPM 2.0 chip has only this path. TPM 2.0 has no command
+		that returns these values, so for a TPM 2.0 chip
+		"[adjusted]" is displayed when the tpm.limits= parameter
+		or the driver set one of the values, or the bounds check
+		changed one.
+
 What:		/sys/class/tpm/tpmX/tpm_version_major
 Date:		October 2019
 KernelVersion:	5.5
diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index b289a7f6f085..6bfc366fa120 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -340,6 +340,8 @@ static struct attribute *tpm1_dev_attrs[] = {
 
 static struct attribute *tpm2_dev_attrs[] = {
 	&dev_attr_tpm_version_major.attr,
+	&dev_attr_durations.attr,
+	&dev_attr_timeouts.attr,
 #ifdef CONFIG_TCG_TPM2_HMAC
 	&dev_attr_null_name.attr,
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 629caaeffa17..8cc1a262d668 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -41,9 +41,26 @@ int tpm2_find_hash_alg(unsigned int crypto_id)
 }
 EXPORT_SYMBOL_GPL(tpm2_find_hash_alg);
 
+static bool tpm2_limits_adjusted(struct tpm_chip *chip, unsigned long mask)
+{
+	const struct tpm_limit_entry *e = chip->limits.entry;
+	int limit;
+
+	for_each_set_bit(limit, &mask, TPM_NR_LIMITS) {
+		if (e[limit].src != TPM_LSRC_DEFAULT ||
+		    e[limit].flags & TPM_LF_CLAMPED)
+			return true;
+	}
+
+	return false;
+}
+
 int tpm2_get_timeouts(struct tpm_chip *chip)
 {
 	tpm_limits_update(chip, NULL);
+	chip->timeout_adjusted = tpm2_limits_adjusted(chip, TPM_LIMIT_INTF_MASK);
+	chip->duration_adjusted =
+		tpm2_limits_adjusted(chip, TPM1_LIMIT_DURATION_MASK);
 	chip->flags |= TPM_CHIP_FLAG_HAVE_TIMEOUTS;
 	return 0;
 }
-- 
2.47.3


  parent reply	other threads:[~2026-11-18  7:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  7:38 [RFC PATCH v4 0/8] tpm: Rework timeout and duration handling Surendran Kanagaraj
2026-11-18  7:38 ` [RFC PATCH v4 1/8] tpm: Add a single table for all TPM wait limits Surendran Kanagaraj
2026-11-20 12:19   ` Jarkko Sakkinen
2026-11-18  7:38 ` [RFC PATCH v4 2/8] tpm: Wire the timing setup to the limits table Surendran Kanagaraj
2026-11-18  7:38 ` [RFC PATCH v4 3/8] tpm: Take command durations from " Surendran Kanagaraj
2026-11-18  7:38 ` [RFC PATCH v4 4/8] tpm: Bound core and CRB waits by " Surendran Kanagaraj
2026-11-20 12:22   ` Jarkko Sakkinen
2026-11-18  7:49 ` [RFC PATCH v4 5/8] tpm: Drop the jiffies timing fields from struct tpm_chip Surendran Kanagaraj
2026-11-18  7:49 ` [RFC PATCH v4 6/8] tpm: Add the tpm.limits= parameter Surendran Kanagaraj
2026-11-18  7:49 ` Surendran Kanagaraj [this message]
2026-11-18  7:49 ` [RFC PATCH v4 8/8] tpm_crb: Raise the limits for Amazon NitroTPM Surendran Kanagaraj

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=20261118074904.60624-3-surenkj@amazon.com \
    --to=surenkj@amazon.com \
    --cc=corbet@lwn.net \
    --cc=graf@amazon.de \
    --cc=gunnarku@amazon.com \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=joshlev@amazon.com \
    --cc=leitao@debian.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nh-open-source@amazon.com \
    --cc=noodles@earth.li \
    --cc=peterhuewe@gmx.de \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.