mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/4] tpm: Cache ACPI TPM2 start method and gate tpm_crb_ffa probe
@ 2026-11-14 19:34 Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 1/4] tpm: Cache TPM2 start method Siddharth Chintamaneni
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Siddharth Chintamaneni @ 2026-11-14 19:34 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Sudeep Holla, Yeoreum Yun, Stuart Yoder, apais,
	rlmenge, hargar, linux-integrity, linux-arm-kernel, linux-kernel,
	Siddharth Chintamaneni

This series caches the ACPI TPM2 start method in tpm_init() and uses
the cached tpm2_acpi_start_method value across tpm_crb_ffa, tpm_tis,
and tpm_crb.

Patch 1 caches the ACPI TPM2 start method once in tpm_init() into
tpm2_acpi_start_method (defaulting to ACPI_TPM2_NOT_ALLOWED when
absent or invalid).
Patch 2 checks tpm2_acpi_start_method in tpm_crb_ffa_probe() and
returns -ENODEV unless ACPI advertises ACPI_TPM2_CRB_WITH_ARM_FFA,
skipping FF-A probing on non-FF-A platforms while keeping modular
tpm_crb/tpm_crb_ffa loading intact.
Patches 3 and 4 update tpm_tis and tpm_crb to use the cached
tpm2_acpi_start_method value during probe.

Changes in v2:
- Expand into a 4-patch series caching tpm2_acpi_start_method in
  tpm_init() and converting tpm_crb_ffa, tpm_tis, and tpm_crb to use
  it (Jarkko Sakkinen).
- Move the tpm_crb_ffa start_method check from module_init into
  tpm_crb_ffa_probe() so tpm_crb.ko and tpm_crb_ffa.ko still load
  cleanly on non-FF-A systems when built as modules.

v1: https://lore.kernel.org/linux-integrity/20261112233807.70664-1-sidchintamaneni@gmail.com/

Jarkko Sakkinen (1):
  tpm: Cache TPM2 start method

Siddharth Chintamaneni (3):
  tpm: tpm_crb_ffa: Only probe when ACPI TPM2 uses FF-A
  tpm: tpm_tis: Use cached tpm2_acpi_start_method
  tpm: tpm_crb: Use cached tpm2_acpi_start_method

 drivers/char/tpm/tpm-interface.c | 21 +++++++++++++++++++++
 drivers/char/tpm/tpm.h           |  1 +
 drivers/char/tpm/tpm_crb.c       | 19 ++++++++++++-------
 drivers/char/tpm/tpm_crb_ffa.c   |  5 +++++
 drivers/char/tpm/tpm_tis.c       | 18 +++++++-----------
 5 files changed, 46 insertions(+), 18 deletions(-)


base-commit: 912c3bad2eb993eb3e83c2689cd4e17361ef087f
-- 
2.45.4


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

* [PATCH v2 1/4] tpm: Cache TPM2 start method
  2026-11-14 19:34 [PATCH v2 0/4] tpm: Cache ACPI TPM2 start method and gate tpm_crb_ffa probe Siddharth Chintamaneni
@ 2026-11-14 19:34 ` Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 2/4] tpm: tpm_crb_ffa: Only probe when ACPI TPM2 uses FF-A Siddharth Chintamaneni
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Siddharth Chintamaneni @ 2026-11-14 19:34 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Sudeep Holla, Yeoreum Yun, Stuart Yoder, apais,
	rlmenge, hargar, linux-integrity, linux-arm-kernel, linux-kernel,
	Siddharth Chintamaneni

From: Jarkko Sakkinen <jarkko@kernel.org>

Both tpm_tis and tpm_crb retrieve the start method from the ACPI TPM2
table during device probe, and tpm_crb_ffa also needs it before chip
allocation.

Cache the start method in tpm2_acpi_start_method during tpm_init() and
export it for the leaf drivers, defaulting to ACPI_TPM2_NOT_ALLOWED when
the table is absent or invalid.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Co-developed-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
 drivers/char/tpm/tpm-interface.c | 21 +++++++++++++++++++++
 drivers/char/tpm/tpm.h           |  1 +
 2 files changed, 22 insertions(+)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index e0385b16616b..7b7da79bee7c 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -534,8 +534,17 @@ int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
 }
 EXPORT_SYMBOL_GPL(tpm_get_random);
 
+#ifdef CONFIG_ACPI
+u32 tpm2_acpi_start_method = ACPI_TPM2_NOT_ALLOWED;
+EXPORT_SYMBOL_GPL(tpm2_acpi_start_method);
+#endif
+
 static int __init tpm_init(void)
 {
+#ifdef CONFIG_ACPI
+	struct acpi_table_tpm2 *tbl;
+	acpi_status status;
+#endif
 	int rc;
 
 	rc = class_register(&tpm_class);
@@ -562,6 +571,18 @@ static int __init tpm_init(void)
 		goto out_unreg_chrdev;
 	}
 
+#ifdef CONFIG_ACPI
+	if (!acpi_disabled) {
+		status = acpi_get_table(ACPI_SIG_TPM2, 1,
+					(struct acpi_table_header **)&tbl);
+		if (ACPI_SUCCESS(status)) {
+			if (tbl->header.length >= sizeof(*tbl))
+				tpm2_acpi_start_method = tbl->start_method;
+			acpi_put_table((struct acpi_table_header *)tbl);
+		}
+	}
+#endif
+
 	return 0;
 
 out_unreg_chrdev:
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index fa554c5ad80b..212ca2410c93 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -100,6 +100,7 @@ void tpm_sysfs_add_device(struct tpm_chip *chip);
 
 
 #ifdef CONFIG_ACPI
+extern u32 tpm2_acpi_start_method;
 extern void tpm_add_ppi(struct tpm_chip *chip);
 #else
 static inline void tpm_add_ppi(struct tpm_chip *chip)
-- 
2.45.4


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

* [PATCH v2 2/4] tpm: tpm_crb_ffa: Only probe when ACPI TPM2 uses FF-A
  2026-11-14 19:34 [PATCH v2 0/4] tpm: Cache ACPI TPM2 start method and gate tpm_crb_ffa probe Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 1/4] tpm: Cache TPM2 start method Siddharth Chintamaneni
@ 2026-11-14 19:34 ` Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 3/4] tpm: tpm_tis: Use cached tpm2_acpi_start_method Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 4/4] tpm: tpm_crb: " Siddharth Chintamaneni
  3 siblings, 0 replies; 5+ messages in thread
From: Siddharth Chintamaneni @ 2026-11-14 19:34 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Sudeep Holla, Yeoreum Yun, Stuart Yoder, apais,
	rlmenge, hargar, linux-integrity, linux-arm-kernel, linux-kernel,
	Siddharth Chintamaneni

Prior to commit 677042afb97a ("tpm: tpm_crb_ffa: revert defered_probed
when tpm_crb_ffa is built-in"), built-in tpm_crb_ffa only registered
tpm_crb_ffa_driver from tpm_crb_ffa_init() after crb_acpi_probe()
confirmed start_method == ACPI_TPM2_CRB_WITH_ARM_FFA. After that
commit, tpm_crb_ffa unconditionally registers on the FF-A bus at
device_initcall time (and when loaded as a module) without checking
the platform's ACPI TPM2 start method.

A platform's firmware may expose a TPM CRB over FF-A Secure Partition
for UEFI boot services while advertising a non-FF-A start method to
the OS in the ACPI TPM2 table. When the ACPI TPM2 table designates a
non-FF-A start method, Linux has no consumer for tpm_crb_ffa and
should not probe the FF-A TPM service.

On Microsoft Cobalt 200 systems, the ACPI TPM2 table does not use
ACPI_TPM2_CRB_WITH_ARM_FFA, yet ffa_init() discovers the FF-A TPM
partition and tpm_crb_ffa_probe() unconditionally sends
CRB_FFA_GET_INTERFACE_VERSION via FFA_MSG_SEND_DIRECT_REQ2/REQ SMC.
That request wedges the calling CPU in Secure World (with Non-Secure
interrupts and GICv3 pseudo-NMIs masked), hanging boot with an RCU CPU
stall:

  [    5.507519] ARM FF-A: Driver version 1.2
  [    5.507519] ARM FF-A: Firmware version 1.2 found
  [    5.507551] ARM FF-A: Notification setup failed -61, not enabled
  [    7.150580] Freeing initrd memory: 293640K
  [   65.515248] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
  [   65.521346] rcu:     10-...0: (3 GPs behind) idle=dd9c/1/0x4000000000000000 softirq=37/37 fqs=5262
  [   65.530031] rcu:              hardirqs   softirqs   csw/system
  [   65.535589] rcu:      number:        0          0            0
  [   65.541146] rcu:     cputime:        0          0            0   ==> 30028(ms)
  [   65.548102] rcu:     (detected by 66, t=15010 jiffies, g=-951, q=1384 ncpus=132)
  [   65.555228] Sending NMI from CPU 66 to CPUs 10:
  [   75.560686] After 10 seconds, these CPUS still haven't responded to the NMI: 10

Check tpm2_acpi_start_method in tpm_crb_ffa_probe() and return -ENODEV
unless it equals ACPI_TPM2_CRB_WITH_ARM_FFA. Checking in probe() rather
than module_init allows tpm_crb_ffa.ko to load as a symbol dependency
of tpm_crb.ko on non-FF-A platforms when built as modules, while
skipping FF-A TPM requests unless ACPI advertises the FF-A start
method.

Fixes: eb93f0734ef1 ("tpm_crb: ffa_tpm: Implement driver compliant to CRB over FF-A")
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
 drivers/char/tpm/tpm_crb_ffa.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/char/tpm/tpm_crb_ffa.c b/drivers/char/tpm/tpm_crb_ffa.c
index 025c4d4b17ca..da676da6f3f0 100644
--- a/drivers/char/tpm/tpm_crb_ffa.c
+++ b/drivers/char/tpm/tpm_crb_ffa.c
@@ -9,9 +9,11 @@
 
 #define pr_fmt(fmt) "CRB_FFA: " fmt
 
+#include <linux/acpi.h>
 #include <linux/arm_ffa.h>
 #include <linux/delay.h>
 #include <linux/moduleparam.h>
+#include "tpm.h"
 #include "tpm_crb_ffa.h"
 
 static unsigned int busy_timeout_ms = 2000;
@@ -324,6 +326,9 @@ static int tpm_crb_ffa_probe(struct ffa_device *ffa_dev)
 	struct tpm_crb_ffa *p;
 	int rc;
 
+	if (tpm2_acpi_start_method != ACPI_TPM2_CRB_WITH_ARM_FFA)
+		return -ENODEV;
+
 	/* only one instance of a TPM partition is supported */
 	if (tpm_crb_ffa && !IS_ERR_VALUE(tpm_crb_ffa))
 		return -EEXIST;
-- 
2.45.4


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

* [PATCH v2 3/4] tpm: tpm_tis: Use cached tpm2_acpi_start_method
  2026-11-14 19:34 [PATCH v2 0/4] tpm: Cache ACPI TPM2 start method and gate tpm_crb_ffa probe Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 1/4] tpm: Cache TPM2 start method Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 2/4] tpm: tpm_crb_ffa: Only probe when ACPI TPM2 uses FF-A Siddharth Chintamaneni
@ 2026-11-14 19:34 ` Siddharth Chintamaneni
  2026-11-14 19:34 ` [PATCH v2 4/4] tpm: tpm_crb: " Siddharth Chintamaneni
  3 siblings, 0 replies; 5+ messages in thread
From: Siddharth Chintamaneni @ 2026-11-14 19:34 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Sudeep Holla, Yeoreum Yun, Stuart Yoder, apais,
	rlmenge, hargar, linux-integrity, linux-arm-kernel, linux-kernel,
	Siddharth Chintamaneni

Use the cached tpm2_acpi_start_method value in check_acpi_tpm2() instead
of mapping and unmapping the ACPI TPM2 table again during probe.

Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
 drivers/char/tpm/tpm_tis.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 6f8344894ea5..a6fb6f889e7d 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -138,28 +138,24 @@ MODULE_DEVICE_TABLE(acpi, tpm_acpi_tbl);
 static int check_acpi_tpm2(struct device *dev)
 {
 	const struct acpi_device_id *aid = acpi_match_device(tpm_acpi_tbl, dev);
-	struct acpi_table_tpm2 *tbl;
-	acpi_status st;
-	int ret = 0;
 
 	if (!aid || aid->driver_data != DEVICE_IS_TPM2)
 		return 0;
 
-	/* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2
-	 * table is mandatory
+	/*
+	 * If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2
+	 * table is mandatory.
 	 */
-	st = acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **)&tbl);
-	if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
+	if (tpm2_acpi_start_method == ACPI_TPM2_NOT_ALLOWED) {
 		dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
 		return -EINVAL;
 	}
 
 	/* The tpm2_crb driver handles this device */
-	if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED)
-		ret = -ENODEV;
+	if (tpm2_acpi_start_method != ACPI_TPM2_MEMORY_MAPPED)
+		return -ENODEV;
 
-	acpi_put_table((struct acpi_table_header *)tbl);
-	return ret;
+	return 0;
 }
 #else
 static int check_acpi_tpm2(struct device *dev)
-- 
2.45.4


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

* [PATCH v2 4/4] tpm: tpm_crb: Use cached tpm2_acpi_start_method
  2026-11-14 19:34 [PATCH v2 0/4] tpm: Cache ACPI TPM2 start method and gate tpm_crb_ffa probe Siddharth Chintamaneni
                   ` (2 preceding siblings ...)
  2026-11-14 19:34 ` [PATCH v2 3/4] tpm: tpm_tis: Use cached tpm2_acpi_start_method Siddharth Chintamaneni
@ 2026-11-14 19:34 ` Siddharth Chintamaneni
  3 siblings, 0 replies; 5+ messages in thread
From: Siddharth Chintamaneni @ 2026-11-14 19:34 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Sudeep Holla, Yeoreum Yun, Stuart Yoder, apais,
	rlmenge, hargar, linux-integrity, linux-arm-kernel, linux-kernel,
	Siddharth Chintamaneni

Check the cached tpm2_acpi_start_method value at the start of
crb_acpi_probe() before mapping the ACPI TPM2 table for CRB-specific
parameters. This avoids mapping the table when it is absent or when the
device uses ACPI_TPM2_MEMORY_MAPPED and belongs to tpm_tis.

Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
 drivers/char/tpm/tpm_crb.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 4749a9183726..c1c2b72459a2 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -945,18 +945,23 @@ static int crb_acpi_probe(struct platform_device *pdev)
 	if (!device)
 		return -ENODEV;
 
-	status = acpi_get_table(ACPI_SIG_TPM2, 1,
-				(struct acpi_table_header **) &buf);
-	if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) {
+	sm = tpm2_acpi_start_method;
+	if (sm == ACPI_TPM2_NOT_ALLOWED) {
 		dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
 		return -EINVAL;
 	}
 
 	/* Should the FIFO driver handle this? */
-	sm = buf->start_method;
-	if (sm == ACPI_TPM2_MEMORY_MAPPED) {
-		rc = -ENODEV;
-		goto out;
+	if (sm == ACPI_TPM2_MEMORY_MAPPED)
+		return -ENODEV;
+
+	status = acpi_get_table(ACPI_SIG_TPM2, 1,
+				(struct acpi_table_header **)&buf);
+	if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) {
+		dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
+		if (ACPI_SUCCESS(status))
+			acpi_put_table((struct acpi_table_header *)buf);
+		return -EINVAL;
 	}
 
 	priv = devm_kzalloc_obj(dev, struct crb_priv);
-- 
2.45.4


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

end of thread, other threads:[~2026-11-14 19:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 19:34 [PATCH v2 0/4] tpm: Cache ACPI TPM2 start method and gate tpm_crb_ffa probe Siddharth Chintamaneni
2026-11-14 19:34 ` [PATCH v2 1/4] tpm: Cache TPM2 start method Siddharth Chintamaneni
2026-11-14 19:34 ` [PATCH v2 2/4] tpm: tpm_crb_ffa: Only probe when ACPI TPM2 uses FF-A Siddharth Chintamaneni
2026-11-14 19:34 ` [PATCH v2 3/4] tpm: tpm_tis: Use cached tpm2_acpi_start_method Siddharth Chintamaneni
2026-11-14 19:34 ` [PATCH v2 4/4] tpm: tpm_crb: " Siddharth Chintamaneni

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®