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 v2 8/8] coresight: tmc: add QECP owned TMC driver
Date: Mon, 30 Nov 2026 07:33:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-240600@kernel.org> (raw)
In-Reply-To: <20261130-introduce-qcom-qecp-feature-v2-8-dff9ae87327b@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] coresight: tmc-qdcp: refcnt leak and ETR resume in
tmc_qdcp_etr_disable_sink()
- [Medium] coresight: tmc-qdcp: missing RWP >= RRP check in
tmc_qdcp_etr_hw_state_valid()
--
commit 568910aefc42f8c1badeac3b8f837013fcf6546b
Author: Jie Gan <jie.gan@oss.qualcomm.com>
coresight: tmc: add QECP owned TMC driver
This commit adds a driver for CoreSight TMC ETR devices managed by the
Qualcomm Embedded Co-Processor (QECP) firmware over the Qualcomm Debug
Control Protocol (QDCP), and exports common TMC ETR helpers for it.
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-qdcp.c b/drivers/hwtracing/coresight/coresight-tmc-qdcp.c
> new file mode 100644
> index 0000000000000..0c73d2834be28
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-tmc-qdcp.c
[ ... ]
> +/*
> + * The pointers come from the firmware, make sure they are inside a flat
> + * buffer before using them as offsets. The scatter-gather sync already
> + * rejects pointers outside of its table.
> + */
> +static bool tmc_qdcp_etr_hw_state_valid(struct etr_buf *etr_buf,
> + const struct tmc_etr_hw_state *state)
> +{
> + u64 start = etr_buf->hwaddr, end = etr_buf->hwaddr + etr_buf->size;
> +
> + if (etr_buf->mode != ETR_MODE_FLAT)
> + return true;
> +
> + return state->rrp >= start && state->rrp < end &&
> + state->rwp >= start && state->rwp < end;
> +}
[Severity: Medium]
Can tmc_qdcp_etr_hw_state_valid() accept state->rwp < state->rrp when
TMC_STS_FULL is not set in state->sts?
If the firmware returns start <= state->rwp < state->rrp < end without
TMC_STS_FULL, tmc_etr_sync_flat_buf() computes a negative etr_buf->len,
passes the wrap check because etr_buf->offset + etr_buf->len equals
rwp - etr_buf->hwaddr, and calls dma_sync_single_for_cpu() with a huge
size_t:
drivers/hwtracing/coresight/coresight-tmc-etr.c:tmc_etr_sync_flat_buf() {
...
etr_buf->offset = rrp - etr_buf->hwaddr;
if (etr_buf->full)
etr_buf->len = etr_buf->size;
else
etr_buf->len = rwp - rrp;
if (etr_buf->offset + etr_buf->len > etr_buf->size)
dma_sync_single_for_cpu(real_dev, flat_buf->daddr,
etr_buf->size, DMA_FROM_DEVICE);
else
dma_sync_single_for_cpu(real_dev,
flat_buf->daddr + etr_buf->offset,
etr_buf->len, DMA_FROM_DEVICE);
}
[ ... ]
> +static int tmc_qdcp_etr_disable_sink(struct coresight_device *csdev)
> +{
> + struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
> + struct tmc_qdcp_drvdata *qdata = to_tmc_qdcp(drvdata);
> + int ret;
> +
> + mutex_lock(&qdata->lock);
> + if (drvdata->reading) {
> + mutex_unlock(&qdata->lock);
> + return -EBUSY;
> + }
> +
> + csdev->refcnt--;
> + if (csdev->refcnt) {
> + mutex_unlock(&qdata->lock);
> + return -EBUSY;
> + }
> +
> + /*
> + * The path is torn down whatever is returned here. If the stop is not
> + * confirmed, the buffer stays pinned and the stop is retried on the
> + * next enable, read or removal.
> + */
> + ret = tmc_qdcp_etr_disable_hw(qdata);
> + drvdata->pid = -1;
> + coresight_set_mode(csdev, CS_MODE_DISABLED);
> + mutex_unlock(&qdata->lock);
> +
> + if (!ret)
> + dev_dbg(&csdev->dev, "TMC-ETR disabled\n");
> + return ret;
> +}
[Severity: High]
Does returning -EBUSY when drvdata->reading is true leak csdev->refcnt and
leave csdev->mode set to CS_MODE_SYSFS?
When a trace source is disabled while the miscdevice is open for reading,
coresight_disable_sysfs() ignores the return value from sink_ops->disable()
and tears down the path. Because tmc_qdcp_etr_disable_sink() returns before
decrementing csdev->refcnt or setting csdev->mode to CS_MODE_DISABLED, closing
the miscdevice in tmc_qdcp_etr_read_unprepare() sees CS_MODE_SYSFS and
re-enables the ETR in firmware with drvdata->sysfs_buf instead of freeing the
buffer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-introduce-qcom-qecp-feature-v2-0-dff9ae87327b@oss.qualcomm.com?part=8
next prev parent reply other threads:[~2026-11-30 7:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 7:11 [PATCH v2 0/8] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
2026-11-30 7:11 ` [PATCH v2 1/8] soc: qcom: add QDCP client library Jie Gan
2026-11-30 7:11 ` [PATCH v2 2/8] coresight: tmc: split ETR buffer sync from hardware state readback Jie Gan
2026-11-30 7:11 ` [PATCH v2 3/8] coresight: tmc: factor out common ETR probe initialisation Jie Gan
2026-11-30 7:20 ` sashiko-bot
2026-11-30 7:11 ` [PATCH v2 4/8] coresight: tmc: move trigger_cntr into its own attribute group Jie Gan
2026-11-30 7:11 ` [PATCH v2 5/8] dt-bindings: arm: qcom: add QECP owned CoreSight STM Jie Gan
2026-11-30 7:11 ` [PATCH v2 6/8] coresight: qcom: add QECP owned STM driver Jie Gan
2026-11-30 7:11 ` [PATCH v2 7/8] dt-bindings: arm: qcom: add QECP owned CoreSight TMC Jie Gan
2026-11-30 7:11 ` [PATCH v2 8/8] coresight: tmc: add QECP owned TMC driver Jie Gan
2026-11-30 7:33 ` sashiko-bot [this message]
2026-11-30 8:15 ` Jie Gan
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-240600@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.