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 RFC 4/6] coresight: qcom: add QDCP STM source
Date: Thu, 19 Nov 2026 09:28:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-222834@kernel.org> (raw)
In-Reply-To: <20261119-introduce-qcom-qecp-feature-v1-4-b1a730d2c57a@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] coresight: qcom: path and refcount leak in qdcp_stm_remove()
- [Medium] coresight: qcom: sysfs enable_source race in
qdcp_stm_remove()
- [Medium] coresight: qcom: premature CS_MODE_SYSFS transition in
qdcp_stm_enable()
- [Medium] coresight: qcom-qdcp-stm: UAF of drvdata and csdev after
qdcp_stm_remove()
--
commit 70d23454ea311ef6b9bc809416627572cf195a8d
Author: Jie Gan <jie.gan@oss.qualcomm.com>
coresight: qcom: add QDCP STM source
This commit adds a Qualcomm CoreSight STM source driver that maps the
AP-visible stimulus aperture and delegates STM enable and disable
operations to QECP firmware via QDCP.
> diff --git a/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c b/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c
> new file mode 100644
> index 0000000000000..39c6a2798a0f9
> --- /dev/null
> +++ b/drivers/hwtracing/coresight/coresight-qcom-qdcp-stm.c
> @@ -0,0 +1,550 @@
[ ... ]
> +static int qdcp_stm_enable(struct coresight_device *csdev,
> + struct perf_event *event, enum cs_mode mode,
> + struct coresight_path *path)
> +{
> + struct qcom_qdcp_stm_drvdata *drvdata;
> + int ret;
> +
> + if (mode != CS_MODE_SYSFS)
> + return -EINVAL;
> +
> + if (!coresight_take_mode(csdev, mode))
> + return -EBUSY;
> +
> + drvdata = dev_get_drvdata(csdev->dev.parent);
> +
> + mutex_lock(&drvdata->qdcp.lock);
> + ret = qdcp_stm_source_enable(drvdata->qdcp.provider, drvdata->qdcp.id,
> + drvdata->traceid, drvdata->port_mask,
> + false);
> + if (!ret)
> + drvdata->fw_stop_failed = false;
> + mutex_unlock(&drvdata->qdcp.lock);
> + if (ret) {
> + coresight_set_mode(csdev, CS_MODE_DISABLED);
> + return ret;
> + }
> +
> + dev_dbg(&csdev->dev, "QDCP STM tracing enabled\n");
> + return 0;
> +}
> +
> +/*
> + * The CoreSight source disable op returns void and the user has already torn
> + * the path down, so the source always ends up disabled from Linux's point of
> + * view. Return the firmware result so the caller can at least report it.
> + */
> +static int qdcp_stm_disable_source(struct coresight_device *csdev)
> +{
> + struct qcom_qdcp_stm_drvdata *drvdata;
> + struct qdcp_data *qdcp;
> + u64 source_id;
> + u8 traceid;
> + int ret;
> +
> + if (coresight_get_mode(csdev) != CS_MODE_SYSFS)
> + return 0;
> +
> + drvdata = dev_get_drvdata(csdev->dev.parent);
> + qdcp = drvdata->qdcp.provider;
> + source_id = drvdata->qdcp.id;
> + traceid = drvdata->traceid;
> +
> + mutex_lock(&drvdata->qdcp.lock);
> + ret = qdcp_stm_source_disable(qdcp, source_id, traceid, false);
> + drvdata->fw_stop_failed = !!ret;
> + mutex_unlock(&drvdata->qdcp.lock);
> +
> + coresight_set_mode(csdev, CS_MODE_DISABLED);
> + dev_dbg(&csdev->dev, "QDCP STM tracing disabled\n");
> + return ret;
> +}
[Severity: Medium]
Can qdcp_stm_packet() write to drvdata->stimulus_base while the STM block
is still unclocked or disabled by firmware?
qdcp_stm_packet() is lockless and checks only coresight_get_mode(csdev)
before performing MMIO writes to drvdata->stimulus_base. Unlike
coresight-stm, QECP firmware controls the block's clocks and power over
sleeping QMI calls:
CPU0 CPU1
qdcp_stm_enable()
coresight_take_mode(...,
CS_MODE_SYSFS)
qdcp_stm_source_enable()
/* sleeping QMI RPC */
qdcp_stm_packet()
coresight_get_mode() == CS_MODE_SYSFS
qdcp_stm_send(channel_addr, ...)
<-- MMIO write before firmware
enables STM clocks/power
The same window exists in qdcp_stm_disable_source(), where csdev->mode
remains CS_MODE_SYSFS until after qdcp_stm_source_disable() completes.
On Qualcomm SoCs, MMIO accesses to an unclocked CoreSight aperture can
cause a synchronous external abort or bus hang.
[ ... ]
> +static void qdcp_stm_remove(struct platform_device *pdev)
> +{
> + struct qcom_qdcp_stm_drvdata *drvdata = platform_get_drvdata(pdev);
> +
> + /*
> + * Unregister the STM first: its unlink callback disables the source
> + * through drvdata->csdev, which must still be live.
> + */
> + stm_unregister_device(&drvdata->stm);
[Severity: Medium]
Can closing an open /dev/qdcp_stmN file descriptor after qdcp_stm_remove()
cause a use-after-free on drvdata and drvdata->csdev?
Unbinding the qcom-qdcp supplier triggers qdcp_stm_remove() via the
DL_FLAG_AUTOREMOVE_CONSUMER device link created by devm_qdcp_get().
stm_unregister_device() only unlinks in-kernel stm_source devices on
stm->link_list; any open userspace struct stm_file still holds stmf->stm
with stm->data pointing to &drvdata->stm:
drivers/hwtracing/stm/core.c:stm_char_release() {
struct stm_file *stmf = file->private_data;
struct stm_device *stm = stmf->stm;
if (stm->data->unlink)
stm->data->unlink(stm->data, stmf->output.master,
stmf->output.channel);
...
}
After qdcp_stm_remove() unregisters drvdata->csdev and devres frees
drvdata, closing the open file descriptor calls qdcp_stm_unlink() ->
coresight_disable_sysfs(drvdata->csdev) on freed memory.
> +
> + /*
> + * No-op unless the source is still in CS_MODE_SYSFS. Without it,
> + * removing an enabled source would leave firmware STM enabled.
> + */
> + qdcp_stm_disable_source(drvdata->csdev);
[Severity: Medium]
Does calling qdcp_stm_disable_source() here instead of
coresight_disable_sysfs() leak csdev->path and leave downstream CoreSight
components enabled?
When the source is enabled in CS_MODE_SYSFS (for example via the sysfs
enable_source attribute), coresight_enable_sysfs() builds csdev->path,
enables the sink and links, and takes device, module, and runtime PM
references on every component in the path via coresight_grab_device().
Calling qdcp_stm_disable_source() directly only disables the source in
firmware and sets csdev->mode to CS_MODE_DISABLED without calling
coresight_disable_path() or coresight_release_path_locked(), leaking the
path and the get_device(&csdev->dev) reference on drvdata->csdev itself.
> +
> + /*
> + * A stop that failed here or earlier (fw_stop_failed) means firmware
> + * may still be tagging trace with this ID. Keep it allocated rather
> + * than let another source reuse it.
> + */
> + if (drvdata->fw_stop_failed)
> + dev_warn(&pdev->dev,
> + "QDCP STM not confirmed stopped, leaking trace ID %u\n",
> + drvdata->traceid);
> + else
> + coresight_trace_id_put_system_id(drvdata->traceid);
> +
> + coresight_unregister(drvdata->csdev);
> +}
[Severity: Medium]
What prevents sysfs enable_source_store() from racing with
qdcp_stm_remove() before coresight_unregister() removes the sysfs
attribute?
Because coresight_unregister() runs last and qdcp_stm_remove() does not
hold coresight_mutex, enable_source Remains accessible while
qdcp_stm_remove() disables the source and releases drvdata->traceid:
CPU0 CPU1
qdcp_stm_remove()
qdcp_stm_disable_source()
enable_source_store()
coresight_enable_sysfs()
qdcp_stm_enable()
qdcp_stm_source_enable(...,
drvdata->traceid, ...)
drvdata->fw_stop_failed = false
if (drvdata->fw_stop_failed)
else
coresight_trace_id_put_system_id(
drvdata->traceid)
<-- trace ID freed while
firmware is enabled
coresight_unregister(csdev)
Unregistering drvdata->csdev before releasing drvdata->traceid (or
tearing down the sysfs session under coresight_mutex during
unregister) would close this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-introduce-qcom-qecp-feature-v1-0-b1a730d2c57a@oss.qualcomm.com?part=4
next prev parent reply other threads:[~2026-11-19 9:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
2026-11-19 9:12 ` sashiko-bot
2026-11-19 14:00 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider Jie Gan
2026-11-19 9:18 ` sashiko-bot
2026-11-19 9:01 ` [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source Jie Gan
2026-11-19 14:02 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 4/6] coresight: " Jie Gan
2026-11-19 9:28 ` sashiko-bot [this message]
2026-11-19 9:01 ` [PATCH RFC 5/6] dt-bindings: arm: qcom: add QDCP TMC ETR sink Jie Gan
2026-11-19 9:01 ` [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support Jie Gan
2026-11-19 9: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-222834@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.