Skip to contentSkip to conversation

tpm: OP-TEE transport core for discrete and firmware TPMs

PATCH Superseded Jorge Ramirez-Ortiz 2 participants 8 messages Nov 11 – Nov 13

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover tpm: OP-TEE transport core for discrete and firmware TPMs

This adds a driver for a discrete TPM that OP-TEE owns and the normal world cannot reach directly, and factors the shared OP-TEE TEE transport into a small core so the existing fTPM driver uses it too:

- a transport core shared by the OP-TEE TPM front-ends;
- a new discrete TPM front-end;
- the fTPM driver converted onto the core, keeping its name, its platform/OF binding and its shutdown path.

Patch 1 is the feature; patch 2 is the fTPM conversion that justifies the core. Both front-ends were exercised on the Qualcomm Lemans EVK over the shared core: the discrete ST33 TPM (patch 1) and the MS-TPM-20 firmware TPM TA (patch 2), each presenting a working /dev/tpm0 (tpm2_getrandom, PCR read). The fTPM TA is the same MS-TPM-20 reference the existing tpm_ftpm_tee platforms use.

This is the normal-world half. The secure-world OP-TEE support it binds to -- the in-core TPM2 SPI (TIS) driver and the mediator pseudo TA that relays commands to it -- is under review separately:

OP-TEE support: https://github.com/OP-TEE/optee_os/pull/8155
locality 4: https://github.com/OP-TEE/optee_os/issues/8160
(design follow-up: the secure world policing normal-world locality access to the shared chip)

Build and test it on the Qualcomm Lemans EVK (a discrete ST33 TPM on SPI, owned by OP-TEE):

https://qualcomm-linux.github.io/qcom-buildroot/lemans/quick-start.html

v1: https://lore.kernel.org/linux-integrity/[email protected]/
v2: https://lore.kernel.org/linux-integrity/[email protected]/

Changes since v2:
- tpm_optee_dtpm: give the discrete-TPM front-end a .shutdown callback so it releases its TEE session and dynamic shared memory on shutdown/kexec, as the fTPM front-end already did; without it the session and the normal-world pages stayed registered in OP-TEE across a kexec, which can stop the next kernel opening a session to the chip.
- move the shared tpm_optee_shutdown() helper into the core patch so that patch builds on its own; the dTPM front-end no longer forward-references a symbol that was added in patch 2.

Changes since v1:
- split the shared TEE transport into a core; the discrete chip is now a thin front-end, the tpm_tis_core-style solution that was asked for.
- convert the fTPM driver onto the same core instead of duplicating it.
- use an optee-prefixed name for the new modules; the fTPM driver keeps its name, no module rename.
- rewrite the commit message with a plain description of the components and the rationale for a separate front-end.
- drop the explicit zeroing in favour of initialisers, and reword the module description.

Jorge Ramirez-Ortiz (2):
tpm: add OP-TEE transport core and a discrete TPM driver
tpm_ftpm_tee: use the tpm_optee transport core

 MAINTAINERS                       |   8 +
 drivers/char/tpm/Kconfig          |  28 +++
 drivers/char/tpm/Makefile         |   2 +
 drivers/char/tpm/tpm_ftpm_tee.c   | 295 ++----------------------------
 drivers/char/tpm/tpm_ftpm_tee.h   |  35 ----
 drivers/char/tpm/tpm_optee.c      | 253 +++++++++++++++++++++++++
 drivers/char/tpm/tpm_optee.h      |  32 ++++
 drivers/char/tpm/tpm_optee_dtpm.c |  73 ++++++++
 8 files changed, 414 insertions(+), 312 deletions(-)
 delete mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
 create mode 100644 drivers/char/tpm/tpm_optee.c
 create mode 100644 drivers/char/tpm/tpm_optee.h
 create mode 100644 drivers/char/tpm/tpm_optee_dtpm.c

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.55.0
#1 lore raw

PATCH v3 1/2 tpm: add OP-TEE transport core and a discrete TPM driver

Some platforms place a real (discrete) TPM on a bus that only the secure world can drive. OP-TEE owns that bus, so the normal world cannot reach the chip directly; it instead exposes a mediator trusted application that relays TPM2 commands. Add a driver that talks to that application and presents the chip as a standard TPM2 character device, so the normal-world TPM stack works unchanged.

This is a separate driver from the firmware-TPM one rather than a reuse of it. The TEE transport is the same and is shared through a common core, but the device identity differs: the firmware TPM uses its own application and a public-login session, whereas a discrete chip needs its own application and is restricted to kernel access so that user space and other applications cannot submit raw commands to it. Folding both into one driver would also break on a platform that has both.

---
 MAINTAINERS                       |   8 +
 drivers/char/tpm/Kconfig          |  27 ++++
 drivers/char/tpm/Makefile         |   2 +
 drivers/char/tpm/tpm_optee.c      | 253 ++++++++++++++++++++++++++++++
 drivers/char/tpm/tpm_optee.h      |  32 ++++
 drivers/char/tpm/tpm_optee_dtpm.c |  73 +++++++++
 6 files changed, 395 insertions(+)
 create mode 100644 drivers/char/tpm/tpm_optee.c
 create mode 100644 drivers/char/tpm/tpm_optee.h
 create mode 100644 drivers/char/tpm/tpm_optee_dtpm.c
MAINTAINERS +8 -0
index 782389bd5cd3..7c39a060ced2 100644
@@ -27710,6 +27710,14 @@ F:	include/linux/tpm*.h
 F:	include/uapi/linux/vtpm_proxy.h
 F:	tools/testing/selftests/tpm2/
 
+TPM TEE DRIVER FOR DISCRETE TPM
+R:	Jorge Ramirez-Ortiz <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/char/tpm/tpm_optee.c
+F:	drivers/char/tpm/tpm_optee.h
+F:	drivers/char/tpm/tpm_optee_dtpm.c
+
 TPS546D24 DRIVER
 M:	Duke Du <[email protected]>
 L:	[email protected]
drivers/char/tpm/Kconfig +27 -0
index 5f672f2c01b0..779154e05204 100644
@@ -243,6 +243,33 @@ config TCG_FTPM_TEE
 	help
 	  This driver proxies for firmware TPM running in TEE.
 
+config TCG_OPTEE
+	tristate
+	depends on TEE && OPTEE
+	help
+	  Shared transport for TPMs reached through an OP-TEE trusted
+	  application. It is selected by the front-end drivers and is not
+	  meant to be enabled on its own.
+
+config TCG_OPTEE_DTPM
+	tristate "OP-TEE based discrete TPM Interface"
+	depends on TEE && OPTEE
+	select TCG_OPTEE
+	help
+	  This driver proxies for a discrete TPM that is owned by OP-TEE and
+	  reachable only from the secure world (for example an SPI TPM behind
+	  OP-TEE's TPM TIS driver). OP-TEE exposes a mediator pseudo TA and
+	  this driver pipes TPM commands through it, presenting a standard
+	  TPM character device to the normal world.
+
+	  The secure world is the sole owner of the TPM and of the bus it
+	  sits on. That bus/controller must be disabled in the non-secure
+	  device tree: disabling only the in-kernel TPM driver (e.g.
+	  tpm_tis_spi) is not enough, because the normal-world bus controller
+	  would still drive the engine in parallel with OP-TEE and corrupt
+	  its transfers. With the bus disabled, the TPM is reached only
+	  through this driver.
+
 config TCG_SVSM
 	tristate "SNP SVSM vTPM interface"
 	depends on AMD_MEM_ENCRYPT
drivers/char/tpm/Makefile +2 -0
index 5b5cdc0d32e4..431d1351c2e3 100644
@@ -45,5 +45,7 @@ obj-$(CONFIG_TCG_CRB) += tpm_crb.o
 obj-$(CONFIG_TCG_ARM_CRB_FFA) += tpm_crb_ffa.o
 obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o
 obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o
+obj-$(CONFIG_TCG_OPTEE) += tpm_optee.o
+obj-$(CONFIG_TCG_OPTEE_DTPM) += tpm_optee_dtpm.o
 obj-$(CONFIG_TCG_SVSM) += tpm_svsm.o
 obj-$(CONFIG_TCG_LOONGSON) += tpm_loongson.o
drivers/char/tpm/tpm_optee.c new file +253 -0

253 lines not on this page · raw message

drivers/char/tpm/tpm_optee.h new file +32 -0
new file mode 100644
index 000000000000..a3a2ea2a951d
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * Shared transport for TPMs reached through an OP-TEE trusted application.
+ */
+
+#ifndef __TPM_OPTEE_H__
+#define __TPM_OPTEE_H__
+
+#include <linux/types.h>
+#include <linux/uuid.h>
+
+struct device;
+
+/**
+ * struct tpm_optee_config - identity of a TPM reached through an OP-TEE TA
+ * @ta_uuid:	UUID of the trusted application to bind
+ * @login:	TEE_IOCTL_LOGIN_* client login used to open the session
+ * @cmd_id:	TA function ID that submits a TPM command
+ */
+struct tpm_optee_config {
+	uuid_t	ta_uuid;
+	u32	login;
+	u32	cmd_id;
+};
+
+int tpm_optee_probe(struct device *dev, const struct tpm_optee_config *cfg);
+void tpm_optee_remove(struct device *dev);
+void tpm_optee_shutdown(struct device *dev);
+
+#endif /* __TPM_OPTEE_H__ */
drivers/char/tpm/tpm_optee_dtpm.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw

PATCH v3 2/2 tpm_ftpm_tee: use the tpm_optee transport core

In reply to Jorge Ramirez-Ortiz

The firmware-TPM driver and the new discrete-TPM driver share the same OP-TEE transport, now factored into a common core. Move the firmware-TPM driver onto it so the transport is not duplicated. The driver keeps its name, its platform/OF binding and its shutdown behaviour; only the transport is shared.

Two functional changes come from sharing the core: a command longer than the caller's buffer is now rejected (it was previously only checked against the application's maximum), and a failed command submission returns -EIO instead of the raw error code from the secure world.

---
 drivers/char/tpm/Kconfig        |   1 +
 drivers/char/tpm/tpm_ftpm_tee.c | 295 ++------------------------------
 drivers/char/tpm/tpm_ftpm_tee.h |  35 ----
 3 files changed, 19 insertions(+), 312 deletions(-)
 delete mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
drivers/char/tpm/Kconfig +1 -0
index 779154e05204..35aff3003a32 100644
@@ -240,6 +240,7 @@ config TCG_VTPM_PROXY
 config TCG_FTPM_TEE
 	tristate "TEE based fTPM Interface"
 	depends on TEE && OPTEE
+	select TCG_OPTEE
 	help
 	  This driver proxies for firmware TPM running in TEE.
 
drivers/char/tpm/tpm_ftpm_tee.c +18 -277

341 lines not on this page · raw message

drivers/char/tpm/tpm_ftpm_tee.h deleted +0 -35
deleted file mode 100644
index 8d5c3f0d2879..000000000000
@@ -1,35 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Copyright (C) Microsoft Corporation
- */
-
-#ifndef __TPM_FTPM_TEE_H__
-#define __TPM_FTPM_TEE_H__
-
-#include <linux/tee_drv.h>
-#include <linux/tpm.h>
-#include <linux/uuid.h>
-
-/* The TAFs ID implemented in this TA */
-#define FTPM_OPTEE_TA_SUBMIT_COMMAND  (0)
-#define FTPM_OPTEE_TA_EMULATE_PPI     (1)
-
-/* max. buffer size supported by fTPM  */
-#define MAX_COMMAND_SIZE       4096
-#define MAX_RESPONSE_SIZE      4096
-
-/**
- * struct ftpm_tee_private - fTPM's private data
- * @chip:     struct tpm_chip instance registered with tpm framework.
- * @session:  fTPM TA session identifier.
- * @ctx:      TEE context handler.
- * @shm:      Memory pool shared with fTPM TA in TEE.
- */
-struct ftpm_tee_private {
-	struct tpm_chip *chip;
-	u32 session;
-	struct tee_context *ctx;
-	struct tee_shm *shm;
-};
-
-#endif /* __TPM_FTPM_TEE_H__ */
Signature · 1 line
2.55.0
#3 lore raw
In reply to Jorge Ramirez-Ortiz
Quoted 25 lines · Jorge Ramirez-Ortiz

This adds a driver for a discrete TPM that OP-TEE owns and the normal world cannot reach directly, and factors the shared OP-TEE TEE transport into a small core so the existing fTPM driver uses it too:

- a transport core shared by the OP-TEE TPM front-ends;
- a new discrete TPM front-end;
- the fTPM driver converted onto the core, keeping its name, its platform/OF binding and its shutdown path.

Patch 1 is the feature; patch 2 is the fTPM conversion that justifies the core. Both front-ends were exercised on the Qualcomm Lemans EVK over the shared core: the discrete ST33 TPM (patch 1) and the MS-TPM-20 firmware TPM TA (patch 2), each presenting a working /dev/tpm0 (tpm2_getrandom, PCR read). The fTPM TA is the same MS-TPM-20 reference the existing tpm_ftpm_tee platforms use.

This is the normal-world half. The secure-world OP-TEE support it binds to -- the in-core TPM2 SPI (TIS) driver and the mediator pseudo TA that relays commands to it -- is under review separately:

OP-TEE support: https://github.com/OP-TEE/optee_os/pull/8155
locality 4: https://github.com/OP-TEE/optee_os/issues/8160
(design follow-up: the secure world policing normal-world locality access to the shared chip)

Quoted 4 lines

Build and test it on the Qualcomm Lemans EVK (a discrete ST33 TPM on SPI, owned by OP-TEE):

https://qualcomm-linux.github.io/qcom-buildroot/lemans/quick-start.html

The above was the wrong link, please use this one:

https://qualcomm-linux.github.io/qcom-buildroot/lemans/devel_lemans_security_dtpm.html

maintainer Reviewed-by
#4 lore raw
Quoted 26 lines · Jorge Ramirez
Quoted 25 lines · Jorge Ramirez-Ortiz

This adds a driver for a discrete TPM that OP-TEE owns and the normal world cannot reach directly, and factors the shared OP-TEE TEE transport into a small core so the existing fTPM driver uses it too:

- a transport core shared by the OP-TEE TPM front-ends;
- a new discrete TPM front-end;
- the fTPM driver converted onto the core, keeping its name, its platform/OF binding and its shutdown path.

Patch 1 is the feature; patch 2 is the fTPM conversion that justifies the core. Both front-ends were exercised on the Qualcomm Lemans EVK over the shared core: the discrete ST33 TPM (patch 1) and the MS-TPM-20 firmware TPM TA (patch 2), each presenting a working /dev/tpm0 (tpm2_getrandom, PCR read). The fTPM TA is the same MS-TPM-20 reference the existing tpm_ftpm_tee platforms use.

This is the normal-world half. The secure-world OP-TEE support it binds to -- the in-core TPM2 SPI (TIS) driver and the mediator pseudo TA that relays commands to it -- is under review separately:

OP-TEE support: https://github.com/OP-TEE/optee_os/pull/8155
locality 4: https://github.com/OP-TEE/optee_os/issues/8160
(design follow-up: the secure world policing normal-world locality access to the shared chip)

Quoted 8 lines
Quoted 4 lines

Build and test it on the Qualcomm Lemans EVK (a discrete ST33 TPM on SPI, owned by OP-TEE):

https://qualcomm-linux.github.io/qcom-buildroot/lemans/quick-start.html

The above was the wrong link, please use this one:

https://qualcomm-linux.github.io/qcom-buildroot/lemans/devel_lemans_security_dtpm.html

Patches look good and further also have zero Sashiko detected regressions:

https://sashiko.dev/#/patchset/20261111215940.3503287-1-jorge.ramirez%40oss.qualcomm.com

So I guess, we're good. Thank you for the effort and patience.

Br, Jarkko

maintainer
#5 lore raw
In reply to Jorge Ramirez-Ortiz
Quoted 73 lines · Jorge Ramirez-Ortiz

This adds a driver for a discrete TPM that OP-TEE owns and the normal world cannot reach directly, and factors the shared OP-TEE TEE transport into a small core so the existing fTPM driver uses it too:

- a transport core shared by the OP-TEE TPM front-ends;
- a new discrete TPM front-end;
- the fTPM driver converted onto the core, keeping its name, its platform/OF binding and its shutdown path.

Patch 1 is the feature; patch 2 is the fTPM conversion that justifies the core. Both front-ends were exercised on the Qualcomm Lemans EVK over the shared core: the discrete ST33 TPM (patch 1) and the MS-TPM-20 firmware TPM TA (patch 2), each presenting a working /dev/tpm0 (tpm2_getrandom, PCR read). The fTPM TA is the same MS-TPM-20 reference the existing tpm_ftpm_tee platforms use.

This is the normal-world half. The secure-world OP-TEE support it binds to -- the in-core TPM2 SPI (TIS) driver and the mediator pseudo TA that relays commands to it -- is under review separately:

OP-TEE support: https://github.com/OP-TEE/optee_os/pull/8155
locality 4: https://github.com/OP-TEE/optee_os/issues/8160
(design follow-up: the secure world policing normal-world locality access to the shared chip)

Build and test it on the Qualcomm Lemans EVK (a discrete ST33 TPM on SPI, owned by OP-TEE):

https://qualcomm-linux.github.io/qcom-buildroot/lemans/quick-start.html

v1: https://lore.kernel.org/linux-integrity/[email protected]/
v2: https://lore.kernel.org/linux-integrity/[email protected]/

Changes since v2:
- tpm_optee_dtpm: give the discrete-TPM front-end a .shutdown callback so it releases its TEE session and dynamic shared memory on shutdown/kexec, as the fTPM front-end already did; without it the session and the normal-world pages stayed registered in OP-TEE across a kexec, which can stop the next kernel opening a session to the chip.
- move the shared tpm_optee_shutdown() helper into the core patch so that patch builds on its own; the dTPM front-end no longer forward-references a symbol that was added in patch 2.

Changes since v1:
- split the shared TEE transport into a core; the discrete chip is now a thin front-end, the tpm_tis_core-style solution that was asked for.
- convert the fTPM driver onto the same core instead of duplicating it.
- use an optee-prefixed name for the new modules; the fTPM driver keeps its name, no module rename.
- rewrite the commit message with a plain description of the components and the rationale for a separate front-end.
- drop the explicit zeroing in favour of initialisers, and reword the module description.

Jorge Ramirez-Ortiz (2):
tpm: add OP-TEE transport core and a discrete TPM driver
tpm_ftpm_tee: use the tpm_optee transport core

 MAINTAINERS                       |   8 +
 drivers/char/tpm/Kconfig          |  28 +++
 drivers/char/tpm/Makefile         |   2 +
 drivers/char/tpm/tpm_ftpm_tee.c   | 295 ++----------------------------
 drivers/char/tpm/tpm_ftpm_tee.h   |  35 ----
 drivers/char/tpm/tpm_optee.c      | 253 +++++++++++++++++++++++++
 drivers/char/tpm/tpm_optee.h      |  32 ++++
 drivers/char/tpm/tpm_optee_dtpm.c |  73 ++++++++
 8 files changed, 414 insertions(+), 312 deletions(-)
 delete mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
 create mode 100644 drivers/char/tpm/tpm_optee.c
 create mode 100644 drivers/char/tpm/tpm_optee.h
 create mode 100644 drivers/char/tpm/tpm_optee_dtpm.c
Quoted 4 lines

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.55.0

I applied but had to fix some merge conflicts so check up my tree.

Br, Jarkko

#6 lore raw
Quoted 74 lines · Jarkko Sakkinen
Quoted 73 lines · Jorge Ramirez-Ortiz

This adds a driver for a discrete TPM that OP-TEE owns and the normal world cannot reach directly, and factors the shared OP-TEE TEE transport into a small core so the existing fTPM driver uses it too:

- a transport core shared by the OP-TEE TPM front-ends;
- a new discrete TPM front-end;
- the fTPM driver converted onto the core, keeping its name, its platform/OF binding and its shutdown path.

Patch 1 is the feature; patch 2 is the fTPM conversion that justifies the core. Both front-ends were exercised on the Qualcomm Lemans EVK over the shared core: the discrete ST33 TPM (patch 1) and the MS-TPM-20 firmware TPM TA (patch 2), each presenting a working /dev/tpm0 (tpm2_getrandom, PCR read). The fTPM TA is the same MS-TPM-20 reference the existing tpm_ftpm_tee platforms use.

This is the normal-world half. The secure-world OP-TEE support it binds to -- the in-core TPM2 SPI (TIS) driver and the mediator pseudo TA that relays commands to it -- is under review separately:

OP-TEE support: https://github.com/OP-TEE/optee_os/pull/8155
locality 4: https://github.com/OP-TEE/optee_os/issues/8160
(design follow-up: the secure world policing normal-world locality access to the shared chip)

Build and test it on the Qualcomm Lemans EVK (a discrete ST33 TPM on SPI, owned by OP-TEE):

https://qualcomm-linux.github.io/qcom-buildroot/lemans/quick-start.html

v1: https://lore.kernel.org/linux-integrity/[email protected]/
v2: https://lore.kernel.org/linux-integrity/[email protected]/

Changes since v2:
- tpm_optee_dtpm: give the discrete-TPM front-end a .shutdown callback so it releases its TEE session and dynamic shared memory on shutdown/kexec, as the fTPM front-end already did; without it the session and the normal-world pages stayed registered in OP-TEE across a kexec, which can stop the next kernel opening a session to the chip.
- move the shared tpm_optee_shutdown() helper into the core patch so that patch builds on its own; the dTPM front-end no longer forward-references a symbol that was added in patch 2.

Changes since v1:
- split the shared TEE transport into a core; the discrete chip is now a thin front-end, the tpm_tis_core-style solution that was asked for.
- convert the fTPM driver onto the same core instead of duplicating it.
- use an optee-prefixed name for the new modules; the fTPM driver keeps its name, no module rename.
- rewrite the commit message with a plain description of the components and the rationale for a separate front-end.
- drop the explicit zeroing in favour of initialisers, and reword the module description.

Jorge Ramirez-Ortiz (2):
tpm: add OP-TEE transport core and a discrete TPM driver
tpm_ftpm_tee: use the tpm_optee transport core

 MAINTAINERS                       |   8 +
 drivers/char/tpm/Kconfig          |  28 +++
 drivers/char/tpm/Makefile         |   2 +
 drivers/char/tpm/tpm_ftpm_tee.c   | 295 ++----------------------------
 drivers/char/tpm/tpm_ftpm_tee.h   |  35 ----
 drivers/char/tpm/tpm_optee.c      | 253 +++++++++++++++++++++++++
 drivers/char/tpm/tpm_optee.h      |  32 ++++
 drivers/char/tpm/tpm_optee_dtpm.c |  73 ++++++++
 8 files changed, 414 insertions(+), 312 deletions(-)
 delete mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
 create mode 100644 drivers/char/tpm/tpm_optee.c
 create mode 100644 drivers/char/tpm/tpm_optee.h
 create mode 100644 drivers/char/tpm/tpm_optee_dtpm.c
Quoted 8 lines
Quoted 4 lines

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.55.0

I applied but had to fix some merge conflicts so check up my tree.

Br, Jarkko

thanks and sorry about it.

I had a look to your tree and it looks good. But I think we could perhaps add the following to the new file (see the patch below)

Not sure how to do it thought- shall I send it standalone?

 drivers/char/tpm/tpm_optee.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm_optee.c +1 -1
index e2223242327e..3c17de1306a1 100644
@@ -166,7 +166,7 @@ int tpm_optee_probe(struct device *dev, const struct tpm_optee_config *cfg)
        struct tpm_chip *chip;
        int rc;
 
-       pvt_data = devm_kzalloc(dev, sizeof(*pvt_data), GFP_KERNEL);
+       pvt_data = devm_kzalloc_obj(dev, struct tpm_optee_private);
        if (!pvt_data)
                return -ENOMEM;
 
maintainer
#7 lore raw
Quoted 100 lines · Jorge Ramirez
Quoted 74 lines · Jarkko Sakkinen
Quoted 73 lines · Jorge Ramirez-Ortiz

This adds a driver for a discrete TPM that OP-TEE owns and the normal world cannot reach directly, and factors the shared OP-TEE TEE transport into a small core so the existing fTPM driver uses it too:

- a transport core shared by the OP-TEE TPM front-ends;
- a new discrete TPM front-end;
- the fTPM driver converted onto the core, keeping its name, its platform/OF binding and its shutdown path.

Patch 1 is the feature; patch 2 is the fTPM conversion that justifies the core. Both front-ends were exercised on the Qualcomm Lemans EVK over the shared core: the discrete ST33 TPM (patch 1) and the MS-TPM-20 firmware TPM TA (patch 2), each presenting a working /dev/tpm0 (tpm2_getrandom, PCR read). The fTPM TA is the same MS-TPM-20 reference the existing tpm_ftpm_tee platforms use.

This is the normal-world half. The secure-world OP-TEE support it binds to -- the in-core TPM2 SPI (TIS) driver and the mediator pseudo TA that relays commands to it -- is under review separately:

OP-TEE support: https://github.com/OP-TEE/optee_os/pull/8155
locality 4: https://github.com/OP-TEE/optee_os/issues/8160
(design follow-up: the secure world policing normal-world locality access to the shared chip)

Build and test it on the Qualcomm Lemans EVK (a discrete ST33 TPM on SPI, owned by OP-TEE):

https://qualcomm-linux.github.io/qcom-buildroot/lemans/quick-start.html

v1: https://lore.kernel.org/linux-integrity/[email protected]/
v2: https://lore.kernel.org/linux-integrity/[email protected]/

Changes since v2:
- tpm_optee_dtpm: give the discrete-TPM front-end a .shutdown callback so it releases its TEE session and dynamic shared memory on shutdown/kexec, as the fTPM front-end already did; without it the session and the normal-world pages stayed registered in OP-TEE across a kexec, which can stop the next kernel opening a session to the chip.
- move the shared tpm_optee_shutdown() helper into the core patch so that patch builds on its own; the dTPM front-end no longer forward-references a symbol that was added in patch 2.

Changes since v1:
- split the shared TEE transport into a core; the discrete chip is now a thin front-end, the tpm_tis_core-style solution that was asked for.
- convert the fTPM driver onto the same core instead of duplicating it.
- use an optee-prefixed name for the new modules; the fTPM driver keeps its name, no module rename.
- rewrite the commit message with a plain description of the components and the rationale for a separate front-end.
- drop the explicit zeroing in favour of initialisers, and reword the module description.

Jorge Ramirez-Ortiz (2):
tpm: add OP-TEE transport core and a discrete TPM driver
tpm_ftpm_tee: use the tpm_optee transport core

 MAINTAINERS                       |   8 +
 drivers/char/tpm/Kconfig          |  28 +++
 drivers/char/tpm/Makefile         |   2 +
 drivers/char/tpm/tpm_ftpm_tee.c   | 295 ++----------------------------
 drivers/char/tpm/tpm_ftpm_tee.h   |  35 ----
 drivers/char/tpm/tpm_optee.c      | 253 +++++++++++++++++++++++++
 drivers/char/tpm/tpm_optee.h      |  32 ++++
 drivers/char/tpm/tpm_optee_dtpm.c |  73 ++++++++
 8 files changed, 414 insertions(+), 312 deletions(-)
 delete mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
 create mode 100644 drivers/char/tpm/tpm_optee.c
 create mode 100644 drivers/char/tpm/tpm_optee.h
 create mode 100644 drivers/char/tpm/tpm_optee_dtpm.c
Quoted 8 lines
Quoted 4 lines

base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222

Signature · 1 line
2.55.0

I applied but had to fix some merge conflicts so check up my tree.

Br, Jarkko

thanks and sorry about it.

I had a look to your tree and it looks good. But I think we could perhaps add the following to the new file (see the patch below)

Not sure how to do it thought- shall I send it standalone?

 drivers/char/tpm/tpm_optee.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/tpm/tpm_optee.c +0 -0
index e2223242327e..3c17de1306a1 100644

drivers/char/tpm/tpm_optee.c int tpm_optee_probe(struct device *dev, const struct tpm_optee_config *cfg) · line 172

Quoted 8 lines
drivers/char/tpm/tpm_optee.c +1 -1
@@ -166,7 +166,7 @@ int tpm_optee_probe(struct device *dev, const struct tpm_optee_config *cfg)
        struct tpm_chip *chip;
        int rc;
 
-       pvt_data = devm_kzalloc(dev, sizeof(*pvt_data), GFP_KERNEL);
+       pvt_data = devm_kzalloc_obj(dev, struct tpm_optee_private);
        if (!pvt_data)
                return -ENOMEM;
 

Send a new version of the full patch set and I'll just replace the current version.

Br, Jarkko