Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] coresight: trbe: Hide enable_sink sysfs file
@ 2026-08-07 10:13 James Clark
  2026-08-11  9:04 ` Leo Yan
  0 siblings, 1 reply; 4+ messages in thread
From: James Clark @ 2026-08-07 10:13 UTC (permalink / raw)
  To: Suzuki K Poulose, Mike Leach, Leo Yan, Yeoreum Yun
  Cc: coresight, linux-arm-kernel, linux-kernel, James Clark

TRBE doesn't support sysfs mode, but the enable_sink file can still be
successfully written to enable the device, and only attempting to enable
the source would later fail.

Avoid misleading users by adding a flag that devices can use to hide
either the enable_sink or enable_source files, and set it for TRBE.

Don't set it for ETE as it's possible that ETE could appear on the
legacy bus and work with sysfs, and writing to enable_source already
reports EINVAL if the device doesn't support sysfs mode.

Signed-off-by: James Clark <james.clark@linaro.org>
---
Changes in v2:
- Re-use CORESIGHT_DESC flags in csdev instead of converting to bool.
- Hide all remaining attrs after label instead of only source and sink
  attrs as there aren't any others anyway (Leo).
- Link to v1: https://lore.kernel.org/r/20260507-james-cs-hide-trbe-enable-v1-1-b4e40439f44c@linaro.org
---
 drivers/hwtracing/coresight/coresight-core.c  |  1 +
 drivers/hwtracing/coresight/coresight-sysfs.c | 15 +++++++++------
 drivers/hwtracing/coresight/coresight-trbe.c  |  7 +++++++
 include/linux/coresight.h                     |  4 ++++
 4 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index f7b1308a759c..a0c098980096 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1543,6 +1543,7 @@ coresight_init_device(struct coresight_desc *desc)
 	csdev->ops = desc->ops;
 	csdev->access = desc->access;
 	csdev->orphan = true;
+	csdev->flags = desc->flags;
 
 	if (desc->flags & CORESIGHT_DESC_CPU_BOUND) {
 		csdev->cpu = desc->cpu;
diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c
index 4b010f8bc4c0..75000fe64fda 100644
--- a/drivers/hwtracing/coresight/coresight-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-sysfs.c
@@ -346,16 +346,19 @@ static ssize_t label_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(label);
 
-static umode_t label_is_visible(struct kobject *kobj,
-				   struct attribute *attr, int n)
+static umode_t coresight_attr_is_visible(struct kobject *kobj,
+					 struct attribute *attr, int n)
 {
 	struct device *dev = kobj_to_dev(kobj);
+	struct coresight_device *csdev = to_coresight_device(dev);
 
 	if (attr == &dev_attr_label.attr) {
 		if (fwnode_property_present(dev_fwnode(dev), "label"))
 			return attr->mode;
 		else
 			return 0;
+	} else if (csdev->flags & CORESIGHT_DESC_NO_SYSFS_MODE) {
+		return 0;
 	}
 
 	return attr->mode;
@@ -369,7 +372,7 @@ static struct attribute *coresight_sink_attrs[] = {
 
 static struct attribute_group coresight_sink_group = {
 	.attrs = coresight_sink_attrs,
-	.is_visible = label_is_visible,
+	.is_visible = coresight_attr_is_visible,
 };
 __ATTRIBUTE_GROUPS(coresight_sink);
 
@@ -381,7 +384,7 @@ static struct attribute *coresight_source_attrs[] = {
 
 static struct attribute_group coresight_source_group = {
 	.attrs = coresight_source_attrs,
-	.is_visible = label_is_visible,
+	.is_visible = coresight_attr_is_visible,
 };
 __ATTRIBUTE_GROUPS(coresight_source);
 
@@ -392,7 +395,7 @@ static struct attribute *coresight_link_attrs[] = {
 
 static struct attribute_group coresight_link_group = {
 	.attrs = coresight_link_attrs,
-	.is_visible = label_is_visible,
+	.is_visible = coresight_attr_is_visible,
 };
 __ATTRIBUTE_GROUPS(coresight_link);
 
@@ -403,7 +406,7 @@ static struct attribute *coresight_helper_attrs[] = {
 
 static struct attribute_group coresight_helper_group = {
 	.attrs = coresight_helper_attrs,
-	.is_visible = label_is_visible,
+	.is_visible = coresight_attr_is_visible,
 };
 __ATTRIBUTE_GROUPS(coresight_helper);
 
diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c
index c7cbca45f2de..eca8e13a9744 100644
--- a/drivers/hwtracing/coresight/coresight-trbe.c
+++ b/drivers/hwtracing/coresight/coresight-trbe.c
@@ -1348,6 +1348,13 @@ static void arm_trbe_register_coresight_cpu(struct trbe_drvdata *drvdata, int cp
 	desc.dev = dev;
 	desc.cpu = cpu;
 	desc.flags = CORESIGHT_DESC_CPU_BOUND;
+	/*
+	 * ETE isn't connected to TRBE with a link like other Coresight devices
+	 * and the TRBE driver has been written to always assume Perf mode, so
+	 * Prevent sysfs from being used.
+	 */
+	desc.flags |= CORESIGHT_DESC_NO_SYSFS_MODE;
+
 	trbe_csdev = coresight_register(&desc);
 	if (IS_ERR(trbe_csdev))
 		goto cpu_clear;
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index add0579cad88..6cd1d01b843b 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -142,6 +142,8 @@ struct csdev_access {
 	})
 
 #define CORESIGHT_DESC_CPU_BOUND	BIT(0)
+/* Device can't be activated from sysfs, only via Perf. */
+#define CORESIGHT_DESC_NO_SYSFS_MODE	BIT(1)
 
 /**
  * struct coresight_desc - description of a component required from drivers
@@ -310,6 +312,8 @@ struct coresight_device {
 	struct list_head config_csdev_list;
 	raw_spinlock_t cscfg_csdev_lock;
 	void *active_cscfg_ctxt;
+	/* CORESIGHT_DESC_[x] flags */
+	u32 flags;
 };
 
 /*

---
base-commit: c8eb4a8dd259fb2b215da32764fa8c6c76519896
change-id: 20260506-james-cs-hide-trbe-enable-3c8d784e72d8

Best regards,
--  
James Clark <james.clark@linaro.org>



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-11  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 10:13 [PATCH v2] coresight: trbe: Hide enable_sink sysfs file James Clark
2026-08-11  9:04 ` Leo Yan
2026-08-11  9:10   ` James Clark
2026-08-11  9:17     ` Suzuki K Poulose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox