[PATCH v6 3/4] coresight: perf: Filter sources lacking the selected configuration

Amir Ayupov aaupov at fb.com
Fri Nov 20 10:54:33 PST 2026


A system configuration may deliberately omit some CoreSight devices.
Keep generic configuration enablement as a successful no-op for
nonparticipants, but exclude ETM sources without the selected
configuration before allocating an AUX session.

Add a setup-only query while the configuration is globally activated,
checking device registration and per-device availability under the
manager mutex. Use the existing path-building failure handling to remove
unsupported CPUs and fail setup if no usable source remains.

Suggested-by: Mike Leach <mike.leach at arm.com>
Assisted-by: Devmate:GPT-6.1-Sol
Signed-off-by: Amir Ayupov <aaupov at fb.com>
---
 .../hwtracing/coresight/coresight-etm-perf.c  |  4 +++
 .../hwtracing/coresight/coresight-syscfg.c    | 32 +++++++++++++++++++
 .../hwtracing/coresight/coresight-syscfg.h    |  2 ++
 3 files changed, 38 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 09b21a711a8764..2d64c3314c0bad 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -350,6 +350,7 @@ etm_event_build_path(struct perf_event *event, int cpu,
 {
 	struct coresight_path *path = NULL;
 	struct coresight_device *source, *sink;
+	u32 cfg_hash = ATTR_CFG_GET_FLD(&event->attr, configid);
 	int ret;
 
 	source = coresight_get_percpu_source_ref(cpu);
@@ -361,6 +362,9 @@ etm_event_build_path(struct perf_event *event, int cpu,
 	if (!source)
 		return NULL;
 
+	if (cfg_hash && !cscfg_csdev_can_activate_config(source, cfg_hash))
+		goto out;
+
 	/*
 	 * If AUX pause feature is enabled but the ETM driver does not
 	 * support the operations, skip for this source.
diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
index 11946e5718fc5e..f4e122f66e98c8 100644
--- a/drivers/hwtracing/coresight/coresight-syscfg.c
+++ b/drivers/hwtracing/coresight/coresight-syscfg.c
@@ -1050,6 +1050,38 @@ void cscfg_deactivate_config(unsigned long cfg_hash)
 }
 EXPORT_SYMBOL_GPL(cscfg_deactivate_config);
 
+/**
+ * cscfg_csdev_can_activate_config - Check whether a configuration is loaded on a device.
+ * @csdev: CoreSight device to check.
+ * @cfg_hash: Selector for the configuration.
+ *
+ * Does not activate or program the configuration. May sleep. The caller must
+ * keep the configuration activated while using the result to prevent unloading.
+ */
+bool cscfg_csdev_can_activate_config(struct coresight_device *csdev,
+				     unsigned long cfg_hash)
+{
+	struct cscfg_registered_csdev *csdev_item;
+	struct cscfg_config_csdev *config_csdev;
+
+	guard(mutex)(&cscfg_mutex);
+	if (!cscfg_mgr)
+		return false;
+
+	/* Unregistered devices do not have initialized configuration lists. */
+	list_for_each_entry(csdev_item, &cscfg_mgr->csdev_desc_list, item) {
+		if (csdev_item->csdev != csdev)
+			continue;
+		list_for_each_entry(config_csdev, &csdev->config_csdev_list, node) {
+			if ((unsigned long)config_csdev->config_desc->event_ea->var == cfg_hash)
+				return config_csdev->config_desc->available;
+		}
+		break;
+	}
+	return false;
+}
+EXPORT_SYMBOL_GPL(cscfg_csdev_can_activate_config);
+
 /**
  * cscfg_csdev_enable_active_config - Enable matching active configuration for device.
  *
diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h
index 658e93c3705f1c..05289060a277e5 100644
--- a/drivers/hwtracing/coresight/coresight-syscfg.h
+++ b/drivers/hwtracing/coresight/coresight-syscfg.h
@@ -120,6 +120,8 @@ int cscfg_register_csdev(struct coresight_device *csdev, u32 match_flags,
 void cscfg_unregister_csdev(struct coresight_device *csdev);
 int cscfg_activate_config(unsigned long cfg_hash);
 void cscfg_deactivate_config(unsigned long cfg_hash);
+bool cscfg_csdev_can_activate_config(struct coresight_device *csdev,
+				     unsigned long cfg_hash);
 void cscfg_csdev_reset_feats(struct coresight_device *csdev);
 int cscfg_csdev_enable_active_config(struct coresight_device *csdev,
 				     unsigned long cfg_hash, int preset);
-- 
2.52.1




More information about the linux-arm-kernel mailing list