[PATCH v2 2/4] coresight: tmc-etf: Prevent per-thread events from sharing a sink

From: James Clark

Date: Thu Jul 09 2026 - 11:26:20 EST


Like the previous commit to ETR, ETF sinks shouldn't share per-thread
events. Fix it by returning -EBUSY if a second per-thread event tries to
use the same sink.

Fixes: 880af782c6e8 ("coresight: tmc-etf: Add support for CPU-wide trace scenarios")
Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
drivers/hwtracing/coresight/coresight-tmc-core.c | 2 --
drivers/hwtracing/coresight/coresight-tmc-etf.c | 23 +++++++----------------
drivers/hwtracing/coresight/coresight-tmc.h | 1 -
3 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index c89fe996af23..77bdf8892617 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -801,8 +801,6 @@ static int __tmc_probe(struct device *dev, struct resource *res)
devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID);
drvdata->config_type = BMVAL(devid, 6, 7);
drvdata->memwidth = tmc_get_memwidth(devid);
- /* This device is not associated with a session */
- drvdata->pid = -1;
drvdata->etr_mode = ETR_MODE_AUTO;

if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) {
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c
index 8882b1c4cdc0..4ed83f07eec8 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etf.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c
@@ -250,11 +250,9 @@ static int tmc_enable_etf_sink_perf(struct coresight_device *csdev,
struct coresight_path *path)
{
int ret = 0;
- pid_t pid;
unsigned long flags;
struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
struct perf_output_handle *handle = path->handle;
- struct cs_buffers *buf = etm_perf_sink_config(handle);

raw_spin_lock_irqsave(&drvdata->spinlock, flags);
do {
@@ -270,10 +268,9 @@ static int tmc_enable_etf_sink_perf(struct coresight_device *csdev,
break;
}

- /* Get a handle on the pid of the process to monitor */
- pid = buf->pid;
-
- if (drvdata->pid != -1 && drvdata->pid != pid) {
+ if (drvdata->event &&
+ !coresight_sink_can_share(drvdata->event,
+ handle->event)) {
ret = -EBUSY;
break;
}
@@ -282,19 +279,15 @@ static int tmc_enable_etf_sink_perf(struct coresight_device *csdev,
if (ret)
break;

- /*
- * No HW configuration is needed if the sink is already in
- * use for this session.
- */
- if (drvdata->pid == pid) {
+ /* No HW configuration is needed if the sink is already in use. */
+ if (csdev->refcnt) {
csdev->refcnt++;
break;
}

ret = tmc_etb_enable_hw(drvdata);
if (!ret) {
- /* Associate with monitored process. */
- drvdata->pid = pid;
+ drvdata->event = handle->event;
coresight_set_mode(csdev, CS_MODE_PERF);
csdev->refcnt++;
}
@@ -351,9 +344,8 @@ static int tmc_disable_etf_sink(struct coresight_device *csdev)
/* Complain if we (somehow) got out of sync */
WARN_ON_ONCE(coresight_get_mode(csdev) == CS_MODE_DISABLED);
tmc_etb_disable_hw(drvdata);
- /* Dissociate from monitored process. */
- drvdata->pid = -1;
coresight_set_mode(csdev, CS_MODE_DISABLED);
+ drvdata->event = NULL;

raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);

@@ -432,7 +424,6 @@ static void *tmc_alloc_etf_buffer(struct coresight_device *csdev,
if (!buf)
return NULL;

- buf->pid = task_pid_nr(event->owner);
buf->snapshot = overwrite;
buf->nr_pages = nr_pages;
buf->data_pages = pages;
diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h
index 220fe45fca83..595d6a3b0767 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -254,7 +254,6 @@ struct tmc_drvdata {
struct miscdevice miscdev;
struct miscdevice crashdev;
raw_spinlock_t spinlock;
- pid_t pid;
bool reading;
bool stop_on_flush;
union {

--
2.34.1