coresight: Fix issue where a source device's helpers aren't disabled
authorJames Clark <james.clark@arm.com>
Mon, 29 Jan 2024 15:40:32 +0000 (15:40 +0000)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Mon, 12 Feb 2024 10:21:37 +0000 (10:21 +0000)
The linked commit reverts the change that accidentally used some sysfs
enable/disable functions from Perf which broke the refcounting, but it
also removes the fact that the sysfs disable function disabled the
helpers.

Add a new wrapper function that does both which is used by both Perf and
sysfs, and label the sysfs disable function appropriately. The naming of
all of the functions will be tidied up later to avoid this happening
again.

Fixes: 287e82cf69aa ("coresight: Fix crash when Perf and sysfs modes are used concurrently")
Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20240129154050.569566-2-james.clark@arm.com
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
drivers/hwtracing/coresight/coresight-core.c
drivers/hwtracing/coresight/coresight-etm-perf.c
drivers/hwtracing/coresight/coresight-priv.h

index 5dde597403b376dc89612a4567412bfce220c8ed..1dd3cd46fda48745fff0891a4871a108b9e2318d 100644 (file)
@@ -441,8 +441,26 @@ static void coresight_disable_helpers(struct coresight_device *csdev)
        }
 }
 
+/*
+ * Helper function to call source_ops(csdev)->disable and also disable the
+ * helpers.
+ *
+ * There is an imbalance between coresight_enable_path() and
+ * coresight_disable_path(). Enabling also enables the source's helpers as part
+ * of the path, but disabling always skips the first item in the path (which is
+ * the source), so sources and their helpers don't get disabled as part of that
+ * function and we need the extra step here.
+ */
+void coresight_disable_source(struct coresight_device *csdev, void *data)
+{
+       if (source_ops(csdev)->disable)
+               source_ops(csdev)->disable(csdev, data);
+       coresight_disable_helpers(csdev);
+}
+EXPORT_SYMBOL_GPL(coresight_disable_source);
+
 /**
- *  coresight_disable_source - Drop the reference count by 1 and disable
+ *  coresight_disable_source_sysfs - Drop the reference count by 1 and disable
  *  the device if there are no users left.
  *
  *  @csdev: The coresight device to disable
@@ -451,17 +469,15 @@ static void coresight_disable_helpers(struct coresight_device *csdev)
  *
  *  Returns true if the device has been disabled.
  */
-bool coresight_disable_source(struct coresight_device *csdev, void *data)
+static bool coresight_disable_source_sysfs(struct coresight_device *csdev,
+                                          void *data)
 {
        if (atomic_dec_return(&csdev->refcnt) == 0) {
-               if (source_ops(csdev)->disable)
-                       source_ops(csdev)->disable(csdev, data);
-               coresight_disable_helpers(csdev);
+               coresight_disable_source(csdev, data);
                csdev->enable = false;
        }
        return !csdev->enable;
 }
-EXPORT_SYMBOL_GPL(coresight_disable_source);
 
 /*
  * coresight_disable_path_from : Disable components in the given path beyond
@@ -1204,7 +1220,7 @@ void coresight_disable(struct coresight_device *csdev)
        if (ret)
                goto out;
 
-       if (!csdev->enable || !coresight_disable_source(csdev, NULL))
+       if (!csdev->enable || !coresight_disable_source_sysfs(csdev, NULL))
                goto out;
 
        switch (csdev->subtype.source_subtype) {
index a52cfcce25d6ddef4ee48eac1f049f7b13143b50..c0c60e6a1703e3fd23ce85d8bc1ac63c242381d4 100644 (file)
@@ -589,7 +589,7 @@ static void etm_event_stop(struct perf_event *event, int mode)
                return;
 
        /* stop tracer */
-       source_ops(csdev)->disable(csdev, event);
+       coresight_disable_source(csdev, event);
 
        /* tell the core */
        event->hw.state = PERF_HES_STOPPED;
index 767076e07970117c890af346a48b8246ce92a246..30c051055e54b35d8e4fcb6f816fd79cbfdcc669 100644 (file)
@@ -233,6 +233,6 @@ void coresight_set_percpu_sink(int cpu, struct coresight_device *csdev);
 struct coresight_device *coresight_get_percpu_sink(int cpu);
 int coresight_enable_source(struct coresight_device *csdev, enum cs_mode mode,
                            void *data);
-bool coresight_disable_source(struct coresight_device *csdev, void *data);
+void coresight_disable_source(struct coresight_device *csdev, void *data);
 
 #endif