From: Marouene Boubakri <marouene.boubakri(a)oss.nxp.com>
The OP-TEE driver reaches OP-TEE through the SMC ABI or the FF-A ABI,
both specific to Arm, and the TEE subsystem and the OP-TEE driver
depend on HAVE_ARM_SMCCC. On RISC-V there is no SMC instruction: OP-TEE
runs in a domain isolated by the M-mode firmware and is reached through
the RISC-V Platform Management Interface (RPMI), carried on an SBI
Message Proxy (MPXY) channel, for which Linux already has a mailbox
driver.
This series only puts the build plumbing in place for a third ABI next
to the SMC and FF-A ones:
- patch 1 builds the Arm-specific code of the driver only on Arm:
smc_abi.c when HAVE_ARM_SMCCC is set and ffa_abi.c when
ARM_FFA_TRANSPORT is enabled, with stubs for their registration
otherwise. The SMCCC header, the SMC and FF-A specific types and the
SMC RPC register parameters in optee_private.h are kept under the
same conditions, so that nothing Arm-specific is left in the common
part of the driver;
- patch 2 adds an RPMI ABI placeholder: an OPTEE_RPMI_ABI option built
when the MPXY mailbox driver is enabled, rpmi_abi.c and its
registration from the driver core. The transport is not implemented,
so the registration fails with -EOPNOTSUPP;
- patch 3 lets the TEE subsystem and the OP-TEE driver be enabled on
RISC-V, and teaches the memory type check of the driver about the
RISC-V page attributes, without which the driver does not build
there. It is kept separate as it changes the dependencies of the
subsystem-wide TEE menu.
There is no functional change. On Arm, OPTEE still depends on
HAVE_ARM_SMCCC and the SMC and FF-A ABIs are built whenever they can be
registered. On RISC-V the driver builds without any Arm-specific code
but no ABI registers, so it does not load. The RPMI transport will be
implemented on top of this in a separate series.
Testing: [TODO before posting: riscv64 defconfig plus TEE/OP-TEE,
built-in and as modules, and arm64 defconfig plus OP-TEE with FF-A
built-in, modular and disabled, with W=1 at every step of the series.]
Marouene Boubakri (3):
tee: optee: build the Arm-specific code only on Arm
tee: optee: add an RPMI ABI placeholder
tee: optee: allow enabling the driver on RISC-V
drivers/tee/Kconfig | 2 +-
drivers/tee/optee/Kconfig | 10 +++++-
drivers/tee/optee/Makefile | 5 +--
drivers/tee/optee/call.c | 8 +++++
drivers/tee/optee/core.c | 8 +++--
drivers/tee/optee/notif.c | 1 -
drivers/tee/optee/optee_private.h | 52 ++++++++++++++++++++++++++++++-
drivers/tee/optee/rpmi_abi.c | 23 ++++++++++++++
8 files changed, 101 insertions(+), 8 deletions(-)
create mode 100644 drivers/tee/optee/rpmi_abi.c
base-commit: 827751b699b79a6e569983359c02dce67f81b94c
--
2.43.0
'select' does not work on config options in a 'choice', so currently it is
possible to enable QCOMTEE without QCOM_TZMEM_MODE_SHMBRIDGE, even though
this is needed at runtime.
There are no users of the generic allocator option,
QCOM_TZMEM_MODE_GENERIC, so let's remove it. Then, we can remove the
containing choice..endchoice, which allows the 'select' to work as
intended.
Suggested-by: Arnd Bergmann <arnd(a)arndb.de>
Signed-off-by: Julian Braha <julianbraha(a)gmail.com>
---
Changes since v2:
- add back stubs for when CONFIG_QCOM_TZMEM_MODE_GENERIC=n
- updated help text accordingly
Link:
https://lore.kernel.org/all/20260729203845.387239-1-julianbraha@gmail.com/
Changes since v1:
- remove TZMEM_MODE_GENERIC instead of removing the dead select
Link:
https://lore.kernel.org/all/20260715092539.18384-1-julianbraha@gmail.com/
---
drivers/firmware/qcom/Kconfig | 26 +++++---------------------
drivers/firmware/qcom/qcom_tzmem.c | 4 ++--
2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig
index c7f8413ab996..95b968d88dc3 100644
--- a/drivers/firmware/qcom/Kconfig
+++ b/drivers/firmware/qcom/Kconfig
@@ -34,33 +34,17 @@ config QCOM_TZMEM
tristate
select GENERIC_ALLOCATOR
-choice
- prompt "TrustZone interface memory allocator mode"
- depends on QCOM_TZMEM
- default QCOM_TZMEM_MODE_GENERIC
- help
- Selects the mode of the memory allocator providing memory buffers of
- suitable format for sharing with the TrustZone. If in doubt, select
- 'Generic'.
-
-config QCOM_TZMEM_MODE_GENERIC
- bool "Generic"
- help
- Use the generic allocator mode. The memory is page-aligned, non-cachable
- and physically contiguous.
-
config QCOM_TZMEM_MODE_SHMBRIDGE
- bool "SHM Bridge"
+ bool "TrustZone interface memory allocator: SHM Bridge"
+ depends on QCOM_TZMEM
help
- Use Qualcomm Shared Memory Bridge. The memory has the same alignment as
- in the 'Generic' allocator but is also explicitly marked as an SHM Bridge
- buffer.
+ Use Qualcomm Shared Memory Bridge as memory allocator. The memory has the
+ same alignment as in the 'Generic' allocator, which is used when this option
+ is disabled, but is also explicitly marked as an SHM Bridge buffer.
With this selected, all buffers passed to the TrustZone must be allocated
using the TZMem allocator or else the TrustZone will refuse to use them.
-endchoice
-
config QCOM_QSEECOM
bool "Qualcomm QSEECOM interface driver"
depends on QCOM_SCM=y
diff --git a/drivers/firmware/qcom/qcom_tzmem.c b/drivers/firmware/qcom/qcom_tzmem.c
index 0fd9581275f1..510474902c3a 100644
--- a/drivers/firmware/qcom/qcom_tzmem.c
+++ b/drivers/firmware/qcom/qcom_tzmem.c
@@ -50,7 +50,7 @@ static struct device *qcom_tzmem_dev;
static RADIX_TREE(qcom_tzmem_chunks, GFP_ATOMIC);
static DEFINE_SPINLOCK(qcom_tzmem_chunks_lock);
-#if IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_GENERIC)
+#ifndef CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE
static int qcom_tzmem_init(void)
{
@@ -67,7 +67,7 @@ static void qcom_tzmem_cleanup_area(struct qcom_tzmem_area *area)
}
-#elif IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE)
+#else
#include <linux/firmware/qcom/qcom_scm.h>
#include <linux/of.h>
--
2.55.0
This RFC adds initial support for communicating with OP-TEE on RISC-V
using the RPMI TEE service group [1] over the SBI MPXY [2]
mailbox framework.
The intention is to provide a transport for RISC-V systems similar in
purpose to the FF-A transport currently used by OP-TEE on Arm systems.
Linux and OP-TEE act as endpoints of the RPMI TEE service group, while
the RPMI framework in machine-mode firmware mediates communication
between them.
The implementation closely follows the existing OP-TEE FF-A backend in
drivers/tee/optee/ffa_abi.c. Where possible, the same overall design and
lifetime rules are preserved, with FF-A operations mapped to equivalent
RPMI TEE services.
For shared memory, FF-A memory handles are replaced by RPMI memory parcel
identifiers. Linux creates an RPMI memory parcel for shared memory and
makes OP-TEE a receiver of that parcel. The parcel identifier is then
used in OP-TEE message parameters in a similar way to the FF-A global
memory handle.
RPMI TEE_CALL is used as the entry mechanism into OP-TEE, serving a role
similar to the FF-A direct-message path. The request and response contain
a small register-like payload carrying the OP-TEE call information and
state required to resume yielding calls. The existing OP-TEE call queue,
RPC handling and shared-memory infrastructure are reused as much as
possible.
The transport uses one SBI MPXY mailbox channel per hart. A TEE call is
issued using the channel corresponding to the CPU on which the call is
running. This preserves the execution model where entering OP-TEE on a
hart results in secure-world execution associated with that hart.
Shared memory is implemented using RPMI TEE memory parcels. The driver
maintains a mapping between parcel identifiers and struct tee_shm objects
and uses parcel create and reclaim operations to manage the lifetime of
memory shared with OP-TEE.
Asynchronous notifications are implemented using the RPMI TEE signal
bus. The RPMI TEE service group does not provide framework notification
events corresponding directly to the OP-TEE asynchronous notification
mechanism, so the signal bus is used to carry notification values from
OP-TEE to Linux.
This is an early RFC and the implementation is not complete. There may
still be functional bugs, incorrect assumptions, missing pieces, or
interfaces that need to change.
The series is being posted at this stage primarily to get feedback on the
overall architecture and on how the OP-TEE ABI is mapped onto the RPMI
TEE service group.
The implementation deliberately follows the FF-A backend and ffa_abi.c
closely. This allows the existing OP-TEE driver design to be reused and
keeps the RISC-V and FF-A transports as consistent as possible. Some of
these abstractions may need to be adjusted where the RPMI execution,
notification, or memory model differs from FF-A, while others may
eventually be shared between the transports.
[1] https://github.com/riscv-non-isa/riscv-rpmi/commits/main/src/srvgrp-tee.adoc
[2] https://github.com/riscv-non-isa/riscv-sbi-doc/releases
Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi(a)oss.qualcomm.com>
---
Amirreza Zarrabi (5):
optee: riscv: add RPMI TEE service group transport
optee: riscv: add shared memory and scheduled calls
optee: riscv: enable persistent shared argument cache
optee: riscv: add asynchronous notifications over the signal bus
dt-bindings: tee: add RISC-V RPMI TEE transport
.../bindings/tee/riscv,rpmi-mpxy-tee.yaml | 65 +
MAINTAINERS | 1 +
drivers/tee/optee/Makefile | 1 +
drivers/tee/optee/core.c | 8 +-
drivers/tee/optee/optee_private.h | 47 +
drivers/tee/optee/optee_riscv.c | 1621 ++++++++++++++++++++
drivers/tee/optee/optee_riscv.h | 334 ++++
include/linux/mailbox/riscv-rpmi-message.h | 1 +
8 files changed, 2076 insertions(+), 2 deletions(-)
---
base-commit: 68142f986ff04b2b70b31db00f719bf690f64a9a
change-id: 20260912-rpmi-tee-service-grp-dev-b2ce2f63e0df
Best regards,
--
Amirreza Zarrabi <amirreza.zarrabi(a)oss.qualcomm.com>
This series makes UFS RPMB work out of the box with an OP-TEE that
implements the standard eMMC RPMB key-derivation flow, without requiring
any fundamental changes on the OP-TEE side.
RPMB provides an authenticated, replay-protected storage area whose
security relies on a secret authentication key. In our setup that key is
never exposed to the kernel: OP-TEE derives it in the secure world from
its hardware-unique key and a device identifier (dev_id) that the RPMB
core hands down. OP-TEE's implementation targets eMMC, where dev_id is
the 16-byte eMMC CID, and both the fixed length and the raw-CID layout
are baked into its key derivation.
Two things stand in the way of reusing that same, unmodified OP-TEE flow
for UFS RPMB:
1. On a cold boot the very first frame sent to the RPMB well-known LU
comes back with a power-on UNIT ATTENTION (ASC 0x29), which the SCSI
core reports rather than retries. RPMB has no earlier guaranteed
access that could clear the condition first, so RPMB fails on every
power cycle. Patch 1 asks the SCSI core to retry the power-on UNIT
ATTENTION on the RPMB WLUN.
2. The UFS RPMB id is "<device_id>-R<region>", which is variable length
and longer than 16 bytes. Passing it verbatim would tie the derived
key to a length OP-TEE does not expect and diverge from the fixed
eMMC CID ABI. Patch 2 hashes it into a fixed 16-byte dev_id with
blake2b, keeping the key stable and unique per region while matching
the eMMC CID layout OP-TEE relies on. The hash algorithm and input
string are thus part of the key-derivation ABI and must stay stable.
With both patches, UFS RPMB is functional from the first access after a
cold boot and derives keys through the existing eMMC-style OP-TEE flow,
(requires minimal OP-TEE changes pending on the CID proposal done here).
Tested on IQ-9075 with Open Firmware [1], pending OP-TEE changes
[1]https://ldts.github.io/qcom-buildroot
Dependencies:
U-boot:
https://lore.kernel.org/u-boot/20260720085202.537019-1-jorge.ramirez@oss.qu…
OP-TEE:
https://github.com/OP-TEE/optee_os/pull/7881
v5:
* added Reviewed-by tags from Bean Huo and Stanley Jhu; no code change.
v4:
* ufs: rpmb: retry power-on UNIT ATTENTION on the RPMB WLUN: open-code
the power-on ASC 0x29 (with a naming comment) as the rest of the SCSI
tree does, instead of a UFS_RPMB_ASC_POWER_ON define; add a
UFS_RPMB_UA_RETRIES define for the retry count; reworded the commit
message.
* ufs: rpmb: use a fixed-length RPMB dev_id: reworded the commit
message; no functional change.
v3:
* ufs: rpmb: use a fixed-length RPMB dev_id: hash into a stack buffer
instead of a kzalloc'd one; rpmb_dev_register() copies dev_id, so the
heap allocation and its cleanup were unnecessary.
v2:
* ufs: rpmb: replace blake2s with blake2b so that the same support
can be added to u-boot (CRYPTO_LIB_BLAKE2B)
* added links to U-boot and OP-TEE changes.
v1:
* ufs: rpmb: retry power-on UNIT ATTENTION on the RPMB WLUN:
- fix using uses SCMD_FAILURE_ASC_ANY to retry any Unit Attention
- fix unused variable
* ufs: rpmb: use a fixed-length RPMB dev_id
- fix selecting a non-existent Kconfig symbol
Jorge Ramirez-Ortiz (2):
ufs: rpmb: retry power-on UNIT ATTENTION on the RPMB WLUN
ufs: rpmb: use a fixed-length RPMB dev_id
drivers/ufs/Kconfig | 1 +
drivers/ufs/core/ufs-rpmb.c | 29 ++++++++++++++++++++++++++---
2 files changed, 27 insertions(+), 3 deletions(-)
--
2.54.0
The driver explicitly sets the .driver_data member of struct
platform_device_id to zero without relying on that value. Drop this
unused assignment.
While touching this array unify spacing and usage of commas and use
a named initializer for .name for improved readability.
Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig(a)baylibre.com>
---
Hello,
while this is a cleanup that can stand on its own, it is also a
preparation for a change to struct platform_device_id that requires that
.driver_data isn't assigned by a list initializer.
Best regards
Uwe
drivers/tee/qcomtee/call.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/tee/qcomtee/call.c b/drivers/tee/qcomtee/call.c
index 0efc5646242a..4a597eeaf174 100644
--- a/drivers/tee/qcomtee/call.c
+++ b/drivers/tee/qcomtee/call.c
@@ -798,7 +798,12 @@ static void qcomtee_remove(struct platform_device *pdev)
kfree(qcomtee);
}
-static const struct platform_device_id qcomtee_ids[] = { { "qcomtee", 0 }, {} };
+static const struct platform_device_id qcomtee_ids[] = {
+ {
+ .name = "qcomtee",
+ },
+ { }
+};
MODULE_DEVICE_TABLE(platform, qcomtee_ids);
static struct platform_driver qcomtee_platform_driver = {
base-commit: 8d6dbbbe3ba62de0a63e962ee004afb848c8e3ac
--
2.47.3
Most of the struct definitions for a given IOCTL definition immediately
preceded that definition. The struct tee_ioctl_shm_register_data is an
exception as it is placed above the TEE_IOC_SHM_REGISTER_FD definition,
not the TEE_IOC_SHM_REGISTER one it is to be used with. Move it down
to match the others.
This is a non-functional change for consistency and to help prevent
someone from accidentally using the wrong struct with the wrong IOCTL
based on the struct's location.
Fix a couple small spelling issues while here.
Signed-off-by: Andrew Davis <afd(a)ti.com>
---
include/uapi/linux/tee.h | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/include/uapi/linux/tee.h b/include/uapi/linux/tee.h
index 5203977ed35d1..76815b0f4b665 100644
--- a/include/uapi/linux/tee.h
+++ b/include/uapi/linux/tee.h
@@ -384,24 +384,6 @@ struct tee_iocl_supp_send_arg {
#define TEE_IOC_SUPPL_SEND _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 7, \
struct tee_ioctl_buf_data)
-/**
- * struct tee_ioctl_shm_register_data - Shared memory register argument
- * @addr: [in] Start address of shared memory to register
- * @length: [in/out] Length of shared memory to register
- * @flags: [in/out] Flags to/from registration.
- * @id: [out] Identifier of the shared memory
- *
- * The flags field should currently be zero as input. Updated by the call
- * with actual flags as defined by TEE_IOCTL_SHM_* above.
- * This structure is used as argument for TEE_IOC_SHM_REGISTER below.
- */
-struct tee_ioctl_shm_register_data {
- __u64 addr;
- __u64 length;
- __u32 flags;
- __s32 id;
-};
-
/**
* struct tee_ioctl_shm_register_fd_data - Shared memory registering argument
* @fd: [in] File descriptor identifying dmabuf reference
@@ -426,13 +408,31 @@ struct tee_ioctl_shm_register_fd_data {
* Returns a file descriptor on success or < 0 on failure
*
* The returned file descriptor refers to the shared memory object in the
- * kernel. The supplied file deccriptor can be closed if it's not needed
+ * kernel. The supplied file descriptor can be closed if it's not needed
* for other purposes. The shared memory is freed when the descriptor is
* closed.
*/
#define TEE_IOC_SHM_REGISTER_FD _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 8, \
struct tee_ioctl_shm_register_fd_data)
+/**
+ * struct tee_ioctl_shm_register_data - Shared memory register argument
+ * @addr: [in] Start address of shared memory to register
+ * @length: [in/out] Length of shared memory to register
+ * @flags: [in/out] Flags to/from registration.
+ * @id: [out] Identifier of the shared memory
+ *
+ * The flags field should currently be zero as input. Updated by the call
+ * with actual flags as defined by TEE_IOCTL_SHM_* above.
+ * This structure is used as argument for TEE_IOC_SHM_REGISTER below.
+ */
+struct tee_ioctl_shm_register_data {
+ __u64 addr;
+ __u64 length;
+ __u32 flags;
+ __s32 id;
+};
+
/**
* TEE_IOC_SHM_REGISTER - Register shared memory argument
*
@@ -440,7 +440,7 @@ struct tee_ioctl_shm_register_fd_data {
*
* Returns a file descriptor on success or < 0 on failure
*
- * The shared memory is unregisterred when the descriptor is closed.
+ * The shared memory is unregistered when the descriptor is closed.
*/
#define TEE_IOC_SHM_REGISTER _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 9, \
struct tee_ioctl_shm_register_data)
--
2.39.2
Most of the struct definitions for a given IOCTL definition immediately
preceded that definition. The struct tee_ioctl_shm_register_data is an
exception as it is placed above the TEE_IOC_SHM_REGISTER_FD definition,
not the TEE_IOC_SHM_REGISTER one it is to be used with. Move it down
to match the others.
This is a non-functional change for consistency and to help prevent
someone from accidentally using the wrong struct with the wrong IOCTL
based on the struct's location.
Fix a couple small spelling issues while here.
Signed-off-by: Andrew Davis <afd(a)ti.com>
---
Resending using folks updated emails :)
include/uapi/linux/tee.h | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/include/uapi/linux/tee.h b/include/uapi/linux/tee.h
index 5203977ed35d1..76815b0f4b665 100644
--- a/include/uapi/linux/tee.h
+++ b/include/uapi/linux/tee.h
@@ -384,24 +384,6 @@ struct tee_iocl_supp_send_arg {
#define TEE_IOC_SUPPL_SEND _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 7, \
struct tee_ioctl_buf_data)
-/**
- * struct tee_ioctl_shm_register_data - Shared memory register argument
- * @addr: [in] Start address of shared memory to register
- * @length: [in/out] Length of shared memory to register
- * @flags: [in/out] Flags to/from registration.
- * @id: [out] Identifier of the shared memory
- *
- * The flags field should currently be zero as input. Updated by the call
- * with actual flags as defined by TEE_IOCTL_SHM_* above.
- * This structure is used as argument for TEE_IOC_SHM_REGISTER below.
- */
-struct tee_ioctl_shm_register_data {
- __u64 addr;
- __u64 length;
- __u32 flags;
- __s32 id;
-};
-
/**
* struct tee_ioctl_shm_register_fd_data - Shared memory registering argument
* @fd: [in] File descriptor identifying dmabuf reference
@@ -426,13 +408,31 @@ struct tee_ioctl_shm_register_fd_data {
* Returns a file descriptor on success or < 0 on failure
*
* The returned file descriptor refers to the shared memory object in the
- * kernel. The supplied file deccriptor can be closed if it's not needed
+ * kernel. The supplied file descriptor can be closed if it's not needed
* for other purposes. The shared memory is freed when the descriptor is
* closed.
*/
#define TEE_IOC_SHM_REGISTER_FD _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 8, \
struct tee_ioctl_shm_register_fd_data)
+/**
+ * struct tee_ioctl_shm_register_data - Shared memory register argument
+ * @addr: [in] Start address of shared memory to register
+ * @length: [in/out] Length of shared memory to register
+ * @flags: [in/out] Flags to/from registration.
+ * @id: [out] Identifier of the shared memory
+ *
+ * The flags field should currently be zero as input. Updated by the call
+ * with actual flags as defined by TEE_IOCTL_SHM_* above.
+ * This structure is used as argument for TEE_IOC_SHM_REGISTER below.
+ */
+struct tee_ioctl_shm_register_data {
+ __u64 addr;
+ __u64 length;
+ __u32 flags;
+ __s32 id;
+};
+
/**
* TEE_IOC_SHM_REGISTER - Register shared memory argument
*
@@ -440,7 +440,7 @@ struct tee_ioctl_shm_register_fd_data {
*
* Returns a file descriptor on success or < 0 on failure
*
- * The shared memory is unregisterred when the descriptor is closed.
+ * The shared memory is unregistered when the descriptor is closed.
*/
#define TEE_IOC_SHM_REGISTER _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 9, \
struct tee_ioctl_shm_register_data)
--
2.39.2
Qualcomm platforms with a discrete TPM (dTPM) talked to it directly over
a non-secure SPI channel from the kernel. Arm's Base Boot Security
Requirements (BBSR) v1.4 require that access to go through TrustZone
instead, so on affected Qualcomm platforms the TPM 2.0 instance is now
fronted by a Trusted Application (TA) running inside Qualcomm's Trusted
Execution Environment (QTEE), which talks to the dTPM (or implements an
fTPM) on the kernel's behalf.
This series adds a kernel driver for that TA, built on the QCOMTEE
object-IPC transport (drivers/tee/qcomtee/) already used to reach other
QTEE services.
This patch series functionally depends on below(patch 5/6 specifically)
for qtee service discovery.
- https://lore.kernel.org/lkml/20260722-qcom_uefisecapp_migrate_qcomtee-v2-0-…
Tested on Glymur-crd target with tpm2-tools utility.
Validations:
- Get capabilities
- Random number generator
- RSA key creation, encryption and decryption.
Signed-off-by: Kuldeep Singh <kuldeep.singh(a)oss.qualcomm.com>
---
Kuldeep Singh (2):
tee: qcomtee: Register qcom.tz.tpm service for discovery
firmware: tpm: Introduce tpm-qcom driver
MAINTAINERS | 7 +
drivers/char/tpm/Kconfig | 9 +
drivers/char/tpm/Makefile | 1 +
drivers/char/tpm/tpm_qcom.c | 371 ++++++++++++++++++++++++++++++++++++++
drivers/char/tpm/tpm_qcom.h | 82 +++++++++
drivers/tee/qcomtee/call.c | 4 +-
drivers/tee/qcomtee/qcomtee_msg.h | 2 +
7 files changed, 475 insertions(+), 1 deletion(-)
---
base-commit: f3e6330d7fe42b204af05a2dbc68b379e0ad179e
change-id: 20260831-tpm_qcom_driver-d21c720e73b2
prerequisite-change-id: 20260408-qcom_uefisecapp_migrate_qcomtee-13869d45e014:v2
prerequisite-patch-id: 4dc81445c9baf36f420da8c2e2bed96e71b31a5b
prerequisite-patch-id: b487dfe2fbc076f4815dc6c73b9e68b0b78c961f
prerequisite-patch-id: c5df2b3696520a96f95b2d3535ed84cdc21cc315
prerequisite-patch-id: bbdd5327c15aeaa99ce9b74bab324a98f084ed48
prerequisite-patch-id: 07d9c4e9fe9fd61f60e3f35b30b9d81716f0734c
prerequisite-patch-id: 10ff88d87586f21f3cff3f72dbd21c27adbfbbcc
Best regards,
--
Kuldeep Singh <kuldeep.singh(a)oss.qualcomm.com>
From: Marouene Boubakri <marouene.boubakri(a)oss.nxp.com>
On RISC-V, OP-TEE runs as a supervisor domain isolated from Linux by the
M-mode firmware. There is no SMC or HVC instruction: the firmware has to
switch the calling hart between the two domains, and the way Linux asks
for that switch has to come from the RISC-V specifications rather than
from an ad-hoc SBI extension.
This series adds RISC-V support to the OP-TEE driver by carrying the
existing SMC ABI over the TEE service group of the RISC-V Platform
Management Interface (RPMI) [1], sent with the SBI Message Proxy (MPXY)
extension of SBI v3.0 [2] through the in-tree MPXY mailbox driver. Each
invocation of the SMC ABI becomes a TEE_CALL request whose service data
holds the register arguments a0-a7, and whose service response holds
the return values a0-a3. The M-mode firmware implementing the service
group (the "RPMI TEE framework") switches the calling hart to the OP-TEE
domain until OP-TEE responds, so a TEE_CALL behaves like an SMC: it runs
on the calling hart and returns when OP-TEE completes the call, requests
an RPC or yields on a foreign interrupt. The SMC ABI, the message
protocol, RPCs, dynamic and static shared memory and notifications are
unchanged, which is why the conduit lives next to the SMCCC one in
smc_abi.c instead of being a new ABI like ffa_abi.c.
Specification status, and how the series is split:
The TEE service group (SERVICEGROUP_ID 0x0010) is part of RPMI v2.0,
which is in development: it was added to the main branch of the
specification repository in June 2026 [3] and is not in the released
RPMI v1.0. Everything in this series that depends on it is kept in the
last three patches, which are RFC until RPMI v2.0 is frozen as required
by Documentation/arch/riscv/patch-acceptance.rst:
- patches 1-3 only rely on SBI v3.0 MPXY and RPMI v1.0 as already
supported by the kernel, and on existing OP-TEE driver internals.
They are meant to be mergeable on their own;
- patches 4-6 add the RPMI v2.0 TEE service group definitions, the
binding and the conduit. They implement TEE_CALL as specified; the
only OP-TEE specific parts are the content of the service data and
service response, which the specification leaves to the service, and
the OP-TEE API UID used as service UUID.
Why this conduit rather than the alternatives:
- A raw ecall to a "TEE" SBI extension, as used by the current OP-TEE OS
RISC-V port and by the RISE reference firmware, relies on an EID that
does not exist in the SBI specification and on returning four values
from an ecall, which the SBI calling convention does not allow.
- The RPMI MANAGEMENT_MODE service group (RPMI v1.0) is defined for UEFI
PI Management Mode communication and its data is the MM communication
buffer; carrying the OP-TEE message protocol in it would go against
the specification's intent and collide with its intended users.
- An implementation specific service group (0x8000-0xFFFF) is allowed by
RPMI v1.0 but would not be a generic OP-TEE conduit.
The one non-obvious part is patch 1. An MPXY message send is an ecall on
the calling hart, using per-hart shared memory, which returns once the
message has been processed. With TEE_CALL that is when OP-TEE has
finished running on that hart, which can take an arbitrarily long time.
Sending such messages with mbox_send_message() would execute OP-TEE from
within msg_submit() with the mailbox channel spinlock held and
interrupts disabled, serializing every hart on that lock. Patch 1 adds
riscv_sbi_mpxy_mbox_call() to the MPXY mailbox driver, which performs
the transfer directly in the calling context with only local interrupts
disabled (the per-hart shared memory is also used from hard interrupt
context by mbox_send_message() users). Harts proceed in parallel since
each one has its own shared memory. The channel is still requested
through the mailbox core so that its ownership is tracked. Opinions on
whether this belongs in the MPXY driver, or whether the MPXY shared
memory handling should move to a core helper usable by several drivers,
are welcome.
Endpoint identifiers: the framework assigns an identifier to every REE
and TEE. The only way for an endpoint to learn them without firmware
help is the optional TEE_PROBE_SYSTEM service, whose response is CBOR
encoded and cannot be parsed in the kernel, so the binding carries the
REE and OP-TEE identifiers as properties that the firmware is expected
to fix up in the device tree. Feedback on this is welcome too.
Known gaps:
- The framework side (OpenSBI: TEE_CALL forwarding through domain
context switching) and the messaging return path of the OP-TEE OS
RISC-V port are being upstreamed separately.
- The service group defines no notification events; OP-TEE asynchronous
notifications on RISC-V are left for later and OP-TEE OS does not
advertise them on this conduit.
- The byte order of the SERVICE UUID field is not specified by RPMI;
this series uses the RFC 4122 order. The memory parcel services of the
service group are not used, secure world accesses registered pages
directly as with the SMC conduit.
Testing: built for riscv64 (defconfig plus TEE/OP-TEE, both built-in and
as modules) and for arm64 (defconfig plus OP-TEE and FF-A) with W=1 at
every step of the series, plus dt_binding_check. [TODO before posting:
describe the runtime testing done on QEMU virt with the OpenSBI and
OP-TEE OS changes mentioned above, e.g. xtest results.]
[1] https://github.com/riscv-non-isa/riscv-rpmi/releases
[2] https://github.com/riscv-non-isa/riscv-sbi-doc/releases
[3] https://github.com/riscv-non-isa/riscv-rpmi/commits/main/src/srvgrp-tee.adoc
Marouene Boubakri (6):
mailbox: riscv-sbi-mpxy: add riscv_sbi_mpxy_mbox_call() for hart-local
requests
tee: optee: select the SMC ABI conduit from the firmware node match
data
tee: optee: teach the memory type check about RISC-V page attributes
mailbox: riscv-rpmi-message: add TEE service group definitions
dt-bindings: firmware: add OP-TEE over the RISC-V RPMI TEE service
group
tee: optee: add a RISC-V conduit over the RPMI TEE service group
.../bindings/firmware/linaro,optee-rpmi.yaml | 79 +++++++
Documentation/tee/op-tee.rst | 18 +-
MAINTAINERS | 2 +
drivers/mailbox/riscv-sbi-mpxy-mbox.c | 60 ++++++
drivers/tee/Kconfig | 2 +-
drivers/tee/optee/Kconfig | 11 +-
drivers/tee/optee/Makefile | 1 +
drivers/tee/optee/call.c | 8 +
drivers/tee/optee/optee_private.h | 3 +
drivers/tee/optee/optee_rpmi.h | 69 ++++++
drivers/tee/optee/rpmi_conduit.c | 203 ++++++++++++++++++
drivers/tee/optee/smc_abi.c | 41 +++-
include/linux/mailbox/riscv-rpmi-message.h | 25 +++
include/linux/mailbox/riscv-sbi-mpxy-mbox.h | 23 ++
14 files changed, 538 insertions(+), 7 deletions(-)
create mode 100644 Documentation/devicetree/bindings/firmware/linaro,optee-rpmi.yaml
create mode 100644 drivers/tee/optee/optee_rpmi.h
create mode 100644 drivers/tee/optee/rpmi_conduit.c
create mode 100644 include/linux/mailbox/riscv-sbi-mpxy-mbox.h
base-commit: 50d05c7c76c96b90462f24debacca971d2e86713
--
2.43.0
This series is a follow-up to the discussion that has started here [1].
While standalone, it also provides primitives reusable for the VPR DMA
heap.
When memory is lent to the Secure world via FF-A, CPU speculative
accesses from NS to the lent pages can still occur as long as it retains
a cacheable mapping to it.
Ideally, lent memory would be "no-map" but that would mean giving up
MiBs of useful memory, so let's try to do better with the help of a CMA
pool.
On arm64, modifying the direct map at runtime is generally restricted
because the linear map defaults to block mapping and splitting blocks at
runtime may trigger fatal page fault, unless the CPU implements BBML3
or the entire direct map was mapped at page granularity from boot.
Forcing last-level mappings system-wide incurs a severe penalty we want
to avoid. Instead, this series introduces targeted last-level mappings
for designated memory regions, along with the "arm,ffa-lend-pool" CMA
driver to manage unmapping and remapping on lend/reclaim transitions:
1. memblock & OF reserved memory ("ll-map"):
- Introduce MEMBLOCK_LLMAP and the DT "ll-map" property for reserved-memory
nodes to force last-level (PTE) mappings only for a specific region.
2. set_memory infrastructure:
- Introduce can_set_direct_map_range() to check if a specific address
range is mapped with last-level entries and can be modified safely.
- Introduce __set_direct_map_*() variants that bypass redundant checks
when the caller has already validated the range.
3. "arm,ffa-lend-pool" driver
- Introduce the "arm,ffa-lend-pool" CMA reserved-memory driver, which
unmaps pages prior to lending (ffa_prepare_lend()) and restores them
when reclaimed (ffa_lend_reclaimed()).
4. Optee support
- Hook OP-TEE dynamic protected memory pools to "arm,ffa-lend-pool" for
both SMC (via DT memory-region phandle) and FF-A (via
ffa_lend_pool_attach()) transports.
Testing:
========
Tested with QEMU v8 using OP-TEE OS (built with CFG_CORE_DYN_PROTMEM=y)
under both SMC and FF-A transports [2]
static void dump_direct_map(const char *label)
{
printf("\n=== %s ===\n", label);
fflush(stdout);
system("sed -n '/Linear Mapping start/,/Linear Mapping end/p' /sys/kernel/debug/kernel_page_tables");
fflush(stdout);
}
int main(int argc, char *argv[])
{
int heap_fd;
int dmabuf_fd;
struct dma_heap_allocation_data data = { 0 };
size_t size = 1024 * 1024; /* 1MB */
if (argc > 1)
size = strtoul(argv[1], NULL, 0);
dump_direct_map("BEFORE ALLOCATION");
heap_fd = open("/dev/dma_heap/protected,secure-video", O_RDWR);
if (heap_fd < 0) {
perror("open /dev/dma_heap/protected,secure-video");
return 1;
}
printf("\nOpened /dev/dma_heap/protected,secure-video\n");
printf("Allocating %zu bytes of protected memory via DMA heap...\n", size);
data.len = size;
data.fd_flags = O_RDWR | O_CLOEXEC;
if (ioctl(heap_fd, DMA_HEAP_IOCTL_ALLOC, &data) < 0) {
perror("ioctl DMA_HEAP_IOCTL_ALLOC");
close(heap_fd);
return 1;
}
dmabuf_fd = data.fd;
printf("Successfully allocated %zu bytes! dmabuf_fd = %d\n", size, dmabuf_fd);
dump_direct_map("DURING LEND (EXPECT HOLE IN DIRECT MAP)");
printf("\nReleasing dmabuf_fd...\n");
close(dmabuf_fd);
close(heap_fd);
dump_direct_map("AFTER RECLAIM (RESTORED DIRECT MAP)");
return 0;
}
[1] https://lore.kernel.org/all/20260807-tegra-vpr-v4-7-5510d16af89e@nvidia.com/
[2] https://optee.readthedocs.io/en/latest/building/gits/build.html#qemu-v8
Vincent Donnefort (10):
memblock: Introduce MEMBLOCK_LLMAP
of: reserved_mem: Introduce "ll-map" property
set_memory.h: Introduce can_set_direct_map_range()
set_memory.h: Introduce __set_direct_map*()
arm64: can_set_direct_map() if BBML3
arm64: Implement can_set_direct_map_range()
arm64: Implement __set_direct_map*()
arm64: Add support for MEMBLOCK_LLMAP
firmware: arm_ffa: Introduce ffa-lend-pool
optee: Add support for arm,ffa-lend-pool
arch/arm64/include/asm/set_memory.h | 7 +
arch/arm64/mm/mmu.c | 23 ++-
arch/arm64/mm/pageattr.c | 67 +++++++-
drivers/firmware/arm_ffa/Kconfig | 5 +
drivers/firmware/arm_ffa/Makefile | 1 +
drivers/firmware/arm_ffa/lend_pool.c | 223 +++++++++++++++++++++++++++
drivers/of/of_reserved_mem.c | 104 ++++++++++---
drivers/tee/optee/ffa_abi.c | 13 +-
drivers/tee/optee/protmem.c | 8 -
drivers/tee/optee/smc_abi.c | 17 +-
drivers/tee/tee_shm.c | 11 +-
include/linux/arm_ffa.h | 21 +++
include/linux/memblock.h | 9 ++
include/linux/set_memory.h | 39 +++++
mm/memblock.c | 50 ++++++
15 files changed, 545 insertions(+), 53 deletions(-)
create mode 100644 drivers/firmware/arm_ffa/lend_pool.c
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
--
2.55.0.970.g62bdec98f9-goog