On 18/11/2026 08:02, Jie Gan wrote:
> Introduce functions for creating and inserting or removing the
> etr_buf_node to/from the etr_buf_list.
>
> The byte-cntr functionality requires two etr_buf to receive trace data.
> The active etr_buf collects the trace data from source device, while the
> byte-cntr reading function accesses the deactivated etr_buf after is
> has been filled and synced, transferring data to the userspace.
>
> Reviewed-by: Mike Leach <mike.leach(a)arm.com>
> Signed-off-by: Jie Gan <jie.gan(a)oss.qualcomm.com>
> ---
> drivers/hwtracing/coresight/coresight-tmc-core.c | 1 +
> drivers/hwtracing/coresight/coresight-tmc-etr.c | 205 ++++++++++++++++++++++-
> drivers/hwtracing/coresight/coresight-tmc.h | 18 ++
> 3 files changed, 222 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
> index bc5a133ada3e..bc7dd676da47 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc-core.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
> @@ -835,6 +835,7 @@ static int __tmc_probe(struct device *dev, struct resource *res)
> idr_init(&drvdata->idr);
> mutex_init(&drvdata->idr_mutex);
> dev_list = "tmc_etr";
> + INIT_LIST_HEAD(&drvdata->etr_buf_list);
> break;
> case TMC_CONFIG_TYPE_ETF:
> desc.groups = coresight_etf_groups;
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> index 361a433e6f0c..e9213f456834 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> @@ -1268,7 +1268,9 @@ static struct etr_buf *tmc_etr_get_sysfs_buffer(struct coresight_device *csdev)
> raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> }
>
> - if (drvdata->reading || coresight_get_mode(csdev) == CS_MODE_PERF) {
> + /* The sysfs_buf is owned by the etr_buf_list, don't replace it */
> + if (drvdata->reading || coresight_get_mode(csdev) == CS_MODE_PERF ||
> + !list_empty(&drvdata->etr_buf_list)) {
> ret = -EBUSY;
> goto out;
> }
> @@ -1918,6 +1920,204 @@ const struct coresight_ops tmc_etr_cs_ops = {
> .panic_ops = &tmc_etr_sync_ops,
> };
>
> +/* Remove the nodes of the list, the buffer @keep is never freed. */
> +static void __tmc_clean_etr_buf_list(struct tmc_drvdata *drvdata,
> + struct etr_buf *keep)
> +{
> + struct etr_buf_node *nd, *next;
> + unsigned long flags;
> +
> + list_for_each_entry_safe(nd, next, &drvdata->etr_buf_list, link) {
> + raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> + if (keep && nd->sysfs_buf == keep) {
> + /*
> + * The buffer is owned by drvdata->sysfs_buf and may hold
> + * the captured trace data, whatever the mode of the sink
> + * is now. Only drop the list's reference to it.
> + */
> + nd->sysfs_buf = NULL;
> + } else if (nd->sysfs_buf == drvdata->sysfs_buf) {
> + if (coresight_get_mode(drvdata->csdev) == CS_MODE_SYSFS)
> + /*
> + * The sink is still enabled in sysfs mode. Keep
> + * the live buffer owned by drvdata->sysfs_buf
> + * and only drop the list's reference to it.
> + */
> + nd->sysfs_buf = NULL;
> + else
> + /* Free the buffer below through nd->sysfs_buf */
> + drvdata->sysfs_buf = NULL;
> + }
> + list_del(&nd->link);
> + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
> +
> + /* Free the buffer (NULL is ignored) and the node out of the lock */
> + tmc_etr_free_sysfs_buf(nd->sysfs_buf);
> + kfree(nd);
> + }
> +}
> +
> +/**
> + * tmc_clean_etr_buf_list - clean the etr_buf_list.
> + * @drvdata: driver data of the TMC device.
> + *
> + * Remove all nodes from @drvdata->etr_buf_list and free their buffers.
> + * If a node holds the live sysfs_buf and the sink is enabled in sysfs mode, the
> + * node is removed but the buffer is not freed; ownership stays with
> + * drvdata->sysfs_buf.
> + *
> + * Locking: must not be called with @drvdata->spinlock held. The spinlock is
> + * taken internally to serialise the @drvdata->sysfs_buf accesses and the
> + * removal of the nodes against the ETR sink enable/disable paths and the
> + * generic sysfs read. There must be only one owner of the list at a time.
> + * Must be called from process context: buffers are freed with the lock
> + * released.
> + */
> +void tmc_clean_etr_buf_list(struct tmc_drvdata *drvdata)
> +{
> + __tmc_clean_etr_buf_list(drvdata, NULL);
> +}
> +EXPORT_SYMBOL_GPL(tmc_clean_etr_buf_list);
> +
> +/**
> + * tmc_create_etr_buf_list - create a list to manage the etr_buf_node.
> + * @drvdata: driver data of the TMC device.
> + * @num_nodes: number of nodes want to create with the list.
> + *
> + * Locking: must not be called with @drvdata->spinlock held. The spinlock is
> + * taken internally to serialise the @drvdata->sysfs_buf accesses and every
> + * update of @drvdata->etr_buf_list against the ETR sink enable/disable paths
> + * and the generic sysfs read. There must be only one owner of the list at a
> + * time. Must be called from process context: buffers and nodes are allocated
> + * with the lock released.
> + *
> + * Return: 0 upon success, else the error number: -EBUSY if a generic sysfs
> + * read is in progress, -EINVAL if the sink is not enabled in sysfs mode or
> + * a buffer is of the reserved buffer mode, or the error of the allocation.
> + * The live sysfs_buf is never freed on failure.
> + */
> +int tmc_create_etr_buf_list(struct tmc_drvdata *drvdata, int num_nodes)
> +{
> + struct etr_buf_node *new_node;
> + struct etr_buf *sysfs_buf, *live_buf = NULL;
> + unsigned long flags;
> + size_t size = drvdata->size;
> + int i = 0, ret = 0;
> +
> + /* We don't need a list if there is only one node */
> + if (num_nodes < 2)
> + return -EINVAL;
> +
> + /*
> + * All the etr_buf of the reserved mode are mapped to the same reserved
> + * region, so they can't be used as separate buffers of the list.
> + */
> + if (drvdata->etr_mode == ETR_MODE_RESRV)
> + return -EINVAL;
> +
> + /*
> + * We expect that sysfs_buf in drvdata has already been allocated.
> + * Wrap the live sysfs_buf into the first node so the captured trace
> + * data is preserved. Take the sysfs_buf and add the node under the
> + * lock, so that the ETR sink enable path sees a non-empty list and
> + * doesn't replace the buffer.
> + */
> + new_node = kzalloc_obj(*new_node, GFP_KERNEL);
> + if (!new_node)
> + return -ENOMEM;
Since we know we need num_node entries at max, could we not allocate
them in oneshot (kcalloc()) and free the unused ones at the end ?
> +
> + raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> + /* The sysfs_buf is in use by a sysfs read session */
> + if (drvdata->reading) {
> + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
> + kfree(new_node);
> + return -EBUSY;
This pattern is repeating quite a lot, do you think this can be a single
exit from the function for such cases, something like goto err_unlock;
> + }
> +
> + /*
> + * The sink enable path reuses or frees the sysfs_buf of a sink which
> + * isn't enabled, so only wrap it while the sink is enabled in sysfs mode.
> + */
> + if (coresight_get_mode(drvdata->csdev) != CS_MODE_SYSFS) {
> + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
> + kfree(new_node);
> + return -EINVAL;
2
> + }
> +
> + if (drvdata->sysfs_buf) {
> + /* The mode may have been changed since the sink was enabled */
> + if (drvdata->sysfs_buf->mode == ETR_MODE_RESRV) {
> + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
> + kfree(new_node);
> + return -EINVAL;
3
> + }
> +
> + live_buf = drvdata->sysfs_buf;
> + /* Keep the buffers of the list in the size of the live one */
> + size = live_buf->size;
> + new_node->sysfs_buf = live_buf;
> + new_node->is_free = false;
> + list_add(&new_node->link, &drvdata->etr_buf_list);
> + new_node = NULL;
> + i++;
> + }
> + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
> + /* Free the node if there is no live sysfs_buf to wrap */
> + kfree(new_node);
> +
> + while (i < num_nodes) {
> + new_node = kzalloc_obj(*new_node, GFP_KERNEL);
> + if (!new_node) {
> + ret = -ENOMEM;
> + break;
> + }
> +
> + /* Allocate the buffer with the lock released */
> + sysfs_buf = tmc_alloc_etr_buf(drvdata, size, 0, cpu_to_node(0), NULL);
> + if (IS_ERR(sysfs_buf)) {
> + kfree(new_node);
> + ret = PTR_ERR(sysfs_buf);
> + break;
> + }
> +
> + /* The buffer mode may have been changed to the reserved mode */
> + if (sysfs_buf->mode == ETR_MODE_RESRV) {
> + tmc_etr_free_sysfs_buf(sysfs_buf);
> + kfree(new_node);
> + ret = -EINVAL;
> + break;
> + }
> +
> + new_node->sysfs_buf = sysfs_buf;
> + /*
> + * The drvdata->sysfs_buf write and the list update need the
> + * spinlock, to serialise against the ETR sink enable/disable
> + * paths.
> + */
> + raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> + /* We don't have an available sysfs_buf in drvdata, set one up */
> + if (!drvdata->sysfs_buf) {
> + drvdata->sysfs_buf = sysfs_buf;
> + new_node->is_free = false;
Is this supposed to be done in enable ?
> + } else {
> + new_node->is_free = true;
> + }
> + list_add_tail(&new_node->link, &drvdata->etr_buf_list);
> + raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
Instead of adding every node as we go, could we maintain a local list
and add that to the the etr_buf_list at the end of all the allocations
and when we are sure that things are still sane to do ?
Set all new_node->free = true and when we get to add the local list
set the sys_buf with the first entry and mark it false.
> + i++;
> + }
> +
> + /*
> + * Clean the list if there is an error, but keep the live sysfs_buf even
> + * if the sink was disabled meanwhile, as it holds the captured trace data.
> + */
> + if (ret)
> + __tmc_clean_etr_buf_list(drvdata, live_buf);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(tmc_create_etr_buf_list);
> +
> int tmc_read_prepare_etr(struct tmc_drvdata *drvdata)
> {
> int ret = 0;
> @@ -1928,7 +2128,8 @@ int tmc_read_prepare_etr(struct tmc_drvdata *drvdata)
> return -EINVAL;
>
> raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> - if (drvdata->reading) {
> + /* The sysfs_buf is owned by the etr_buf_list */
> + if (drvdata->reading || !list_empty(&drvdata->etr_buf_list)) {
> ret = -EBUSY;
> goto out;
> }
> diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h
> index 319a354ede9f..7c604b9f92e5 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc.h
> +++ b/drivers/hwtracing/coresight/coresight-tmc.h
> @@ -208,6 +208,20 @@ struct tmc_resrv_buf {
> s64 len;
> };
>
> +/**
> + * struct etr_buf_node - node of the etr_buf_list
> + * @sysfs_buf: Allocated sysfs_buf.
> + * @is_free: Indicates whether the buffer is free to choose.
super minor nit: Does this mean the buffer is available for tracing ?
Simply "free" is good enough. Or choose inverted logic "live" or "busy"
Suzuki
> + * @pos: Offset to the start of the buffer.
> + * @link: list_head of the node.
> + */
> +struct etr_buf_node {
> + struct etr_buf *sysfs_buf;
> + bool is_free;
> + loff_t pos;
> + struct list_head link;
> +};
> +
> /**
> * struct tmc_drvdata - specifics associated to an TMC component
> * @atclk: optional clock for the core parts of the TMC.
> @@ -245,6 +259,7 @@ struct tmc_resrv_buf {
> * (after crash) by default.
> * @crash_mdata: Reserved memory for storing tmc crash metadata.
> * Used by ETR/ETF.
> + * @etr_buf_list: List that is used to manage allocated etr_buf.
> */
> struct tmc_drvdata {
> struct clk *atclk;
> @@ -275,6 +290,7 @@ struct tmc_drvdata {
> struct etr_buf *perf_buf;
> struct tmc_resrv_buf resrv_buf;
> struct tmc_resrv_buf crash_mdata;
> + struct list_head etr_buf_list;
> };
>
> struct etr_buf_operations {
> @@ -447,5 +463,7 @@ struct etr_buf *tmc_etr_get_buffer(struct coresight_device *csdev,
> enum cs_mode mode,
> struct coresight_path *path);
> extern const struct attribute_group coresight_etr_group;
> +void tmc_clean_etr_buf_list(struct tmc_drvdata *drvdata);
> +int tmc_create_etr_buf_list(struct tmc_drvdata *drvdata, int num_nodes);
>
> #endif
>
On Tue, Nov 17, 2026 at 08:50:00PM +0200, Igor Velkov wrote:
> On Tue, Nov 17, 2026 at 06:32:41PM +0000, Leo Yan wrote:
> > Could we explore a hook in the CPU hard lockup detector? Seems this
> > module is more relevant to hard lockup rather than panic.
>
> Yes, that fits better. The hard lockup detector reports a CPU that
> missed its watchdog hrtimer interrupts, so it runs with IRQs masked and
> is not in an idle powerdown. The backtrace request then names the CPUs
> that did not answer ("these CPUS still haven't responded"). I would
> sample PCSR only for those, from a hook at that point, and leave the
> panic notifier alone. Does that sound right?
Yes, sampling CPUs that do not respond to the backtrace request sounds
reasonable.
The hard lockup detector can also call panic(), so we should avoid a
second dump from the panic notifier. After hook with hard-lockup
diagnosis, then makes sense to remove that panic notifier.
For CPU power state, could we take a cautious approach in the driver?
1) If idle_cpu(cpu) == 0, sample the CPU directly.
2) If idle_cpu(cpu) == 1, follow the existing flow to request
power-up before sampling.
3) Consider adding a module parameter, such as skip_idle, for
hardware that doesn't support or honour EDPRCR_COREPURQ. This
would allow the driver to sample only active CPUs.
Thanks,
Leo
On 18/11/2026 07:01, Jie Gan wrote:
> The traceNoC (Trace Network-On-Chip) node on kaanapali, sm8750 and glymur
> is described with the "qcom,coresight-tnoc", "arm,primecell" compatible,
> so the device is created on the AMBA bus. To bind an AMBA device, the bus
> reads the peripheral and component ID registers (PID/CID) at the top of
> the device's register block and matches them against the primecell ID.
> On these platforms the Component ID returned by the hardware is
> 0x00000000 instead of a valid AMBA Component ID, so the AMBA probe fails
> and the traceNoC is left stuck in deferred probe indefinitely, leaving
> its trace path unavailable.
>
> This series fixes the issue in the simplest way: keep the existing
> "arm,primecell" compatible and add the "arm,primecell-periphid" property
> to the traceNoC nodes. The AMBA bus then uses the peripheral ID given in
> the device tree instead of reading it from the device, which lets the
> traceNoC probe on this hardware. No binding or driver change is needed.
>
> History of this issue:
>
> This is an alternative to the series that fixes the same problem by
> moving the traceNoC onto the platform bus instead of AMBA.
>
> Latest revision of that series:
> https://lore.kernel.org/all/20261110-fix-trace-noc-probe-issue-v7-0-2f06905…
>
> That approach requires a binding change and a driver change in addition
> to the DT changes. This series instead keeps the hardware described as an
> AMBA device and works around the invalid Component ID with the existing
> "arm,primecell-periphid" property, so only the device tree is touched.
>
> Signed-off-by: Jie Gan <jie.gan(a)oss.qualcomm.com>
> ---
> Jie Gan (4):
> dt-bindings: arm: coresight-tnoc: Allow arm,primecell-periphid
> arm64: dts: qcom: kaanapali: add periphid for traceNoC
> arm64: dts: qcom: sm8750: add periphid for traceNoC
> arm64: dts: qcom: glymur: use Aggregator TNOC compatible
>
> Documentation/devicetree/bindings/arm/qcom,coresight-tnoc.yaml | 5 ++++-
> arch/arm64/boot/dts/qcom/glymur.dtsi | 8 +++++---
> arch/arm64/boot/dts/qcom/kaanapali.dtsi | 2 ++
> arch/arm64/boot/dts/qcom/sm8750.dtsi | 2 ++
> 4 files changed, 13 insertions(+), 4 deletions(-)
> ---
> base-commit: 7cfbf79c66c63e807ea452abf0546e6f6d6833a6
> change-id: 20261118-fix-tracenoc-probe-bf8025cad2ca
>
> Best regards,
I assume this would go through the qcom platform tree, as this is mostly
DTS changes.
For the series,
Acked-by: Suzuki K Poulose <suzuki.poulose(a)arm.com>
On Sat, Nov 14, 2026 at 02:08:16AM +0200, Igor Velkov wrote:
> The cpu-debug panic notifier reads every possible CPU after COREPURQ;
> on RK3399 on the crash path without pseudo-NMI it hit an SError on the
> first CPU that was off.
Seems the SoC does not honor COREPURQ. The current driver relies on an
accessible debug interface; these platform limitations are already
documented in [1].
> So I would send:
> 1. cpu-debug notifier: online CPUs other than the panic CPU, read only
> with PU=1, R=0 and DLK=0, no COREPURQ;
Sampling only CPUs still online after the stop request may help, but the
online mask does not guarantee register accessibility. A late stop
acknowledgement can race with that check, and an offline CPU may still be
running (or stuck) in firmware - the driver is also helpful for CPU stuck
not in kernel.
We also need to consider FEAT_DoPD: EDPRCR and EDPRSR move from debug
power domain into the Core power domain, and COREPURQ is absent. We then
need another mechanism before accessing PCSR register.
I would check a bit if any suggestions for safely access registers.
Otherwise, we may need to explore kernel states as you suggested (not
only cpu online but also idle states).
> 2. PMPCSR when EDDEVID.PCSample is 0 and PMDEVID.PCSample is not.
This is fine for me.
> Panic notifiers run after the stop only with crash_kexec_post_notifiers;
> with a crash kernel loaded and without it, they do not run at all. Is
> that acceptable, or would you rather see a hook in the crash stop path?
I agree that the notifier need improvement.
Could we explore a hook in the CPU hard lockup detector? Seems this
module is more relevant to hard lockup rather than panic.
Thanks,
Leo
[1] Documentation/trace/coresight/coresight-cpu-debug.rst
On Mon, Nov 16, 2026 at 10:58:13AM +0800, Johnny Fan wrote:
> On Fri, Nov 13, 2026 at 04:00:41PM +0000, Leo Yan wrote:
>
> [...]
>
> > Based on above idea, I would fold your patch into my series (but I will
> > drop the first patch for changing TRBE/SPE drivers). I will keep you as
> > the author but please bear me a bit that I may refactor it to fit into
> > the extensions. Hope this is fine for you.
>
>
> Hi Leo,
>
> Thanks for the detailed review, and yes — please go ahead and fold it
> into your series. I'm happy for you to keep me as the author and to
> refactor it as you see fit.
Cool!
> I'll hold off posting a v4 so we don't end up with two versions under
> review. Ping me when there's something you'd like tested on the CIX
> board.
Thanks for offering to test! I'll test on my Orion6 board and send out
the patches this week. You're welcome to test them and any comments.
Even if we're testing on the same SoC, your results would still be
valuable, maybe we're using different firmware versions.
Thanks,
Leo
On 16/11/2026 02:03, Jie Gan wrote:
>
>
> On 11/12/2026 4:43 AM, Leo Yan wrote:
>> On Tue, Nov 10, 2026 at 09:46:43AM -0600, Rob Herring wrote:
>>> On Tue, Nov 10, 2026 at 09:21:13AM +0800, Jie Gan wrote:
>>>> The CoreSight TNOC (Trace Network-On-Chip) binding so far only
>>>> allowed the
>>>> two-string AMBA form "qcom,coresight-tnoc", "arm,primecell". That form
>>>> forces the device onto the AMBA bus, where the driver must read the
>>>> peripheral ID from the device registers during probe. On several QCOM
>>>> platforms this AMBA peripheral-ID probing fails, so the traceNoC device
>>>> never probes and its trace path is unavailable.
>>>
>>> But it works fine on some platforms? We have a property to override the
>>> peripheral-ID which would solve your issue. That would be much simpler
>>> and avoid the ABI break on any of the working platforms.
>>
>> Looking back at the earlier discussion [1], Jie in v2 already proposed
>> "arm,primecell-periphid". Questions about AMBA IDs and ATID handling got
>> mixed together. The series later moved towards platform-device probing,
>> then became current shape.
>>
>> Hope we make the right decision on arm,primecell-periphid this time.
>>
>> Anyway, I'd like to apologise to Jie for all the back and forth.
>>
>
> Never mind.
>
> Hi Suzuki, Rob,
>
> The "arm,primecell-periphid" override is the simplest fix for the issue.
> Which fix are your preferring for the issue? If we want fix it with DT
> property, we can revert the patch series and I will post a new one to
> fix it.
>
> As Leo mentioned, the AMBA probe is not affecting by the series.
Alright, I will remove it from the coresight next, please send the DT
fix.
Cheers
Suzuki
Hi Johnny,
On Mon, Nov 02, 2026 at 04:41:52PM +0800, Johnny.Fan wrote:
[...]
> Group the CPUs by (hetero id, interrupt) and register one platform
> device per group. A GSI may be shared between groups with
> non-overlapping CPU masks, so only unregister the GSI mapping once no
> successfully registered device uses it, as the mapping is not reference
> counted.
This is fine for me in general. For CPU grouping, we would prefter to
use MIDR rather than hetid, as events should be able to migrate between
CPUs with the same MIDR.
My concern is that we need particular change in SPE/TRBE drivers to
retrieve IRQ affinity based on this change. It is better to improve
fwnode layer to provide a general way for retrieve IRQ affinity. I did
a bit experiment with using swnode and seems it makes sense.
I would also consolidate CPU PMU device registration. That means we need
to extend the device registration to support SPI. We also need to update
PMU platform driver for ACPI device probe.
Based on above idea, I would fold your patch into my series (but I will
drop the first patch for changing TRBE/SPE drivers). I will keep you as
the author but please bear me a bit that I may refactor it to fit into
the extensions. Hope this is fine for you.
Thanks,
Leo