Hello soc maintainers,
Please pull this patch to only build the SMC and FF-A code where supported.
The OP-TEE driver is still only built for Arm, but that will change in a
not too distant future.
Thanks,
Jens
The following changes since commit 8d3ae59288f1e7d58d76558a6ee96d533bc5019f:
Linux 7.2 (2026-08-16 14:32:26 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee.git tags/optee-for-v7.4
for you to fetch changes up to ccd4b23398acaf2139cf04f1ba0a66150cbf2663:
tee: optee: build the Arm-specific code only on Arm (2026-10-02 16:28:41 +0200)
----------------------------------------------------------------
Build the OP-TEE driver's SMC and FF-A code only where supported
----------------------------------------------------------------
Marouene Boubakri (1):
tee: optee: build the Arm-specific code only on Arm
drivers/tee/optee/Kconfig | 1 +
drivers/tee/optee/Makefile | 4 ++--
drivers/tee/optee/ffa_abi.c | 8 ++------
drivers/tee/optee/notif.c | 1 -
drivers/tee/optee/optee_private.h | 39 ++++++++++++++++++++++++++++++++++++++-
5 files changed, 43 insertions(+), 10 deletions(-)
Shared-memory allocator services (e.g., Android's gralloc)
allocate dma-bufs on behalf of client processes in different
cgroups. Today those allocations are charged to the allocator's
own cgroup, leaving client cgroups with no visibility into their
actual memory consumption and defeating resource limits.
This series adds memory cgroup accounting for dma-buf allocations,
building on T.J. Mercier's earlier series [1] and incorporating
feedback from previous versions and LPC discussions [2].
Patch 1 introduces the MEMCG_DMABUF stat and reserve/commit/cancel
and uncharge helpers. Rather than charging at the page level via
__GFP_ACCOUNT (which would require every dma-buf exporter to implement
charging, and makes cross-cgroup transfer impractical without access
to backing pages), we track charges externally on struct dma_buf via
a MEMCG_DMABUF stat counter and route all accounting through a single
path, removing the __GFP_ACCOUNT flag from system-heap allocations
to avoid double counting.
Patch 2 adds a charge_fd field to DMA_HEAP_IOCTL_ALLOC, accepting
either a pidfd or a cgroupfd to identify the target cgroup at
allocation time. If the target cgroup cannot accommodate the charge,
the allocation returns -ENOMEM.
Patches 3-6 add access control for cross-cgroup charging. Letting
userspace decide who to charge needs to be a privileged operation
because it has material impact on OOM decission and resource limits.
We gate it via LSM hooks for the two charge_fd flavours:
security_dma_buf_charge_task() gates the pidfd path (target
identified by task credentials) and security_dma_buf_charge_cgroup()
gates the cgroupfd path (target identified by cgroup directory label),
with SELinux implementations under a dma_buf object class.
Patch 7 adds DMA_BUF_IOCTL_XFER_CHARGE, a general ioctl on any
dma-buf fd to transfer charges post-allocation. This covers the
double-hop allocator case (SurfaceFlinger -> gralloc -> kernel)
and works for buffers from any exporter (DRM, V4L2, etc.). A new
memcg_account flag is added for dma_buf_export() to ensure that
transfer/charge is only applied for buffers backed by reclaimable
system memory. If the receiving cgroup lacks capacity for the charge,
the ioctl returns -ENOMEM and the original charge is preserved.
Patch 8 adds selftests.
Known limitations:
- Single-owner model: a dma-buf carries one memcg charge regardless
of how many processes share it.
- Only memcg accounting. CMA heaps would additionally need dmem
controller integration.
- If a transfer of an uncharged buffer fails, it remains uncharged.
The allocator (userspace) is expected to handle this (retry, free, ...).
- The LSM hooks are intentionally narrow. Broader cgroup access controls
(e.g. for the memfd/kexec handover case [2]) could be a separate effort
reusing the same pattern.
- Only system heap sets memcg_account today. Other exporters
(DRM, V4L2, etc.) can opt in by setting the flag, but are not
covered by this series.
[1] https://lore.kernel.org/cgroups/20230109213809.418135-1-tjmercier@google.co…
[2] https://lpc.events/event/20/contributions/2416/
Signed-off-by: Albert Esteve <aesteve(a)redhat.com>
---
Changes in v3:
- Split mem_cgroup_charge_dmabuf() into reserve/commit/cancel three-phase API
- Extract mem_cgroup_get_from_fd() helper shared by allocate and xfer paths
- Rename __padding to flags in struct dma_buf_transfer_charge
- Fix UAF race: move mod_memcg_state() before cmpxchg in transfer
- Add memcg_account opt-in flag; xfer returns -EOPNOTSUPP if unset
- Wrap dma_buf_charge_cgroup hook in #ifdef CONFIG_CGROUPS
- Fix TOCTOU in SELinux charge_cgroup xattr length handling
- Link to v2: https://lore.kernel.org/r/20261021-v2_20230123_tjmercier_google_com-v2-0-ef…
Changes in v2:
- Move charge_pid_fd to charge_fd, accepting cgroupfd in addition
to pidfd per Christian König.
- New DMA_BUF_IOCTL_XFER_CHARGE ioctl for post-allocation charge
transfer on any dma-buf, not just dma-heap buffers per Christian König
and T.J. Mercier.
- Moved __GFP_ACCOUNT removal to patch 1 per Barry Song.
- dma-buf charge/uncharge helpers take struct dma_buf * directly
to avoid the need for caller to manage size calculations.
- Added test_xfer_charge_cgroupfd_self to dmabuf-heap selftests.
- Added LSM and SELinux hooks for cgroupfd-based charging.
- Rebased to v7.3-rc7.
- Link to v1: https://lore.kernel.org/r/20260512-v2_20230123_tjmercier_google_com-v1-0-63…
---
Albert Esteve (7):
dma-heap: charge dma-buf memory via explicit memcg
security: dma-buf: Add dma_buf_charge_task LSM hook
security: dma-buf: Add dma_buf_charge_cgroup LSM hook
selinux: Restrict cross-cgroup dma-buf charging
selinux: Restrict dma-buf direct cgroup charging
dma-buf: transfer memcg charges via DMA_BUF_IOCTL_XFER_CHARGE
selftests/dmabuf-heaps: Add dma-buf memcg accounting tests
T.J. Mercier (1):
memcg: Add MEMCG_DMABUF accounting infrastructure
Documentation/admin-guide/cgroup-v2.rst | 5 +
drivers/dma-buf/dma-buf.c | 46 ++++
drivers/dma-buf/dma-heap.c | 28 +-
drivers/dma-buf/heaps/cma_heap.c | 3 +-
drivers/dma-buf/heaps/system_heap.c | 22 +-
drivers/tee/tee_heap.c | 3 +-
include/linux/dma-buf.h | 9 +
include/linux/dma-heap.h | 3 +-
include/linux/lsm_hook_defs.h | 4 +
include/linux/memcontrol.h | 52 ++++
include/linux/security.h | 18 ++
include/uapi/linux/dma-buf.h | 26 ++
include/uapi/linux/dma-heap.h | 7 +
mm/memcontrol.c | 192 ++++++++++++++
security/security.c | 34 +++
security/selinux/hooks.c | 44 ++++
security/selinux/include/classmap.h | 1 +
tools/testing/selftests/cgroup/Makefile | 2 +-
tools/testing/selftests/cgroup/test_memcontrol.c | 290 ++++++++++++++++++++-
tools/testing/selftests/dmabuf-heaps/config | 1 +
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 227 +++++++++++++++-
tools/testing/selftests/dmabuf-heaps/vmtest.sh | 226 ++++++++++++++++
22 files changed, 1228 insertions(+), 15 deletions(-)
---
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
change-id: 20260508-v2_20230123_tjmercier_google_com-f44fcfb16530
Best regards,
--
Albert Esteve <aesteve(a)redhat.com>
This adds a driver on top of the rpmb subsystem for virtio-rpmb devices.
Alex Bennée had an earlier virtio-rpmb driver in his RPMB series [1]
but that stalled due to the user space API.
The one that merged later has no user space API and OP-TEE routes frames
through it so this driver only needs to implement route_frames().
I added patch 1 to fix a use-after-free that I hit while testing
removing the device (OP-TEE can still route frames after driver unregisters
the rpmb device).
I tested this with UML (virtio_uml) and a vhost-user backend I wrote
for this on top of rust-vmm's vhost-device with KASAN, lockdep:
- key programming
- write counter
- single and multi block write and read
- MAC and counter failures
- max_wr_cnt
- unbinding the driver when the rpmb device is held
With OP-TEE 4.11 on QEMU virt arm64 the secure_storage example TA keeps
its objects in RPMB through the driver and an object written to in one
boot is found in the one after.
I have added myself in MAINTAINERS. I would like to maintain the driver.
Changes in v3:
- Take a spinlock around the virtqueue operations, so the completion
callback can not call virtqueue_get_buf() while a new request is
added (sashiko)
- Do not delete the virtqueue twice when restore failed (sashiko)
- Explain the reliable_wr_count calculation in a comment
- v2: https://lore.kernel.org/all/20261029124132.2354314-1-harukak@zohomail.eu/
Changes in v2:
- Use guard() and scoped_guard() for the locks in both patches (Greg)
- Call virtio_device_ready() before vr->vq is set, so a request on
restore can not kick the queue before DRIVER_OK (sashiko)
- v1: https://lore.kernel.org/all/20261029081317.2264887-1-harukak@zohomail.eu/
- haruka
[1] https://lore.kernel.org/all/20220405093759.1126835-1-alex.bennee@linaro.org/
Haruka Kuze (2):
rpmb: stop the routing after unregister
rpmb: add a virtio RPMB device driver
MAINTAINERS | 7 +
drivers/misc/Kconfig | 10 ++
drivers/misc/Makefile | 1 +
drivers/misc/rpmb-core.c | 14 +-
drivers/misc/virtio_rpmb.c | 300 +++++++++++++++++++++++++++++++
include/linux/rpmb.h | 4 +
include/uapi/linux/virtio_rpmb.h | 56 ++++++
7 files changed, 391 insertions(+), 1 deletion(-)
create mode 100644 drivers/misc/virtio_rpmb.c
create mode 100644 include/uapi/linux/virtio_rpmb.h
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
--
2.55.0
This adds a driver on top of the rpmb subsystem for virtio-rpmb devices.
Alex Bennée had an earlier virtio-rpmb driver in his RPMB series [1]
but that stalled due to the user space API.
The one that merged later has no user space API and OP-TEE routes frames
through it so this driver only needs to implement route_frames().
I added patch 1 to fix a use-after-free that I hit while testing
removing the device (OP-TEE can still route frames after driver unregisters
the rpmb device).
I tested this with UML (virtio_uml) and a vhost-user backend I wrote
for this on top of rust-vmm's vhost-device with KASAN, lockdep:
- key programming
- write counter
- single and multi block write and read
- MAC and counter failures
- max_wr_cnt
- unbinding the driver when the rpmb device is held
With OP-TEE 4.11 on QEMU virt arm64 the secure_storage example TA keeps
its objects in RPMB through the driver and an object written to in one
boot is found in the one after.
I have added myself in MAINTAINERS. I would like to maintain the driver.
Changes in v2:
- Use guard() and scoped_guard() for the locks in both patches (Greg)
- Call virtio_device_ready() before vr->vq is set, so a request on
restore can not kick the queue before DRIVER_OK (sashiko)
- v1: https://lore.kernel.org/all/20261029081317.2264887-1-harukak@zohomail.eu/
- haruka
[1] https://lore.kernel.org/all/20220405093759.1126835-1-alex.bennee@linaro.org/
Haruka Kuze (2):
rpmb: stop the routing after unregister
rpmb: add a virtio RPMB device driver
MAINTAINERS | 7 +
drivers/misc/Kconfig | 10 ++
drivers/misc/Makefile | 1 +
drivers/misc/rpmb-core.c | 14 +-
drivers/misc/virtio_rpmb.c | 286 +++++++++++++++++++++++++++++++
include/linux/rpmb.h | 4 +
include/uapi/linux/virtio_rpmb.h | 56 ++++++
7 files changed, 377 insertions(+), 1 deletion(-)
create mode 100644 drivers/misc/virtio_rpmb.c
create mode 100644 include/uapi/linux/virtio_rpmb.h
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
--
2.55.0
This adds a driver on top of the rpmb subsystem for virtio-rpmb devices.
Alex Bennée had an earlier virtio-rpmb driver in his RPMB series [1]
but that stalled due to the user space API.
The one that merged later has no user space API and OP-TEE routes frames
through it so this driver only needs to implement route_frames().
I added patch 1 to fix a use-after-free that I hit while testing
removing the device (OP-TEE can still route frames after driver unregisters
the rpmb device).
I tested this with UML (virtio_uml) and a vhost-user backend I wrote
for this on top of rust-vmm's vhost-device with KASAN, lockdep:
- key programming
- write counter
- single and multi block write and read
- MAC and counter failures
- max_wr_cnt
- unbinding the driver when the rpmb device is held
With OP-TEE 4.11 on QEMU virt arm64 the secure_storage example TA keeps
its objects in RPMB through the driver and an object written to in one
boot is found in the one after.
I have added myself in MAINTAINERS. I would like to maintain the driver.
- haruka
[1] https://lore.kernel.org/all/20220405093759.1126835-1-alex.bennee@linaro.org/
Haruka Kuze (2):
rpmb: stop the routing after unregister
rpmb: add a virtio RPMB device driver
MAINTAINERS | 7 +
drivers/misc/Kconfig | 10 ++
drivers/misc/Makefile | 1 +
drivers/misc/rpmb-core.c | 22 ++-
drivers/misc/virtio_rpmb.c | 294 +++++++++++++++++++++++++++++++
include/linux/rpmb.h | 4 +
include/uapi/linux/virtio_rpmb.h | 56 ++++++
7 files changed, 391 insertions(+), 3 deletions(-)
create mode 100644 drivers/misc/virtio_rpmb.c
create mode 100644 include/uapi/linux/virtio_rpmb.h
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
--
2.55.0
From: Sumit Garg <sumit.garg(a)oss.qualcomm.com>
As per testing the SCM backend just ignores it while OP-TEE makes
use of it to for proper book keeping purpose.
Reviewed-by: Mukesh Ojha <mukesh.ojha(a)oss.qualcomm.com>
Tested-by: Mukesh Ojha <mukesh.ojha(a)oss.qualcomm.com> # Lemans
Reviewed-by: Vikash Garodia <vikash.garodia(a)oss.qualcomm.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio(a)oss.qualcomm.com>
Signed-off-by: Sumit Garg <sumit.garg(a)oss.qualcomm.com>
---
Changes in v10:
- Resent standalone, as all the earlier patches of the series are merged.
- Link to v9: https://lore.kernel.org/all/20260702115835.167602-11-sumit.garg@kernel.org/
---
drivers/media/platform/qcom/iris/iris_firmware.c | 2 +-
drivers/media/platform/qcom/venus/firmware.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/qcom/iris/iris_firmware.c b/drivers/media/platform/qcom/iris/iris_firmware.c
index 21f57d37da18..ed2bd0e83797 100644
--- a/drivers/media/platform/qcom/iris/iris_firmware.c
+++ b/drivers/media/platform/qcom/iris/iris_firmware.c
@@ -262,5 +262,5 @@ int iris_fw_unload(struct iris_core *core)
int iris_set_hw_state(struct iris_core *core, bool resume)
{
- return qcom_pas_set_remote_state(resume, 0);
+ return qcom_pas_set_remote_state(resume, IRIS_PAS_ID);
}
diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c
index 3a38ff985822..3c0727ea137d 100644
--- a/drivers/media/platform/qcom/venus/firmware.c
+++ b/drivers/media/platform/qcom/venus/firmware.c
@@ -59,7 +59,7 @@ int venus_set_hw_state(struct venus_core *core, bool resume)
int ret;
if (core->use_tz) {
- ret = qcom_pas_set_remote_state(resume, 0);
+ ret = qcom_pas_set_remote_state(resume, VENUS_PAS_ID);
if (resume && ret == -EINVAL)
ret = 0;
return ret;
---
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
change-id: 20261027-pas-id-media-7cc70fc5716f
Best regards,
--
Sumit Garg <sumit.garg(a)oss.qualcomm.com>
tee_dyn_shm_alloc_helper() passes the size from TEE_IOC_SHM_ALLOC to
alloc_pages_exact(), which needs one physically contiguous block. A size
above 4 MiB (MAX_PAGE_ORDER with 4 KiB pages) is more than the page
allocator can serve, so it trips its order warning; on a panic_on_warn
kernel that is a panic.
The size comes from userspace and the request fails with -ENOMEM anyway,
so pass __GFP_NOWARN.
Fixes: cf4441503e20 ("tee: optee: Move pool_op helper functions")
Cc: stable(a)vger.kernel.org
Cc: lvc-project(a)linuxtesting.org
Signed-off-by: Georgiy Osokin <g.osokin(a)auroraos.dev>
---
drivers/tee/tee_shm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index daa4af1..8b117d6 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -352,7 +352,7 @@ int tee_dyn_shm_alloc_helper(struct tee_shm *shm, size_t size, size_t align,
* and there's no need for any larger alignment.
*/
shm->kaddr = alloc_pages_exact(nr_pages * PAGE_SIZE,
- GFP_KERNEL | __GFP_ZERO);
+ GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN);
if (!shm->kaddr)
return -ENOMEM;
--
2.54.0
From: Christian Stefan Kövér-Draxl <ckoever(a)outlook.de>
The X98Q's vendor BL32 runs OP-TEE 3.8 and reports sec_caps 0x5, that is
HAVE_RESERVED_SHM | DYNAMIC_SHM, with neither UNREGISTERED_SHM nor
RPC_ARG.
For that combination optee_probe() picks the dynamic pool and sets
OPTEE_SHM_ARG_ALLOC_PRIV, so every message argument is an unregistered
private page passed to secure world by physical address via
OPTEE_SMC_CALL_WITH_ARG. This OP-TEE will not accept that: every call
comes back OPTEE_SMC_RETURN_EBADADDR (4), which optee_open_session()
converts into TEEC_ERROR_COMMUNICATION / TEEC_ORIGIN_COMMS. The result
is that no session can be opened at all - not to the Amlogic firmware
loading PTA the video decoder needs, and not to any built-in PTA either.
Registering memory works fine, and HAVE_RESERVED_SHM is set, so the
existing static pool path is usable. Add optee.no_dyn_shm to select it.
With the reserved pool the device enumeration PTA opens cleanly and the
system PTA answers with its own ACCESS_DENIED, so the ABI is healthy.
The driver arguably should not use unregistered arguments unless secure
world advertised UNREGISTERED_SHM; a parameter keeps the change local
until that is confirmed upstream.
Signed-off-by: Christian Stefan Kövér-Draxl <ckoever(a)outlook.de>
---
Tool use (Documentation/process/generated-content.rst):
This work was done with the help of an AI coding assistant, Claude
(Anthropic), used through Claude Code over many sessions. It did a large
part of the hands-on work: it read the vendor kernel and the firmware
interfaces, probed registers on the board, drafted the code and the
changelogs, and ran the builds, checkpatch, dt_binding_check and the
tests on the hardware. I directed the work, reviewed every change and
the final patches, and take responsibility for them. There is no single
prompt to quote; the sessions were of the form "find out why X fails on
this board, fix it, test it on the box".
Tested on an Amediatech X98Q TV box (Amlogic S905W2, S4 family, 2 GiB),
vendor U-Boot and BL31/OP-TEE, Linux 7.3 plus this work.
drivers/tee/optee/smc_abi.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
index 51624443359b..1824aead78a6 100644
--- a/drivers/tee/optee/smc_abi.c
+++ b/drivers/tee/optee/smc_abi.c
@@ -34,6 +34,11 @@
#define CREATE_TRACE_POINTS
#include "optee_trace.h"
+static bool optee_no_dyn_shm;
+module_param_named(no_dyn_shm, optee_no_dyn_shm, bool, 0444);
+MODULE_PARM_DESC(no_dyn_shm,
+ "Ignore the secure world's dynamic shared memory capability and use the reserved pool instead");
+
/*
* This file implement the SMC ABI used when communicating with secure world
* OP-TEE OS via raw SMCs.
@@ -1770,7 +1775,7 @@ static int optee_probe(struct platform_device *pdev)
/*
* Try to use dynamic shared memory if possible
*/
- if (sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) {
+ if ((sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) && !optee_no_dyn_shm) {
/*
* If we have OPTEE_SMC_SEC_CAP_RPC_ARG we can ask
* optee_get_msg_arg() to pre-register (by having
base-commit: 7be4bc52fd9e0e55dc9a2e0232b89427d2c4b614
--
2.56.0
Hi,
On Tuesday next week, it's time for another OP-TEE contributors' monthly
meeting. For time and connection details, see the calendar at
https://www.trustedfirmware.org/meetings/
We've released OP-TEE version 4.11.0 :-)
MbedTLS end-of-life April 2027:
https://lists.trustedfirmware.org/archives/list/mbed-tls@lists.trustedfirmw…
No urgent action needed. We can stick with MbedTLS for now, but we
can't maintain it.
CI updates and the way forward:
- Replaced the branch push trigger with a nightly CI job and a CI
status badge in the README.md
- Switch and renovate CI image https://github.com/OP-TEE/optee_os/pull/8021
I pushed the patches to a ci_testing branch in optee_os to give it a
spin and to generate the needed ci-image.
Rebased optee out-of-tree kernel patches on v7.3
optee_client for Zephyr, etc. https://github.com/OP-TEE/optee_client/issues/428
Any other topic?
Cheers,
Jens
Hi,
With the release out, it's a good time for changes. I've just rebased
the optee branch @ linaro-swg/kernel onto the latest kernel, v7.3.
Please let me know if there are any issues. The old branch is
reachable from the signed optee-4.11.0 tag.
Cheers,
Jens