[PATCH RFC 0/2] Add support to display QTEE/OPTEE secure logs on Qualcomm platforms

From: Kuldeep Singh

Date: Tue Dec 01 2026 - 17:34:16 EST


Hi,

This RFC explores an approach for retrieving diagnostic logs produced by
Qualcomm secure firmware while keeping firmware-specific log parsing
outside the kernel. This logging mechanism will be able to dump TZ/QSEE
logs for QTEE(COTS devices and upcoming) and for OPTEE enabled
devices(TZ diag only).

There are two classes of logs considered here:

- TZ diagnostic logs
- QSEE logs

The two log sources have different buffer ownership and discovery
models. In addition, QSEE logs can be made available through different
interfaces depending on the capabilities provided by the secure
firmware.

The intent of this RFC is therefore not to introduce a common logging
transport. Instead, existing kernel mechanisms are used to provide
controlled access to the underlying buffers, while userspace handles
the firmware-specific log format.

The proposed model is:

Secure firmware (QTEE)
/ \
/ \
TZ diagnostic QSEE
logs logs
| / \
| / \
firmware-owned legacy SCM CSecureLog
buffer | IDL
| | |
existing Kernel QCOMTEE MO
discovery(Kernel) buffer |
| | TEE
| | |
+--------------+-----------+
|
userspace
|
parse / format /
persist

Please go through below information first, to refer how userspace
implementation looks like:

https://github.com/qualcomm/minkipc/pull/125/changes

Please note, not doing complete implementation in the series as wanted
to hear early feedback on design and then conclude on final set of
changes. The series is compiled tested to display an overall design
idea.

Also, taken LLM assistance for the current implementation.

1. TZ diagnostic logs
=====================

The TZ diagnostic buffer is owned and populated by secure firmware.
Secure firmware publishes the physical address of the diagnostic region
through a known location in OCIMEM memory.

First, HLOS maps the corresponding OCIMEM location:

OCIMEM
|
+------------------------+
| TZ diagnostic pointer |
+------------------------+
|
readl()
|
v
diagnostic buffer PA

The value read from this location is the physical address of the
firmware-owned TZ diagnostic region. HLOS then maps that second region:

diagnostic buffer PA
|
ioremap()
|
v
+-------------------------+
| TZ diagnostic metadata |
| |
| ring state |
| |
| TZ diagnostic log data |
+-------------------------+
^
|
TZ/QTEE writes

The complete discovery path is therefore:

known OCIMEM location
|
first ioremap()
|
readl()
|
v
TZ diagnostic PA
|
second ioremap()
|
v
TZ diagnostic region

The first mapping is used only to discover the physical address of the
diagnostic region. It is not the log buffer itself.
The second mapping provides access to the actual diagnostic region
populated by secure firmware.

After locating and validating the diagnostic region, the proposed
kernel interface provides controlled read-only access to the actual
diagnostic region:

TZ/QTEE
|
writes logs
|
v
TZ diagnostic region
|
kernel mapping
|
controlled RO access
|
v
userspace
|
TZ diagnostic parser
|
console / file

Capturing tz diag base address in kernel is needed as userpsace cannot
map physical to virtual address. Kernel will basically do necessary
mapping and share memory via mmap to userspace for log dump logic etc.

Userspace is not given access to the OCIMEM pointer location. It only
gets access to the validated diagnostic region containing the
firmware-generated data.

The kernel therefore needs to understand only the discovery mechanism
and the boundaries and memory attributes of the diagnostic region. It
does not need to understand the TZ diagnostic header, ring-buffer
producer state, wrap handling, or individual diagnostic records.

Please note, Optee-os contains logs at same physical region and hence,
this feature interface can be reused to display optee-os logs too.

2. Legacy QSEE logging through SCM
==================================

Secure firmware also provides the register_qsee_log_buf SCM interface
over qcom_scm driver.

For this mechanism HLOS allocates the QSEE log buffer and registers the
physical buffer with secure firmware.

Conceptually:

kernel
|
allocate QSEE
log buffer
|
v
+-----------------+
| QSEE log buffer |
+-----------------+
|
register_qsee_log_buf
SCM call
|
v
TZ/QSEE
|
writes logs
|
v
+-----------------+
| same HLOS-owned |
| buffer |
+-----------------+
|
read-only access
|
v
userspace
|
parse / display

The kernel owns the buffer in this case because its address and
lifetime are provided directly to secure firmware through the SCM ABI.

The corresponding kernel driver therefore needs to:

- allocate memory satisfying the SCM ABI requirements;
- register its address and size with secure firmware;
- retain the memory for as long as firmware can access it;
- perform any required synchronization for secure-world writes; and
- provide controlled read-only access to a userspace consumer.

The kernel does not parse the QSEE log-buffer format.

3. QSEE/secure logging through CSecureLog idl interface
=======================================================

Some QTEE firmware versions provide a QCOMTEE CSecureLog IDL service.

This is a separate mechanism from register_qsee_log_buf and should not
be implemented on top of the legacy SCM registration call.

When CSecureLog is available, userspace can create a memory object using
the existing QCOMTEE memory-object infrastructure and provide that object
to the CSecureLog service using the QCOMTEE/SMCInvoke interface.

Conceptually:

userspace
|
create QCOMTEE
memory object
|
v
+----------------+
| shared MO |
+----------------+
|
CSecureLog IDL
via SMCInvoke
|
v
QTEE
|
registers/maps
the MO
|
writes logs
|
v
+----------------+
| same shared MO |
+----------------+
|
userspace
|
parse / display

No register_qsee_log_buf SCM call is involved in this path.

Support for this path is conditional on the corresponding service being
provided by the QTEE firmware.

4. Kernel/userspace boundary
============================

Although the buffers are obtained differently, the same responsibility
split is proposed for all of them.

Kernel responsibilities:
- allocate and register the QSEE buffer when the legacy SCM ABI is
used;
- provide QCOMTEE memory-object and SMCInvoke mechanisms where the
CSecureLog service is used;
- maintain memory lifetime and access permissions;
- perform the required memory/DMA synchronization;

Userspace responsibilities:
- understand TZ and QSEE diagnostic buffer formats;
- validate firmware-specific headers;
- track producer/consumer positions;
- handle ring-buffer wrapping and overwritten data;
- format individual diagnostic records;
- select whether logs are printed, persisted or forwarded.

The goal is to keep the kernel independent of the firmware diagnostic
record formats.

5. Why not implement log parser in the kernel?
==============================================

The buffers contain diagnostic information rather than kernel-owned
state.

Parsing the logs in the kernel would require Linux to understand and
maintain firmware-specific details including:

- diagnostic format versions;
- TZ/QSEE header layouts;
- producer state;
- ring-buffer wrapping;
- individual diagnostic record formats;
- differences between firmware revisions.

These operations do not inherently require kernel privilege.

Keeping the parser in userspace leaves the kernel responsible for the
operations which do require it: physical memory access, SCM calls,
QCOMTEE memory sharing, memory lifetime, permissions and secure-world
notification.

It also avoids making each firmware diagnostic format part of the
kernel implementation.

6. Can use same /dev/secure_log interface for TZ and QSEE logs?
===========================================================

One approach can be to expose log source through a single interface such
as /dev/secure_log for both logs i.e TZ and QSEE logs.

However, the buffers have substantially different ownership models:

TZ diagnostic log:

secure firmware owns memory
|
HLOS discovers it

legacy QSEE log:/CSecureLog

kernel owns memory
|
Kernel registers memory with QTEE
|
QTEE will write content in buffer and userspace will read.

Forcing all three mechanisms behind another common character-device
UAPI adds an abstraction without removing these underlying lifetime
and ownership differences.

This RFC therefore tries to reuse the existing SCM and QCOMTEE
interfaces rather than introducing a new common secure-log transport.

The legacy TZ and QSEE cases may still require a restricted userspace
interface because their buffers are not originally userspace-owned.

Keeping different nodes for TZ diag and QSEE logs for time being as it's
in discussion phase.

7. Notification(Future)
======================

Access to a shared buffer and notification of new data are separate
problems.

Mapping or otherwise exposing a log buffer allows userspace to read it,
but does not tell userspace when secure firmware has produced new data.

For existing firmware an explicit log notification may not be
available.

In that case userspace can either:

- periodically inspect the producer state; or
- where appropriate, use relevant QCOMTEE activity as an opportunity
to inspect the buffer again.

A secure call or callback completion must not be interpreted as
guaranteeing that new log data exists.

After any such trigger userspace still checks the producer state in the
shared buffer.

For RFC, didn't implement notification interface and would rather do
polling to get logs for specific duration. This can be scaled in future
to even write logs to a file right after bootup and create daemon to
basically let kernel notify userspace about new log activity in tz/qsee
buffers.

8. Future FF-A support
======================

Certain QTEE firmware versions support required FF-A shared-memory and
notification functionality, secure logging can become event driven.

Conceptually:

HLOS
|
shared memory
|
FF-A sharing
|
v
QTEE
|
writes logs
|
notification /
doorbell
|
v
kernel
|
wake userspace
|
v
userspace
|
parse buffer

This separates the two paths cleanly:

data:

QTEE -> shared memory -> userspace

notification:

QTEE -> FF-A notification -> kernel -> userspace

This RFC does not implement the FF-A mechanism. The exact sharing and
notification semantics should be defined against firmware providing
the corresponding functionality rather than introducing speculative
kernel interfaces.

9. Resulting capability model
=============================

The resulting architecture is:

Secure logs
|
+--------------+--------------+
| |
TZ logs QSEE logs
| |
firmware-owned +----------+----------+
diag buffer | |
| legacy SCM CSecureLog
| | |
existing discovery kernel buffer userspace MO
| | |
| register_qsee_log_buf QCOMTEE /
| | SMCInvoke
| | |
+-----------------+---------------------+
|
userspace
|
firmware parser
|
+-------+-------+
| |
console file/etc.

|
future capability:
|
FF-A + notification
|
event-driven wakeup

10. Questions for discussion
=============================

I would appreciate feedback on the following:

1. Is keeping the firmware-specific TZ/QSEE ring-buffer parsing in
userspace the appropriate kernel/userspace boundary?

2. What would be the preferred upstream mechanism for controlled,
read-only access to the existing firmware-owned TZ diagnostic
buffer?

3. For firmware using register_qsee_log_buf, is an HLOS-owned buffer
managed by a small kernel driver and exposed read-only to userspace
an acceptable model?

Really appreciate feedback on series and suggestions/improvements etc.
Please let me know if something unclear or better way to portrait the
design.

Thanks,
Kuldeep Singh

---
Kuldeep Singh (2):
firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs
firmware: qcom: Add legacy QSEE secure log support

drivers/firmware/qcom/Kconfig | 9 +
drivers/firmware/qcom/Makefile | 1 +
drivers/firmware/qcom/qcom_scm.c | 34 +++
drivers/firmware/qcom/qcom_scm.h | 3 +
drivers/firmware/qcom/qcom_secure_log.c | 393 ++++++++++++++++++++++++++++++++
include/linux/firmware/qcom/qcom_scm.h | 2 +
6 files changed, 442 insertions(+)
---
base-commit: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8
change-id: 20261202-qcom_secure_log_rfc-304aed95b6b4

Best regards,
--
Kuldeep Singh <kuldeep.singh@xxxxxxxxxxxxxxxx>