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

Leo Yan leo.yan at arm.com
Mon Nov 30 09:47:28 PST 2026


On Fri, Nov 20, 2026 at 10:54:33AM -0800, Amir Ayupov wrote:

[...]

> 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;

Can we reuse cscfg_csdev_enable_active_config() for the check?

@@ -535,7 +533,7 @@ static void cscfg_set_configs_available(struct cscfg_config_desc **config_descs)
 
        if (config_descs) {
                for (i = 0; config_descs[i]; i++)
-                       config_descs[i]->available = true;
+                       smp_store_release(&config_descs[i]->available, true);
        }
 }
 
@@ -1119,8 +1117,16 @@ int cscfg_csdev_enable_active_config(struct coresight_device *csdev,
        raw_spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags);
        list_for_each_entry(config_csdev_item, &csdev->config_csdev_list, node) {
                config_desc = config_csdev_item->config_desc;
-               if (((unsigned long)config_desc->event_ea->var == cfg_hash) &&
-                               cscfg_config_desc_get(config_desc)) {
+               if ((unsigned long)config_desc->event_ea->var != cfg_hash)
+                       continue;
+
+               /* Pairs with cscfg_set_configs_available() after loading */
+               if (!smp_load_acquire(&config_desc->available)) {
+                       err = -EBUSY;
+                       break;
+               }
+
+               if (cscfg_config_desc_get(config_desc)) {
                        config_csdev_active = config_csdev_item;
                        csdev->active_cscfg_ctxt = (void *)config_csdev_active;
                        break;

Please see whole change suggest by AI: https://termbin.com/fjkw3 (it
also tries to fix a race condition).

@Mike, does this seem feasible to you? I'd prefer not to introduce new
interfaces here.



More information about the linux-arm-kernel mailing list