All of lore.kernel.org
 help / color / mirror / Atom feed
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 v21 3/8] coresight: tmc: add a function to switch the ETR to a free etr_buf
Date: Mon, 02 Nov 2026 10:08:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-193237@kernel.org> (raw)
In-Reply-To: <20261102-enable-byte-cntr-for-ctcu-v21-3-231e069b7853@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] coresight: tmc: active read buffer reuse in tmc_etr_switch_buf_node()
--

commit edde9bcbd54db59cd64f7044e1302e2f89c8fc07
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 to a
free etr_buf from etr_buf_list, and restart the ETR under drvdata->spinlock
while returning the switched-out buffer node for reading.

> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
> index eee98a9269df4..2de31d73a4b47 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)

[ ... ]

> +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)
> +			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;

[Severity: High]
Can tmc_etr_switch_buf_node() re-select a buffer node while it is still
being read by userspace?

When curr_node is switched out for reading, curr_node->is_free is
immediately set to true alongside curr_node->reading = true, while the
selection loop above only checks nd->is_free and does not check
!nd->reading:

	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)
			picked_node = nd;
	}

In tmc_create_etr_buf_list(), all nodes other than the active
drvdata->sysfs_buf start with is_free = true, and in the caller added later
in the series (tmc_byte_cntr_get_data() in coresight-ctcu-byte-cntr.c),
finishing a buffer read only clears byte_cntr_data->buf_node->reading =
false without updating is_free.

Because every node other than the active drvdata->sysfs_buf always has
is_free == true even while reading == true, the documented NULL return when
there is no free buffer cannot be reached. If tmc_etr_switch_buf_node() is
called again before the previous buffer has been fully read (for instance,
via concurrent read() calls on the same open descriptor since tmc_open()
uses nonseekable_open(), or when num_nodes > 2 and an earlier node in
etr_buf_list is still being read while a later node is idle), won't it pick
a node with reading == true and restart ETR DMA into that buffer while it
is being read?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261102-enable-byte-cntr-for-ctcu-v21-0-231e069b7853@oss.qualcomm.com?part=3

  reply	other threads:[~2026-11-02 10:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  9:46 [PATCH v21 0/8] coresight: ctcu: Enable byte-cntr function for TMC ETR Jie Gan
2026-11-02  9:46 ` [PATCH v21 1/8] coresight: core: refactor ctcu_get_active_port and make it generic Jie Gan
2026-11-02  9:46 ` [PATCH v21 2/8] coresight: tmc: add create/clean functions for etr_buf_list Jie Gan
2026-11-02 10:07   ` sashiko-bot
2026-11-02  9:46 ` [PATCH v21 3/8] coresight: tmc: add a function to switch the ETR to a free etr_buf Jie Gan
2026-11-02 10:08   ` sashiko-bot [this message]
2026-11-02  9:46 ` [PATCH v21 4/8] coresight: tmc: introduce tmc_sysfs_ops to wrap sysfs read operations Jie Gan
2026-11-02  9:46 ` [PATCH v21 5/8] coresight: etr: add a new function to retrieve the CTCU device Jie Gan
2026-11-02  9:46 ` [PATCH v21 6/8] dt-bindings: arm: add an interrupt property for Coresight CTCU Jie Gan
2026-11-02  9:46 ` [PATCH v21 7/8] coresight: ctcu: enable byte-cntr for TMC ETR devices Jie Gan
2026-11-02 10:17   ` sashiko-bot
2026-11-02  9:46 ` [PATCH v21 8/8] arm64: dts: qcom: lemans: add interrupts to CTCU device Jie Gan
2026-11-02 10:11   ` 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-193237@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.