From: sashiko-bot@kernel.org
To: "Jie Gan" <jie.gan@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v23 3/8] coresight: tmc: add a function to switch the ETR to a free etr_buf
Date: Wed, 18 Nov 2026 08:20:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-220427@kernel.org> (raw)
In-Reply-To: <20261118-enable-byte-cntr-for-ctcu-v23-3-67fd9db6bc0e@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] coresight: tmc: unhandled enable failure in
tmc_etr_switch_buf_node()
- [Low] coresight: tmc: redundant register writes in
tmc_etr_reset_sysfs_buf()
--
commit 4182b8271c7f6d8ac88e30050f83e36bc405e320
Author: Jie Gan <jie.gan@oss.qualcomm.com>
coresight: tmc: add a function to switch the ETR to a free etr_buf
This commit adds tmc_etr_switch_buf_node() to stop the ETR, switch
drvdata->sysfs_buf and drvdata->etr_buf to a free buffer node from
etr_buf_list, and restart the ETR under drvdata->spinlock.
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> index e9213f4568341..5032f5598e15b 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> @@ -1224,6 +1224,71 @@ static void __tmc_etr_disable_hw(struct tmc_drvdata *drvdata)
>
> }
>
> +static void tmc_etr_reset_sysfs_buf(struct tmc_drvdata *drvdata)
> +{
> + u32 sts;
> +
> + CS_UNLOCK(drvdata->base);
> + tmc_write_rrp(drvdata, drvdata->sysfs_buf->hwaddr);
> + tmc_write_rwp(drvdata, drvdata->sysfs_buf->hwaddr);
> + sts = readl_relaxed(drvdata->base + TMC_STS) & ~TMC_STS_FULL;
> + writel_relaxed(sts, drvdata->base + TMC_STS);
> + CS_LOCK(drvdata->base);
> +}
[Severity: Low]
Is tmc_etr_reset_sysfs_buf() needed when __tmc_etr_enable_hw() is called
immediately afterwards?
__tmc_etr_enable_hw() already resets TMC_RRP, TMC_RWP, and TMC_STS_FULL
after waiting for tmc_wait_for_tmcready() and updating TMC_DBA when the
device has TMC_ETR_SAVE_RESTORE:
drivers/hwtracing/coresight/coresight-tmc-etr.c:__tmc_etr_enable_hw() {
...
if (tmc_etr_has_cap(drvdata, TMC_ETR_SAVE_RESTORE)) {
tmc_write_rrp(drvdata, etr_buf->hwaddr);
tmc_write_rwp(drvdata, etr_buf->hwaddr);
sts = readl_relaxed(drvdata->base + TMC_STS) & ~TMC_STS_FULL;
writel_relaxed(sts, drvdata->base + TMC_STS);
}
...
}
Calling tmc_etr_reset_sysfs_buf() before __tmc_etr_enable_hw() duplicates
those writes without checking TMC_ETR_SAVE_RESTORE or waiting for
TMCReady.
> +
> +/**
> + * tmc_etr_switch_buf_node - switch the ETR to a free buffer of the etr_buf_list.
> + * @drvdata: drvdata of the TMC device.
> + *
> + * Stop the ETR, hand over the current buffer for reading, switch to a free
> + * buffer and restart the ETR. All of this is done with @drvdata->spinlock held,
> + * so it can't race with the sink disable path.
> + *
> + * Return: the node of the switched out buffer, or NULL if the sink isn't in
> + * sysfs mode or there is no free buffer. The ETR is left untouched in both
> + * cases.
> + */
> +struct etr_buf_node *tmc_etr_switch_buf_node(struct tmc_drvdata *drvdata)
> +{
> + struct etr_buf_node *nd, *curr_node = NULL, *picked_node = NULL;
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&drvdata->spinlock, flags);
> + if (coresight_get_mode(drvdata->csdev) != CS_MODE_SYSFS)
> + goto out;
> +
> + list_for_each_entry(nd, &drvdata->etr_buf_list, link) {
> + if (nd->sysfs_buf == drvdata->sysfs_buf)
> + curr_node = nd;
> + else if (!picked_node && nd->is_free && !nd->reading)
> + picked_node = nd;
> + }
> +
> + if (!curr_node || !picked_node) {
> + curr_node = NULL;
> + goto out;
> + }
> +
> + __tmc_etr_disable_hw(drvdata);
> +
> + /* The switched out buffer is free again once it has been read */
> + curr_node->is_free = true;
> + curr_node->pos = 0;
> + curr_node->reading = true;
> + picked_node->is_free = false;
> + drvdata->sysfs_buf = picked_node->sysfs_buf;
> + drvdata->etr_buf = picked_node->sysfs_buf;
> +
> + tmc_etr_reset_sysfs_buf(drvdata);
> + if (__tmc_etr_enable_hw(drvdata))
> + dev_err(&drvdata->csdev->dev, "Failed to restart the ETR\n");
[Severity: Medium]
What happens if __tmc_etr_enable_hw() fails when tmc_wait_for_tmcready()
times out?
__tmc_etr_enable_hw() returns early before programming TMC_DBA or
re-enabling the ETR, but drvdata->sysfs_buf and drvdata->etr_buf are left
pointing to picked_node->sysfs_buf while the sink mode stays
CS_MODE_SYSFS. A later tmc_disable_etr_sink() or
tmc_etr_switch_buf_node() call will run __tmc_etr_disable_hw() ->
tmc_etr_sync_sysfs_buf() and sync picked_node->sysfs_buf against stale
hardware registers from the previous session. In flat buffer mode,
tmc_etr_sync_flat_buf() computes etr_buf->offset = rrp - etr_buf->hwaddr
using the old RRP, which can exceed etr_buf->size and underflow
etr_buf->size - offset in tmc_etr_buf_get_data(), leading to an
out-of-bounds memory access.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-enable-byte-cntr-for-ctcu-v23-0-67fd9db6bc0e@oss.qualcomm.com?part=3
next prev parent reply other threads:[~2026-11-18 8:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 8:02 [PATCH v23 0/8] coresight: ctcu: Enable byte-cntr function for TMC ETR Jie Gan
2026-11-18 8:02 ` [PATCH v23 1/8] coresight: core: refactor ctcu_get_active_port and make it generic Jie Gan
2026-11-18 8:02 ` [PATCH v23 2/8] coresight: tmc: add create/clean functions for etr_buf_list Jie Gan
2026-11-18 8:02 ` [PATCH v23 3/8] coresight: tmc: add a function to switch the ETR to a free etr_buf Jie Gan
2026-11-18 8:20 ` sashiko-bot [this message]
2026-11-18 8:02 ` [PATCH v23 4/8] coresight: tmc: introduce tmc_sysfs_ops to wrap sysfs read operations Jie Gan
2026-11-18 8:02 ` [PATCH v23 5/8] coresight: etr: add a new function to retrieve the CTCU device Jie Gan
2026-11-18 8:02 ` [PATCH v23 6/8] dt-bindings: arm: add an interrupt property for Coresight CTCU Jie Gan
2026-11-18 8:02 ` [PATCH v23 7/8] coresight: ctcu: enable byte-cntr for TMC ETR devices Jie Gan
2026-11-18 8:40 ` sashiko-bot
2026-11-18 8:02 ` [PATCH v23 8/8] arm64: dts: qcom: lemans: add interrupts to CTCU device Jie Gan
2026-11-18 8:25 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-220427@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jie.gan@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.