From: James Clark <james.clark@linaro.org>
To: Suzuki K Poulose <suzuki.poulose@arm.com>,
Mike Leach <mike.leach@arm.com>, Leo Yan <leo.yan@arm.com>,
Suyash Mahar <smahar@meta.com>,
Yeoreum Yun <yeoreum.yun@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Qi Liu <liuqi115@huawei.com>, Junhao He <hejunhao3@huawei.com>,
coresight@lists.linaro.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
James Clark <james.clark@linaro.org>,
Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH v4 03/10] coresight: etm-perf: Serialize AUX topology access
Date: Fri, 16 Oct 2026 11:46:13 +0100 [thread overview]
Message-ID: <20261016-james-cs-multiple-per-threads-v4-3-dedf961aca0e@linaro.org> (raw)
In-Reply-To: <20261016-james-cs-multiple-per-threads-v4-0-dedf961aca0e@linaro.org>
Perf AUX setup walks the CoreSight connections to select a sink, build
paths and acquire references to the devices and their helpers. Unlike
sysfs tracing, it does not hold coresight_mutex. Driver registration and
removal can therefore change or free connections while setup walks them.
Adding a CTI helper can also reallocate an existing device's output
connection array even when the device is already referenced by a path.
Hold coresight_mutex from sink selection through buffer allocation.
The allocation must also be protected because ETR buffers can look up a
connected CATU. Release the mutex before calling etm_free_aux() on error.
AUX cleanup walks helper connections again when releasing paths. Add a
locking coresight_release_path() wrapper and use
coresight_release_path_locked() for sysfs and setup error paths which
already hold the mutex. Leave sink buffer freeing and configuration
deactivation outside the mutex. AUX cleanup runs in sleepable context
following the preceding workqueue removal.
Add lockdep assertions to path construction and release to document the
existing sysfs locking contract and enforce it for perf as well. This
protects sleepable AUX topology walks; connection reads in atomic path
enable/disable callbacks need a separate solution.
Fixes: 0bcbf2e30ff2 ("coresight: etm-perf: new PMU driver for ETM tracers")
Signed-off-by: James Clark <james.clark@linaro.org>
---
drivers/hwtracing/coresight/coresight-core.c | 20 ++++++++++++++++----
drivers/hwtracing/coresight/coresight-etm-perf.c | 11 +++++++----
drivers/hwtracing/coresight/coresight-priv.h | 1 +
drivers/hwtracing/coresight/coresight-sysfs.c | 4 ++--
4 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index d2f9c1fb77d9..c05d657cde73 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -30,8 +30,8 @@
#include "coresight-trace-id.h"
/*
- * Mutex used to lock all sysfs enable and disable actions and loading and
- * unloading devices by the Coresight core.
+ * Mutex used to serialize device registration and removal, sysfs enable and
+ * disable actions, and perf AUX setup and path release.
*/
DEFINE_MUTEX(coresight_mutex);
static DEFINE_PER_CPU(struct coresight_device *, csdev_sink);
@@ -910,6 +910,8 @@ static void coresight_drop_device(struct coresight_device *csdev)
{
int i;
+ lockdep_assert_held(&coresight_mutex);
+
coresight_put_ref(csdev);
for (i = 0; i < csdev->pdata->nr_outconns; i++) {
struct coresight_device *child;
@@ -1046,6 +1048,8 @@ struct coresight_path *coresight_build_path(struct coresight_device *source,
struct coresight_path *path;
int rc;
+ lockdep_assert_held(&coresight_mutex);
+
if (!sink)
return ERR_PTR(-EINVAL);
@@ -1065,17 +1069,19 @@ struct coresight_path *coresight_build_path(struct coresight_device *source,
}
/**
- * coresight_release_path - release a previously built path.
+ * coresight_release_path_locked - release a path with coresight_mutex held.
* @path: the path to release.
*
* Go through all the elements of a path and 1) removed it from the list and
* 2) free the memory allocated for each node.
*/
-void coresight_release_path(struct coresight_path *path)
+void coresight_release_path_locked(struct coresight_path *path)
{
struct coresight_device *csdev;
struct coresight_node *nd, *next;
+ lockdep_assert_held(&coresight_mutex);
+
list_for_each_entry_safe(nd, next, &path->path_list, link) {
csdev = nd->csdev;
@@ -1087,6 +1093,12 @@ void coresight_release_path(struct coresight_path *path)
kfree(path);
}
+void coresight_release_path(struct coresight_path *path)
+{
+ guard(mutex)(&coresight_mutex);
+ coresight_release_path_locked(path);
+}
+
/* return true if the device is a suitable type for a default sink */
static bool coresight_is_def_sink_type(struct coresight_device *csdev)
{
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 2323a68584d4..faec4c7bb83d 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -402,7 +402,7 @@ etm_event_build_path(struct perf_event *event, int cpu,
/* ensure we can allocate a trace ID for this CPU */
ret = coresight_path_assign_trace_id(path, CS_MODE_PERF);
if (ret) {
- coresight_release_path(path);
+ coresight_release_path_locked(path);
path = NULL;
goto out;
}
@@ -428,6 +428,9 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
if (!event_data)
return NULL;
+ /* Protect sink selection, path construction and buffer allocation. */
+ mutex_lock(&coresight_mutex);
+
/* First get the selected sink from user space. */
sink_hash = ATTR_CFG_GET_FLD(&event->attr, sinkid);
if (sink_hash)
@@ -498,13 +501,13 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
if (!event_data->snk_config)
goto err;
-out:
+ mutex_unlock(&coresight_mutex);
return event_data;
err:
+ mutex_unlock(&coresight_mutex);
etm_free_aux(event_data);
- event_data = NULL;
- goto out;
+ return NULL;
}
static int etm_event_resume(struct coresight_path *path)
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index dddac946659f..edec5a7d2be3 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -143,6 +143,7 @@ coresight_find_default_sink(struct coresight_device *csdev);
struct coresight_path *coresight_build_path(struct coresight_device *csdev,
struct coresight_device *sink);
void coresight_release_path(struct coresight_path *path);
+void coresight_release_path_locked(struct coresight_path *path);
int coresight_add_sysfs_link(struct coresight_sysfs_link *info);
void coresight_remove_sysfs_link(struct coresight_sysfs_link *info);
int coresight_create_conns_sysfs_group(struct coresight_device *csdev);
diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c
index 75000fe64fda..5dd4e9b0426e 100644
--- a/drivers/hwtracing/coresight/coresight-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-sysfs.c
@@ -230,7 +230,7 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
coresight_disable_path(path);
err_path:
- coresight_release_path(path);
+ coresight_release_path_locked(path);
goto out;
}
EXPORT_SYMBOL_GPL(coresight_enable_sysfs);
@@ -256,7 +256,7 @@ void coresight_disable_sysfs(struct coresight_device *csdev)
goto out;
coresight_disable_path(path);
- coresight_release_path(path);
+ coresight_release_path_locked(path);
out:
mutex_unlock(&coresight_mutex);
--
2.43.0
next prev parent reply other threads:[~2026-10-16 10:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 10:46 [PATCH v4 00/10] coresight: Prevent per-thread events from sharing a sink James Clark
2026-10-16 10:46 ` [PATCH v4 01/10] coresight: configfs: Don't assume active until cscfg_mgr is set James Clark
2026-10-16 10:46 ` [PATCH v4 02/10] coresight: etm-perf: Remove workqueue for freeing AUX data James Clark
2026-10-16 10:46 ` James Clark [this message]
2026-10-16 10:46 ` [PATCH v4 04/10] coresight: etm-perf: Reject event if building path fails James Clark
2026-10-16 10:46 ` [PATCH v4 05/10] coresight: etm-perf: Prevent sink sharing at setup time James Clark
2026-10-16 10:46 ` [PATCH v4 06/10] coresight: tmc-etr: Reflect new sharing rules in allocator James Clark
2026-10-16 10:46 ` [PATCH v4 07/10] coresight: tmc-etr: Remove sharing guards from ETR James Clark
2026-10-16 10:46 ` [PATCH v4 08/10] coresight: tmc-etf: Remove sharing guards from ETF James Clark
2026-10-16 10:46 ` [PATCH v4 09/10] coresight: etb10: Remove sharing guards from ETB10 James Clark
2026-10-16 10:46 ` [PATCH v4 10/10] coresight: ultrasoc-smb: Remove sharing guards from SMB James Clark
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=20261016-james-cs-multiple-per-threads-v4-3-dedf961aca0e@linaro.org \
--to=james.clark@linaro.org \
--cc=coresight@lists.linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hejunhao3@huawei.com \
--cc=jic23@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuqi115@huawei.com \
--cc=mike.leach@arm.com \
--cc=smahar@meta.com \
--cc=suzuki.poulose@arm.com \
--cc=yeoreum.yun@arm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®