* [PATCH RFC 0/2] Add support to display QTEE/OPTEE secure logs on Qualcomm platforms
@ 2026-12-01 22:33 Kuldeep Singh
2026-12-01 22:33 ` [PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs Kuldeep Singh
2026-12-01 22:33 ` [PATCH RFC 2/2] firmware: qcom: Add legacy QSEE secure log support Kuldeep Singh
0 siblings, 2 replies; 7+ messages in thread
From: Kuldeep Singh @ 2026-12-01 22:33 UTC (permalink / raw)
To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Dmitry Baryshkov
Cc: linux-kernel, linux-arm-msm, Kuldeep Singh
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@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs 2026-12-01 22:33 [PATCH RFC 0/2] Add support to display QTEE/OPTEE secure logs on Qualcomm platforms Kuldeep Singh @ 2026-12-01 22:33 ` Kuldeep Singh 2026-12-02 9:10 ` Konrad Dybcio 2026-12-01 22:33 ` [PATCH RFC 2/2] firmware: qcom: Add legacy QSEE secure log support Kuldeep Singh 1 sibling, 1 reply; 7+ messages in thread From: Kuldeep Singh @ 2026-12-01 22:33 UTC (permalink / raw) To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Dmitry Baryshkov Cc: linux-kernel, linux-arm-msm, Kuldeep Singh Define an interface to basically map TZ diag ocimem physical address as per soc family and ioremap further to map region for userspace access. The ocimem address is roughly same over targets(few possible values only) and hence, maintaining machine compatible list and size for target family. Signed-off-by: Kuldeep Singh <kuldeep.singh@oss.qualcomm.com> --- drivers/firmware/qcom/Kconfig | 8 ++ drivers/firmware/qcom/Makefile | 1 + drivers/firmware/qcom/qcom_secure_log.c | 228 ++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index 3ad22f8fc3e5..8ca173677c64 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -46,6 +46,14 @@ config QCOM_TZMEM_MODE_SHMBRIDGE 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. +config QCOM_SECURE_LOG + tristate "Qualcomm secure-world log userspace interface" + depends on ARCH_QCOM || COMPILE_TEST + help + Provide a provisional userspace ABI for Qualcomm secure-world log + buffers. Userspace is expected to mmap supported log regions and + parse the firmware log format. + config QCOM_QSEECOM bool "Qualcomm QSEECOM interface driver" depends on QCOM_SCM=y diff --git a/drivers/firmware/qcom/Makefile b/drivers/firmware/qcom/Makefile index 88ce74d74c3e..bec90e13d0cb 100644 --- a/drivers/firmware/qcom/Makefile +++ b/drivers/firmware/qcom/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_QCOM_SCM) += qcom-scm.o qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o CFLAGS_qcom_scm-smc.o := -I$(src) obj-$(CONFIG_QCOM_TZMEM) += qcom_tzmem.o +obj-$(CONFIG_QCOM_SECURE_LOG) += qcom_secure_log.o obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o obj-$(CONFIG_QCOM_PAS) += qcom_pas.o diff --git a/drivers/firmware/qcom/qcom_secure_log.c b/drivers/firmware/qcom/qcom_secure_log.c new file mode 100644 index 000000000000..7760ad46bd29 --- /dev/null +++ b/drivers/firmware/qcom/qcom_secure_log.c @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Qualcomm secure-world log userspace interface + * + * Copyright (c) 2026 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include <linux/fs.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/miscdevice.h> +#include <linux/mm.h> +#include <linux/module.h> +#include <linux/of.h> + +#define QCOM_SECURE_LOG_SIZE 0x3000 + +/** + * struct qcom_secure_log_config - target-specific secure log configuration + * @compatibles: NULL-terminated root machine compatible string list + * @imem_phys: physical IMEM address that stores the TZ diagnostic buffer base + * @size: TZ diagnostic buffer size + */ +struct qcom_secure_log_config { + const char * const *compatibles; + phys_addr_t imem_phys; + size_t size; +}; + +/** + * struct qcom_secure_log - secure-log device state + * @miscdev: userspace miscdevice + * @config: selected target-specific secure log configuration + * @imem_base: mapping of the IMEM pointer area + * @tz_diag_base: kernel mapping of the TZ diagnostic buffer + * @tz_diag_phys: physical start of the TZ diagnostic buffer + */ +struct qcom_secure_log { + struct miscdevice miscdev; + const struct qcom_secure_log_config *config; + void __iomem *imem_base; + void __iomem *tz_diag_base; + phys_addr_t tz_diag_phys; +}; + +static const char * const qcom_secure_log_c125720[] = { + "qcom,qcs8300", + NULL, +}; + +static const char * const qcom_secure_log_146bf720[] = { + "qcom,sm8150", + NULL, +}; + +static const char * const qcom_secure_log_14680720[] = { + "qcom,lanai", + "qcom,sm8750", + "qcom,kaanapali", + "qcom,hawi", + NULL, +}; + +static const char * const qcom_secure_log_146aa720[] = { + "qcom,qcm6490", + "qcom,hamoa", + NULL, +}; + +static const char * const qcom_secure_log_c11e720[] = { + "qcom,shikra", + NULL, +}; + +static const struct qcom_secure_log_config qcom_secure_log_configs[] = { + { + .compatibles = qcom_secure_log_c125720, + .imem_phys = 0x0c125720, + .size = QCOM_SECURE_LOG_SIZE, + }, + { + .compatibles = qcom_secure_log_146bf720, + .imem_phys = 0x146bf720, + .size = QCOM_SECURE_LOG_SIZE, + }, + { + .compatibles = qcom_secure_log_14680720, + .imem_phys = 0x14680720, + .size = QCOM_SECURE_LOG_SIZE, + }, + { + .compatibles = qcom_secure_log_146aa720, + .imem_phys = 0x146aa720, + .size = QCOM_SECURE_LOG_SIZE, + }, + { + .compatibles = qcom_secure_log_c11e720, + .imem_phys = 0x0c11e720, + .size = QCOM_SECURE_LOG_SIZE, + }, +}; + +static struct qcom_secure_log qcom_secure_log; + +static int qcom_secure_log_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct qcom_secure_log *log = container_of(file->private_data, + struct qcom_secure_log, + miscdev); + unsigned long size = vma->vm_end - vma->vm_start; + + if (vma->vm_flags & VM_WRITE) + return -EPERM; + + if (vma->vm_pgoff) + return -EINVAL; + + if (size != log->config->size) + return -EINVAL; + + vm_flags_clear(vma, VM_MAYWRITE); + vm_flags_set(vma, VM_IO | VM_DONTDUMP | VM_DONTEXPAND); + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + + return remap_pfn_range(vma, vma->vm_start, PHYS_PFN(log->tz_diag_phys), + size, vma->vm_page_prot); +} + +static const struct file_operations qcom_secure_log_fops = { + .owner = THIS_MODULE, + .mmap = qcom_secure_log_mmap, + .llseek = noop_llseek, +}; + +static const struct qcom_secure_log_config *qcom_secure_log_find_config(void) +{ + const struct qcom_secure_log_config *config; + const char * const *compatible; + int i; + + for (i = 0; i < ARRAY_SIZE(qcom_secure_log_configs); i++) { + config = &qcom_secure_log_configs[i]; + + for (compatible = config->compatibles; *compatible; compatible++) { + if (of_machine_is_compatible(*compatible)) + return config; + } + } + + return NULL; +} + +static int qcom_secure_log_init_tz_diag(struct qcom_secure_log *log) +{ + phys_addr_t tz_diag_phys; + + log->config = qcom_secure_log_find_config(); + if (!log->config) + return -ENODEV; + + log->imem_base = ioremap(log->config->imem_phys, log->config->size); + if (!log->imem_base) + return -ENOMEM; + + tz_diag_phys = readl_relaxed(log->imem_base); + if (!tz_diag_phys || !PAGE_ALIGNED(tz_diag_phys)) + goto err_unmap_imem; + + log->tz_diag_base = ioremap(tz_diag_phys, log->config->size); + if (!log->tz_diag_base) + goto err_unmap_imem; + + log->tz_diag_phys = tz_diag_phys; + + return 0; + +err_unmap_imem: + iounmap(log->imem_base); + log->imem_base = NULL; + return -ENODEV; +} + +static void qcom_secure_log_release_tz_diag(struct qcom_secure_log *log) +{ + if (log->tz_diag_base) + iounmap(log->tz_diag_base); + + if (log->imem_base) + iounmap(log->imem_base); +} + +static int __init qcom_secure_log_init(void) +{ + struct qcom_secure_log *log = &qcom_secure_log; + int ret; + + ret = qcom_secure_log_init_tz_diag(log); + if (ret) + goto err_release_tz_diag; + + log->miscdev.minor = MISC_DYNAMIC_MINOR; + log->miscdev.name = "secure_log"; + log->miscdev.fops = &qcom_secure_log_fops; + + ret = misc_register(&log->miscdev); + if (ret) + goto err_release_tz_diag; + + return 0; + +err_release_tz_diag: + qcom_secure_log_release_tz_diag(log); + return ret; +} + +static void __exit qcom_secure_log_exit(void) +{ + struct qcom_secure_log *log = &qcom_secure_log; + + misc_deregister(&log->miscdev); + qcom_secure_log_release_tz_diag(log); +} + +module_init(qcom_secure_log_init); +module_exit(qcom_secure_log_exit); + +MODULE_DESCRIPTION("Qualcomm TZ diagnostic log"); +MODULE_LICENSE("GPL"); -- 2.34.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs 2026-12-01 22:33 ` [PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs Kuldeep Singh @ 2026-12-02 9:10 ` Konrad Dybcio 2026-12-02 12:14 ` Kuldeep Singh 0 siblings, 1 reply; 7+ messages in thread From: Konrad Dybcio @ 2026-12-02 9:10 UTC (permalink / raw) To: Kuldeep Singh, Bjorn Andersson, Konrad Dybcio, Abel Vesa, Dmitry Baryshkov Cc: linux-kernel, linux-arm-msm On 12/1/26 11:33 PM, Kuldeep Singh wrote: > Define an interface to basically map TZ diag ocimem physical address as > per soc family and ioremap further to map region for userspace access. > The ocimem address is roughly same over targets(few possible values > only) and hence, maintaining machine compatible list and size for target > family. > > Signed-off-by: Kuldeep Singh <kuldeep.singh@oss.qualcomm.com> > --- [...] > +static const struct qcom_secure_log_config qcom_secure_log_configs[] = { > + { > + .compatibles = qcom_secure_log_c125720, > + .imem_phys = 0x0c125720, We already define IMEM in the dt - just grab a reference to a subnode of it (or better, bind the driver to it) Konrad ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs 2026-12-02 9:10 ` Konrad Dybcio @ 2026-12-02 12:14 ` Kuldeep Singh 0 siblings, 0 replies; 7+ messages in thread From: Kuldeep Singh @ 2026-12-02 12:14 UTC (permalink / raw) To: Konrad Dybcio, Bjorn Andersson, Konrad Dybcio, Abel Vesa, Dmitry Baryshkov Cc: linux-kernel, linux-arm-msm On 02-12-2026 14:40, Konrad Dybcio wrote: > On 12/1/26 11:33 PM, Kuldeep Singh wrote: >> Define an interface to basically map TZ diag ocimem physical address as >> per soc family and ioremap further to map region for userspace access. >> The ocimem address is roughly same over targets(few possible values >> only) and hence, maintaining machine compatible list and size for target >> family. >> >> Signed-off-by: Kuldeep Singh <kuldeep.singh@oss.qualcomm.com> >> --- > > [...] > >> +static const struct qcom_secure_log_config qcom_secure_log_configs[] = { >> + { >> + .compatibles = qcom_secure_log_c125720, >> + .imem_phys = 0x0c125720, > > We already define IMEM in the dt - just grab a reference to a subnode > of it (or better, bind the driver to it) Ahh, I see base imem addr is mentioned and need to add subnode for tz-diag base ptr for all targets. I can understand what's needed here. Let me update. Thanks!! Btw, can you please take a look at overall design mentioned in cover letter? I'll incorporate this piece. -- Regards Kuldeep ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH RFC 2/2] firmware: qcom: Add legacy QSEE secure log support 2026-12-01 22:33 [PATCH RFC 0/2] Add support to display QTEE/OPTEE secure logs on Qualcomm platforms Kuldeep Singh 2026-12-01 22:33 ` [PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs Kuldeep Singh @ 2026-12-01 22:33 ` Kuldeep Singh 2026-12-02 9:12 ` Konrad Dybcio 1 sibling, 1 reply; 7+ messages in thread From: Kuldeep Singh @ 2026-12-01 22:33 UTC (permalink / raw) To: Bjorn Andersson, Konrad Dybcio, Abel Vesa, Dmitry Baryshkov Cc: linux-kernel, linux-arm-msm, Kuldeep Singh QSee log(or TA log buffer) is owned by kernel and QTEE doesn't own of it's own. Implement new scm call to register this buffer with QTEE where QTEE maps buffer as RW and RO for kernel by imposing access restriction. The qsee log read mechanism is somewhat similar to reading TZ diag logs and be done in userspace. Signed-off-by: Kuldeep Singh <kuldeep.singh@oss.qualcomm.com> --- drivers/firmware/qcom/Kconfig | 1 + drivers/firmware/qcom/qcom_scm.c | 34 +++++ drivers/firmware/qcom/qcom_scm.h | 3 + drivers/firmware/qcom/qcom_secure_log.c | 237 +++++++++++++++++++++++++++----- include/linux/firmware/qcom/qcom_scm.h | 2 + 5 files changed, 241 insertions(+), 36 deletions(-) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index 8ca173677c64..5698cac9bb2a 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -49,6 +49,7 @@ config QCOM_TZMEM_MODE_SHMBRIDGE config QCOM_SECURE_LOG tristate "Qualcomm secure-world log userspace interface" depends on ARCH_QCOM || COMPILE_TEST + depends on QCOM_SCM || !QCOM_SCM help Provide a provisional userspace ABI for Qualcomm secure-world log buffers. Userspace is expected to mmap supported log regions and diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index fa94eaa020c3..3ae452b4e93e 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1099,6 +1099,40 @@ bool qcom_scm_restore_sec_cfg_available(void) } EXPORT_SYMBOL_GPL(qcom_scm_restore_sec_cfg_available); +/** + * qcom_scm_register_qsee_log_buf() - register a legacy QSEE log buffer + * @buf: physical address of the HLOS-owned log buffer + * @len: size of the log buffer + * + * Register a DMA/coherent buffer that secure firmware may use for legacy + * QSEE log output. The caller owns the buffer and must keep it alive while + * secure firmware may write to it. + * + * Return: 0 on success, negative errno on failure, or a positive firmware + * status value if firmware rejects the buffer. + */ +int qcom_scm_register_qsee_log_buf(phys_addr_t buf, size_t len) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_QSEELOG, + .cmd = QCOM_SCM_QSEELOG_REGISTER, + .owner = ARM_SMCCC_OWNER_TRUSTED_OS, + .args[0] = buf, + .args[1] = len, + .arginfo = QCOM_SCM_ARGS(2, QCOM_SCM_RW, QCOM_SCM_VAL), + }; + struct qcom_scm_res res; + int ret; + + if (!len) + return -EINVAL; + + ret = qcom_scm_call(__scm->dev, &desc, &res); + + return ret ? : res.result[0]; +} +EXPORT_SYMBOL_GPL(qcom_scm_register_qsee_log_buf); + int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare) { struct qcom_scm_desc desc = { diff --git a/drivers/firmware/qcom/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h index cf90a565fdfb..d3d18041881a 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -111,6 +111,9 @@ int qcom_scm_shm_bridge_enable(struct device *scm_dev); #define QCOM_SCM_IO_READ 0x01 #define QCOM_SCM_IO_WRITE 0x02 +#define QCOM_SCM_SVC_QSEELOG 0x01 +#define QCOM_SCM_QSEELOG_REGISTER 0x06 + #define QCOM_SCM_SVC_INFO 0x06 #define QCOM_SCM_INFO_IS_CALL_AVAIL 0x01 diff --git a/drivers/firmware/qcom/qcom_secure_log.c b/drivers/firmware/qcom/qcom_secure_log.c index 7760ad46bd29..1e0c8de753b3 100644 --- a/drivers/firmware/qcom/qcom_secure_log.c +++ b/drivers/firmware/qcom/qcom_secure_log.c @@ -6,14 +6,21 @@ */ #include <linux/fs.h> +#include <linux/dma-mapping.h> #include <linux/io.h> #include <linux/kernel.h> #include <linux/miscdevice.h> #include <linux/mm.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/sizes.h> +#include <linux/slab.h> + +#include <linux/firmware/qcom/qcom_scm.h> #define QCOM_SECURE_LOG_SIZE 0x3000 +#define QCOM_QSEE_LOG_SIZE SZ_128K /** * struct qcom_secure_log_config - target-specific secure log configuration @@ -34,6 +41,14 @@ struct qcom_secure_log_config { * @imem_base: mapping of the IMEM pointer area * @tz_diag_base: kernel mapping of the TZ diagnostic buffer * @tz_diag_phys: physical start of the TZ diagnostic buffer + * @qsee_miscdev: userspace miscdevice for the legacy QSEE log buffer + * @qsee_pdev: device owning the QSEE DMA allocation + * @qsee_dev: device used for QSEE DMA allocation + * @qsee_buf: CPU mapping of the coherent QSEE log buffer + * @qsee_dma: DMA/physical address registered with secure firmware + * @qsee_size: QSEE log buffer size + * @tz_registered: true after the TZ diagnostic miscdevice is registered + * @qsee_registered: true after the QSEE miscdevice is registered */ struct qcom_secure_log { struct miscdevice miscdev; @@ -41,6 +56,14 @@ struct qcom_secure_log { void __iomem *imem_base; void __iomem *tz_diag_base; phys_addr_t tz_diag_phys; + struct miscdevice qsee_miscdev; + struct platform_device *qsee_pdev; + struct device *qsee_dev; + void *qsee_buf; + dma_addr_t qsee_dma; + size_t qsee_size; + bool tz_registered; + bool qsee_registered; }; static const char * const qcom_secure_log_c125720[] = { @@ -102,36 +125,6 @@ static const struct qcom_secure_log_config qcom_secure_log_configs[] = { static struct qcom_secure_log qcom_secure_log; -static int qcom_secure_log_mmap(struct file *file, struct vm_area_struct *vma) -{ - struct qcom_secure_log *log = container_of(file->private_data, - struct qcom_secure_log, - miscdev); - unsigned long size = vma->vm_end - vma->vm_start; - - if (vma->vm_flags & VM_WRITE) - return -EPERM; - - if (vma->vm_pgoff) - return -EINVAL; - - if (size != log->config->size) - return -EINVAL; - - vm_flags_clear(vma, VM_MAYWRITE); - vm_flags_set(vma, VM_IO | VM_DONTDUMP | VM_DONTEXPAND); - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - - return remap_pfn_range(vma, vma->vm_start, PHYS_PFN(log->tz_diag_phys), - size, vma->vm_page_prot); -} - -static const struct file_operations qcom_secure_log_fops = { - .owner = THIS_MODULE, - .mmap = qcom_secure_log_mmap, - .llseek = noop_llseek, -}; - static const struct qcom_secure_log_config *qcom_secure_log_find_config(void) { const struct qcom_secure_log_config *config; @@ -150,6 +143,26 @@ static const struct qcom_secure_log_config *qcom_secure_log_find_config(void) return NULL; } +static int qcom_secure_log_map_readonly(struct vm_area_struct *vma, + size_t expected_size) +{ + unsigned long size = vma->vm_end - vma->vm_start; + + if (vma->vm_flags & VM_WRITE) + return -EPERM; + + if (vma->vm_pgoff) + return -EINVAL; + + if (size != expected_size) + return -EINVAL; + + vm_flags_clear(vma, VM_MAYWRITE); + vm_flags_set(vma, VM_DONTDUMP | VM_DONTEXPAND); + + return 0; +} + static int qcom_secure_log_init_tz_diag(struct qcom_secure_log *log) { phys_addr_t tz_diag_phys; @@ -180,6 +193,53 @@ static int qcom_secure_log_init_tz_diag(struct qcom_secure_log *log) return -ENODEV; } +static int qcom_secure_log_tz_mmap(struct file *file, + struct vm_area_struct *vma) +{ + struct qcom_secure_log *log = container_of(file->private_data, + struct qcom_secure_log, + miscdev); + int ret; + + ret = qcom_secure_log_map_readonly(vma, log->config->size); + if (ret) + return ret; + + vm_flags_set(vma, VM_IO); + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + + return remap_pfn_range(vma, vma->vm_start, PHYS_PFN(log->tz_diag_phys), + log->config->size, vma->vm_page_prot); +} + +static int qcom_secure_log_qsee_mmap(struct file *file, + struct vm_area_struct *vma) +{ + struct qcom_secure_log *log = container_of(file->private_data, + struct qcom_secure_log, + qsee_miscdev); + int ret; + + ret = qcom_secure_log_map_readonly(vma, log->qsee_size); + if (ret) + return ret; + + return dma_mmap_coherent(log->qsee_dev, vma, log->qsee_buf, log->qsee_dma, + log->qsee_size); +} + +static const struct file_operations qcom_secure_log_tz_fops = { + .owner = THIS_MODULE, + .mmap = qcom_secure_log_tz_mmap, + .llseek = noop_llseek, +}; + +static const struct file_operations qcom_secure_log_qsee_fops = { + .owner = THIS_MODULE, + .mmap = qcom_secure_log_qsee_mmap, + .llseek = noop_llseek, +}; + static void qcom_secure_log_release_tz_diag(struct qcom_secure_log *log) { if (log->tz_diag_base) @@ -189,23 +249,24 @@ static void qcom_secure_log_release_tz_diag(struct qcom_secure_log *log) iounmap(log->imem_base); } -static int __init qcom_secure_log_init(void) +static int qcom_secure_log_register_tz(struct qcom_secure_log *log) { - struct qcom_secure_log *log = &qcom_secure_log; int ret; ret = qcom_secure_log_init_tz_diag(log); if (ret) - goto err_release_tz_diag; + return ret; log->miscdev.minor = MISC_DYNAMIC_MINOR; log->miscdev.name = "secure_log"; - log->miscdev.fops = &qcom_secure_log_fops; + log->miscdev.fops = &qcom_secure_log_tz_fops; ret = misc_register(&log->miscdev); if (ret) goto err_release_tz_diag; + log->tz_registered = true; + return 0; err_release_tz_diag: @@ -213,16 +274,120 @@ static int __init qcom_secure_log_init(void) return ret; } +static void qcom_secure_log_release_qsee(struct qcom_secure_log *log) +{ + if (log->qsee_registered) { + misc_deregister(&log->qsee_miscdev); + log->qsee_registered = false; + } + + if (log->qsee_buf) { + dma_free_coherent(log->qsee_dev, log->qsee_size, log->qsee_buf, + log->qsee_dma); + log->qsee_buf = NULL; + log->qsee_dma = 0; + log->qsee_dev = NULL; + } + + if (log->qsee_pdev) { + platform_device_unregister(log->qsee_pdev); + log->qsee_pdev = NULL; + } +} + +static int qcom_secure_log_register_qsee(struct qcom_secure_log *log) +{ + struct platform_device *pdev; + int ret; + + if (!qcom_scm_is_available()) + return -ENODEV; + + pdev = platform_device_register_simple("qcom-secure-log-qsee", -1, + NULL, 0); + if (IS_ERR(pdev)) + return PTR_ERR(pdev); + + log->qsee_pdev = pdev; + log->qsee_dev = &pdev->dev; + + ret = dma_set_mask_and_coherent(log->qsee_dev, DMA_BIT_MASK(64)); + if (ret) + ret = dma_set_mask_and_coherent(log->qsee_dev, DMA_BIT_MASK(32)); + if (ret) + goto err_release_qsee; + + log->qsee_size = QCOM_QSEE_LOG_SIZE; + log->qsee_buf = dma_alloc_coherent(log->qsee_dev, log->qsee_size, + &log->qsee_dma, GFP_KERNEL); + if (!log->qsee_buf) { + ret = -ENOMEM; + goto err_release_qsee; + } + + memset(log->qsee_buf, 0, log->qsee_size); + + ret = qcom_scm_register_qsee_log_buf(log->qsee_dma, log->qsee_size); + if (ret) + goto err_release_qsee; + + log->qsee_miscdev.minor = MISC_DYNAMIC_MINOR; + log->qsee_miscdev.name = "qsee_log"; + log->qsee_miscdev.fops = &qcom_secure_log_qsee_fops; + + ret = misc_register(&log->qsee_miscdev); + if (ret) + goto err_release_qsee; + + log->qsee_registered = true; + + return 0; + +err_release_qsee: + qcom_secure_log_release_qsee(log); + return ret; +} + +static int __init qcom_secure_log_init(void) +{ + struct qcom_secure_log *log = &qcom_secure_log; + int ret; + + ret = qcom_secure_log_register_tz(log); + if (ret && ret != -ENODEV) + return ret; + + ret = qcom_secure_log_register_qsee(log); + if (ret && ret != -ENODEV) + goto err_release_tz; + + return 0; + +err_release_tz: + if (log->tz_registered) { + misc_deregister(&log->miscdev); + log->tz_registered = false; + } + qcom_secure_log_release_tz_diag(log); + return ret; +} + static void __exit qcom_secure_log_exit(void) { struct qcom_secure_log *log = &qcom_secure_log; - misc_deregister(&log->miscdev); + qcom_secure_log_release_qsee(log); + + if (log->tz_registered) { + misc_deregister(&log->miscdev); + log->tz_registered = false; + } + qcom_secure_log_release_tz_diag(log); } module_init(qcom_secure_log_init); module_exit(qcom_secure_log_exit); -MODULE_DESCRIPTION("Qualcomm TZ diagnostic log"); +MODULE_DESCRIPTION("Qualcomm secure-world log interface"); MODULE_LICENSE("GPL"); diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h index a0a6bc0229c4..f73664132e05 100644 --- a/include/linux/firmware/qcom/qcom_scm.h +++ b/include/linux/firmware/qcom/qcom_scm.h @@ -61,6 +61,8 @@ enum qcom_scm_ice_cipher { bool qcom_scm_is_available(void); +int qcom_scm_register_qsee_log_buf(phys_addr_t buf, size_t len); + int qcom_scm_set_cold_boot_addr(void *entry); int qcom_scm_set_warm_boot_addr(void *entry); void qcom_scm_cpu_power_down(u32 flags); -- 2.34.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC 2/2] firmware: qcom: Add legacy QSEE secure log support 2026-12-01 22:33 ` [PATCH RFC 2/2] firmware: qcom: Add legacy QSEE secure log support Kuldeep Singh @ 2026-12-02 9:12 ` Konrad Dybcio 2026-12-02 12:15 ` Kuldeep Singh 0 siblings, 1 reply; 7+ messages in thread From: Konrad Dybcio @ 2026-12-02 9:12 UTC (permalink / raw) To: Kuldeep Singh, Bjorn Andersson, Konrad Dybcio, Abel Vesa, Dmitry Baryshkov Cc: linux-kernel, linux-arm-msm On 12/1/26 11:33 PM, Kuldeep Singh wrote: > QSee log(or TA log buffer) is owned by kernel and QTEE doesn't own of > it's own. Implement new scm call to register this buffer with QTEE where > QTEE maps buffer as RW and RO for kernel by imposing access restriction. > > The qsee log read mechanism is somewhat similar to reading TZ diag logs > and be done in userspace. > > Signed-off-by: Kuldeep Singh <kuldeep.singh@oss.qualcomm.com> > --- [...] > -static int qcom_secure_log_mmap(struct file *file, struct vm_area_struct *vma) > -{ > - struct qcom_secure_log *log = container_of(file->private_data, > - struct qcom_secure_log, > - miscdev); Please massage patch 1 to more closely reflect the final state of this file (renames, placement etc.) so that this diff ends up being smaller [...] > -MODULE_DESCRIPTION("Qualcomm TZ diagnostic log"); > +MODULE_DESCRIPTION("Qualcomm secure-world log interface"); This is also something p1 should get right Konrad ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH RFC 2/2] firmware: qcom: Add legacy QSEE secure log support 2026-12-02 9:12 ` Konrad Dybcio @ 2026-12-02 12:15 ` Kuldeep Singh 0 siblings, 0 replies; 7+ messages in thread From: Kuldeep Singh @ 2026-12-02 12:15 UTC (permalink / raw) To: Konrad Dybcio, Bjorn Andersson, Konrad Dybcio, Abel Vesa, Dmitry Baryshkov Cc: linux-kernel, linux-arm-msm On 02-12-2026 14:42, Konrad Dybcio wrote: > On 12/1/26 11:33 PM, Kuldeep Singh wrote: >> QSee log(or TA log buffer) is owned by kernel and QTEE doesn't own of >> it's own. Implement new scm call to register this buffer with QTEE where >> QTEE maps buffer as RW and RO for kernel by imposing access restriction. >> >> The qsee log read mechanism is somewhat similar to reading TZ diag logs >> and be done in userspace. >> >> Signed-off-by: Kuldeep Singh <kuldeep.singh@oss.qualcomm.com> >> --- > > [...] > >> -static int qcom_secure_log_mmap(struct file *file, struct vm_area_struct *vma) >> -{ >> - struct qcom_secure_log *log = container_of(file->private_data, >> - struct qcom_secure_log, >> - miscdev); > > Please massage patch 1 to more closely reflect the final state of > this file (renames, placement etc.) so that this diff ends up being > smaller My bad! It's renaming functions and adding more diff. I'll reduce the churn in next rev. -- Regards Kuldeep ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-02 12:15 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-12-01 22:33 [PATCH RFC 0/2] Add support to display QTEE/OPTEE secure logs on Qualcomm platforms Kuldeep Singh 2026-12-01 22:33 ` [PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs Kuldeep Singh 2026-12-02 9:10 ` Konrad Dybcio 2026-12-02 12:14 ` Kuldeep Singh 2026-12-01 22:33 ` [PATCH RFC 2/2] firmware: qcom: Add legacy QSEE secure log support Kuldeep Singh 2026-12-02 9:12 ` Konrad Dybcio 2026-12-02 12:15 ` Kuldeep Singh
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®