linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 00/24] coresight: allow to build coresight as modules
@ 2020-08-07 11:11 Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 01/24] coresight: cpu_debug: add module name in Kconfig Tingwei Zhang
                   ` (23 more replies)
  0 siblings, 24 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel


Allow to build coresight as modules. This gives developers the feasibility to
test their code without reboot.

This series is based on below two series.

 - "coresight: allow to build components as modules"
   https://lkml.org/lkml/2018/6/5/989
 - "coresight: make drivers modular"
   https://lkml.org/lkml/2020/1/17/468

Change from v7:
Depends on below change for ETM hotplug (Sai)
https://lore.kernel.org/linux-arm-kernel/20200729051310.18436-1-saiprakash.ranjan@codeaurora.org/
Add mutex lock to protect etmdrvdata[] (Suzuki)
Add helper function coresight_get_ref()	(Suzuki)
Reorg replicator and funnel change. Use two patches to support these
two drivers. (Suzuki)
Add fix tag to "coresight: etm: perf: Fix warning caused by etm_setup_aux
failure" (Suzuki)
Update author of "coresight: cti: Fix bug clearing sysfs links on callback"

Change from v6:
Correct module description for CATU (Mike)
Check ect_ret equals 0 and set ect_enabled flag (Mike)
Add Tested-by and Reviewed-by from Mike

Change from v5:
Add below CTI clean up change from Mike into series
 -https://lists.linaro.org/pipermail/coresight/2020-July/004349.html
Increase module reference count when enabling CTI device (Mike)

Change from v4:
Fix error handling in coresight_grab_devicei() (Greg)
Add coresight: cti: Fix remove sysfs link error from Mike
 -https://lists.linaro.org/pipermail/coresight/2020-July/004275.html
Move cti_remove_conn_xrefs() into cti_remove() (Mike)
Align patch subject to coresight: <component>: <description> (Mike)

Change from v3:
Rebase to coresight-next (Mike and Mathieu)
Reorder try_get_module() (Suzuki)
Clean up etmdrvdata[] in device remote path (Mike)
Move cti_remove_conn_xrefs to cti_remove (Mike)

Change from v2:
Rebase to 5.8-rc5. Export coresight_add_sysfs_link and
coresight_remove_sysfs_link
Fix one cut and paste error on MODULE_DESCRIPTION of CTI

Change from v1:
Use try_module_get() to avoid module to be unloaded when device is used
in active trace session. (Mathieu P)

Change from above two series.
This series adds the support to dynamically remove module when the device in
that module is enabled and used by some trace path. It disables all trace
paths with that device and release the trace path.
Kim Phillips (8):
  coresight: use IS_ENABLED for CONFIGs that may be modules
  coresight: etm3x: allow etm3x to be built as a module
  coresight: etm4x: allow etm4x to be built as a module
  coresight: etb: allow etb to be built as a module
  coresight: tpiu: allow tpiu to be built as a module
  coresight: tmc: allow tmc to be built as a module
  coresight: allow funnel driver to be built as module
  coresight: allow replicator driver to be built as module

Mian Yousaf Kaukab (2):
  coresight: export global symbols
  coresight: tmc-etr: add function to register catu ops

Mike Leach (2):
  coresight: cti: Fix remove sysfs link error
  coresight: cti: Fix bug clearing sysfs links on callback

Tingwei Zhang (12):
  coresight: cpu_debug: add module name in Kconfig
  coresight: cpu_debug: define MODULE_DEVICE_TABLE
  coresight: add coresight prefix to barrier_pkt
  coresight: add try_get_module() in coresight_grab_device()
  coresight: stm: allow to build coresight-stm as a module
  coresight: etm: perf: Fix warning caused by etm_setup_aux failure
  coresight: cti: add function to register cti associate ops
  coresight: cti: don't disable ect device if it's not enabled
  coresight: cti: increase reference count when enabling cti
  coresight: cti: allow cti to be built as a module
  coresight: catu: allow catu drivers to be built as modules
  coresight: allow the coresight core driver to be built as a module

 drivers/hwtracing/coresight/Kconfig           |  54 ++++--
 drivers/hwtracing/coresight/Makefile          |  22 +--
 drivers/hwtracing/coresight/coresight-catu.c  |  37 ++++-
 drivers/hwtracing/coresight/coresight-catu.h  |   2 -
 .../{coresight.c => coresight-core.c}         | 156 +++++++++++++++---
 .../hwtracing/coresight/coresight-cpu-debug.c |   2 +
 .../{coresight-cti.c => coresight-cti-core.c} |  62 ++++++-
 drivers/hwtracing/coresight/coresight-etb10.c |  27 ++-
 .../hwtracing/coresight/coresight-etm-perf.c  |  13 +-
 .../hwtracing/coresight/coresight-etm-perf.h  |   5 +-
 ...resight-etm3x.c => coresight-etm3x-core.c} |  27 ++-
 ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++----
 .../hwtracing/coresight/coresight-funnel.c    |  62 ++++++-
 .../hwtracing/coresight/coresight-platform.c  |   1 +
 drivers/hwtracing/coresight/coresight-priv.h  |  24 ++-
 .../coresight/coresight-replicator.c          |  63 ++++++-
 drivers/hwtracing/coresight/coresight-stm.c   |  20 ++-
 drivers/hwtracing/coresight/coresight-sysfs.c |   2 +
 .../{coresight-tmc.c => coresight-tmc-core.c} |  24 ++-
 .../hwtracing/coresight/coresight-tmc-etf.c   |   2 +-
 .../hwtracing/coresight/coresight-tmc-etr.c   |  21 ++-
 drivers/hwtracing/coresight/coresight-tmc.h   |   3 +
 drivers/hwtracing/coresight/coresight-tpiu.c  |  19 ++-
 include/linux/coresight.h                     |   3 +-
 24 files changed, 650 insertions(+), 119 deletions(-)
 rename drivers/hwtracing/coresight/{coresight.c => coresight-core.c} (92%)
 rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} (94%)
 rename drivers/hwtracing/coresight/{coresight-etm3x.c => coresight-etm3x-core.c} (97%)
 rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (95%)
 rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} (95%)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 01/24] coresight: cpu_debug: add module name in Kconfig
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-12 17:16   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 02/24] coresight: cpu_debug: define MODULE_DEVICE_TABLE Tingwei Zhang
                   ` (22 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

Provide name of cpu_debug module in Kconfig help section.

Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 02dbb5ca3bcf..4663fd1bbffc 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -110,6 +110,9 @@ config CORESIGHT_CPU_DEBUG
 	  properly, please refer Documentation/trace/coresight/coresight-cpu-debug.rst
 	  for detailed description and the example for usage.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-cpu-debug.
+
 config CORESIGHT_CTI
 	bool "CoreSight Cross Trigger Interface (CTI) driver"
 	depends on ARM || ARM64
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 02/24] coresight: cpu_debug: define MODULE_DEVICE_TABLE
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 01/24] coresight: cpu_debug: add module name in Kconfig Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules Tingwei Zhang
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

Define a MODULE_DEVICE_TABLE for cpu_debug so module can
be auto loaded on boot.

Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-cpu-debug.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c
index 96544b348c27..1d0880b3764a 100644
--- a/drivers/hwtracing/coresight/coresight-cpu-debug.c
+++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c
@@ -665,6 +665,8 @@ static const struct amba_id debug_ids[] = {
 	{},
 };
 
+MODULE_DEVICE_TABLE(amba, debug_ids);
+
 static struct amba_driver debug_driver = {
 	.drv = {
 		.name   = "coresight-cpu-debug",
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 01/24] coresight: cpu_debug: add module name in Kconfig Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 02/24] coresight: cpu_debug: define MODULE_DEVICE_TABLE Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-12 17:54   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 04/24] coresight: add coresight prefix to barrier_pkt Tingwei Zhang
                   ` (20 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Checking for ifdef CONFIG_x fails if CONFIG_x=m.  Use IS_ENABLED
that is true for both built-ins and modules, instead.  Required
when building coresight components as modules.

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-etm-perf.h | 2 +-
 drivers/hwtracing/coresight/coresight-priv.h     | 2 +-
 include/linux/coresight.h                        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
index 015213abe00a..05f89723e282 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.h
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
@@ -57,7 +57,7 @@ struct etm_event_data {
 	struct list_head * __percpu *path;
 };
 
-#ifdef CONFIG_CORESIGHT
+#if IS_ENABLED(CONFIG_CORESIGHT)
 int etm_perf_symlink(struct coresight_device *csdev, bool link);
 int etm_perf_add_symlink_sink(struct coresight_device *csdev);
 void etm_perf_del_symlink_sink(struct coresight_device *csdev);
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index f2dc625ea585..d801a2755432 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -165,7 +165,7 @@ int coresight_make_links(struct coresight_device *orig,
 void coresight_remove_links(struct coresight_device *orig,
 			    struct coresight_connection *conn);
 
-#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
+#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X)
 extern int etm_readl_cp14(u32 off, unsigned int *val);
 extern int etm_writel_cp14(u32 off, u32 val);
 #else
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 58fffdecdbfd..3bb738f9a326 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -324,7 +324,7 @@ struct coresight_ops {
 	const struct coresight_ops_ect *ect_ops;
 };
 
-#ifdef CONFIG_CORESIGHT
+#if IS_ENABLED(CONFIG_CORESIGHT)
 extern struct coresight_device *
 coresight_register(struct coresight_desc *desc);
 extern void coresight_unregister(struct coresight_device *csdev);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 04/24] coresight: add coresight prefix to barrier_pkt
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (2 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-12 17:58   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 05/24] coresight: export global symbols Tingwei Zhang
                   ` (19 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

Add coresight prefix to make it specific. It will be a export symbol.

Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-etb10.c   | 2 +-
 drivers/hwtracing/coresight/coresight-priv.h    | 8 ++++----
 drivers/hwtracing/coresight/coresight-tmc-etf.c | 2 +-
 drivers/hwtracing/coresight/coresight.c         | 3 ++-
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c
index 03e3f2590191..04ee9cda988d 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -525,7 +525,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
 
 	cur = buf->cur;
 	offset = buf->offset;
-	barrier = barrier_pkt;
+	barrier = coresight_barrier_pkt;
 
 	for (i = 0; i < to_read; i += 4) {
 		buf_ptr = buf->data_pages[cur] + offset;
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index d801a2755432..dcb8aeb6af62 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -66,8 +66,8 @@ static DEVICE_ATTR_RO(name)
 #define coresight_simple_reg64(type, name, lo_off, hi_off)		\
 	__coresight_simple_func(type, NULL, name, lo_off, hi_off)
 
-extern const u32 barrier_pkt[4];
-#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(barrier_pkt))
+extern const u32 coresight_barrier_pkt[4];
+#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(coresight_barrier_pkt))
 
 enum etm_addr_type {
 	ETM_ADDR_TYPE_NONE,
@@ -104,10 +104,10 @@ struct cs_buffers {
 static inline void coresight_insert_barrier_packet(void *buf)
 {
 	if (buf)
-		memcpy(buf, barrier_pkt, CORESIGHT_BARRIER_PKT_SIZE);
+		memcpy(buf, coresight_barrier_pkt,
+				CORESIGHT_BARRIER_PKT_SIZE);
 }
 
-
 static inline void CS_LOCK(void __iomem *addr)
 {
 	do {
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c
index 6375504ba8b0..44402d413ebb 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etf.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c
@@ -519,7 +519,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev,
 
 	cur = buf->cur;
 	offset = buf->offset;
-	barrier = barrier_pkt;
+	barrier = coresight_barrier_pkt;
 
 	/* for every byte to read */
 	for (i = 0; i < to_read; i += 4) {
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index e9c90f2de34a..310b1b825dd1 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -53,7 +53,8 @@ static struct list_head *stm_path;
  * beginning of the data collected in a buffer.  That way the decoder knows that
  * it needs to look for another sync sequence.
  */
-const u32 barrier_pkt[4] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
+const u32 coresight_barrier_pkt[4] = {
+		0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
 
 static int coresight_id_match(struct device *dev, void *data)
 {
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 05/24] coresight: export global symbols
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (3 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 04/24] coresight: add coresight prefix to barrier_pkt Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 06/24] coresight: add try_get_module() in coresight_grab_device() Tingwei Zhang
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

From: Mian Yousaf Kaukab <ykaukab@suse.de>

Export symbols used among coresight modules.

Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 1 +
 drivers/hwtracing/coresight/coresight-sysfs.c    | 2 ++
 drivers/hwtracing/coresight/coresight-tmc-etr.c  | 6 ++++++
 drivers/hwtracing/coresight/coresight.c          | 8 ++++++++
 4 files changed, 17 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 1a3169e69bb1..dcb0592418ae 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -517,6 +517,7 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(etm_perf_symlink);
 
 static ssize_t etm_perf_sink_name_show(struct device *dev,
 				       struct device_attribute *dattr,
diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c
index 82afeaf2ccc4..34d2a2d31d00 100644
--- a/drivers/hwtracing/coresight/coresight-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-sysfs.c
@@ -102,6 +102,7 @@ int coresight_add_sysfs_link(struct coresight_sysfs_link *info)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(coresight_add_sysfs_link);
 
 void coresight_remove_sysfs_link(struct coresight_sysfs_link *info)
 {
@@ -122,6 +123,7 @@ void coresight_remove_sysfs_link(struct coresight_sysfs_link *info)
 	info->orig->nr_links--;
 	info->target->nr_links--;
 }
+EXPORT_SYMBOL_GPL(coresight_remove_sysfs_link);
 
 /*
  * coresight_make_links: Make a link for a connection from a @orig
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index b29c2db94d96..ad991a37e2d2 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -255,6 +255,7 @@ void tmc_free_sg_table(struct tmc_sg_table *sg_table)
 	tmc_free_table_pages(sg_table);
 	tmc_free_data_pages(sg_table);
 }
+EXPORT_SYMBOL_GPL(tmc_free_sg_table);
 
 /*
  * Alloc pages for the table. Since this will be used by the device,
@@ -340,6 +341,7 @@ struct tmc_sg_table *tmc_alloc_sg_table(struct device *dev,
 
 	return sg_table;
 }
+EXPORT_SYMBOL_GPL(tmc_alloc_sg_table);
 
 /*
  * tmc_sg_table_sync_data_range: Sync the data buffer written
@@ -360,6 +362,7 @@ void tmc_sg_table_sync_data_range(struct tmc_sg_table *table,
 					PAGE_SIZE, DMA_FROM_DEVICE);
 	}
 }
+EXPORT_SYMBOL_GPL(tmc_sg_table_sync_data_range);
 
 /* tmc_sg_sync_table: Sync the page table */
 void tmc_sg_table_sync_table(struct tmc_sg_table *sg_table)
@@ -372,6 +375,7 @@ void tmc_sg_table_sync_table(struct tmc_sg_table *sg_table)
 		dma_sync_single_for_device(real_dev, table_pages->daddrs[i],
 					   PAGE_SIZE, DMA_TO_DEVICE);
 }
+EXPORT_SYMBOL_GPL(tmc_sg_table_sync_table);
 
 /*
  * tmc_sg_table_get_data: Get the buffer pointer for data @offset
@@ -401,6 +405,7 @@ ssize_t tmc_sg_table_get_data(struct tmc_sg_table *sg_table,
 		*bufpp = page_address(data_pages->pages[pg_idx]) + pg_offset;
 	return len;
 }
+EXPORT_SYMBOL_GPL(tmc_sg_table_get_data);
 
 #ifdef ETR_SG_DEBUG
 /* Map a dma address to virtual address */
@@ -766,6 +771,7 @@ tmc_etr_get_catu_device(struct tmc_drvdata *drvdata)
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(tmc_etr_get_catu_device);
 
 static inline int tmc_etr_enable_catu(struct tmc_drvdata *drvdata,
 				      struct etr_buf *etr_buf)
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 310b1b825dd1..b7151c5f81b1 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -55,6 +55,7 @@ static struct list_head *stm_path;
  */
 const u32 coresight_barrier_pkt[4] = {
 		0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
+EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
 
 static int coresight_id_match(struct device *dev, void *data)
 {
@@ -180,6 +181,7 @@ int coresight_claim_device_unlocked(void __iomem *base)
 	coresight_clear_claim_tags(base);
 	return -EBUSY;
 }
+EXPORT_SYMBOL_GPL(coresight_claim_device_unlocked);
 
 int coresight_claim_device(void __iomem *base)
 {
@@ -191,6 +193,7 @@ int coresight_claim_device(void __iomem *base)
 
 	return rc;
 }
+EXPORT_SYMBOL_GPL(coresight_claim_device);
 
 /*
  * coresight_disclaim_device_unlocked : Clear the claim tags for the device.
@@ -209,6 +212,7 @@ void coresight_disclaim_device_unlocked(void __iomem *base)
 		 */
 		WARN_ON_ONCE(1);
 }
+EXPORT_SYMBOL_GPL(coresight_disclaim_device_unlocked);
 
 void coresight_disclaim_device(void __iomem *base)
 {
@@ -216,6 +220,7 @@ void coresight_disclaim_device(void __iomem *base)
 	coresight_disclaim_device_unlocked(base);
 	CS_LOCK(base);
 }
+EXPORT_SYMBOL_GPL(coresight_disclaim_device);
 
 /* enable or disable an associated CTI device of the supplied CS device */
 static int
@@ -468,6 +473,7 @@ void coresight_disable_path(struct list_head *path)
 {
 	coresight_disable_path_from(path, NULL);
 }
+EXPORT_SYMBOL_GPL(coresight_disable_path);
 
 int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data)
 {
@@ -1377,6 +1383,7 @@ int coresight_timeout(void __iomem *addr, u32 offset, int position, int value)
 
 	return -EAGAIN;
 }
+EXPORT_SYMBOL_GPL(coresight_timeout);
 
 struct bus_type coresight_bustype = {
 	.name	= "coresight",
@@ -1553,6 +1560,7 @@ bool coresight_loses_context_with_cpu(struct device *dev)
 	return fwnode_property_present(dev_fwnode(dev),
 				       "arm,coresight-loses-context-with-cpu");
 }
+EXPORT_SYMBOL_GPL(coresight_loses_context_with_cpu);
 
 /*
  * coresight_alloc_device_name - Get an index for a given device in the
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 06/24] coresight: add try_get_module() in coresight_grab_device()
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (4 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 05/24] coresight: export global symbols Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-12 19:36   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 07/24] coresight: stm: allow to build coresight-stm as a module Tingwei Zhang
                   ` (17 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

When coresight device is in an active session, driver module of
that device should not be removed. Use try_get_module() in
coresight_grab_device() to prevent module to be unloaded.
Use get_device()/put_device() to protect device data
in the middle of active session.

Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight.c | 61 ++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index b7151c5f81b1..0b0e31577b9b 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -634,13 +634,45 @@ struct coresight_device *coresight_get_sink_by_id(u32 id)
 	return dev ? to_coresight_device(dev) : NULL;
 }
 
+/**
+ * coresight_get_ref- Helper function to increase reference count to module
+ * and device.
+ * Return true in successful case and power up the device.
+ * Return false when failed to get reference of module.
+ */
+static inline bool coresight_get_ref(struct coresight_device *csdev)
+{
+	struct device *dev = csdev->dev.parent;
+
+	/* Make sure the driver can't be removed */
+	if (!try_module_get(dev->driver->owner))
+		return false;
+	/* Make sure the device can't go away */
+	get_device(dev);
+	pm_runtime_get_sync(dev);
+	return true;
+}
+
+/**
+ * coresight_put_ref- Helper function to decrease reference count to module
+ * and device. Power off the device.
+ */
+static inline void coresight_put_ref(struct coresight_device *csdev)
+{
+	struct device *dev = csdev->dev.parent;
+
+	pm_runtime_put(dev);
+	put_device(dev);
+	module_put(dev->driver->owner);
+}
+
 /*
  * coresight_grab_device - Power up this device and any of the helper
  * devices connected to it for trace operation. Since the helper devices
  * don't appear on the trace path, they should be handled along with the
  * the master device.
  */
-static void coresight_grab_device(struct coresight_device *csdev)
+static int coresight_grab_device(struct coresight_device *csdev)
 {
 	int i;
 
@@ -649,9 +681,20 @@ static void coresight_grab_device(struct coresight_device *csdev)
 
 		child  = csdev->pdata->conns[i].child_dev;
 		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-			pm_runtime_get_sync(child->dev.parent);
+			if (!coresight_get_ref(child))
+				goto err;
+	}
+	if (coresight_get_ref(csdev))
+		return 0;
+err:
+	for (i--; i >= 0; i--) {
+		struct coresight_device *child;
+
+		child  = csdev->pdata->conns[i].child_dev;
+		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
+			coresight_put_ref(child);
 	}
-	pm_runtime_get_sync(csdev->dev.parent);
+	return -ENODEV;
 }
 
 /*
@@ -662,13 +705,13 @@ static void coresight_drop_device(struct coresight_device *csdev)
 {
 	int i;
 
-	pm_runtime_put(csdev->dev.parent);
+	coresight_put_ref(csdev);
 	for (i = 0; i < csdev->pdata->nr_outport; i++) {
 		struct coresight_device *child;
 
 		child  = csdev->pdata->conns[i].child_dev;
 		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-			pm_runtime_put(child->dev.parent);
+			coresight_put_ref(child);
 	}
 }
 
@@ -687,7 +730,7 @@ static int _coresight_build_path(struct coresight_device *csdev,
 				 struct coresight_device *sink,
 				 struct list_head *path)
 {
-	int i;
+	int i, ret;
 	bool found = false;
 	struct coresight_node *node;
 
@@ -721,7 +764,11 @@ static int _coresight_build_path(struct coresight_device *csdev,
 	if (!node)
 		return -ENOMEM;
 
-	coresight_grab_device(csdev);
+	ret = coresight_grab_device(csdev);
+	if (ret) {
+		kfree(node);
+		return ret;
+	}
 	node->csdev = csdev;
 	list_add(&node->link, path);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 07/24] coresight: stm: allow to build coresight-stm as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (5 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 06/24] coresight: add try_get_module() in coresight_grab_device() Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure Tingwei Zhang
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

- Kconfig becomes a tristate, to allow =m
- add a stm_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/Kconfig         |  5 ++++-
 drivers/hwtracing/coresight/coresight-stm.c | 20 +++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 4663fd1bbffc..6433f835fc97 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -86,7 +86,7 @@ config CORESIGHT_SOURCE_ETM4X
 	  data tracing may also be available.
 
 config CORESIGHT_STM
-	bool "CoreSight System Trace Macrocell driver"
+	tristate "CoreSight System Trace Macrocell driver"
 	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
 	select CORESIGHT_LINKS_AND_SINKS
 	select STM
@@ -96,6 +96,9 @@ config CORESIGHT_STM
 	  logging useful software events or data coming from various entities
 	  in the system, possibly running different OSs
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-stm.
+
 config CORESIGHT_CPU_DEBUG
 	tristate "CoreSight CPU Debug driver"
 	depends on ARM || ARM64
diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
index 673d2f56ed1e..b74072e78436 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -948,6 +948,17 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
 	return ret;
 }
 
+static int __exit stm_remove(struct amba_device *adev)
+{
+	struct stm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	coresight_unregister(drvdata->csdev);
+
+	stm_unregister_device(&drvdata->stm);
+
+	return 0;
+}
+
 #ifdef CONFIG_PM
 static int stm_runtime_suspend(struct device *dev)
 {
@@ -980,6 +991,8 @@ static const struct amba_id stm_ids[] = {
 	{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, stm_ids);
+
 static struct amba_driver stm_driver = {
 	.drv = {
 		.name   = "coresight-stm",
@@ -988,7 +1001,12 @@ static struct amba_driver stm_driver = {
 		.suppress_bind_attrs = true,
 	},
 	.probe          = stm_probe,
+	.remove         = stm_remove,
 	.id_table	= stm_ids,
 };
 
-builtin_amba_driver(stm_driver);
+module_amba_driver(stm_driver);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_DESCRIPTION("Arm CoreSight System Trace Macrocell driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (6 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 07/24] coresight: stm: allow to build coresight-stm as a module Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-12 20:48   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module Tingwei Zhang
                   ` (15 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

When coresight_build_path() fails on all the cpus, etm_setup_aux
calls etm_free_aux() to free allocated event_data.
WARN_ON(cpumask_empty(mask) will be triggered since cpu mask is empty.
Check event_data->snk_config is not NULL first to avoid this
warning.

Fixes: f5200aa9831f38 ("coresight: perf: Refactor function free_event_data()")
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index dcb0592418ae..3728c44e5763 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -126,10 +126,10 @@ static void free_sink_buffer(struct etm_event_data *event_data)
 	cpumask_t *mask = &event_data->mask;
 	struct coresight_device *sink;
 
-	if (WARN_ON(cpumask_empty(mask)))
+	if (!event_data->snk_config)
 		return;
 
-	if (!event_data->snk_config)
+	if (WARN_ON(cpumask_empty(mask)))
 		return;
 
 	cpu = cpumask_first(mask);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (7 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-12 20:47   ` Mathieu Poirier
  2020-08-13  9:47   ` Suzuki K Poulose
  2020-08-07 11:11 ` [PATCH v8 10/24] coresight: etm4x: allow etm4x " Tingwei Zhang
                   ` (14 subsequent siblings)
  23 siblings, 2 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-etm3x as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-etm3x by the Makefile
- add an etm_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
---
 drivers/hwtracing/coresight/Kconfig           |  5 +++-
 drivers/hwtracing/coresight/Makefile          |  3 ++-
 ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++-
 3 files changed, 32 insertions(+), 3 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm3x.c => coresight-etm3x-core.c} (97%)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 6433f835fc97..8fd9fd139cf3 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
 	  special enhancement or added features.
 
 config CORESIGHT_SOURCE_ETM3X
-	bool "CoreSight Embedded Trace Macrocell 3.x driver"
+	tristate "CoreSight Embedded Trace Macrocell 3.x driver"
 	depends on !ARM64
 	select CORESIGHT_LINKS_AND_SINKS
 	help
@@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
 	  This is primarily useful for instruction level tracing.  Depending
 	  the ETM version data tracing may also be available.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-etm3x.
+
 config CORESIGHT_SOURCE_ETM4X
 	bool "CoreSight Embedded Trace Macrocell 4.x driver"
 	depends on ARM64
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index 19497d1d92bf..d619cfd0abd8 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
 obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
 obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
 					   coresight-replicator.o
-obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o coresight-etm-cp14.o \
+obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
+coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
 					coresight-etm3x-sysfs.o
 obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
 					coresight-etm4x-sysfs.o
diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c
similarity index 97%
rename from drivers/hwtracing/coresight/coresight-etm3x.c
rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
index bf22dcfd3327..82b333c40006 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
@@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
 	return ret;
 }
 
+static int __exit etm_remove(struct amba_device *adev)
+{
+	struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	etm_perf_symlink(drvdata->csdev, false);
+
+	if (--etm_count == 0) {
+		cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
+		if (hp_online)
+			cpuhp_remove_state_nocalls(hp_online);
+	}
+
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
+
 #ifdef CONFIG_PM
 static int etm_runtime_suspend(struct device *dev)
 {
@@ -937,6 +954,8 @@ static const struct amba_id etm_ids[] = {
 	{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, etm_ids);
+
 static struct amba_driver etm_driver = {
 	.drv = {
 		.name	= "coresight-etm3x",
@@ -945,6 +964,12 @@ static struct amba_driver etm_driver = {
 		.suppress_bind_attrs = true,
 	},
 	.probe		= etm_probe,
+	.remove         = etm_remove,
 	.id_table	= etm_ids,
 };
-builtin_amba_driver(etm_driver);
+module_amba_driver(etm_driver);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (8 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-13 19:39   ` Mathieu Poirier
                     ` (2 more replies)
  2020-08-07 11:11 ` [PATCH v8 11/24] coresight: etb: allow etb " Tingwei Zhang
                   ` (13 subsequent siblings)
  23 siblings, 3 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-etm4x as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-etm4x by the Makefile
- add an etm4_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot
- protect etmdrvdata[] with mutex lock from racing
  between module unload and CPU hotplug

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
---
 drivers/hwtracing/coresight/Kconfig           |   5 +-
 drivers/hwtracing/coresight/Makefile          |   4 +-
 ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++++++-----
 3 files changed, 92 insertions(+), 35 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (95%)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 8fd9fd139cf3..d6e107bbd30b 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
 	  module will be called coresight-etm3x.
 
 config CORESIGHT_SOURCE_ETM4X
-	bool "CoreSight Embedded Trace Macrocell 4.x driver"
+	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
 	depends on ARM64
 	select CORESIGHT_LINKS_AND_SINKS
 	select PID_IN_CONTEXTIDR
@@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
 	  for instruction level tracing. Depending on the implemented version
 	  data tracing may also be available.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-etm4x.
+
 config CORESIGHT_STM
 	tristate "CoreSight System Trace Macrocell driver"
 	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index d619cfd0abd8..271dc255454f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
 obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
 coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
 					coresight-etm3x-sysfs.o
-obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
-					coresight-etm4x-sysfs.o
+obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
+coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
 obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
 obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
 obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
similarity index 95%
rename from drivers/hwtracing/coresight/coresight-etm4x.c
rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
index fddfd93b9a7b..ae9847e194a3 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
 MODULE_PARM_DESC(pm_save_enable,
 	"Save/restore state on power down: 1 = never, 2 = self-hosted");
 
+static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
 static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
 static void etm4_set_default_config(struct etmv4_config *config);
 static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
@@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config *config)
 
 static int etm4_online_cpu(unsigned int cpu)
 {
-	if (!etmdrvdata[cpu])
+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
+	if (!etmdrvdata[cpu]) {
+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
 		return 0;
+	}
 
 	if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
 		coresight_enable(etmdrvdata[cpu]->csdev);
+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
 	return 0;
 }
 
 static int etm4_starting_cpu(unsigned int cpu)
 {
-	if (!etmdrvdata[cpu])
+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
+	if (!etmdrvdata[cpu]) {
+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
 		return 0;
+	}
 
 	spin_lock(&etmdrvdata[cpu]->spinlock);
 	if (!etmdrvdata[cpu]->os_unlock)
@@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
 	if (local_read(&etmdrvdata[cpu]->mode))
 		etm4_enable_hw(etmdrvdata[cpu]);
 	spin_unlock(&etmdrvdata[cpu]->spinlock);
+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
 	return 0;
 }
 
 static int etm4_dying_cpu(unsigned int cpu)
 {
-	if (!etmdrvdata[cpu])
+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
+	if (!etmdrvdata[cpu]) {
+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
 		return 0;
+	}
 
 	spin_lock(&etmdrvdata[cpu]->spinlock);
 	if (local_read(&etmdrvdata[cpu]->mode))
 		etm4_disable_hw(etmdrvdata[cpu]);
 	spin_unlock(&etmdrvdata[cpu]->spinlock);
+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
 	return 0;
 }
 
@@ -1360,24 +1373,30 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
 {
 	struct etmv4_drvdata *drvdata;
 	unsigned int cpu = smp_processor_id();
+	int ret = NOTIFY_OK;
 
+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
 	if (!etmdrvdata[cpu])
-		return NOTIFY_OK;
+		goto out;
 
 	drvdata = etmdrvdata[cpu];
 
 	if (!drvdata->save_state)
-		return NOTIFY_OK;
+		goto out;
 
-	if (WARN_ON_ONCE(drvdata->cpu != cpu))
-		return NOTIFY_BAD;
+	if (WARN_ON_ONCE(drvdata->cpu != cpu)) {
+		ret = NOTIFY_BAD;
+		goto out;
+	}
 
 	switch (cmd) {
 	case CPU_PM_ENTER:
 		/* save the state if self-hosted coresight is in use */
 		if (local_read(&drvdata->mode))
-			if (etm4_cpu_save(drvdata))
-				return NOTIFY_BAD;
+			if (etm4_cpu_save(drvdata)) {
+				ret = NOTIFY_BAD;
+				goto out;
+			}
 		break;
 	case CPU_PM_EXIT:
 		/* fallthrough */
@@ -1386,10 +1405,12 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
 			etm4_cpu_restore(drvdata);
 		break;
 	default:
-		return NOTIFY_DONE;
+		goto out;
 	}
 
-	return NOTIFY_OK;
+out:
+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
+	return ret;
 }
 
 static struct notifier_block etm4_cpu_pm_nb = {
@@ -1430,7 +1451,7 @@ static int __init etm4_pm_setup(void)
 	return ret;
 }
 
-static void __init etm4_pm_clear(void)
+static void etm4_pm_clear(void)
 {
 	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
 	cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
@@ -1487,25 +1508,20 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	if (!desc.name)
 		return -ENOMEM;
 
-	etmdrvdata[drvdata->cpu] = drvdata;
-
 	if (smp_call_function_single(drvdata->cpu,
 				etm4_init_arch_data,  drvdata, 1))
 		dev_err(dev, "ETM arch init failed\n");
 
-	if (etm4_arch_supported(drvdata->arch) == false) {
-		ret = -EINVAL;
-		goto err_arch_supported;
-	}
+	if (etm4_arch_supported(drvdata->arch) == false)
+		return -EINVAL;
 
 	etm4_init_trace_id(drvdata);
 	etm4_set_default(&drvdata->config);
 
 	pdata = coresight_get_platform_data(dev);
-	if (IS_ERR(pdata)) {
-		ret = PTR_ERR(pdata);
-		goto err_arch_supported;
-	}
+	if (IS_ERR(pdata))
+		return PTR_ERR(pdata);
+
 	adev->dev.platform_data = pdata;
 
 	desc.type = CORESIGHT_DEV_TYPE_SOURCE;
@@ -1515,17 +1531,19 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	desc.dev = dev;
 	desc.groups = coresight_etmv4_groups;
 	drvdata->csdev = coresight_register(&desc);
-	if (IS_ERR(drvdata->csdev)) {
-		ret = PTR_ERR(drvdata->csdev);
-		goto err_arch_supported;
-	}
+	if (IS_ERR(drvdata->csdev))
+		return PTR_ERR(drvdata->csdev);
 
 	ret = etm_perf_symlink(drvdata->csdev, true);
 	if (ret) {
 		coresight_unregister(drvdata->csdev);
-		goto err_arch_supported;
+		return ret;
 	}
 
+	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
+	etmdrvdata[drvdata->cpu] = drvdata;
+	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
+
 	pm_runtime_put(&adev->dev);
 	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
 		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
@@ -1536,10 +1554,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	}
 
 	return 0;
-
-err_arch_supported:
-	etmdrvdata[drvdata->cpu] = NULL;
-	return ret;
 }
 
 static struct amba_cs_uci_id uci_id_etm4[] = {
@@ -1551,6 +1565,22 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
 	}
 };
 
+static int __exit etm4_remove(struct amba_device *adev)
+{
+	struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	etm_perf_symlink(drvdata->csdev, false);
+
+	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
+	etmdrvdata[drvdata->cpu] = NULL;
+	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
+
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
+
+
 static const struct amba_id etm4_ids[] = {
 	CS_AMBA_ID(0x000bb95d),			/* Cortex-A53 */
 	CS_AMBA_ID(0x000bb95e),			/* Cortex-A57 */
@@ -1568,18 +1598,26 @@ static const struct amba_id etm4_ids[] = {
 	{},
 };
 
+MODULE_DEVICE_TABLE(amba, etm4_ids);
+
 static struct amba_driver etm4x_driver = {
 	.drv = {
 		.name   = "coresight-etm4x",
+		.owner  = THIS_MODULE,
 		.suppress_bind_attrs = true,
 	},
 	.probe		= etm4_probe,
+	.remove         = etm4_remove,
 	.id_table	= etm4_ids,
 };
 
 static int __init etm4x_init(void)
 {
 	int ret;
+	int cpu;
+
+	for_each_possible_cpu(cpu)
+		mutex_init(&per_cpu(etmdrvdata_lock, cpu));
 
 	ret = etm4_pm_setup();
 
@@ -1595,4 +1633,20 @@ static int __init etm4x_init(void)
 
 	return ret;
 }
-device_initcall(etm4x_init);
+
+static void __exit etm4x_exit(void)
+{
+	int cpu;
+
+	amba_driver_unregister(&etm4x_driver);
+	etm4_pm_clear();
+	for_each_possible_cpu(cpu)
+		mutex_destroy(&per_cpu(etmdrvdata_lock, cpu));
+}
+module_init(etm4x_init);
+module_exit(etm4x_exit);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 11/24] coresight: etb: allow etb to be built as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (9 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 10/24] coresight: etm4x: allow etm4x " Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 12/24] coresight: tpiu: allow tpiu " Tingwei Zhang
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-etb10 as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- add an etb_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/Kconfig           |  5 +++-
 drivers/hwtracing/coresight/coresight-etb10.c | 25 ++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index d6e107bbd30b..996d84a1edb8 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -57,13 +57,16 @@ config CORESIGHT_SINK_TPIU
 	  the on-board coresight memory can handle.
 
 config CORESIGHT_SINK_ETBV10
-	bool "Coresight ETBv1.0 driver"
+	tristate "Coresight ETBv1.0 driver"
 	depends on CORESIGHT_LINKS_AND_SINKS
 	help
 	  This enables support for the Embedded Trace Buffer version 1.0 driver
 	  that complies with the generic implementation of the component without
 	  special enhancement or added features.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-etb10.
+
 config CORESIGHT_SOURCE_ETM3X
 	tristate "CoreSight Embedded Trace Macrocell 3.x driver"
 	depends on !ARM64
diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c
index 04ee9cda988d..29ef6c7f7be5 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -801,6 +801,21 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
 	return ret;
 }
 
+static int __exit etb_remove(struct amba_device *adev)
+{
+	struct etb_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	/*
+	 * Since misc_open() holds a refcount on the f_ops, which is
+	 * etb fops in this case, device is there until last file
+	 * handler to this device is closed.
+	 */
+	misc_deregister(&drvdata->miscdev);
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
+
 #ifdef CONFIG_PM
 static int etb_runtime_suspend(struct device *dev)
 {
@@ -835,6 +850,8 @@ static const struct amba_id etb_ids[] = {
 	{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, etb_ids);
+
 static struct amba_driver etb_driver = {
 	.drv = {
 		.name	= "coresight-etb10",
@@ -844,6 +861,12 @@ static struct amba_driver etb_driver = {
 
 	},
 	.probe		= etb_probe,
+	.remove		= etb_remove,
 	.id_table	= etb_ids,
 };
-builtin_amba_driver(etb_driver);
+module_amba_driver(etb_driver);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight Embedded Trace Buffer driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 12/24] coresight: tpiu: allow tpiu to be built as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (10 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 11/24] coresight: etb: allow etb " Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 13/24] coresight: tmc: allow tmc " Tingwei Zhang
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-tpiu as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- add a tpiu_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/Kconfig          |  5 ++++-
 drivers/hwtracing/coresight/coresight-tpiu.c | 19 ++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 996d84a1edb8..8fd9887fb03b 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -46,7 +46,7 @@ config CORESIGHT_CATU
 	   mode where the address is not translated.
 
 config CORESIGHT_SINK_TPIU
-	bool "Coresight generic TPIU driver"
+	tristate "Coresight generic TPIU driver"
 	depends on CORESIGHT_LINKS_AND_SINKS
 	help
 	  This enables support for the Trace Port Interface Unit driver,
@@ -56,6 +56,9 @@ config CORESIGHT_SINK_TPIU
 	  connected to an external host for use case capturing more traces than
 	  the on-board coresight memory can handle.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-tpiu.
+
 config CORESIGHT_SINK_ETBV10
 	tristate "Coresight ETBv1.0 driver"
 	depends on CORESIGHT_LINKS_AND_SINKS
diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c
index f8583e4032a6..e4ddd9801535 100644
--- a/drivers/hwtracing/coresight/coresight-tpiu.c
+++ b/drivers/hwtracing/coresight/coresight-tpiu.c
@@ -173,6 +173,15 @@ static int tpiu_probe(struct amba_device *adev, const struct amba_id *id)
 	return PTR_ERR(drvdata->csdev);
 }
 
+static int __exit tpiu_remove(struct amba_device *adev)
+{
+	struct tpiu_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
+
 #ifdef CONFIG_PM
 static int tpiu_runtime_suspend(struct device *dev)
 {
@@ -216,6 +225,8 @@ static const struct amba_id tpiu_ids[] = {
 	{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, tpiu_ids);
+
 static struct amba_driver tpiu_driver = {
 	.drv = {
 		.name	= "coresight-tpiu",
@@ -224,6 +235,12 @@ static struct amba_driver tpiu_driver = {
 		.suppress_bind_attrs = true,
 	},
 	.probe		= tpiu_probe,
+	.remove         = tpiu_remove,
 	.id_table	= tpiu_ids,
 };
-builtin_amba_driver(tpiu_driver);
+module_amba_driver(tpiu_driver);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight TPIU (Trace Port Interface Unit) driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 13/24] coresight: tmc: allow tmc to be built as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (11 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 12/24] coresight: tpiu: allow tpiu " Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-13 20:36   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 14/24] coresight: allow funnel driver to be built as module Tingwei Zhang
                   ` (10 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-tmc as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-tmc by the Makefile
- add an tmc_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/Kconfig           |  6 ++++-
 drivers/hwtracing/coresight/Makefile          |  6 ++---
 .../{coresight-tmc.c => coresight-tmc-core.c} | 24 ++++++++++++++++++-
 3 files changed, 31 insertions(+), 5 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} (95%)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 8fd9887fb03b..fc48ae086746 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -25,7 +25,8 @@ config CORESIGHT_LINKS_AND_SINKS
 	  entity at run time to form a complete trace path.
 
 config CORESIGHT_LINK_AND_SINK_TMC
-	bool "Coresight generic TMC driver"
+	tristate "Coresight generic TMC driver"
+
 	depends on CORESIGHT_LINKS_AND_SINKS
 	help
 	  This enables support for the Trace Memory Controller driver.
@@ -34,6 +35,9 @@ config CORESIGHT_LINK_AND_SINK_TMC
 	  complies with the generic implementation of the component without
 	  special enhancement or added features.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-tmc.
+
 config CORESIGHT_CATU
 	bool "Coresight Address Translation Unit (CATU) driver"
 	depends on CORESIGHT_LINK_AND_SINK_TMC
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index 271dc255454f..f2a568b969c4 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -4,9 +4,9 @@
 #
 obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
 			   coresight-platform.o coresight-sysfs.o
-obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o \
-					     coresight-tmc-etf.o \
-					     coresight-tmc-etr.o
+obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
+coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
+		      coresight-tmc-etr.o
 obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
 obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
 obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
similarity index 95%
rename from drivers/hwtracing/coresight/coresight-tmc.c
rename to drivers/hwtracing/coresight/coresight-tmc-core.c
index 7040d583bed9..f46852489adf 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -561,6 +561,21 @@ static void tmc_shutdown(struct amba_device *adev)
 	spin_unlock_irqrestore(&drvdata->spinlock, flags);
 }
 
+static int __exit tmc_remove(struct amba_device *adev)
+{
+	struct tmc_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	/*
+	 * Since misc_open() holds a refcount on the f_ops, which is
+	 * etb fops in this case, device is there until last file
+	 * handler to this device is closed.
+	 */
+	misc_deregister(&drvdata->miscdev);
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
+
 static const struct amba_id tmc_ids[] = {
 	CS_AMBA_ID(0x000bb961),
 	/* Coresight SoC 600 TMC-ETR/ETS */
@@ -572,6 +587,8 @@ static const struct amba_id tmc_ids[] = {
 	{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, tmc_ids);
+
 static struct amba_driver tmc_driver = {
 	.drv = {
 		.name   = "coresight-tmc",
@@ -580,6 +597,11 @@ static struct amba_driver tmc_driver = {
 	},
 	.probe		= tmc_probe,
 	.shutdown	= tmc_shutdown,
+	.remove		= tmc_remove,
 	.id_table	= tmc_ids,
 };
-builtin_amba_driver(tmc_driver);
+module_amba_driver(tmc_driver);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 14/24] coresight: allow funnel driver to be built as module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (12 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 13/24] coresight: tmc: allow tmc " Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-13 20:15   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 15/24] coresight: allow replicator " Tingwei Zhang
                   ` (9 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-funnel as module, for ease of development.

- combine static and dynamic funnel init into single
  module_init/exit call
- add funnel_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Co-developed-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
---
 .../hwtracing/coresight/coresight-funnel.c    | 62 ++++++++++++++++++-
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c
index 900690a9f7f0..062694ef9879 100644
--- a/drivers/hwtracing/coresight/coresight-funnel.c
+++ b/drivers/hwtracing/coresight/coresight-funnel.c
@@ -274,6 +274,15 @@ static int funnel_probe(struct device *dev, struct resource *res)
 	return ret;
 }
 
+static int __exit funnel_remove(struct device *dev)
+{
+	struct funnel_drvdata *drvdata = dev_get_drvdata(dev);
+
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
+
 #ifdef CONFIG_PM
 static int funnel_runtime_suspend(struct device *dev)
 {
@@ -319,20 +328,31 @@ static int static_funnel_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static int __exit static_funnel_remove(struct platform_device *pdev)
+{
+	funnel_remove(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	return 0;
+}
+
 static const struct of_device_id static_funnel_match[] = {
 	{.compatible = "arm,coresight-static-funnel"},
 	{}
 };
 
+MODULE_DEVICE_TABLE(of, static_funnel_match);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id static_funnel_ids[] = {
 	{"ARMHC9FE", 0},
 	{},
 };
+MODULE_DEVICE_TABLE(acpi, static_funnel_ids);
 #endif
 
 static struct platform_driver static_funnel_driver = {
 	.probe          = static_funnel_probe,
+	.probe          = static_funnel_remove,
 	.driver         = {
 		.name   = "coresight-static-funnel",
 		.of_match_table = static_funnel_match,
@@ -341,7 +361,6 @@ static struct platform_driver static_funnel_driver = {
 		.suppress_bind_attrs = true,
 	},
 };
-builtin_platform_driver(static_funnel_driver);
 
 static int dynamic_funnel_probe(struct amba_device *adev,
 				const struct amba_id *id)
@@ -349,6 +368,11 @@ static int dynamic_funnel_probe(struct amba_device *adev,
 	return funnel_probe(&adev->dev, &adev->res);
 }
 
+static int __exit dynamic_funnel_remove(struct amba_device *adev)
+{
+	return funnel_remove(&adev->dev);
+}
+
 static const struct amba_id dynamic_funnel_ids[] = {
 	{
 		.id     = 0x000bb908,
@@ -362,6 +386,8 @@ static const struct amba_id dynamic_funnel_ids[] = {
 	{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, dynamic_funnel_ids);
+
 static struct amba_driver dynamic_funnel_driver = {
 	.drv = {
 		.name	= "coresight-dynamic-funnel",
@@ -370,6 +396,38 @@ static struct amba_driver dynamic_funnel_driver = {
 		.suppress_bind_attrs = true,
 	},
 	.probe		= dynamic_funnel_probe,
+	.remove		= dynamic_funnel_remove,
 	.id_table	= dynamic_funnel_ids,
 };
-builtin_amba_driver(dynamic_funnel_driver);
+
+static int __init funnel_init(void)
+{
+	int ret;
+
+	ret = platform_driver_register(&static_funnel_driver);
+	if (ret) {
+		pr_info("Error registering platform driver\n");
+		return ret;
+	}
+
+	ret = amba_driver_register(&dynamic_funnel_driver);
+	if (ret) {
+		pr_info("Error registering amba driver\n");
+		platform_driver_unregister(&static_funnel_driver);
+	}
+
+	return ret;
+}
+
+static void __exit funnel_exit(void)
+{
+	platform_driver_unregister(&static_funnel_driver);
+	amba_driver_unregister(&dynamic_funnel_driver);
+}
+
+module_init(funnel_init);
+module_exit(funnel_exit);
+
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight Funnel Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 15/24] coresight: allow replicator driver to be built as module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (13 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 14/24] coresight: allow funnel driver to be built as module Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-13 20:35   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 16/24] coresight: cti: add function to register cti associate ops Tingwei Zhang
                   ` (8 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-replicator as modules, for ease of development.

- Kconfig becomes a tristate, to allow =m
- combine static and dynamic replicator init into single
  module_init/exit call
- add replicator_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Co-developed-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
---
 drivers/hwtracing/coresight/Kconfig           |  5 +-
 .../coresight/coresight-replicator.c          | 63 ++++++++++++++++++-
 2 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index fc48ae086746..f31778dd0b5d 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -17,13 +17,16 @@ menuconfig CORESIGHT
 
 if CORESIGHT
 config CORESIGHT_LINKS_AND_SINKS
-	bool "CoreSight Link and Sink drivers"
+	tristate "CoreSight Link and Sink drivers"
 	help
 	  This enables support for CoreSight link and sink drivers that are
 	  responsible for transporting and collecting the trace data
 	  respectively.  Link and sinks are dynamically aggregated with a trace
 	  entity at run time to form a complete trace path.
 
+	  To compile these drivers as modules, choose M here: the
+	  modules will be called coresight-funnel and coresight-replicator.
+
 config CORESIGHT_LINK_AND_SINK_TMC
 	tristate "Coresight generic TMC driver"
 
diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c
index 78acf29c49ca..05db434c79d0 100644
--- a/drivers/hwtracing/coresight/coresight-replicator.c
+++ b/drivers/hwtracing/coresight/coresight-replicator.c
@@ -291,6 +291,14 @@ static int replicator_probe(struct device *dev, struct resource *res)
 	return ret;
 }
 
+static int __exit replicator_remove(struct device *dev)
+{
+	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
+
+	coresight_unregister(drvdata->csdev);
+	return 0;
+}
+
 static int static_replicator_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -310,6 +318,13 @@ static int static_replicator_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static int __exit static_replicator_remove(struct platform_device *pdev)
+{
+	replicator_remove(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	return 0;
+}
+
 #ifdef CONFIG_PM
 static int replicator_runtime_suspend(struct device *dev)
 {
@@ -342,25 +357,28 @@ static const struct of_device_id static_replicator_match[] = {
 	{.compatible = "arm,coresight-static-replicator"},
 	{}
 };
+MODULE_DEVICE_TABLE(of, static_replicator_match);
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id static_replicator_acpi_ids[] = {
 	{"ARMHC985", 0}, /* ARM CoreSight Static Replicator */
 	{}
 };
+MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids);
 #endif
 
 static struct platform_driver static_replicator_driver = {
 	.probe          = static_replicator_probe,
+	.remove         = static_replicator_remove,
 	.driver         = {
 		.name   = "coresight-static-replicator",
+		.owner	= THIS_MODULE,
 		.of_match_table = of_match_ptr(static_replicator_match),
 		.acpi_match_table = ACPI_PTR(static_replicator_acpi_ids),
 		.pm	= &replicator_dev_pm_ops,
 		.suppress_bind_attrs = true,
 	},
 };
-builtin_platform_driver(static_replicator_driver);
 
 static int dynamic_replicator_probe(struct amba_device *adev,
 				    const struct amba_id *id)
@@ -368,19 +386,60 @@ static int dynamic_replicator_probe(struct amba_device *adev,
 	return replicator_probe(&adev->dev, &adev->res);
 }
 
+static int __exit dynamic_replicator_remove(struct amba_device *adev)
+{
+	return replicator_remove(&adev->dev);
+}
+
 static const struct amba_id dynamic_replicator_ids[] = {
 	CS_AMBA_ID(0x000bb909),
 	CS_AMBA_ID(0x000bb9ec),		/* Coresight SoC-600 */
 	{},
 };
 
+MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
+
 static struct amba_driver dynamic_replicator_driver = {
 	.drv = {
 		.name	= "coresight-dynamic-replicator",
 		.pm	= &replicator_dev_pm_ops,
+		.owner	= THIS_MODULE,
 		.suppress_bind_attrs = true,
 	},
 	.probe		= dynamic_replicator_probe,
+	.remove         = dynamic_replicator_remove,
 	.id_table	= dynamic_replicator_ids,
 };
-builtin_amba_driver(dynamic_replicator_driver);
+
+static int __init replicator_init(void)
+{
+	int ret;
+
+	ret = platform_driver_register(&static_replicator_driver);
+	if (ret) {
+		pr_info("Error registering platform driver\n");
+		return ret;
+	}
+
+	ret = amba_driver_register(&dynamic_replicator_driver);
+	if (ret) {
+		pr_info("Error registering amba driver\n");
+		platform_driver_unregister(&static_replicator_driver);
+	}
+
+	return ret;
+}
+
+static void __exit replicator_exit(void)
+{
+	platform_driver_unregister(&static_replicator_driver);
+	amba_driver_unregister(&dynamic_replicator_driver);
+}
+
+module_init(replicator_init);
+module_exit(replicator_exit);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight Replicator Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 16/24] coresight: cti: add function to register cti associate ops
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (14 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 15/24] coresight: allow replicator " Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-17 16:02   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 17/24] coresight: cti: Fix remove sysfs link error Tingwei Zhang
                   ` (7 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

Add static cti_assoc_ops to coresight core driver. Let cti
driver register the add_assoc and remove_assoc call back.
Avoid coresight core driver to depend on cti driver.

Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
---
 drivers/hwtracing/coresight/coresight-cti.c  | 32 ++++++++++++++++++--
 drivers/hwtracing/coresight/coresight-priv.h | 14 ++++-----
 drivers/hwtracing/coresight/coresight.c      | 21 +++++++++++--
 3 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
index 3ccc703dc940..1f470c47ba70 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -589,7 +589,6 @@ void cti_add_assoc_to_csdev(struct coresight_device *csdev)
 cti_add_done:
 	mutex_unlock(&ect_mutex);
 }
-EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
 
 /*
  * Removing the associated devices is easier.
@@ -616,7 +615,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
 	}
 	mutex_unlock(&ect_mutex);
 }
-EXPORT_SYMBOL_GPL(cti_remove_assoc_from_csdev);
+
+/*
+ * Operations to add and remove associated CTI.
+ * Register to coresight core driver as call back function.
+ */
+static struct cti_assoc_op cti_assoc_ops = {
+	.add = cti_add_assoc_to_csdev,
+	.remove = cti_remove_assoc_from_csdev
+};
 
 /*
  * Update the cross references where the associated device was found
@@ -972,4 +979,23 @@ static struct amba_driver cti_driver = {
 	.probe		= cti_probe,
 	.id_table	= cti_ids,
 };
-builtin_amba_driver(cti_driver);
+
+static int __init cti_init(void)
+{
+	int ret;
+
+	ret = amba_driver_register(&cti_driver);
+	if (ret)
+		pr_info("Error registering cti driver\n");
+	coresight_set_cti_ops(&cti_assoc_ops);
+	return ret;
+}
+
+static void __exit cti_exit(void)
+{
+	coresight_remove_cti_ops();
+	amba_driver_unregister(&cti_driver);
+}
+
+module_init(cti_init);
+module_exit(cti_exit);
diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
index dcb8aeb6af62..6cde6cf42554 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -173,15 +173,13 @@ static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
 static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
 #endif
 
-#ifdef CONFIG_CORESIGHT_CTI
-extern void cti_add_assoc_to_csdev(struct coresight_device *csdev);
-extern void cti_remove_assoc_from_csdev(struct coresight_device *csdev);
+struct cti_assoc_op {
+	void (*add)(struct coresight_device *csdev);
+	void (*remove)(struct coresight_device *csdev);
+};
 
-#else
-static inline void cti_add_assoc_to_csdev(struct coresight_device *csdev) {}
-static inline void
-cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}
-#endif
+extern void coresight_set_cti_ops(const struct cti_assoc_op *cti_op);
+extern void coresight_remove_cti_ops(void);
 
 /*
  * Macros and inline functions to handle CoreSight UCI data and driver
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 0b0e31577b9b..31b9ec8d3b9c 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -57,6 +57,20 @@ const u32 coresight_barrier_pkt[4] = {
 		0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
 EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
 
+static const struct cti_assoc_op *cti_assoc_ops;
+
+void coresight_set_cti_ops(const struct cti_assoc_op *cti_op)
+{
+	cti_assoc_ops = cti_op;
+}
+EXPORT_SYMBOL_GPL(coresight_set_cti_ops);
+
+void coresight_remove_cti_ops(void)
+{
+	cti_assoc_ops = NULL;
+}
+EXPORT_SYMBOL_GPL(coresight_remove_cti_ops);
+
 static int coresight_id_match(struct device *dev, void *data)
 {
 	int trace_id, i_trace_id;
@@ -1242,7 +1256,8 @@ static void coresight_device_release(struct device *dev)
 {
 	struct coresight_device *csdev = to_coresight_device(dev);
 
-	cti_remove_assoc_from_csdev(csdev);
+	if (cti_assoc_ops && cti_assoc_ops->remove)
+		cti_assoc_ops->remove(csdev);
 	fwnode_handle_put(csdev->dev.fwnode);
 	kfree(csdev->refcnt);
 	kfree(csdev);
@@ -1553,8 +1568,8 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 		ret = coresight_fixup_device_conns(csdev);
 	if (!ret)
 		ret = coresight_fixup_orphan_conns(csdev);
-	if (!ret)
-		cti_add_assoc_to_csdev(csdev);
+	if (!ret && cti_assoc_ops && cti_assoc_ops->add)
+		cti_assoc_ops->add(csdev);
 
 	mutex_unlock(&coresight_mutex);
 	if (ret) {
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 17/24] coresight: cti: Fix remove sysfs link error
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (15 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 16/24] coresight: cti: add function to register cti associate ops Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-17 16:15   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 18/24] coresight: cti: Fix bug clearing sysfs links on callback Tingwei Zhang
                   ` (6 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

From: Mike Leach <mike.leach@linaro.org>

CTI code to remove sysfs link to other devices on shutdown, incorrectly
tries to remove a single ended link when these are all double ended. This
implementation leaves elements in the link info structure undefined which
results in a crash in recent tests for driver module unload.

This patch corrects the link removal code.

Fixes: 73274abb6557 (coresight: cti: Add in sysfs links to other coresight devices)
Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
Signed-off-by: Mike Leach <mike.leach@linaro.org>
---
 drivers/hwtracing/coresight/coresight-cti.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
index 1f470c47ba70..1c34db7d1b1b 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -511,12 +511,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata *drvdata,
 	return !link_err;
 }
 
-static void cti_remove_sysfs_link(struct cti_trig_con *tc)
+static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
+				  struct cti_trig_con *tc)
 {
 	struct coresight_sysfs_link link_info;
 
+	link_info.orig = drvdata->csdev;
 	link_info.orig_name = tc->con_dev_name;
 	link_info.target = tc->con_dev;
+	link_info.target_name = dev_name(&drvdata->csdev->dev);
 	coresight_remove_sysfs_link(&link_info);
 }
 
@@ -606,7 +609,7 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
 		ctidev = &ctidrv->ctidev;
 		list_for_each_entry(tc, &ctidev->trig_cons, node) {
 			if (tc->con_dev == csdev->ect_dev) {
-				cti_remove_sysfs_link(tc);
+				cti_remove_sysfs_link(ctidrv, tc);
 				tc->con_dev = NULL;
 				break;
 			}
@@ -658,7 +661,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata *drvdata)
 		if (tc->con_dev) {
 			coresight_set_assoc_ectdev_mutex(tc->con_dev,
 							 NULL);
-			cti_remove_sysfs_link(tc);
+			cti_remove_sysfs_link(drvdata, tc);
 			tc->con_dev = NULL;
 		}
 	}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 18/24] coresight: cti: Fix bug clearing sysfs links on callback
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (16 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 17/24] coresight: cti: Fix remove sysfs link error Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-17 16:21   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled Tingwei Zhang
                   ` (5 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

From: Mike Leach <mike.leach@linaro.org>

During module unload, a coresight driver module will call back into
the CTI driver to remove any links between the two devices.

The current code has 2 issues:-
1) in the CTI driver the matching code is matching to the wrong device
so misses all the links.
2) The callback is called too late in the unload process resulting in a
crash.

This fixes both the issues.

Fixes: 177af8285b59 (coresight: cti: Enable CTI associated with devices)
Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
Signed-off-by: Mike Leach <mike.leach@linaro.org>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Acked-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-cti.c | 2 +-
 drivers/hwtracing/coresight/coresight.c     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
index 1c34db7d1b1b..6bb06c5715db 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -608,7 +608,7 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
 		ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
 		ctidev = &ctidrv->ctidev;
 		list_for_each_entry(tc, &ctidev->trig_cons, node) {
-			if (tc->con_dev == csdev->ect_dev) {
+			if (tc->con_dev == csdev) {
 				cti_remove_sysfs_link(ctidrv, tc);
 				tc->con_dev = NULL;
 				break;
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 31b9ec8d3b9c..d066411aa794 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1256,8 +1256,6 @@ static void coresight_device_release(struct device *dev)
 {
 	struct coresight_device *csdev = to_coresight_device(dev);
 
-	if (cti_assoc_ops && cti_assoc_ops->remove)
-		cti_assoc_ops->remove(csdev);
 	fwnode_handle_put(csdev->dev.fwnode);
 	kfree(csdev->refcnt);
 	kfree(csdev);
@@ -1592,6 +1590,8 @@ void coresight_unregister(struct coresight_device *csdev)
 {
 	etm_perf_del_symlink_sink(csdev);
 	/* Remove references of that device in the topology */
+	if (cti_assoc_ops && cti_assoc_ops->remove)
+		cti_assoc_ops->remove(csdev);
 	coresight_remove_conns(csdev);
 	coresight_clear_default_sink(csdev);
 	coresight_release_platform_data(csdev, csdev->pdata);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (17 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 18/24] coresight: cti: Fix bug clearing sysfs links on callback Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-17 16:38   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 20/24] coresight: cti: increase reference count when enabling cti Tingwei Zhang
                   ` (4 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

If associated ect device is not enabled at first place, disable
routine should not be called. Add ect_enabled flag to check whether
ect device is enabled. Fix the issue in below case.  Ect device is
not available when associated coresight device enabled and the
association is established after coresight device is enabled.

Signed-off-by: Mike Leach <mike.leach@linaro.org>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
---
 drivers/hwtracing/coresight/coresight.c | 11 ++++++++---
 include/linux/coresight.h               |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index d066411aa794..27ad8317e3cf 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -245,13 +245,18 @@ coresight_control_assoc_ectdev(struct coresight_device *csdev, bool enable)
 
 	if (!ect_csdev)
 		return 0;
+	if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
+		return 0;
 
 	if (enable) {
-		if (ect_ops(ect_csdev)->enable)
-			ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+		ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+		if (!ect_ret)
+			csdev->ect_enabled = true;
 	} else {
-		if (ect_ops(ect_csdev)->disable)
+		if (csdev->ect_enabled) {
 			ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+			csdev->ect_enabled = false;
+		}
 	}
 
 	/* output warning if ECT enable is preventing trace operation */
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 3bb738f9a326..7d3c87e5b97c 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -208,6 +208,7 @@ struct coresight_device {
 	/* sysfs links between components */
 	int nr_links;
 	bool has_conns_grp;
+	bool ect_enabled; /* true only if associated ect device is enabled */
 };
 
 /*
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 20/24] coresight: cti: increase reference count when enabling cti
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (18 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 21/24] coresight: cti: allow cti to be built as a module Tingwei Zhang
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

CTI device is enabled when associated coresight device is enabled.
Increase the module and device reference count for CTI device
when it's enabled. This can prevent CTI device be removed or
module be unloaded when CTI device is enabled by an active trace
session.

Signed-off-by: Mike Leach <mike.leach@linaro.org>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
---
 drivers/hwtracing/coresight/coresight.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 27ad8317e3cf..8dcd73ea33b4 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -242,19 +242,30 @@ coresight_control_assoc_ectdev(struct coresight_device *csdev, bool enable)
 {
 	int ect_ret = 0;
 	struct coresight_device *ect_csdev = csdev->ect_dev;
+	struct module *mod;
 
 	if (!ect_csdev)
 		return 0;
 	if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
 		return 0;
 
+	mod = ect_csdev->dev.parent->driver->owner;
 	if (enable) {
-		ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
-		if (!ect_ret)
-			csdev->ect_enabled = true;
+		if (try_module_get(mod)) {
+			ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+			if (ect_ret) {
+				module_put(mod);
+			} else {
+				get_device(ect_csdev->dev.parent);
+				csdev->ect_enabled = true;
+			}
+		} else
+			ect_ret = -ENODEV;
 	} else {
 		if (csdev->ect_enabled) {
 			ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+			put_device(ect_csdev->dev.parent);
+			module_put(mod);
 			csdev->ect_enabled = false;
 		}
 	}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 21/24] coresight: cti: allow cti to be built as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (19 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 20/24] coresight: cti: increase reference count when enabling cti Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-17 17:13   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 22/24] coresight: tmc-etr: add function to register catu ops Tingwei Zhang
                   ` (2 subsequent siblings)
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

Allow to build coresight-cti as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-cti by the Makefile
- add an cti_remove function, for module unload
- move cti_remove_conn_xrefs to cti_remove
- add a MODULE_DEVICE_TABLE for autoloading on boot

Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
---
 drivers/hwtracing/coresight/Kconfig           |  5 ++++-
 drivers/hwtracing/coresight/Makefile          |  4 ++--
 .../{coresight-cti.c => coresight-cti-core.c} | 19 ++++++++++++++++++-
 .../hwtracing/coresight/coresight-platform.c  |  1 +
 drivers/hwtracing/coresight/coresight.c       |  1 +
 5 files changed, 26 insertions(+), 4 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} (98%)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index f31778dd0b5d..b04aae2ceecc 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -136,7 +136,7 @@ config CORESIGHT_CPU_DEBUG
 	  module will be called coresight-cpu-debug.
 
 config CORESIGHT_CTI
-	bool "CoreSight Cross Trigger Interface (CTI) driver"
+	tristate "CoreSight Cross Trigger Interface (CTI) driver"
 	depends on ARM || ARM64
 	help
 	  This driver provides support for CoreSight CTI and CTM components.
@@ -147,6 +147,9 @@ config CORESIGHT_CTI
 	  halt compared to disabling sources and sinks normally in driver
 	  software.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-cti.
+
 config CORESIGHT_CTI_INTEGRATION_REGS
 	bool "Access CTI CoreSight Integration Registers"
 	depends on CORESIGHT_CTI
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index f2a568b969c4..0359d5a1588f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -19,6 +19,6 @@ coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
 obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
 obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
 obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
-obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o \
-				coresight-cti-platform.o \
+obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
+coresight-cti-y := coresight-cti-core.o	coresight-cti-platform.o \
 				coresight-cti-sysfs.o
diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti-core.c
similarity index 98%
rename from drivers/hwtracing/coresight/coresight-cti.c
rename to drivers/hwtracing/coresight/coresight-cti-core.c
index 6bb06c5715db..ca31da6cf1c0 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti-core.c
@@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
 	struct cti_drvdata *ect_item, *ect_tmp;
 
 	mutex_lock(&ect_mutex);
-	cti_remove_conn_xrefs(drvdata);
 	cti_pm_release(drvdata);
 
 	/* remove from the list */
@@ -853,6 +852,18 @@ static void cti_device_release(struct device *dev)
 	if (drvdata->csdev_release)
 		drvdata->csdev_release(dev);
 }
+static int __exit cti_remove(struct amba_device *adev)
+{
+	struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	mutex_lock(&ect_mutex);
+	cti_remove_conn_xrefs(drvdata);
+	mutex_unlock(&ect_mutex);
+
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
 
 static int cti_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -972,6 +983,7 @@ static const struct amba_id cti_ids[] = {
 	CS_AMBA_UCI_ID(0x000bb9ed, uci_id_cti), /* Coresight CTI (SoC 600) */
 	{ 0, 0},
 };
+MODULE_DEVICE_TABLE(amba, cti_ids);
 
 static struct amba_driver cti_driver = {
 	.drv = {
@@ -980,6 +992,7 @@ static struct amba_driver cti_driver = {
 		.suppress_bind_attrs = true,
 	},
 	.probe		= cti_probe,
+	.remove		= cti_remove,
 	.id_table	= cti_ids,
 };
 
@@ -1002,3 +1015,7 @@ static void __exit cti_exit(void)
 
 module_init(cti_init);
 module_exit(cti_exit);
+
+MODULE_AUTHOR("Mike Leach <mike.leach@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index bfd44231d7ad..635d55c1d580 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -75,6 +75,7 @@ coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode)
 	}
 	return csdev;
 }
+EXPORT_SYMBOL_GPL(coresight_find_csdev_by_fwnode);
 
 #ifdef CONFIG_OF
 static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep)
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
index 8dcd73ea33b4..f9566d667261 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -289,6 +289,7 @@ void coresight_set_assoc_ectdev_mutex(struct coresight_device *csdev,
 	csdev->ect_dev = ect_csdev;
 	mutex_unlock(&coresight_mutex);
 }
+EXPORT_SYMBOL_GPL(coresight_set_assoc_ectdev_mutex);
 
 static int coresight_enable_sink(struct coresight_device *csdev,
 				 u32 mode, void *data)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 22/24] coresight: tmc-etr: add function to register catu ops
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (20 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 21/24] coresight: cti: allow cti to be built as a module Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 23/24] coresight: catu: allow catu drivers to be built as modules Tingwei Zhang
  2020-08-07 11:11 ` [PATCH v8 24/24] coresight: allow the coresight core driver to be built as a module Tingwei Zhang
  23 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

From: Mian Yousaf Kaukab <ykaukab@suse.de>

Make etr_catu_buf_ops static. Instead of directly accessing it in
etr_buf_ops[], add a function to let catu driver register the ops at
runtime. Break circular dependency between tmc-etr and catu drivers.

Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by : Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-catu.c  | 22 +++++++++++++++++--
 drivers/hwtracing/coresight/coresight-catu.h  |  2 --
 .../hwtracing/coresight/coresight-tmc-etr.c   | 15 +++++++++++--
 drivers/hwtracing/coresight/coresight-tmc.h   |  3 +++
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c
index 1801804a7762..47696a7d24a7 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -358,7 +358,7 @@ static int catu_alloc_etr_buf(struct tmc_drvdata *tmc_drvdata,
 	return 0;
 }
 
-const struct etr_buf_operations etr_catu_buf_ops = {
+static const struct etr_buf_operations etr_catu_buf_ops = {
 	.alloc = catu_alloc_etr_buf,
 	.free = catu_free_etr_buf,
 	.sync = catu_sync_etr_buf,
@@ -582,4 +582,22 @@ static struct amba_driver catu_driver = {
 	.id_table			= catu_ids,
 };
 
-builtin_amba_driver(catu_driver);
+static int __init catu_init(void)
+{
+	int ret;
+
+	ret = amba_driver_register(&catu_driver);
+	if (ret)
+		pr_info("Error registering catu driver\n");
+	tmc_etr_set_catu_ops(&etr_catu_buf_ops);
+	return ret;
+}
+
+static void __exit catu_exit(void)
+{
+	tmc_etr_remove_catu_ops();
+	amba_driver_unregister(&catu_driver);
+}
+
+module_init(catu_init);
+module_exit(catu_exit);
diff --git a/drivers/hwtracing/coresight/coresight-catu.h b/drivers/hwtracing/coresight/coresight-catu.h
index 80ceee3c739c..6160c2d75a56 100644
--- a/drivers/hwtracing/coresight/coresight-catu.h
+++ b/drivers/hwtracing/coresight/coresight-catu.h
@@ -108,6 +108,4 @@ static inline bool coresight_is_catu_device(struct coresight_device *csdev)
 	return true;
 }
 
-extern const struct etr_buf_operations etr_catu_buf_ops;
-
 #endif
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index ad991a37e2d2..714f9e867e5f 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -794,10 +794,21 @@ static inline void tmc_etr_disable_catu(struct tmc_drvdata *drvdata)
 static const struct etr_buf_operations *etr_buf_ops[] = {
 	[ETR_MODE_FLAT] = &etr_flat_buf_ops,
 	[ETR_MODE_ETR_SG] = &etr_sg_buf_ops,
-	[ETR_MODE_CATU] = IS_ENABLED(CONFIG_CORESIGHT_CATU)
-						? &etr_catu_buf_ops : NULL,
+	[ETR_MODE_CATU] = NULL,
 };
 
+void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu)
+{
+	etr_buf_ops[ETR_MODE_CATU] = catu;
+}
+EXPORT_SYMBOL_GPL(tmc_etr_set_catu_ops);
+
+void tmc_etr_remove_catu_ops(void)
+{
+	etr_buf_ops[ETR_MODE_CATU] = NULL;
+}
+EXPORT_SYMBOL_GPL(tmc_etr_remove_catu_ops);
+
 static inline int tmc_etr_mode_alloc_buf(int mode,
 					 struct tmc_drvdata *drvdata,
 					 struct etr_buf *etr_buf, int node,
diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h
index 6e8d2dc33d17..b91ec7dde7bc 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -326,4 +326,7 @@ tmc_sg_table_buf_size(struct tmc_sg_table *sg_table)
 
 struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
 
+void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu);
+void tmc_etr_remove_catu_ops(void);
+
 #endif
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 23/24] coresight: catu: allow catu drivers to be built as modules
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (21 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 22/24] coresight: tmc-etr: add function to register catu ops Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-17 17:39   ` Mathieu Poirier
  2020-08-07 11:11 ` [PATCH v8 24/24] coresight: allow the coresight core driver to be built as a module Tingwei Zhang
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Greg Kroah-Hartman, coresight, Randy Dunlap, Mian Yousaf Kaukab,
	Russell King, Tingwei Zhang, Leo Yan, linux-arm-kernel

Allow to build coresight-catu as modules, for ease of development.
- Kconfig becomes a tristate, to allow =m
- add catu_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/Kconfig          |  5 ++++-
 drivers/hwtracing/coresight/coresight-catu.c | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index b04aae2ceecc..dfe407cde262 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -42,7 +42,7 @@ config CORESIGHT_LINK_AND_SINK_TMC
 	  module will be called coresight-tmc.
 
 config CORESIGHT_CATU
-	bool "Coresight Address Translation Unit (CATU) driver"
+	tristate "Coresight Address Translation Unit (CATU) driver"
 	depends on CORESIGHT_LINK_AND_SINK_TMC
 	help
 	   Enable support for the Coresight Address Translation Unit (CATU).
@@ -52,6 +52,9 @@ config CORESIGHT_CATU
 	   by looking up the provided table. CATU can also be used in pass-through
 	   mode where the address is not translated.
 
+	   To compile this driver as a module, choose M here: the
+	   module will be called coresight-catu.
+
 config CORESIGHT_SINK_TPIU
 	tristate "Coresight generic TPIU driver"
 	depends on CORESIGHT_LINKS_AND_SINKS
diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c
index 47696a7d24a7..99430f6cf5a5 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -567,11 +567,21 @@ static int catu_probe(struct amba_device *adev, const struct amba_id *id)
 	return ret;
 }
 
+static int __exit catu_remove(struct amba_device *adev)
+{
+	struct catu_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	coresight_unregister(drvdata->csdev);
+	return 0;
+}
+
 static struct amba_id catu_ids[] = {
 	CS_AMBA_ID(0x000bb9ee),
 	{},
 };
 
+MODULE_DEVICE_TABLE(amba, catu_ids);
+
 static struct amba_driver catu_driver = {
 	.drv = {
 		.name			= "coresight-catu",
@@ -579,6 +589,7 @@ static struct amba_driver catu_driver = {
 		.suppress_bind_attrs	= true,
 	},
 	.probe				= catu_probe,
+	.remove				= catu_remove,
 	.id_table			= catu_ids,
 };
 
@@ -601,3 +612,7 @@ static void __exit catu_exit(void)
 
 module_init(catu_init);
 module_exit(catu_exit);
+
+MODULE_AUTHOR("Suzuki K Poulose <suzuki.poulose@arm.com>");
+MODULE_DESCRIPTION("Arm CoreSight Address Translation Unit (CATU) Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v8 24/24] coresight: allow the coresight core driver to be built as a module
  2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
                   ` (22 preceding siblings ...)
  2020-08-07 11:11 ` [PATCH v8 23/24] coresight: catu: allow catu drivers to be built as modules Tingwei Zhang
@ 2020-08-07 11:11 ` Tingwei Zhang
  2020-08-17 17:47   ` Mathieu Poirier
  23 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-07 11:11 UTC (permalink / raw)
  To: Mathieu Poirier, Suzuki K Poulose, Alexander Shishkin, Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Greg Kroah-Hartman, coresight, Randy Dunlap,
	Mian Yousaf Kaukab, Russell King, Tingwei Zhang, Leo Yan,
	linux-arm-kernel

Enhance coresight developer's efficiency to debug coresight drivers.
- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight by the Makefile
- modules can have only one init/exit, so we add the etm_perf
  register/unregister function calls to the core init/exit
  functions.
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
Tested-by: Mike Leach <mike.leach@linaro.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/Kconfig           |  5 ++-
 drivers/hwtracing/coresight/Makefile          |  5 ++-
 .../{coresight.c => coresight-core.c}         | 42 ++++++++++++++-----
 .../hwtracing/coresight/coresight-etm-perf.c  |  8 +++-
 .../hwtracing/coresight/coresight-etm-perf.h  |  3 ++
 5 files changed, 48 insertions(+), 15 deletions(-)
 rename drivers/hwtracing/coresight/{coresight.c => coresight-core.c} (98%)

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index dfe407cde262..c1198245461d 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -3,7 +3,7 @@
 # Coresight configuration
 #
 menuconfig CORESIGHT
-	bool "CoreSight Tracing Support"
+	tristate "CoreSight Tracing Support"
 	depends on ARM || ARM64
 	depends on OF || ACPI
 	select ARM_AMBA
@@ -15,6 +15,9 @@ menuconfig CORESIGHT
 	  specification and configure the right series of components when a
 	  trace source gets enabled.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight.
+
 if CORESIGHT
 config CORESIGHT_LINKS_AND_SINKS
 	tristate "CoreSight Link and Sink drivers"
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index 0359d5a1588f..1b35b55bd420 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -2,8 +2,9 @@
 #
 # Makefile for CoreSight drivers.
 #
-obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
-			   coresight-platform.o coresight-sysfs.o
+obj-$(CONFIG_CORESIGHT) += coresight.o
+coresight-y := coresight-core.o  coresight-etm-perf.o coresight-platform.o \
+		coresight-sysfs.o
 obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
 coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
 		      coresight-tmc-etr.o
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight-core.c
similarity index 98%
rename from drivers/hwtracing/coresight/coresight.c
rename to drivers/hwtracing/coresight/coresight-core.c
index f9566d667261..045416ac962f 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1462,16 +1462,6 @@ int coresight_timeout(void __iomem *addr, u32 offset, int position, int value)
 }
 EXPORT_SYMBOL_GPL(coresight_timeout);
 
-struct bus_type coresight_bustype = {
-	.name	= "coresight",
-};
-
-static int __init coresight_init(void)
-{
-	return bus_register(&coresight_bustype);
-}
-postcore_initcall(coresight_init);
-
 /*
  * coresight_release_platform_data: Release references to the devices connected
  * to the output port of this device.
@@ -1680,3 +1670,35 @@ char *coresight_alloc_device_name(struct coresight_dev_list *dict,
 	return name;
 }
 EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
+
+struct bus_type coresight_bustype = {
+	.name	= "coresight",
+};
+
+static int __init coresight_init(void)
+{
+	int ret;
+
+	ret = bus_register(&coresight_bustype);
+	if (ret)
+		return ret;
+
+	ret = etm_perf_init();
+	if (ret)
+		bus_unregister(&coresight_bustype);
+
+	return ret;
+}
+
+static void __exit coresight_exit(void)
+{
+	etm_perf_exit();
+	bus_unregister(&coresight_bustype);
+}
+
+module_init(coresight_init);
+module_exit(coresight_exit);
+
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight tracer driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 3728c44e5763..668b3ff11576 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -591,7 +591,7 @@ void etm_perf_del_symlink_sink(struct coresight_device *csdev)
 	csdev->ea = NULL;
 }
 
-static int __init etm_perf_init(void)
+int __init etm_perf_init(void)
 {
 	int ret;
 
@@ -618,4 +618,8 @@ static int __init etm_perf_init(void)
 
 	return ret;
 }
-device_initcall(etm_perf_init);
+
+void __exit etm_perf_exit(void)
+{
+	perf_pmu_unregister(&etm_pmu);
+}
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
index 05f89723e282..3e4f2ad5e193 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.h
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
@@ -82,4 +82,7 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
 
 #endif /* CONFIG_CORESIGHT */
 
+int __init etm_perf_init(void);
+void __exit etm_perf_exit(void);
+
 #endif
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 01/24] coresight: cpu_debug: add module name in Kconfig
  2020-08-07 11:11 ` [PATCH v8 01/24] coresight: cpu_debug: add module name in Kconfig Tingwei Zhang
@ 2020-08-12 17:16   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-12 17:16 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:30PM +0800, Tingwei Zhang wrote:
> Provide name of cpu_debug module in Kconfig help section.
> 
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/Kconfig | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 02dbb5ca3bcf..4663fd1bbffc 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -110,6 +110,9 @@ config CORESIGHT_CPU_DEBUG
>  	  properly, please refer Documentation/trace/coresight/coresight-cpu-debug.rst
>  	  for detailed description and the example for usage.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-cpu-debug.
> +

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  config CORESIGHT_CTI
>  	bool "CoreSight Cross Trigger Interface (CTI) driver"
>  	depends on ARM || ARM64
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules
  2020-08-07 11:11 ` [PATCH v8 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules Tingwei Zhang
@ 2020-08-12 17:54   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-12 17:54 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:32PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Checking for ifdef CONFIG_x fails if CONFIG_x=m.  Use IS_ENABLED
> that is true for both built-ins and modules, instead.  Required
> when building coresight components as modules.
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-etm-perf.h | 2 +-
>  drivers/hwtracing/coresight/coresight-priv.h     | 2 +-
>  include/linux/coresight.h                        | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)

For patches 02 and 03:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> 
> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
> index 015213abe00a..05f89723e282 100644
> --- a/drivers/hwtracing/coresight/coresight-etm-perf.h
> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
> @@ -57,7 +57,7 @@ struct etm_event_data {
>  	struct list_head * __percpu *path;
>  };
>  
> -#ifdef CONFIG_CORESIGHT
> +#if IS_ENABLED(CONFIG_CORESIGHT)
>  int etm_perf_symlink(struct coresight_device *csdev, bool link);
>  int etm_perf_add_symlink_sink(struct coresight_device *csdev);
>  void etm_perf_del_symlink_sink(struct coresight_device *csdev);
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index f2dc625ea585..d801a2755432 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -165,7 +165,7 @@ int coresight_make_links(struct coresight_device *orig,
>  void coresight_remove_links(struct coresight_device *orig,
>  			    struct coresight_connection *conn);
>  
> -#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
> +#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X)
>  extern int etm_readl_cp14(u32 off, unsigned int *val);
>  extern int etm_writel_cp14(u32 off, u32 val);
>  #else
> diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> index 58fffdecdbfd..3bb738f9a326 100644
> --- a/include/linux/coresight.h
> +++ b/include/linux/coresight.h
> @@ -324,7 +324,7 @@ struct coresight_ops {
>  	const struct coresight_ops_ect *ect_ops;
>  };
>  
> -#ifdef CONFIG_CORESIGHT
> +#if IS_ENABLED(CONFIG_CORESIGHT)
>  extern struct coresight_device *
>  coresight_register(struct coresight_desc *desc);
>  extern void coresight_unregister(struct coresight_device *csdev);
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 04/24] coresight: add coresight prefix to barrier_pkt
  2020-08-07 11:11 ` [PATCH v8 04/24] coresight: add coresight prefix to barrier_pkt Tingwei Zhang
@ 2020-08-12 17:58   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-12 17:58 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:33PM +0800, Tingwei Zhang wrote:
> Add coresight prefix to make it specific. It will be a export symbol.
> 
> Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-etb10.c   | 2 +-
>  drivers/hwtracing/coresight/coresight-priv.h    | 8 ++++----
>  drivers/hwtracing/coresight/coresight-tmc-etf.c | 2 +-
>  drivers/hwtracing/coresight/coresight.c         | 3 ++-
>  4 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c
> index 03e3f2590191..04ee9cda988d 100644
> --- a/drivers/hwtracing/coresight/coresight-etb10.c
> +++ b/drivers/hwtracing/coresight/coresight-etb10.c
> @@ -525,7 +525,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
>  
>  	cur = buf->cur;
>  	offset = buf->offset;
> -	barrier = barrier_pkt;
> +	barrier = coresight_barrier_pkt;
>  
>  	for (i = 0; i < to_read; i += 4) {
>  		buf_ptr = buf->data_pages[cur] + offset;
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index d801a2755432..dcb8aeb6af62 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -66,8 +66,8 @@ static DEVICE_ATTR_RO(name)
>  #define coresight_simple_reg64(type, name, lo_off, hi_off)		\
>  	__coresight_simple_func(type, NULL, name, lo_off, hi_off)
>  
> -extern const u32 barrier_pkt[4];
> -#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(barrier_pkt))
> +extern const u32 coresight_barrier_pkt[4];
> +#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(coresight_barrier_pkt))
>  
>  enum etm_addr_type {
>  	ETM_ADDR_TYPE_NONE,
> @@ -104,10 +104,10 @@ struct cs_buffers {
>  static inline void coresight_insert_barrier_packet(void *buf)
>  {
>  	if (buf)
> -		memcpy(buf, barrier_pkt, CORESIGHT_BARRIER_PKT_SIZE);
> +		memcpy(buf, coresight_barrier_pkt,
> +				CORESIGHT_BARRIER_PKT_SIZE);

Indentation problem.

>  }
>  
> -
>  static inline void CS_LOCK(void __iomem *addr)
>  {
>  	do {
> diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c
> index 6375504ba8b0..44402d413ebb 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c
> @@ -519,7 +519,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev,
>  
>  	cur = buf->cur;
>  	offset = buf->offset;
> -	barrier = barrier_pkt;
> +	barrier = coresight_barrier_pkt;
>  
>  	/* for every byte to read */
>  	for (i = 0; i < to_read; i += 4) {
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index e9c90f2de34a..310b1b825dd1 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -53,7 +53,8 @@ static struct list_head *stm_path;
>   * beginning of the data collected in a buffer.  That way the decoder knows that
>   * it needs to look for another sync sequence.
>   */
> -const u32 barrier_pkt[4] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
> +const u32 coresight_barrier_pkt[4] = {
> +		0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};

As of kernel 5.8 lines up to 100 characters are allowed.  No need to break this
line.

With that: 

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  
>  static int coresight_id_match(struct device *dev, void *data)
>  {
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 06/24] coresight: add try_get_module() in coresight_grab_device()
  2020-08-07 11:11 ` [PATCH v8 06/24] coresight: add try_get_module() in coresight_grab_device() Tingwei Zhang
@ 2020-08-12 19:36   ` Mathieu Poirier
  2020-08-13  7:37     ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-12 19:36 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:35PM +0800, Tingwei Zhang wrote:
> When coresight device is in an active session, driver module of
> that device should not be removed. Use try_get_module() in
> coresight_grab_device() to prevent module to be unloaded.
> Use get_device()/put_device() to protect device data
> in the middle of active session.
> 
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight.c | 61 ++++++++++++++++++++++---
>  1 file changed, 54 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index b7151c5f81b1..0b0e31577b9b 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -634,13 +634,45 @@ struct coresight_device *coresight_get_sink_by_id(u32 id)
>  	return dev ? to_coresight_device(dev) : NULL;
>  }
>  
> +/**
> + * coresight_get_ref- Helper function to increase reference count to module
> + * and device.
> + * Return true in successful case and power up the device.
> + * Return false when failed to get reference of module.
> + */
> +static inline bool coresight_get_ref(struct coresight_device *csdev)
> +{
> +	struct device *dev = csdev->dev.parent;
> +
> +	/* Make sure the driver can't be removed */
> +	if (!try_module_get(dev->driver->owner))
> +		return false;
> +	/* Make sure the device can't go away */
> +	get_device(dev);
> +	pm_runtime_get_sync(dev);
> +	return true;
> +}
> +
> +/**
> + * coresight_put_ref- Helper function to decrease reference count to module
> + * and device. Power off the device.
> + */
> +static inline void coresight_put_ref(struct coresight_device *csdev)
> +{
> +	struct device *dev = csdev->dev.parent;
> +
> +	pm_runtime_put(dev);
> +	put_device(dev);
> +	module_put(dev->driver->owner);
> +}
> +
>  /*
>   * coresight_grab_device - Power up this device and any of the helper
>   * devices connected to it for trace operation. Since the helper devices
>   * don't appear on the trace path, they should be handled along with the
>   * the master device.
>   */
> -static void coresight_grab_device(struct coresight_device *csdev)
> +static int coresight_grab_device(struct coresight_device *csdev)
>  {
>  	int i;
>  
> @@ -649,9 +681,20 @@ static void coresight_grab_device(struct coresight_device *csdev)
>  
>  		child  = csdev->pdata->conns[i].child_dev;
>  		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
> -			pm_runtime_get_sync(child->dev.parent);
> +			if (!coresight_get_ref(child))
> +				goto err;
> +	}
> +	if (coresight_get_ref(csdev))
> +		return 0;
> +err:
> +	for (i--; i >= 0; i--) {
> +		struct coresight_device *child;
> +
> +		child  = csdev->pdata->conns[i].child_dev;
> +		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
> +			coresight_put_ref(child);
>  	}
> -	pm_runtime_get_sync(csdev->dev.parent);
> +	return -ENODEV;
>  }
>  
>  /*
> @@ -662,13 +705,13 @@ static void coresight_drop_device(struct coresight_device *csdev)
>  {
>  	int i;
>  
> -	pm_runtime_put(csdev->dev.parent);
> +	coresight_put_ref(csdev);
>  	for (i = 0; i < csdev->pdata->nr_outport; i++) {
>  		struct coresight_device *child;
>  
>  		child  = csdev->pdata->conns[i].child_dev;
>  		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
> -			pm_runtime_put(child->dev.parent);
> +			coresight_put_ref(child);
>  	}
>  }
>  
> @@ -687,7 +730,7 @@ static int _coresight_build_path(struct coresight_device *csdev,
>  				 struct coresight_device *sink,
>  				 struct list_head *path)
>  {
> -	int i;
> +	int i, ret;
>  	bool found = false;
>  	struct coresight_node *node;
>  
> @@ -721,7 +764,11 @@ static int _coresight_build_path(struct coresight_device *csdev,
>  	if (!node)
>  		return -ENOMEM;
>  
> -	coresight_grab_device(csdev);
> +	ret = coresight_grab_device(csdev);

I suggest trying to grab the device before allocating memory for the node.  If
grabing the device fails memory doesn't have to be allocated and released
needlessly.

I will likely come back to this patch later after reviewing the rest the this
set.

Thanks,
Mathieu

> +	if (ret) {
> +		kfree(node);
> +		return ret;
> +	}
>  	node->csdev = csdev;
>  	list_add(&node->link, path);
>  
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module
  2020-08-07 11:11 ` [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module Tingwei Zhang
@ 2020-08-12 20:47   ` Mathieu Poirier
  2020-08-13  2:16     ` Tingwei Zhang
  2020-08-13  9:47   ` Suzuki K Poulose
  1 sibling, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-12 20:47 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:38PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-etm3x as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-etm3x by the Makefile
> - add an etm_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Reviewed-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/Kconfig           |  5 +++-
>  drivers/hwtracing/coresight/Makefile          |  3 ++-
>  ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++-
>  3 files changed, 32 insertions(+), 3 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-etm3x.c => coresight-etm3x-core.c} (97%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 6433f835fc97..8fd9fd139cf3 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
>  	  special enhancement or added features.
>  
>  config CORESIGHT_SOURCE_ETM3X
> -	bool "CoreSight Embedded Trace Macrocell 3.x driver"
> +	tristate "CoreSight Embedded Trace Macrocell 3.x driver"
>  	depends on !ARM64
>  	select CORESIGHT_LINKS_AND_SINKS
>  	help
> @@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
>  	  This is primarily useful for instruction level tracing.  Depending
>  	  the ETM version data tracing may also be available.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-etm3x.
> +
>  config CORESIGHT_SOURCE_ETM4X
>  	bool "CoreSight Embedded Trace Macrocell 4.x driver"
>  	depends on ARM64
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index 19497d1d92bf..d619cfd0abd8 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
>  obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
>  obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
>  					   coresight-replicator.o
> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o coresight-etm-cp14.o \
> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> +coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>  					coresight-etm3x-sysfs.o
>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
>  					coresight-etm4x-sysfs.o
> diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> similarity index 97%
> rename from drivers/hwtracing/coresight/coresight-etm3x.c
> rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
> index bf22dcfd3327..82b333c40006 100644
> --- a/drivers/hwtracing/coresight/coresight-etm3x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> @@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
>  	return ret;
>  }
>  
> +static int __exit etm_remove(struct amba_device *adev)
> +{

Not sure adding __exit does anything special here since all the code is
removed by the kernel anyway.  The same comment goes for the other drivers in
this set.

> +	struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	etm_perf_symlink(drvdata->csdev, false);
> +
> +	if (--etm_count == 0) {
> +		cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> +		if (hp_online)
> +			cpuhp_remove_state_nocalls(hp_online);
> +	}
> +
> +	coresight_unregister(drvdata->csdev);
> +
> +	return 0;
> +}
> +
>  #ifdef CONFIG_PM
>  static int etm_runtime_suspend(struct device *dev)
>  {
> @@ -937,6 +954,8 @@ static const struct amba_id etm_ids[] = {
>  	{ 0, 0},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, etm_ids);
> +
>  static struct amba_driver etm_driver = {
>  	.drv = {
>  		.name	= "coresight-etm3x",
> @@ -945,6 +964,12 @@ static struct amba_driver etm_driver = {
>  		.suppress_bind_attrs = true,
>  	},
>  	.probe		= etm_probe,
> +	.remove         = etm_remove,
>  	.id_table	= etm_ids,
>  };
> -builtin_amba_driver(etm_driver);
> +module_amba_driver(etm_driver);
> +
> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace driver");

That should be "Arm CoreSight Embedded Trace Macrocell 3.x driver"

With the above: 

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure
  2020-08-07 11:11 ` [PATCH v8 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure Tingwei Zhang
@ 2020-08-12 20:48   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-12 20:48 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:37PM +0800, Tingwei Zhang wrote:
> When coresight_build_path() fails on all the cpus, etm_setup_aux
> calls etm_free_aux() to free allocated event_data.
> WARN_ON(cpumask_empty(mask) will be triggered since cpu mask is empty.
> Check event_data->snk_config is not NULL first to avoid this
> warning.
> 
> Fixes: f5200aa9831f38 ("coresight: perf: Refactor function free_event_data()")
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Reviewed-by: Mike Leach <mike.leach@linaro.org>
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>

For patches 07 and 08:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> ---
>  drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
> index dcb0592418ae..3728c44e5763 100644
> --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> @@ -126,10 +126,10 @@ static void free_sink_buffer(struct etm_event_data *event_data)
>  	cpumask_t *mask = &event_data->mask;
>  	struct coresight_device *sink;
>  
> -	if (WARN_ON(cpumask_empty(mask)))
> +	if (!event_data->snk_config)
>  		return;
>  
> -	if (!event_data->snk_config)
> +	if (WARN_ON(cpumask_empty(mask)))
>  		return;
>  
>  	cpu = cpumask_first(mask);
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module
  2020-08-12 20:47   ` Mathieu Poirier
@ 2020-08-13  2:16     ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-13  2:16 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Thu, Aug 13, 2020 at 04:47:41AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:38PM +0800, Tingwei Zhang wrote:
> > From: Kim Phillips <kim.phillips@arm.com>
> > 
> > Allow to build coresight-etm3x as a module, for ease of development.
> > 
> > - Kconfig becomes a tristate, to allow =m
> > - append -core to source file name to allow module to
> >   be called coresight-etm3x by the Makefile
> > - add an etm_remove function, for module unload
> > - add a MODULE_DEVICE_TABLE for autoloading on boot
> > 
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Leo Yan <leo.yan@linaro.org>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Randy Dunlap <rdunlap@infradead.org>
> > Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Russell King <linux@armlinux.org.uk>
> > Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Reviewed-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  drivers/hwtracing/coresight/Kconfig           |  5 +++-
> >  drivers/hwtracing/coresight/Makefile          |  3 ++-
> >  ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++-
> >  3 files changed, 32 insertions(+), 3 deletions(-)
> >  rename drivers/hwtracing/coresight/{coresight-etm3x.c =>
> coresight-etm3x-core.c} (97%)
> > 
> > diff --git a/drivers/hwtracing/coresight/Kconfig
> b/drivers/hwtracing/coresight/Kconfig
> > index 6433f835fc97..8fd9fd139cf3 100644
> > --- a/drivers/hwtracing/coresight/Kconfig
> > +++ b/drivers/hwtracing/coresight/Kconfig
> > @@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
> >  	  special enhancement or added features.
> >  
> >  config CORESIGHT_SOURCE_ETM3X
> > -	bool "CoreSight Embedded Trace Macrocell 3.x driver"
> > +	tristate "CoreSight Embedded Trace Macrocell 3.x driver"
> >  	depends on !ARM64
> >  	select CORESIGHT_LINKS_AND_SINKS
> >  	help
> > @@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
> >  	  This is primarily useful for instruction level tracing.
> Depending
> >  	  the ETM version data tracing may also be available.
> >  
> > +	  To compile this driver as a module, choose M here: the
> > +	  module will be called coresight-etm3x.
> > +
> >  config CORESIGHT_SOURCE_ETM4X
> >  	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> >  	depends on ARM64
> > diff --git a/drivers/hwtracing/coresight/Makefile
> b/drivers/hwtracing/coresight/Makefile
> > index 19497d1d92bf..d619cfd0abd8 100644
> > --- a/drivers/hwtracing/coresight/Makefile
> > +++ b/drivers/hwtracing/coresight/Makefile
> > @@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
> >  obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
> >  obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
> >  					   coresight-replicator.o
> > -obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> coresight-etm-cp14.o \
> > +obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > +coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> >  					coresight-etm3x-sysfs.o
> >  obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> >  					coresight-etm4x-sysfs.o
> > diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c
> b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> > similarity index 97%
> > rename from drivers/hwtracing/coresight/coresight-etm3x.c
> > rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
> > index bf22dcfd3327..82b333c40006 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm3x.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> > @@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev,
> const struct amba_id *id)
> >  	return ret;
> >  }
> >  
> > +static int __exit etm_remove(struct amba_device *adev)
> > +{
> 
> Not sure adding __exit does anything special here since all the code is
> removed by the kernel anyway.  The same comment goes for the other drivers
> in
> this set.
> 
We still need to remove any reference in other part of Kernel to etm device.
For example, we remove ETM module but keep coresight module. ETM-perf and
coresight-core still could access ETM device structure if etm_perf_symlink()
and coresigh_unregister() are not called in etm_remove. We need clean any
reference to ETM device structure up.

Thanks,
Tingwei

> > +	struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > +
> > +	etm_perf_symlink(drvdata->csdev, false);
> > +
> > +	if (--etm_count == 0) {
> > +
> cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> > +		if (hp_online)
> > +			cpuhp_remove_state_nocalls(hp_online);
> > +	}
> > +
> > +	coresight_unregister(drvdata->csdev);
> > +
> > +	return 0;
> > +}
> > +
> >  #ifdef CONFIG_PM
> >  static int etm_runtime_suspend(struct device *dev)
> >  {
> > @@ -937,6 +954,8 @@ static const struct amba_id etm_ids[] = {
> >  	{ 0, 0},
> >  };
> >  
> > +MODULE_DEVICE_TABLE(amba, etm_ids);
> > +
> >  static struct amba_driver etm_driver = {
> >  	.drv = {
> >  		.name	= "coresight-etm3x",
> > @@ -945,6 +964,12 @@ static struct amba_driver etm_driver = {
> >  		.suppress_bind_attrs = true,
> >  	},
> >  	.probe		= etm_probe,
> > +	.remove         = etm_remove,
> >  	.id_table	= etm_ids,
> >  };
> > -builtin_amba_driver(etm_driver);
> > +module_amba_driver(etm_driver);
> > +
> > +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> > +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> > +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace driver");
> 
> That should be "Arm CoreSight Embedded Trace Macrocell 3.x driver"
> 
> With the above: 
> 
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> > +MODULE_LICENSE("GPL v2");
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 06/24] coresight: add try_get_module() in coresight_grab_device()
  2020-08-12 19:36   ` Mathieu Poirier
@ 2020-08-13  7:37     ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-13  7:37 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Thu, Aug 13, 2020 at 03:36:12AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:35PM +0800, Tingwei Zhang wrote:
> > When coresight device is in an active session, driver module of
> > that device should not be removed. Use try_get_module() in
> > coresight_grab_device() to prevent module to be unloaded.
> > Use get_device()/put_device() to protect device data
> > in the middle of active session.
> > 
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Tested-by: Mike Leach <mike.leach@linaro.org>
> > Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > ---
> >  drivers/hwtracing/coresight/coresight.c | 61 ++++++++++++++++++++++---
> >  1 file changed, 54 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight.c
> b/drivers/hwtracing/coresight/coresight.c
> > index b7151c5f81b1..0b0e31577b9b 100644
> > --- a/drivers/hwtracing/coresight/coresight.c
> > +++ b/drivers/hwtracing/coresight/coresight.c
> > @@ -634,13 +634,45 @@ struct coresight_device
> *coresight_get_sink_by_id(u32 id)
> >  	return dev ? to_coresight_device(dev) : NULL;
> >  }
> >  
> > +/**
> > + * coresight_get_ref- Helper function to increase reference count to
> module
> > + * and device.
> > + * Return true in successful case and power up the device.
> > + * Return false when failed to get reference of module.
> > + */
> > +static inline bool coresight_get_ref(struct coresight_device *csdev)
> > +{
> > +	struct device *dev = csdev->dev.parent;
> > +
> > +	/* Make sure the driver can't be removed */
> > +	if (!try_module_get(dev->driver->owner))
> > +		return false;
> > +	/* Make sure the device can't go away */
> > +	get_device(dev);
> > +	pm_runtime_get_sync(dev);
> > +	return true;
> > +}
> > +
> > +/**
> > + * coresight_put_ref- Helper function to decrease reference count to
> module
> > + * and device. Power off the device.
> > + */
> > +static inline void coresight_put_ref(struct coresight_device *csdev)
> > +{
> > +	struct device *dev = csdev->dev.parent;
> > +
> > +	pm_runtime_put(dev);
> > +	put_device(dev);
> > +	module_put(dev->driver->owner);
> > +}
> > +
> >  /*
> >   * coresight_grab_device - Power up this device and any of the helper
> >   * devices connected to it for trace operation. Since the helper
> devices
> >   * don't appear on the trace path, they should be handled along with
> the
> >   * the master device.
> >   */
> > -static void coresight_grab_device(struct coresight_device *csdev)
> > +static int coresight_grab_device(struct coresight_device *csdev)
> >  {
> >  	int i;
> >  
> > @@ -649,9 +681,20 @@ static void coresight_grab_device(struct
> coresight_device *csdev)
> >  
> >  		child  = csdev->pdata->conns[i].child_dev;
> >  		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
> > -			pm_runtime_get_sync(child->dev.parent);
> > +			if (!coresight_get_ref(child))
> > +				goto err;
> > +	}
> > +	if (coresight_get_ref(csdev))
> > +		return 0;
> > +err:
> > +	for (i--; i >= 0; i--) {
> > +		struct coresight_device *child;
> > +
> > +		child  = csdev->pdata->conns[i].child_dev;
> > +		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
> > +			coresight_put_ref(child);
> >  	}
> > -	pm_runtime_get_sync(csdev->dev.parent);
> > +	return -ENODEV;
> >  }
> >  
> >  /*
> > @@ -662,13 +705,13 @@ static void coresight_drop_device(struct
> coresight_device *csdev)
> >  {
> >  	int i;
> >  
> > -	pm_runtime_put(csdev->dev.parent);
> > +	coresight_put_ref(csdev);
> >  	for (i = 0; i < csdev->pdata->nr_outport; i++) {
> >  		struct coresight_device *child;
> >  
> >  		child  = csdev->pdata->conns[i].child_dev;
> >  		if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
> > -			pm_runtime_put(child->dev.parent);
> > +			coresight_put_ref(child);
> >  	}
> >  }
> >  
> > @@ -687,7 +730,7 @@ static int _coresight_build_path(struct
> coresight_device *csdev,
> >  				 struct coresight_device *sink,
> >  				 struct list_head *path)
> >  {
> > -	int i;
> > +	int i, ret;
> >  	bool found = false;
> >  	struct coresight_node *node;
> >  
> > @@ -721,7 +764,11 @@ static int _coresight_build_path(struct
> coresight_device *csdev,
> >  	if (!node)
> >  		return -ENOMEM;
> >  
> > -	coresight_grab_device(csdev);
> > +	ret = coresight_grab_device(csdev);
> 
> I suggest trying to grab the device before allocating memory for the node.
> If
> grabing the device fails memory doesn't have to be allocated and released
> needlessly.
> 
Agree. I'll fix in next revision.

Thanks,
Tingwei

> I will likely come back to this patch later after reviewing the rest the
> this
> set.
> 
> Thanks,
> Mathieu
> 
> > +	if (ret) {
> > +		kfree(node);
> > +		return ret;
> > +	}
> >  	node->csdev = csdev;
> >  	list_add(&node->link, path);
> >  
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module
  2020-08-07 11:11 ` [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module Tingwei Zhang
  2020-08-12 20:47   ` Mathieu Poirier
@ 2020-08-13  9:47   ` Suzuki K Poulose
  2020-08-13 10:56     ` Tingwei Zhang
  1 sibling, 1 reply; 68+ messages in thread
From: Suzuki K Poulose @ 2020-08-13  9:47 UTC (permalink / raw)
  To: tingwei, mathieu.poirier, alexander.shishkin, mike.leach
  Cc: tsoni, saiprakash.ranjan, kim.phillips, jinlmao, gregkh,
	coresight, rdunlap, ykaukab, linux, leo.yan, linux-arm-kernel

On 08/07/2020 12:11 PM, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-etm3x as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>    be called coresight-etm3x by the Makefile
> - add an etm_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Reviewed-by: Mike Leach <mike.leach@linaro.org>
> ---
>   drivers/hwtracing/coresight/Kconfig           |  5 +++-
>   drivers/hwtracing/coresight/Makefile          |  3 ++-
>   ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++-
>   3 files changed, 32 insertions(+), 3 deletions(-)
>   rename drivers/hwtracing/coresight/{coresight-etm3x.c => coresight-etm3x-core.c} (97%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 6433f835fc97..8fd9fd139cf3 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
>   	  special enhancement or added features.
>   
>   config CORESIGHT_SOURCE_ETM3X
> -	bool "CoreSight Embedded Trace Macrocell 3.x driver"
> +	tristate "CoreSight Embedded Trace Macrocell 3.x driver"
>   	depends on !ARM64
>   	select CORESIGHT_LINKS_AND_SINKS
>   	help
> @@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
>   	  This is primarily useful for instruction level tracing.  Depending
>   	  the ETM version data tracing may also be available.
>   
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-etm3x.
> +
>   config CORESIGHT_SOURCE_ETM4X
>   	bool "CoreSight Embedded Trace Macrocell 4.x driver"
>   	depends on ARM64
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index 19497d1d92bf..d619cfd0abd8 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
>   obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
>   obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
>   					   coresight-replicator.o
> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o coresight-etm-cp14.o \
> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> +coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>   					coresight-etm3x-sysfs.o
>   obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
>   					coresight-etm4x-sysfs.o
> diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> similarity index 97%
> rename from drivers/hwtracing/coresight/coresight-etm3x.c
> rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
> index bf22dcfd3327..82b333c40006 100644
> --- a/drivers/hwtracing/coresight/coresight-etm3x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> @@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
>   	return ret;
>   }
>   
> +static int __exit etm_remove(struct amba_device *adev)
> +{
> +	struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	etm_perf_symlink(drvdata->csdev, false);
> +
> +	if (--etm_count == 0) {
> +		cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> +		if (hp_online)
> +			cpuhp_remove_state_nocalls(hp_online);
> +	}
> +

As mentioned in the previous version, this needs fixing
similar to the etm4x to avoid races with etm_count. I understand
that it is an exisiting problem. But this set exposes it more
due to etm_remove() calls and is much more probable to hit it.


Suzuki

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module
  2020-08-13  9:47   ` Suzuki K Poulose
@ 2020-08-13 10:56     ` Tingwei Zhang
  2020-08-13 17:00       ` Mathieu Poirier
  0 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-13 10:56 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: tsoni, saiprakash.ranjan, kim.phillips, mathieu.poirier,
	alexander.shishkin, gregkh, coresight, rdunlap, ykaukab, linux,
	jinlmao, tingwei, leo.yan, linux-arm-kernel, mike.leach

On Thu, Aug 13, 2020 at 05:47:22PM +0800, Suzuki K Poulose wrote:
> On 08/07/2020 12:11 PM, Tingwei Zhang wrote:
> >From: Kim Phillips <kim.phillips@arm.com>
> >
> >Allow to build coresight-etm3x as a module, for ease of development.
> >
> >- Kconfig becomes a tristate, to allow =m
> >- append -core to source file name to allow module to
> >   be called coresight-etm3x by the Makefile
> >- add an etm_remove function, for module unload
> >- add a MODULE_DEVICE_TABLE for autoloading on boot
> >
> >Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> >Cc: Leo Yan <leo.yan@linaro.org>
> >Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> >Cc: Randy Dunlap <rdunlap@infradead.org>
> >Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> >Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >Cc: Russell King <linux@armlinux.org.uk>
> >Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> >Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> >Reviewed-by: Mike Leach <mike.leach@linaro.org>
> >---
> >  drivers/hwtracing/coresight/Kconfig           |  5 +++-
> >  drivers/hwtracing/coresight/Makefile          |  3 ++-
> >  ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++-
> >  3 files changed, 32 insertions(+), 3 deletions(-)
> >  rename drivers/hwtracing/coresight/{coresight-etm3x.c =>
> >coresight-etm3x-core.c} (97%)
> >
> >diff --git a/drivers/hwtracing/coresight/Kconfig
> >b/drivers/hwtracing/coresight/Kconfig
> >index 6433f835fc97..8fd9fd139cf3 100644
> >--- a/drivers/hwtracing/coresight/Kconfig
> >+++ b/drivers/hwtracing/coresight/Kconfig
> >@@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
> >  	  special enhancement or added features.
> >
> >  config CORESIGHT_SOURCE_ETM3X
> >-	bool "CoreSight Embedded Trace Macrocell 3.x driver"
> >+	tristate "CoreSight Embedded Trace Macrocell 3.x driver"
> >  	depends on !ARM64
> >  	select CORESIGHT_LINKS_AND_SINKS
> >  	help
> >@@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
> >  	  This is primarily useful for instruction level tracing.  Depending
> >  	  the ETM version data tracing may also be available.
> >
> >+	  To compile this driver as a module, choose M here: the
> >+	  module will be called coresight-etm3x.
> >+
> >  config CORESIGHT_SOURCE_ETM4X
> >  	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> >  	depends on ARM64
> >diff --git a/drivers/hwtracing/coresight/Makefile
> >b/drivers/hwtracing/coresight/Makefile
> >index 19497d1d92bf..d619cfd0abd8 100644
> >--- a/drivers/hwtracing/coresight/Makefile
> >+++ b/drivers/hwtracing/coresight/Makefile
> >@@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
> >  obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
> >  obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
> >  					   coresight-replicator.o
> >-obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> >coresight-etm-cp14.o \
> >+obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> >+coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> >  					coresight-etm3x-sysfs.o
> >  obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> >  					coresight-etm4x-sysfs.o
> >diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c
> >b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> >similarity index 97%
> >rename from drivers/hwtracing/coresight/coresight-etm3x.c
> >rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
> >index bf22dcfd3327..82b333c40006 100644
> >--- a/drivers/hwtracing/coresight/coresight-etm3x.c
> >+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> >@@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const
> >struct amba_id *id)
> >  	return ret;
> >  }
> >
> >+static int __exit etm_remove(struct amba_device *adev)
> >+{
> >+	struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> >+
> >+	etm_perf_symlink(drvdata->csdev, false);
> >+
> >+	if (--etm_count == 0) {
> >+		cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> >+		if (hp_online)
> >+			cpuhp_remove_state_nocalls(hp_online);
> >+	}
> >+
> 
> As mentioned in the previous version, this needs fixing
> similar to the etm4x to avoid races with etm_count. I understand
> that it is an exisiting problem. But this set exposes it more
> due to etm_remove() calls and is much more probable to hit it.
> 
OK. I'll fix this. Can you help to review ETM4 fix? If that's fine,
I'll make similar fix here.

Unfortunately, I don't have any device with ETM3. Can anyone help
to verify the function on ETM3? I'll really appreciate that.

Thanks,
Tingwei
> 
> Suzuki

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module
  2020-08-13 10:56     ` Tingwei Zhang
@ 2020-08-13 17:00       ` Mathieu Poirier
  2020-08-13 23:44         ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-13 17:00 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg KH, Coresight ML,
	Randy Dunlap, Mian Yousaf Kaukab, Russell King, Tingwei Zhang,
	Leo Yan, linux-arm-kernel, Mike Leach

On Thu, 13 Aug 2020 at 04:57, Tingwei Zhang <tingweiz@codeaurora.org> wrote:
>
> On Thu, Aug 13, 2020 at 05:47:22PM +0800, Suzuki K Poulose wrote:
> > On 08/07/2020 12:11 PM, Tingwei Zhang wrote:
> > >From: Kim Phillips <kim.phillips@arm.com>
> > >
> > >Allow to build coresight-etm3x as a module, for ease of development.
> > >
> > >- Kconfig becomes a tristate, to allow =m
> > >- append -core to source file name to allow module to
> > >   be called coresight-etm3x by the Makefile
> > >- add an etm_remove function, for module unload
> > >- add a MODULE_DEVICE_TABLE for autoloading on boot
> > >
> > >Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > >Cc: Leo Yan <leo.yan@linaro.org>
> > >Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > >Cc: Randy Dunlap <rdunlap@infradead.org>
> > >Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > >Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > >Cc: Russell King <linux@armlinux.org.uk>
> > >Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > >Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > >Reviewed-by: Mike Leach <mike.leach@linaro.org>
> > >---
> > >  drivers/hwtracing/coresight/Kconfig           |  5 +++-
> > >  drivers/hwtracing/coresight/Makefile          |  3 ++-
> > >  ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++-
> > >  3 files changed, 32 insertions(+), 3 deletions(-)
> > >  rename drivers/hwtracing/coresight/{coresight-etm3x.c =>
> > >coresight-etm3x-core.c} (97%)
> > >
> > >diff --git a/drivers/hwtracing/coresight/Kconfig
> > >b/drivers/hwtracing/coresight/Kconfig
> > >index 6433f835fc97..8fd9fd139cf3 100644
> > >--- a/drivers/hwtracing/coresight/Kconfig
> > >+++ b/drivers/hwtracing/coresight/Kconfig
> > >@@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
> > >       special enhancement or added features.
> > >
> > >  config CORESIGHT_SOURCE_ETM3X
> > >-    bool "CoreSight Embedded Trace Macrocell 3.x driver"
> > >+    tristate "CoreSight Embedded Trace Macrocell 3.x driver"
> > >     depends on !ARM64
> > >     select CORESIGHT_LINKS_AND_SINKS
> > >     help
> > >@@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
> > >       This is primarily useful for instruction level tracing.  Depending
> > >       the ETM version data tracing may also be available.
> > >
> > >+      To compile this driver as a module, choose M here: the
> > >+      module will be called coresight-etm3x.
> > >+
> > >  config CORESIGHT_SOURCE_ETM4X
> > >     bool "CoreSight Embedded Trace Macrocell 4.x driver"
> > >     depends on ARM64
> > >diff --git a/drivers/hwtracing/coresight/Makefile
> > >b/drivers/hwtracing/coresight/Makefile
> > >index 19497d1d92bf..d619cfd0abd8 100644
> > >--- a/drivers/hwtracing/coresight/Makefile
> > >+++ b/drivers/hwtracing/coresight/Makefile
> > >@@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
> > >  obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
> > >  obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
> > >                                        coresight-replicator.o
> > >-obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > >coresight-etm-cp14.o \
> > >+obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > >+coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> > >                                     coresight-etm3x-sysfs.o
> > >  obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> > >                                     coresight-etm4x-sysfs.o
> > >diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c
> > >b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> > >similarity index 97%
> > >rename from drivers/hwtracing/coresight/coresight-etm3x.c
> > >rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
> > >index bf22dcfd3327..82b333c40006 100644
> > >--- a/drivers/hwtracing/coresight/coresight-etm3x.c
> > >+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> > >@@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const
> > >struct amba_id *id)
> > >     return ret;
> > >  }
> > >
> > >+static int __exit etm_remove(struct amba_device *adev)
> > >+{
> > >+    struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > >+
> > >+    etm_perf_symlink(drvdata->csdev, false);
> > >+
> > >+    if (--etm_count == 0) {
> > >+            cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> > >+            if (hp_online)
> > >+                    cpuhp_remove_state_nocalls(hp_online);
> > >+    }
> > >+
> >
> > As mentioned in the previous version, this needs fixing
> > similar to the etm4x to avoid races with etm_count. I understand
> > that it is an exisiting problem. But this set exposes it more
> > due to etm_remove() calls and is much more probable to hit it.
> >
> OK. I'll fix this. Can you help to review ETM4 fix? If that's fine,
> I'll make similar fix here.
>
> Unfortunately, I don't have any device with ETM3. Can anyone help
> to verify the function on ETM3? I'll really appreciate that.

I'll take care of ETMv3.  Please wait before sending a new revision
since I am still reviewing the current set.  I will let you know when
I am done.

>
> Thanks,
> Tingwei
> >
> > Suzuki

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-07 11:11 ` [PATCH v8 10/24] coresight: etm4x: allow etm4x " Tingwei Zhang
@ 2020-08-13 19:39   ` Mathieu Poirier
  2020-08-13 23:46     ` Suzuki K Poulose
  2020-08-13 19:40   ` Mathieu Poirier
  2020-08-13 19:45   ` Mathieu Poirier
  2 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-13 19:39 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-etm4x as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-etm4x by the Makefile
> - add an etm4_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> - protect etmdrvdata[] with mutex lock from racing
>   between module unload and CPU hotplug
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/Kconfig           |   5 +-
>  drivers/hwtracing/coresight/Makefile          |   4 +-
>  ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++++++-----
>  3 files changed, 92 insertions(+), 35 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (95%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 8fd9fd139cf3..d6e107bbd30b 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
>  	  module will be called coresight-etm3x.
>  
>  config CORESIGHT_SOURCE_ETM4X
> -	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> +	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
>  	depends on ARM64
>  	select CORESIGHT_LINKS_AND_SINKS
>  	select PID_IN_CONTEXTIDR
> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
>  	  for instruction level tracing. Depending on the implemented version
>  	  data tracing may also be available.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-etm4x.
> +
>  config CORESIGHT_STM
>  	tristate "CoreSight System Trace Macrocell driver"
>  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index d619cfd0abd8..271dc255454f 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>  					coresight-etm3x-sysfs.o
> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> -					coresight-etm4x-sysfs.o
> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> similarity index 95%
> rename from drivers/hwtracing/coresight/coresight-etm4x.c
> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> index fddfd93b9a7b..ae9847e194a3 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
>  MODULE_PARM_DESC(pm_save_enable,
>  	"Save/restore state on power down: 1 = never, 2 = self-hosted");
>  
> +static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
>  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
>  static void etm4_set_default_config(struct etmv4_config *config);
>  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> @@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config *config)
>  
>  static int etm4_online_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
>  		coresight_enable(etmdrvdata[cpu]->csdev);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
>  static int etm4_starting_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	spin_lock(&etmdrvdata[cpu]->spinlock);
>  	if (!etmdrvdata[cpu]->os_unlock)
> @@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
>  	if (local_read(&etmdrvdata[cpu]->mode))
>  		etm4_enable_hw(etmdrvdata[cpu]);
>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));

Ouch!  

A mutex wrapping a spinlock to protect the exact same drvdata structure.
Because etmdrvdata_lock[] is a per cpu variable I suggest to get rid of
drvdata::spinlock altogether.  To do so:

1) In etm4_enable_sysfs(), get rid of the spinlock/unlock().
2) In etm4_enable_hw_smp_call(), grab the mutex based on the value of
drvdata->cpu and set drvdata->stick_enable based on the return value of
etm4_enable_hw() while holding the mutex.
3) In etm4_disable_sysfs(), just change spinlock/unlock to mutex operations.
4) Get rid of spinlock operations in etm4_starting/dying_cpu().

As Suzuki pointed out the same kind of gymnastic needs to be done for ETMv3.

>  	return 0;
>  }
>  
>  static int etm4_dying_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	spin_lock(&etmdrvdata[cpu]->spinlock);
>  	if (local_read(&etmdrvdata[cpu]->mode))
>  		etm4_disable_hw(etmdrvdata[cpu]);
>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
> @@ -1360,24 +1373,30 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
>  {
>  	struct etmv4_drvdata *drvdata;
>  	unsigned int cpu = smp_processor_id();
> +	int ret = NOTIFY_OK;
>  
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
>  	if (!etmdrvdata[cpu])
> -		return NOTIFY_OK;
> +		goto out;
>  
>  	drvdata = etmdrvdata[cpu];
>  
>  	if (!drvdata->save_state)
> -		return NOTIFY_OK;
> +		goto out;
>  
> -	if (WARN_ON_ONCE(drvdata->cpu != cpu))
> -		return NOTIFY_BAD;
> +	if (WARN_ON_ONCE(drvdata->cpu != cpu)) {
> +		ret = NOTIFY_BAD;
> +		goto out;
> +	}
>  
>  	switch (cmd) {
>  	case CPU_PM_ENTER:
>  		/* save the state if self-hosted coresight is in use */
>  		if (local_read(&drvdata->mode))
> -			if (etm4_cpu_save(drvdata))
> -				return NOTIFY_BAD;
> +			if (etm4_cpu_save(drvdata)) {
> +				ret = NOTIFY_BAD;
> +				goto out;
> +			}
>  		break;
>  	case CPU_PM_EXIT:
>  		/* fallthrough */
> @@ -1386,10 +1405,12 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
>  			etm4_cpu_restore(drvdata);
>  		break;
>  	default:
> -		return NOTIFY_DONE;
> +		goto out;
>  	}
>  
> -	return NOTIFY_OK;
> +out:
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> +	return ret;
>  }
>  
>  static struct notifier_block etm4_cpu_pm_nb = {
> @@ -1430,7 +1451,7 @@ static int __init etm4_pm_setup(void)
>  	return ret;
>  }
>  
> -static void __init etm4_pm_clear(void)
> +static void etm4_pm_clear(void)
>  {
>  	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
>  	cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> @@ -1487,25 +1508,20 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	if (!desc.name)
>  		return -ENOMEM;
>  
> -	etmdrvdata[drvdata->cpu] = drvdata;
> -
>  	if (smp_call_function_single(drvdata->cpu,
>  				etm4_init_arch_data,  drvdata, 1))
>  		dev_err(dev, "ETM arch init failed\n");
>  
> -	if (etm4_arch_supported(drvdata->arch) == false) {
> -		ret = -EINVAL;
> -		goto err_arch_supported;
> -	}
> +	if (etm4_arch_supported(drvdata->arch) == false)
> +		return -EINVAL;
>  
>  	etm4_init_trace_id(drvdata);
>  	etm4_set_default(&drvdata->config);
>  
>  	pdata = coresight_get_platform_data(dev);
> -	if (IS_ERR(pdata)) {
> -		ret = PTR_ERR(pdata);
> -		goto err_arch_supported;
> -	}
> +	if (IS_ERR(pdata))
> +		return PTR_ERR(pdata);
> +
>  	adev->dev.platform_data = pdata;
>  
>  	desc.type = CORESIGHT_DEV_TYPE_SOURCE;
> @@ -1515,17 +1531,19 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	desc.dev = dev;
>  	desc.groups = coresight_etmv4_groups;
>  	drvdata->csdev = coresight_register(&desc);
> -	if (IS_ERR(drvdata->csdev)) {
> -		ret = PTR_ERR(drvdata->csdev);
> -		goto err_arch_supported;
> -	}
> +	if (IS_ERR(drvdata->csdev))
> +		return PTR_ERR(drvdata->csdev);
>  
>  	ret = etm_perf_symlink(drvdata->csdev, true);
>  	if (ret) {
>  		coresight_unregister(drvdata->csdev);
> -		goto err_arch_supported;
> +		return ret;
>  	}
>  
> +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +	etmdrvdata[drvdata->cpu] = drvdata;
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +
>  	pm_runtime_put(&adev->dev);
>  	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
>  		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
> @@ -1536,10 +1554,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	}
>  
>  	return 0;
> -
> -err_arch_supported:
> -	etmdrvdata[drvdata->cpu] = NULL;
> -	return ret;
>  }
>  
>  static struct amba_cs_uci_id uci_id_etm4[] = {
> @@ -1551,6 +1565,22 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
>  	}
>  };
>  
> +static int __exit etm4_remove(struct amba_device *adev)
> +{
> +	struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	etm_perf_symlink(drvdata->csdev, false);
> +
> +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +	etmdrvdata[drvdata->cpu] = NULL;
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +
> +	coresight_unregister(drvdata->csdev);
> +
> +	return 0;
> +}
> +
> +
>  static const struct amba_id etm4_ids[] = {
>  	CS_AMBA_ID(0x000bb95d),			/* Cortex-A53 */
>  	CS_AMBA_ID(0x000bb95e),			/* Cortex-A57 */
> @@ -1568,18 +1598,26 @@ static const struct amba_id etm4_ids[] = {
>  	{},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, etm4_ids);
> +
>  static struct amba_driver etm4x_driver = {
>  	.drv = {
>  		.name   = "coresight-etm4x",
> +		.owner  = THIS_MODULE,
>  		.suppress_bind_attrs = true,
>  	},
>  	.probe		= etm4_probe,
> +	.remove         = etm4_remove,
>  	.id_table	= etm4_ids,
>  };
>  
>  static int __init etm4x_init(void)
>  {
>  	int ret;
> +	int cpu;
> +
> +	for_each_possible_cpu(cpu)
> +		mutex_init(&per_cpu(etmdrvdata_lock, cpu));
>  
>  	ret = etm4_pm_setup();
>  
> @@ -1595,4 +1633,20 @@ static int __init etm4x_init(void)
>  
>  	return ret;
>  }
> -device_initcall(etm4x_init);
> +
> +static void __exit etm4x_exit(void)
> +{
> +	int cpu;
> +
> +	amba_driver_unregister(&etm4x_driver);
> +	etm4_pm_clear();
> +	for_each_possible_cpu(cpu)
> +		mutex_destroy(&per_cpu(etmdrvdata_lock, cpu));
> +}
> +module_init(etm4x_init);
> +module_exit(etm4x_exit);
> +
> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-07 11:11 ` [PATCH v8 10/24] coresight: etm4x: allow etm4x " Tingwei Zhang
  2020-08-13 19:39   ` Mathieu Poirier
@ 2020-08-13 19:40   ` Mathieu Poirier
  2020-08-13 23:58     ` Tingwei Zhang
  2020-08-13 19:45   ` Mathieu Poirier
  2 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-13 19:40 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-etm4x as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-etm4x by the Makefile
> - add an etm4_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> - protect etmdrvdata[] with mutex lock from racing
>   between module unload and CPU hotplug
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/Kconfig           |   5 +-
>  drivers/hwtracing/coresight/Makefile          |   4 +-
>  ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++++++-----
>  3 files changed, 92 insertions(+), 35 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (95%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 8fd9fd139cf3..d6e107bbd30b 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
>  	  module will be called coresight-etm3x.
>  
>  config CORESIGHT_SOURCE_ETM4X
> -	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> +	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
>  	depends on ARM64
>  	select CORESIGHT_LINKS_AND_SINKS
>  	select PID_IN_CONTEXTIDR
> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
>  	  for instruction level tracing. Depending on the implemented version
>  	  data tracing may also be available.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-etm4x.
> +
>  config CORESIGHT_STM
>  	tristate "CoreSight System Trace Macrocell driver"
>  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index d619cfd0abd8..271dc255454f 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>  					coresight-etm3x-sysfs.o
> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> -					coresight-etm4x-sysfs.o
> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> similarity index 95%
> rename from drivers/hwtracing/coresight/coresight-etm4x.c
> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> index fddfd93b9a7b..ae9847e194a3 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
>  MODULE_PARM_DESC(pm_save_enable,
>  	"Save/restore state on power down: 1 = never, 2 = self-hosted");
>  
> +static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
>  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
>  static void etm4_set_default_config(struct etmv4_config *config);
>  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> @@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config *config)
>  
>  static int etm4_online_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
>  		coresight_enable(etmdrvdata[cpu]->csdev);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
>  static int etm4_starting_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	spin_lock(&etmdrvdata[cpu]->spinlock);
>  	if (!etmdrvdata[cpu]->os_unlock)
> @@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
>  	if (local_read(&etmdrvdata[cpu]->mode))
>  		etm4_enable_hw(etmdrvdata[cpu]);
>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
>  static int etm4_dying_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	spin_lock(&etmdrvdata[cpu]->spinlock);
>  	if (local_read(&etmdrvdata[cpu]->mode))
>  		etm4_disable_hw(etmdrvdata[cpu]);
>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
> @@ -1360,24 +1373,30 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
>  {
>  	struct etmv4_drvdata *drvdata;
>  	unsigned int cpu = smp_processor_id();
> +	int ret = NOTIFY_OK;
>  
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
>  	if (!etmdrvdata[cpu])
> -		return NOTIFY_OK;
> +		goto out;
>  
>  	drvdata = etmdrvdata[cpu];
>  
>  	if (!drvdata->save_state)
> -		return NOTIFY_OK;
> +		goto out;
>  
> -	if (WARN_ON_ONCE(drvdata->cpu != cpu))
> -		return NOTIFY_BAD;
> +	if (WARN_ON_ONCE(drvdata->cpu != cpu)) {
> +		ret = NOTIFY_BAD;
> +		goto out;
> +	}
>  
>  	switch (cmd) {
>  	case CPU_PM_ENTER:
>  		/* save the state if self-hosted coresight is in use */
>  		if (local_read(&drvdata->mode))
> -			if (etm4_cpu_save(drvdata))
> -				return NOTIFY_BAD;
> +			if (etm4_cpu_save(drvdata)) {
> +				ret = NOTIFY_BAD;
> +				goto out;
> +			}
>  		break;
>  	case CPU_PM_EXIT:
>  		/* fallthrough */
> @@ -1386,10 +1405,12 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
>  			etm4_cpu_restore(drvdata);
>  		break;
>  	default:
> -		return NOTIFY_DONE;
> +		goto out;
>  	}
>  
> -	return NOTIFY_OK;
> +out:
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> +	return ret;
>  }
>  
>  static struct notifier_block etm4_cpu_pm_nb = {
> @@ -1430,7 +1451,7 @@ static int __init etm4_pm_setup(void)
>  	return ret;
>  }
>  
> -static void __init etm4_pm_clear(void)
> +static void etm4_pm_clear(void)
>  {
>  	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
>  	cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> @@ -1487,25 +1508,20 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	if (!desc.name)
>  		return -ENOMEM;
>  
> -	etmdrvdata[drvdata->cpu] = drvdata;
> -
>  	if (smp_call_function_single(drvdata->cpu,
>  				etm4_init_arch_data,  drvdata, 1))
>  		dev_err(dev, "ETM arch init failed\n");
>  
> -	if (etm4_arch_supported(drvdata->arch) == false) {
> -		ret = -EINVAL;
> -		goto err_arch_supported;
> -	}
> +	if (etm4_arch_supported(drvdata->arch) == false)
> +		return -EINVAL;
>  
>  	etm4_init_trace_id(drvdata);
>  	etm4_set_default(&drvdata->config);
>  
>  	pdata = coresight_get_platform_data(dev);
> -	if (IS_ERR(pdata)) {
> -		ret = PTR_ERR(pdata);
> -		goto err_arch_supported;
> -	}
> +	if (IS_ERR(pdata))
> +		return PTR_ERR(pdata);
> +
>  	adev->dev.platform_data = pdata;
>  
>  	desc.type = CORESIGHT_DEV_TYPE_SOURCE;
> @@ -1515,17 +1531,19 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	desc.dev = dev;
>  	desc.groups = coresight_etmv4_groups;
>  	drvdata->csdev = coresight_register(&desc);
> -	if (IS_ERR(drvdata->csdev)) {
> -		ret = PTR_ERR(drvdata->csdev);
> -		goto err_arch_supported;
> -	}
> +	if (IS_ERR(drvdata->csdev))
> +		return PTR_ERR(drvdata->csdev);
>  
>  	ret = etm_perf_symlink(drvdata->csdev, true);
>  	if (ret) {
>  		coresight_unregister(drvdata->csdev);
> -		goto err_arch_supported;
> +		return ret;
>  	}
>  
> +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +	etmdrvdata[drvdata->cpu] = drvdata;
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +
>  	pm_runtime_put(&adev->dev);
>  	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
>  		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
> @@ -1536,10 +1554,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	}
>  
>  	return 0;
> -
> -err_arch_supported:
> -	etmdrvdata[drvdata->cpu] = NULL;
> -	return ret;
>  }
>  
>  static struct amba_cs_uci_id uci_id_etm4[] = {
> @@ -1551,6 +1565,22 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
>  	}
>  };
>  
> +static int __exit etm4_remove(struct amba_device *adev)
> +{
> +	struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	etm_perf_symlink(drvdata->csdev, false);
> +
> +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +	etmdrvdata[drvdata->cpu] = NULL;
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +
> +	coresight_unregister(drvdata->csdev);
> +
> +	return 0;
> +}
> +
> +
>  static const struct amba_id etm4_ids[] = {
>  	CS_AMBA_ID(0x000bb95d),			/* Cortex-A53 */
>  	CS_AMBA_ID(0x000bb95e),			/* Cortex-A57 */
> @@ -1568,18 +1598,26 @@ static const struct amba_id etm4_ids[] = {
>  	{},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, etm4_ids);
> +
>  static struct amba_driver etm4x_driver = {
>  	.drv = {
>  		.name   = "coresight-etm4x",
> +		.owner  = THIS_MODULE,
>  		.suppress_bind_attrs = true,
>  	},
>  	.probe		= etm4_probe,
> +	.remove         = etm4_remove,
>  	.id_table	= etm4_ids,
>  };
>  
>  static int __init etm4x_init(void)
>  {
>  	int ret;
> +	int cpu;
> +
> +	for_each_possible_cpu(cpu)
> +		mutex_init(&per_cpu(etmdrvdata_lock, cpu));
>  
>  	ret = etm4_pm_setup();
>  
> @@ -1595,4 +1633,20 @@ static int __init etm4x_init(void)
>  
>  	return ret;
>  }
> -device_initcall(etm4x_init);
> +
> +static void __exit etm4x_exit(void)
> +{
> +	int cpu;
> +
> +	amba_driver_unregister(&etm4x_driver);
> +	etm4_pm_clear();
> +	for_each_possible_cpu(cpu)
> +		mutex_destroy(&per_cpu(etmdrvdata_lock, cpu));
> +}
> +module_init(etm4x_init);
> +module_exit(etm4x_exit);
> +
> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");

... And this should be "Arm CoreSight Embedded Trace Macrocell 4.x driver".

> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-07 11:11 ` [PATCH v8 10/24] coresight: etm4x: allow etm4x " Tingwei Zhang
  2020-08-13 19:39   ` Mathieu Poirier
  2020-08-13 19:40   ` Mathieu Poirier
@ 2020-08-13 19:45   ` Mathieu Poirier
  2020-08-13 23:57     ` Tingwei Zhang
  2 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-13 19:45 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-etm4x as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-etm4x by the Makefile
> - add an etm4_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> - protect etmdrvdata[] with mutex lock from racing
>   between module unload and CPU hotplug
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/Kconfig           |   5 +-
>  drivers/hwtracing/coresight/Makefile          |   4 +-
>  ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++++++-----
>  3 files changed, 92 insertions(+), 35 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (95%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 8fd9fd139cf3..d6e107bbd30b 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
>  	  module will be called coresight-etm3x.
>  
>  config CORESIGHT_SOURCE_ETM4X
> -	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> +	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
>  	depends on ARM64
>  	select CORESIGHT_LINKS_AND_SINKS
>  	select PID_IN_CONTEXTIDR
> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
>  	  for instruction level tracing. Depending on the implemented version
>  	  data tracing may also be available.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-etm4x.
> +
>  config CORESIGHT_STM
>  	tristate "CoreSight System Trace Macrocell driver"
>  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index d619cfd0abd8..271dc255454f 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>  					coresight-etm3x-sysfs.o
> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> -					coresight-etm4x-sysfs.o
> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> similarity index 95%
> rename from drivers/hwtracing/coresight/coresight-etm4x.c
> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> index fddfd93b9a7b..ae9847e194a3 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
>  MODULE_PARM_DESC(pm_save_enable,
>  	"Save/restore state on power down: 1 = never, 2 = self-hosted");
>  
> +static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
>  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
>  static void etm4_set_default_config(struct etmv4_config *config);
>  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> @@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config *config)
>  
>  static int etm4_online_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
>  		coresight_enable(etmdrvdata[cpu]->csdev);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
>  static int etm4_starting_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	spin_lock(&etmdrvdata[cpu]->spinlock);
>  	if (!etmdrvdata[cpu]->os_unlock)
> @@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
>  	if (local_read(&etmdrvdata[cpu]->mode))
>  		etm4_enable_hw(etmdrvdata[cpu]);
>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
>  static int etm4_dying_cpu(unsigned int cpu)
>  {
> -	if (!etmdrvdata[cpu])
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> +	if (!etmdrvdata[cpu]) {
> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  		return 0;
> +	}
>  
>  	spin_lock(&etmdrvdata[cpu]->spinlock);
>  	if (local_read(&etmdrvdata[cpu]->mode))
>  		etm4_disable_hw(etmdrvdata[cpu]);
>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>  	return 0;
>  }
>  
> @@ -1360,24 +1373,30 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
>  {
>  	struct etmv4_drvdata *drvdata;
>  	unsigned int cpu = smp_processor_id();
> +	int ret = NOTIFY_OK;
>  
> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
>  	if (!etmdrvdata[cpu])
> -		return NOTIFY_OK;
> +		goto out;
>  
>  	drvdata = etmdrvdata[cpu];
>  
>  	if (!drvdata->save_state)
> -		return NOTIFY_OK;
> +		goto out;
>  
> -	if (WARN_ON_ONCE(drvdata->cpu != cpu))
> -		return NOTIFY_BAD;
> +	if (WARN_ON_ONCE(drvdata->cpu != cpu)) {
> +		ret = NOTIFY_BAD;
> +		goto out;
> +	}
>  
>  	switch (cmd) {
>  	case CPU_PM_ENTER:
>  		/* save the state if self-hosted coresight is in use */
>  		if (local_read(&drvdata->mode))
> -			if (etm4_cpu_save(drvdata))
> -				return NOTIFY_BAD;
> +			if (etm4_cpu_save(drvdata)) {
> +				ret = NOTIFY_BAD;
> +				goto out;
> +			}
>  		break;
>  	case CPU_PM_EXIT:
>  		/* fallthrough */
> @@ -1386,10 +1405,12 @@ static int etm4_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
>  			etm4_cpu_restore(drvdata);
>  		break;
>  	default:
> -		return NOTIFY_DONE;
> +		goto out;
>  	}
>  
> -	return NOTIFY_OK;
> +out:
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> +	return ret;
>  }
>  
>  static struct notifier_block etm4_cpu_pm_nb = {
> @@ -1430,7 +1451,7 @@ static int __init etm4_pm_setup(void)
>  	return ret;
>  }
>  
> -static void __init etm4_pm_clear(void)
> +static void etm4_pm_clear(void)
>  {
>  	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
>  	cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> @@ -1487,25 +1508,20 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	if (!desc.name)
>  		return -ENOMEM;
>  
> -	etmdrvdata[drvdata->cpu] = drvdata;
> -
>  	if (smp_call_function_single(drvdata->cpu,
>  				etm4_init_arch_data,  drvdata, 1))
>  		dev_err(dev, "ETM arch init failed\n");
>  
> -	if (etm4_arch_supported(drvdata->arch) == false) {
> -		ret = -EINVAL;
> -		goto err_arch_supported;
> -	}
> +	if (etm4_arch_supported(drvdata->arch) == false)
> +		return -EINVAL;
>  
>  	etm4_init_trace_id(drvdata);
>  	etm4_set_default(&drvdata->config);
>  
>  	pdata = coresight_get_platform_data(dev);
> -	if (IS_ERR(pdata)) {
> -		ret = PTR_ERR(pdata);
> -		goto err_arch_supported;
> -	}
> +	if (IS_ERR(pdata))
> +		return PTR_ERR(pdata);
> +
>  	adev->dev.platform_data = pdata;
>  
>  	desc.type = CORESIGHT_DEV_TYPE_SOURCE;
> @@ -1515,17 +1531,19 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	desc.dev = dev;
>  	desc.groups = coresight_etmv4_groups;
>  	drvdata->csdev = coresight_register(&desc);
> -	if (IS_ERR(drvdata->csdev)) {
> -		ret = PTR_ERR(drvdata->csdev);
> -		goto err_arch_supported;
> -	}
> +	if (IS_ERR(drvdata->csdev))
> +		return PTR_ERR(drvdata->csdev);
>  
>  	ret = etm_perf_symlink(drvdata->csdev, true);
>  	if (ret) {
>  		coresight_unregister(drvdata->csdev);
> -		goto err_arch_supported;
> +		return ret;
>  	}
>  
> +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +	etmdrvdata[drvdata->cpu] = drvdata;
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +
>  	pm_runtime_put(&adev->dev);
>  	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
>  		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
> @@ -1536,10 +1554,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
>  	}
>  
>  	return 0;
> -
> -err_arch_supported:
> -	etmdrvdata[drvdata->cpu] = NULL;
> -	return ret;
>  }
>  
>  static struct amba_cs_uci_id uci_id_etm4[] = {
> @@ -1551,6 +1565,22 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
>  	}
>  };
>  
> +static int __exit etm4_remove(struct amba_device *adev)
> +{
> +	struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	etm_perf_symlink(drvdata->csdev, false);
> +
> +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +	etmdrvdata[drvdata->cpu] = NULL;
> +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> +
> +	coresight_unregister(drvdata->csdev);
> +
> +	return 0;
> +}
> +
> +

Extra line

>  static const struct amba_id etm4_ids[] = {
>  	CS_AMBA_ID(0x000bb95d),			/* Cortex-A53 */
>  	CS_AMBA_ID(0x000bb95e),			/* Cortex-A57 */
> @@ -1568,18 +1598,26 @@ static const struct amba_id etm4_ids[] = {
>  	{},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, etm4_ids);
> +
>  static struct amba_driver etm4x_driver = {
>  	.drv = {
>  		.name   = "coresight-etm4x",
> +		.owner  = THIS_MODULE,
>  		.suppress_bind_attrs = true,
>  	},
>  	.probe		= etm4_probe,
> +	.remove         = etm4_remove,
>  	.id_table	= etm4_ids,
>  };
>  
>  static int __init etm4x_init(void)
>  {
>  	int ret;
> +	int cpu;
> +
> +	for_each_possible_cpu(cpu)
> +		mutex_init(&per_cpu(etmdrvdata_lock, cpu));
>  
>  	ret = etm4_pm_setup();
>  
> @@ -1595,4 +1633,20 @@ static int __init etm4x_init(void)
>  
>  	return ret;
>  }
> -device_initcall(etm4x_init);
> +
> +static void __exit etm4x_exit(void)
> +{
> +	int cpu;
> +
> +	amba_driver_unregister(&etm4x_driver);
> +	etm4_pm_clear();
> +	for_each_possible_cpu(cpu)
> +		mutex_destroy(&per_cpu(etmdrvdata_lock, cpu));
> +}
> +module_init(etm4x_init);
> +module_exit(etm4x_exit);
> +
> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 14/24] coresight: allow funnel driver to be built as module
  2020-08-07 11:11 ` [PATCH v8 14/24] coresight: allow funnel driver to be built as module Tingwei Zhang
@ 2020-08-13 20:15   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-13 20:15 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:43PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-funnel as module, for ease of development.
> 
> - combine static and dynamic funnel init into single
>   module_init/exit call
> - add funnel_remove functions, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Co-developed-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> ---
>  .../hwtracing/coresight/coresight-funnel.c    | 62 ++++++++++++++++++-
>  1 file changed, 60 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c
> index 900690a9f7f0..062694ef9879 100644
> --- a/drivers/hwtracing/coresight/coresight-funnel.c
> +++ b/drivers/hwtracing/coresight/coresight-funnel.c
> @@ -274,6 +274,15 @@ static int funnel_probe(struct device *dev, struct resource *res)
>  	return ret;
>  }
>  
> +static int __exit funnel_remove(struct device *dev)
> +{
> +	struct funnel_drvdata *drvdata = dev_get_drvdata(dev);
> +
> +	coresight_unregister(drvdata->csdev);
> +
> +	return 0;
> +}
> +
>  #ifdef CONFIG_PM
>  static int funnel_runtime_suspend(struct device *dev)
>  {
> @@ -319,20 +328,31 @@ static int static_funnel_probe(struct platform_device *pdev)
>  	return ret;
>  }
>  
> +static int __exit static_funnel_remove(struct platform_device *pdev)
> +{
> +	funnel_remove(&pdev->dev);
> +	pm_runtime_disable(&pdev->dev);
> +	return 0;
> +}
> +
>  static const struct of_device_id static_funnel_match[] = {
>  	{.compatible = "arm,coresight-static-funnel"},
>  	{}
>  };
>  
> +MODULE_DEVICE_TABLE(of, static_funnel_match);
> +
>  #ifdef CONFIG_ACPI
>  static const struct acpi_device_id static_funnel_ids[] = {
>  	{"ARMHC9FE", 0},
>  	{},
>  };

Add extra line to be consistent with the rest of your patchset.

With the that:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> +MODULE_DEVICE_TABLE(acpi, static_funnel_ids);
>  #endif
>  
>  static struct platform_driver static_funnel_driver = {
>  	.probe          = static_funnel_probe,
> +	.probe          = static_funnel_remove,
>  	.driver         = {
>  		.name   = "coresight-static-funnel",
>  		.of_match_table = static_funnel_match,
> @@ -341,7 +361,6 @@ static struct platform_driver static_funnel_driver = {
>  		.suppress_bind_attrs = true,
>  	},
>  };
> -builtin_platform_driver(static_funnel_driver);
>  
>  static int dynamic_funnel_probe(struct amba_device *adev,
>  				const struct amba_id *id)
> @@ -349,6 +368,11 @@ static int dynamic_funnel_probe(struct amba_device *adev,
>  	return funnel_probe(&adev->dev, &adev->res);
>  }
>  
> +static int __exit dynamic_funnel_remove(struct amba_device *adev)
> +{
> +	return funnel_remove(&adev->dev);
> +}
> +
>  static const struct amba_id dynamic_funnel_ids[] = {
>  	{
>  		.id     = 0x000bb908,
> @@ -362,6 +386,8 @@ static const struct amba_id dynamic_funnel_ids[] = {
>  	{ 0, 0},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, dynamic_funnel_ids);
> +
>  static struct amba_driver dynamic_funnel_driver = {
>  	.drv = {
>  		.name	= "coresight-dynamic-funnel",
> @@ -370,6 +396,38 @@ static struct amba_driver dynamic_funnel_driver = {
>  		.suppress_bind_attrs = true,
>  	},
>  	.probe		= dynamic_funnel_probe,
> +	.remove		= dynamic_funnel_remove,
>  	.id_table	= dynamic_funnel_ids,
>  };
> -builtin_amba_driver(dynamic_funnel_driver);
> +
> +static int __init funnel_init(void)
> +{
> +	int ret;
> +
> +	ret = platform_driver_register(&static_funnel_driver);
> +	if (ret) {
> +		pr_info("Error registering platform driver\n");
> +		return ret;
> +	}
> +
> +	ret = amba_driver_register(&dynamic_funnel_driver);
> +	if (ret) {
> +		pr_info("Error registering amba driver\n");
> +		platform_driver_unregister(&static_funnel_driver);
> +	}
> +
> +	return ret;
> +}
> +
> +static void __exit funnel_exit(void)
> +{
> +	platform_driver_unregister(&static_funnel_driver);
> +	amba_driver_unregister(&dynamic_funnel_driver);
> +}
> +
> +module_init(funnel_init);
> +module_exit(funnel_exit);
> +
> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Funnel Driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 15/24] coresight: allow replicator driver to be built as module
  2020-08-07 11:11 ` [PATCH v8 15/24] coresight: allow replicator " Tingwei Zhang
@ 2020-08-13 20:35   ` Mathieu Poirier
  2020-08-14  0:08     ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-13 20:35 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:44PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-replicator as modules, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - combine static and dynamic replicator init into single
>   module_init/exit call
> - add replicator_remove functions, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Co-developed-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/Kconfig           |  5 +-
>  .../coresight/coresight-replicator.c          | 63 ++++++++++++++++++-
>  2 files changed, 65 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index fc48ae086746..f31778dd0b5d 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -17,13 +17,16 @@ menuconfig CORESIGHT
>  
>  if CORESIGHT
>  config CORESIGHT_LINKS_AND_SINKS
> -	bool "CoreSight Link and Sink drivers"
> +	tristate "CoreSight Link and Sink drivers"
>  	help
>  	  This enables support for CoreSight link and sink drivers that are
>  	  responsible for transporting and collecting the trace data
>  	  respectively.  Link and sinks are dynamically aggregated with a trace
>  	  entity at run time to form a complete trace path.

With the passage of time and the refinement of the supported components, the
CONFIG_ and description are no longer valid.  I'll leave it up to you to decide
if you want to fix it as part of this set, the choice is entirely up to you.

>  
> +	  To compile these drivers as modules, choose M here: the
> +	  modules will be called coresight-funnel and coresight-replicator.
> +
>  config CORESIGHT_LINK_AND_SINK_TMC
>  	tristate "Coresight generic TMC driver"
>  
> diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c
> index 78acf29c49ca..05db434c79d0 100644
> --- a/drivers/hwtracing/coresight/coresight-replicator.c
> +++ b/drivers/hwtracing/coresight/coresight-replicator.c
> @@ -291,6 +291,14 @@ static int replicator_probe(struct device *dev, struct resource *res)
>  	return ret;
>  }
>  
> +static int __exit replicator_remove(struct device *dev)
> +{
> +	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
> +
> +	coresight_unregister(drvdata->csdev);
> +	return 0;
> +}
> +
>  static int static_replicator_probe(struct platform_device *pdev)
>  {
>  	int ret;
> @@ -310,6 +318,13 @@ static int static_replicator_probe(struct platform_device *pdev)
>  	return ret;
>  }
>  
> +static int __exit static_replicator_remove(struct platform_device *pdev)
> +{
> +	replicator_remove(&pdev->dev);
> +	pm_runtime_disable(&pdev->dev);
> +	return 0;
> +}
> +
>  #ifdef CONFIG_PM
>  static int replicator_runtime_suspend(struct device *dev)
>  {
> @@ -342,25 +357,28 @@ static const struct of_device_id static_replicator_match[] = {
>  	{.compatible = "arm,coresight-static-replicator"},
>  	{}
>  };
> +MODULE_DEVICE_TABLE(of, static_replicator_match);

Pick a way to do this, a newline or not, but stick with it for _all_ the drivers
in this set.

>  
>  #ifdef CONFIG_ACPI
>  static const struct acpi_device_id static_replicator_acpi_ids[] = {
>  	{"ARMHC985", 0}, /* ARM CoreSight Static Replicator */
>  	{}
>  };
> +MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids);

Same as above

>  #endif
>  
>  static struct platform_driver static_replicator_driver = {
>  	.probe          = static_replicator_probe,
> +	.remove         = static_replicator_remove,
>  	.driver         = {
>  		.name   = "coresight-static-replicator",
> +		.owner	= THIS_MODULE,
>  		.of_match_table = of_match_ptr(static_replicator_match),
>  		.acpi_match_table = ACPI_PTR(static_replicator_acpi_ids),
>  		.pm	= &replicator_dev_pm_ops,
>  		.suppress_bind_attrs = true,
>  	},
>  };
> -builtin_platform_driver(static_replicator_driver);
>  
>  static int dynamic_replicator_probe(struct amba_device *adev,
>  				    const struct amba_id *id)
> @@ -368,19 +386,60 @@ static int dynamic_replicator_probe(struct amba_device *adev,
>  	return replicator_probe(&adev->dev, &adev->res);
>  }
>  
> +static int __exit dynamic_replicator_remove(struct amba_device *adev)
> +{
> +	return replicator_remove(&adev->dev);
> +}
> +
>  static const struct amba_id dynamic_replicator_ids[] = {
>  	CS_AMBA_ID(0x000bb909),
>  	CS_AMBA_ID(0x000bb9ec),		/* Coresight SoC-600 */
>  	{},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
> +
>  static struct amba_driver dynamic_replicator_driver = {
>  	.drv = {
>  		.name	= "coresight-dynamic-replicator",
>  		.pm	= &replicator_dev_pm_ops,
> +		.owner	= THIS_MODULE,
>  		.suppress_bind_attrs = true,
>  	},
>  	.probe		= dynamic_replicator_probe,
> +	.remove         = dynamic_replicator_remove,
>  	.id_table	= dynamic_replicator_ids,
>  };
> -builtin_amba_driver(dynamic_replicator_driver);
> +
> +static int __init replicator_init(void)
> +{
> +	int ret;
> +
> +	ret = platform_driver_register(&static_replicator_driver);
> +	if (ret) {
> +		pr_info("Error registering platform driver\n");
> +		return ret;
> +	}
> +
> +	ret = amba_driver_register(&dynamic_replicator_driver);
> +	if (ret) {
> +		pr_info("Error registering amba driver\n");
> +		platform_driver_unregister(&static_replicator_driver);
> +	}
> +
> +	return ret;
> +}
> +
> +static void __exit replicator_exit(void)
> +{
> +	platform_driver_unregister(&static_replicator_driver);
> +	amba_driver_unregister(&dynamic_replicator_driver);
> +}
> +

Same here, choose to add a newline or not but stay consistent for all the
drives.

> +module_init(replicator_init);
> +module_exit(replicator_exit);
> +
> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");

Pratik should also be mentioned in the funnel driver.

> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Replicator Driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 13/24] coresight: tmc: allow tmc to be built as a module
  2020-08-07 11:11 ` [PATCH v8 13/24] coresight: tmc: allow tmc " Tingwei Zhang
@ 2020-08-13 20:36   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-13 20:36 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:42PM +0800, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-tmc as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-tmc by the Makefile
> - add an tmc_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>

For patches 11, 12 and 13:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> ---
>  drivers/hwtracing/coresight/Kconfig           |  6 ++++-
>  drivers/hwtracing/coresight/Makefile          |  6 ++---
>  .../{coresight-tmc.c => coresight-tmc-core.c} | 24 ++++++++++++++++++-
>  3 files changed, 31 insertions(+), 5 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} (95%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 8fd9887fb03b..fc48ae086746 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -25,7 +25,8 @@ config CORESIGHT_LINKS_AND_SINKS
>  	  entity at run time to form a complete trace path.
>  
>  config CORESIGHT_LINK_AND_SINK_TMC
> -	bool "Coresight generic TMC driver"
> +	tristate "Coresight generic TMC driver"
> +
>  	depends on CORESIGHT_LINKS_AND_SINKS
>  	help
>  	  This enables support for the Trace Memory Controller driver.
> @@ -34,6 +35,9 @@ config CORESIGHT_LINK_AND_SINK_TMC
>  	  complies with the generic implementation of the component without
>  	  special enhancement or added features.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-tmc.
> +
>  config CORESIGHT_CATU
>  	bool "Coresight Address Translation Unit (CATU) driver"
>  	depends on CORESIGHT_LINK_AND_SINK_TMC
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index 271dc255454f..f2a568b969c4 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -4,9 +4,9 @@
>  #
>  obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
>  			   coresight-platform.o coresight-sysfs.o
> -obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o \
> -					     coresight-tmc-etf.o \
> -					     coresight-tmc-etr.o
> +obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
> +coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
> +		      coresight-tmc-etr.o
>  obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
>  obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
>  obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
> diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
> similarity index 95%
> rename from drivers/hwtracing/coresight/coresight-tmc.c
> rename to drivers/hwtracing/coresight/coresight-tmc-core.c
> index 7040d583bed9..f46852489adf 100644
> --- a/drivers/hwtracing/coresight/coresight-tmc.c
> +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
> @@ -561,6 +561,21 @@ static void tmc_shutdown(struct amba_device *adev)
>  	spin_unlock_irqrestore(&drvdata->spinlock, flags);
>  }
>  
> +static int __exit tmc_remove(struct amba_device *adev)
> +{
> +	struct tmc_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	/*
> +	 * Since misc_open() holds a refcount on the f_ops, which is
> +	 * etb fops in this case, device is there until last file
> +	 * handler to this device is closed.
> +	 */
> +	misc_deregister(&drvdata->miscdev);
> +	coresight_unregister(drvdata->csdev);
> +
> +	return 0;
> +}
> +
>  static const struct amba_id tmc_ids[] = {
>  	CS_AMBA_ID(0x000bb961),
>  	/* Coresight SoC 600 TMC-ETR/ETS */
> @@ -572,6 +587,8 @@ static const struct amba_id tmc_ids[] = {
>  	{ 0, 0},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, tmc_ids);
> +
>  static struct amba_driver tmc_driver = {
>  	.drv = {
>  		.name   = "coresight-tmc",
> @@ -580,6 +597,11 @@ static struct amba_driver tmc_driver = {
>  	},
>  	.probe		= tmc_probe,
>  	.shutdown	= tmc_shutdown,
> +	.remove		= tmc_remove,
>  	.id_table	= tmc_ids,
>  };
> -builtin_amba_driver(tmc_driver);
> +module_amba_driver(tmc_driver);
> +
> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module
  2020-08-13 17:00       ` Mathieu Poirier
@ 2020-08-13 23:44         ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-13 23:44 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Suzuki K Poulose,
	Alexander Shishkin, Greg KH, Coresight ML, Mao Jinlong,
	Mian Yousaf Kaukab, Russell King, Randy Dunlap, Tingwei Zhang,
	Leo Yan, linux-arm-kernel, Mike Leach

On Thu, Aug 13, 2020 at 11:00:04AM -0600, Mathieu Poirier wrote:
> On Thu, 13 Aug 2020 at 04:57, Tingwei Zhang <tingweiz@codeaurora.org> wrote:
> >
> > On Thu, Aug 13, 2020 at 05:47:22PM +0800, Suzuki K Poulose wrote:
> > > On 08/07/2020 12:11 PM, Tingwei Zhang wrote:
> > > >From: Kim Phillips <kim.phillips@arm.com>
> > > >
> > > >Allow to build coresight-etm3x as a module, for ease of development.
> > > >
> > > >- Kconfig becomes a tristate, to allow =m
> > > >- append -core to source file name to allow module to
> > > >   be called coresight-etm3x by the Makefile
> > > >- add an etm_remove function, for module unload
> > > >- add a MODULE_DEVICE_TABLE for autoloading on boot
> > > >
> > > >Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > > >Cc: Leo Yan <leo.yan@linaro.org>
> > > >Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > > >Cc: Randy Dunlap <rdunlap@infradead.org>
> > > >Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > > >Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > >Cc: Russell King <linux@armlinux.org.uk>
> > > >Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > > >Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > > >Reviewed-by: Mike Leach <mike.leach@linaro.org>
> > > >---
> > > >  drivers/hwtracing/coresight/Kconfig           |  5 +++-
> > > >  drivers/hwtracing/coresight/Makefile          |  3 ++-
> > > >  ...resight-etm3x.c => coresight-etm3x-core.c} | 27 ++++++++++++++++++-
> > > >  3 files changed, 32 insertions(+), 3 deletions(-)
> > > >  rename drivers/hwtracing/coresight/{coresight-etm3x.c =>
> > > >coresight-etm3x-core.c} (97%)
> > > >
> > > >diff --git a/drivers/hwtracing/coresight/Kconfig
> > > >b/drivers/hwtracing/coresight/Kconfig
> > > >index 6433f835fc97..8fd9fd139cf3 100644
> > > >--- a/drivers/hwtracing/coresight/Kconfig
> > > >+++ b/drivers/hwtracing/coresight/Kconfig
> > > >@@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
> > > >       special enhancement or added features.
> > > >
> > > >  config CORESIGHT_SOURCE_ETM3X
> > > >-    bool "CoreSight Embedded Trace Macrocell 3.x driver"
> > > >+    tristate "CoreSight Embedded Trace Macrocell 3.x driver"
> > > >     depends on !ARM64
> > > >     select CORESIGHT_LINKS_AND_SINKS
> > > >     help
> > > >@@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
> > > >       This is primarily useful for instruction level tracing.  Depending
> > > >       the ETM version data tracing may also be available.
> > > >
> > > >+      To compile this driver as a module, choose M here: the
> > > >+      module will be called coresight-etm3x.
> > > >+
> > > >  config CORESIGHT_SOURCE_ETM4X
> > > >     bool "CoreSight Embedded Trace Macrocell 4.x driver"
> > > >     depends on ARM64
> > > >diff --git a/drivers/hwtracing/coresight/Makefile
> > > >b/drivers/hwtracing/coresight/Makefile
> > > >index 19497d1d92bf..d619cfd0abd8 100644
> > > >--- a/drivers/hwtracing/coresight/Makefile
> > > >+++ b/drivers/hwtracing/coresight/Makefile
> > > >@@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
> > > >  obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
> > > >  obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
> > > >                                        coresight-replicator.o
> > > >-obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > > >coresight-etm-cp14.o \
> > > >+obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > > >+coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> > > >                                     coresight-etm3x-sysfs.o
> > > >  obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> > > >                                     coresight-etm4x-sysfs.o
> > > >diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c
> > > >b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> > > >similarity index 97%
> > > >rename from drivers/hwtracing/coresight/coresight-etm3x.c
> > > >rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
> > > >index bf22dcfd3327..82b333c40006 100644
> > > >--- a/drivers/hwtracing/coresight/coresight-etm3x.c
> > > >+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
> > > >@@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const
> > > >struct amba_id *id)
> > > >     return ret;
> > > >  }
> > > >
> > > >+static int __exit etm_remove(struct amba_device *adev)
> > > >+{
> > > >+    struct etm_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > > >+
> > > >+    etm_perf_symlink(drvdata->csdev, false);
> > > >+
> > > >+    if (--etm_count == 0) {
> > > >+            cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> > > >+            if (hp_online)
> > > >+                    cpuhp_remove_state_nocalls(hp_online);
> > > >+    }
> > > >+
> > >
> > > As mentioned in the previous version, this needs fixing
> > > similar to the etm4x to avoid races with etm_count. I understand
> > > that it is an exisiting problem. But this set exposes it more
> > > due to etm_remove() calls and is much more probable to hit it.
> > >
> > OK. I'll fix this. Can you help to review ETM4 fix? If that's fine,
> > I'll make similar fix here.
> >
> > Unfortunately, I don't have any device with ETM3. Can anyone help
> > to verify the function on ETM3? I'll really appreciate that.
> 
> I'll take care of ETMv3.  Please wait before sending a new revision
> since I am still reviewing the current set.  I will let you know when
> I am done.
> 

Thanks a lot, Mathieu. I'll wait for your comments.

> >
> > Thanks,
> > Tingwei
> > >
> > > Suzuki
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-13 19:39   ` Mathieu Poirier
@ 2020-08-13 23:46     ` Suzuki K Poulose
  2020-08-14  9:52       ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Suzuki K Poulose @ 2020-08-13 23:46 UTC (permalink / raw)
  To: mathieu.poirier, tingwei
  Cc: tsoni, saiprakash.ranjan, kim.phillips, jinlmao,
	alexander.shishkin, gregkh, coresight, rdunlap, ykaukab, linux,
	leo.yan, linux-arm-kernel, mike.leach

On 08/13/2020 08:39 PM, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
>> From: Kim Phillips <kim.phillips@arm.com>
>>
>> Allow to build coresight-etm4x as a module, for ease of development.
>>
>> - Kconfig becomes a tristate, to allow =m
>> - append -core to source file name to allow module to
>>    be called coresight-etm4x by the Makefile
>> - add an etm4_remove function, for module unload
>> - add a MODULE_DEVICE_TABLE for autoloading on boot
>> - protect etmdrvdata[] with mutex lock from racing
>>    between module unload and CPU hotplug
>>
>> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
>> Cc: Leo Yan <leo.yan@linaro.org>
>> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>> Cc: Randy Dunlap <rdunlap@infradead.org>
>> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: Russell King <linux@armlinux.org.uk>
>> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
>> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
>> Tested-by: Mike Leach <mike.leach@linaro.org>
>> ---
>>   drivers/hwtracing/coresight/Kconfig           |   5 +-
>>   drivers/hwtracing/coresight/Makefile          |   4 +-
>>   ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++++++-----
>>   3 files changed, 92 insertions(+), 35 deletions(-)
>>   rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (95%)
>>
>> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
>> index 8fd9fd139cf3..d6e107bbd30b 100644
>> --- a/drivers/hwtracing/coresight/Kconfig
>> +++ b/drivers/hwtracing/coresight/Kconfig
>> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
>>   	  module will be called coresight-etm3x.
>>   
>>   config CORESIGHT_SOURCE_ETM4X
>> -	bool "CoreSight Embedded Trace Macrocell 4.x driver"
>> +	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
>>   	depends on ARM64
>>   	select CORESIGHT_LINKS_AND_SINKS
>>   	select PID_IN_CONTEXTIDR
>> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
>>   	  for instruction level tracing. Depending on the implemented version
>>   	  data tracing may also be available.
>>   
>> +	  To compile this driver as a module, choose M here: the
>> +	  module will be called coresight-etm4x.
>> +
>>   config CORESIGHT_STM
>>   	tristate "CoreSight System Trace Macrocell driver"
>>   	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
>> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
>> index d619cfd0abd8..271dc255454f 100644
>> --- a/drivers/hwtracing/coresight/Makefile
>> +++ b/drivers/hwtracing/coresight/Makefile
>> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
>>   obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
>>   coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>>   					coresight-etm3x-sysfs.o
>> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
>> -					coresight-etm4x-sysfs.o
>> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
>> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
>>   obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>>   obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>>   obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
>> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> similarity index 95%
>> rename from drivers/hwtracing/coresight/coresight-etm4x.c
>> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
>> index fddfd93b9a7b..ae9847e194a3 100644
>> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
>> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> @@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
>>   MODULE_PARM_DESC(pm_save_enable,
>>   	"Save/restore state on power down: 1 = never, 2 = self-hosted");
>>   
>> +static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
>>   static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
>>   static void etm4_set_default_config(struct etmv4_config *config);
>>   static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
>> @@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config *config)
>>   
>>   static int etm4_online_cpu(unsigned int cpu)
>>   {
>> -	if (!etmdrvdata[cpu])
>> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
>> +	if (!etmdrvdata[cpu]) {
>> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>>   		return 0;
>> +	}
>>   
>>   	if (etmdrvdata[cpu]->boot_enable && !etmdrvdata[cpu]->sticky_enable)
>>   		coresight_enable(etmdrvdata[cpu]->csdev);
>> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>>   	return 0;
>>   }
>>   
>>   static int etm4_starting_cpu(unsigned int cpu)
>>   {
>> -	if (!etmdrvdata[cpu])
>> +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
>> +	if (!etmdrvdata[cpu]) {
>> +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>>   		return 0;
>> +	}
>>   
>>   	spin_lock(&etmdrvdata[cpu]->spinlock);
>>   	if (!etmdrvdata[cpu]->os_unlock)
>> @@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
>>   	if (local_read(&etmdrvdata[cpu]->mode))
>>   		etm4_enable_hw(etmdrvdata[cpu]);
>>   	spin_unlock(&etmdrvdata[cpu]->spinlock);
>> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> 
> Ouch!
> 
> A mutex wrapping a spinlock to protect the exact same drvdata structure.

Actually this mutex is for "protecting" etmdrvdata[cpu], not the
drvdata struct as such. But as you said, it becomes like a double lock.

Having mutex is an overkill for sure and can't be used replace
spin_lock, especially if needed from atomic context. Having looked
at the code, we only ever access/modify the etmdrvdata[cpu] on a
different CPU is when we probe and there are chances of races.
One of such is described here

http://lists.infradead.org/pipermail/linux-arm-kernel/2020-July/589941.html

I will see if I can spin a couple of patches to address these.
Once we make sure that the etmdrvdata[cpu] is only modified by "cpu"
then we don't need this mutex and stick with what we have.

Suzuki


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-13 19:45   ` Mathieu Poirier
@ 2020-08-13 23:57     ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-13 23:57 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 14, 2020 at 03:45:06AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> > From: Kim Phillips <kim.phillips@arm.com>
> > 
> > Allow to build coresight-etm4x as a module, for ease of development.
> > 
> > - Kconfig becomes a tristate, to allow =m
> > - append -core to source file name to allow module to
> >   be called coresight-etm4x by the Makefile
> > - add an etm4_remove function, for module unload
> > - add a MODULE_DEVICE_TABLE for autoloading on boot
> > - protect etmdrvdata[] with mutex lock from racing
> >   between module unload and CPU hotplug
> > 
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Leo Yan <leo.yan@linaro.org>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Randy Dunlap <rdunlap@infradead.org>
> > Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Russell King <linux@armlinux.org.uk>
> > Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Tested-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  drivers/hwtracing/coresight/Kconfig           |   5 +-
> >  drivers/hwtracing/coresight/Makefile          |   4 +-
> >  ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++++++-----
> >  3 files changed, 92 insertions(+), 35 deletions(-)
> >  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> coresight-etm4x-core.c} (95%)
> > 
> > diff --git a/drivers/hwtracing/coresight/Kconfig
> b/drivers/hwtracing/coresight/Kconfig
> > index 8fd9fd139cf3..d6e107bbd30b 100644
> > --- a/drivers/hwtracing/coresight/Kconfig
> > +++ b/drivers/hwtracing/coresight/Kconfig
> > @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
> >  	  module will be called coresight-etm3x.
> >  
> >  config CORESIGHT_SOURCE_ETM4X
> > -	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> > +	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
> >  	depends on ARM64
> >  	select CORESIGHT_LINKS_AND_SINKS
> >  	select PID_IN_CONTEXTIDR
> > @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
> >  	  for instruction level tracing. Depending on the implemented
> version
> >  	  data tracing may also be available.
> >  
> > +	  To compile this driver as a module, choose M here: the
> > +	  module will be called coresight-etm4x.
> > +
> >  config CORESIGHT_STM
> >  	tristate "CoreSight System Trace Macrocell driver"
> >  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> > diff --git a/drivers/hwtracing/coresight/Makefile
> b/drivers/hwtracing/coresight/Makefile
> > index d619cfd0abd8..271dc255454f 100644
> > --- a/drivers/hwtracing/coresight/Makefile
> > +++ b/drivers/hwtracing/coresight/Makefile
> > @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> coresight-funnel.o \
> >  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> >  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> >  					coresight-etm3x-sysfs.o
> > -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> > -					coresight-etm4x-sysfs.o
> > +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> > +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> >  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> >  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> >  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> > diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > similarity index 95%
> > rename from drivers/hwtracing/coresight/coresight-etm4x.c
> > rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> > index fddfd93b9a7b..ae9847e194a3 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > @@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
> >  MODULE_PARM_DESC(pm_save_enable,
> >  	"Save/restore state on power down: 1 = never, 2 = self-hosted");
> >  
> > +static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
> >  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
> >  static void etm4_set_default_config(struct etmv4_config *config);
> >  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> > @@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config
> *config)
> >  
> >  static int etm4_online_cpu(unsigned int cpu)
> >  {
> > -	if (!etmdrvdata[cpu])
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > +	if (!etmdrvdata[cpu]) {
> > +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  		return 0;
> > +	}
> >  
> >  	if (etmdrvdata[cpu]->boot_enable &&
> !etmdrvdata[cpu]->sticky_enable)
> >  		coresight_enable(etmdrvdata[cpu]->csdev);
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  	return 0;
> >  }
> >  
> >  static int etm4_starting_cpu(unsigned int cpu)
> >  {
> > -	if (!etmdrvdata[cpu])
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > +	if (!etmdrvdata[cpu]) {
> > +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  		return 0;
> > +	}
> >  
> >  	spin_lock(&etmdrvdata[cpu]->spinlock);
> >  	if (!etmdrvdata[cpu]->os_unlock)
> > @@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
> >  	if (local_read(&etmdrvdata[cpu]->mode))
> >  		etm4_enable_hw(etmdrvdata[cpu]);
> >  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  	return 0;
> >  }
> >  
> >  static int etm4_dying_cpu(unsigned int cpu)
> >  {
> > -	if (!etmdrvdata[cpu])
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > +	if (!etmdrvdata[cpu]) {
> > +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  		return 0;
> > +	}
> >  
> >  	spin_lock(&etmdrvdata[cpu]->spinlock);
> >  	if (local_read(&etmdrvdata[cpu]->mode))
> >  		etm4_disable_hw(etmdrvdata[cpu]);
> >  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  	return 0;
> >  }
> >  
> > @@ -1360,24 +1373,30 @@ static int etm4_cpu_pm_notify(struct
> notifier_block *nb, unsigned long cmd,
> >  {
> >  	struct etmv4_drvdata *drvdata;
> >  	unsigned int cpu = smp_processor_id();
> > +	int ret = NOTIFY_OK;
> >  
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> >  	if (!etmdrvdata[cpu])
> > -		return NOTIFY_OK;
> > +		goto out;
> >  
> >  	drvdata = etmdrvdata[cpu];
> >  
> >  	if (!drvdata->save_state)
> > -		return NOTIFY_OK;
> > +		goto out;
> >  
> > -	if (WARN_ON_ONCE(drvdata->cpu != cpu))
> > -		return NOTIFY_BAD;
> > +	if (WARN_ON_ONCE(drvdata->cpu != cpu)) {
> > +		ret = NOTIFY_BAD;
> > +		goto out;
> > +	}
> >  
> >  	switch (cmd) {
> >  	case CPU_PM_ENTER:
> >  		/* save the state if self-hosted coresight is in use */
> >  		if (local_read(&drvdata->mode))
> > -			if (etm4_cpu_save(drvdata))
> > -				return NOTIFY_BAD;
> > +			if (etm4_cpu_save(drvdata)) {
> > +				ret = NOTIFY_BAD;
> > +				goto out;
> > +			}
> >  		break;
> >  	case CPU_PM_EXIT:
> >  		/* fallthrough */
> > @@ -1386,10 +1405,12 @@ static int etm4_cpu_pm_notify(struct
> notifier_block *nb, unsigned long cmd,
> >  			etm4_cpu_restore(drvdata);
> >  		break;
> >  	default:
> > -		return NOTIFY_DONE;
> > +		goto out;
> >  	}
> >  
> > -	return NOTIFY_OK;
> > +out:
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > +	return ret;
> >  }
> >  
> >  static struct notifier_block etm4_cpu_pm_nb = {
> > @@ -1430,7 +1451,7 @@ static int __init etm4_pm_setup(void)
> >  	return ret;
> >  }
> >  
> > -static void __init etm4_pm_clear(void)
> > +static void etm4_pm_clear(void)
> >  {
> >  	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
> >  	cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> > @@ -1487,25 +1508,20 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
> >  	if (!desc.name)
> >  		return -ENOMEM;
> >  
> > -	etmdrvdata[drvdata->cpu] = drvdata;
> > -
> >  	if (smp_call_function_single(drvdata->cpu,
> >  				etm4_init_arch_data,  drvdata, 1))
> >  		dev_err(dev, "ETM arch init failed\n");
> >  
> > -	if (etm4_arch_supported(drvdata->arch) == false) {
> > -		ret = -EINVAL;
> > -		goto err_arch_supported;
> > -	}
> > +	if (etm4_arch_supported(drvdata->arch) == false)
> > +		return -EINVAL;
> >  
> >  	etm4_init_trace_id(drvdata);
> >  	etm4_set_default(&drvdata->config);
> >  
> >  	pdata = coresight_get_platform_data(dev);
> > -	if (IS_ERR(pdata)) {
> > -		ret = PTR_ERR(pdata);
> > -		goto err_arch_supported;
> > -	}
> > +	if (IS_ERR(pdata))
> > +		return PTR_ERR(pdata);
> > +
> >  	adev->dev.platform_data = pdata;
> >  
> >  	desc.type = CORESIGHT_DEV_TYPE_SOURCE;
> > @@ -1515,17 +1531,19 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
> >  	desc.dev = dev;
> >  	desc.groups = coresight_etmv4_groups;
> >  	drvdata->csdev = coresight_register(&desc);
> > -	if (IS_ERR(drvdata->csdev)) {
> > -		ret = PTR_ERR(drvdata->csdev);
> > -		goto err_arch_supported;
> > -	}
> > +	if (IS_ERR(drvdata->csdev))
> > +		return PTR_ERR(drvdata->csdev);
> >  
> >  	ret = etm_perf_symlink(drvdata->csdev, true);
> >  	if (ret) {
> >  		coresight_unregister(drvdata->csdev);
> > -		goto err_arch_supported;
> > +		return ret;
> >  	}
> >  
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +	etmdrvdata[drvdata->cpu] = drvdata;
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +
> >  	pm_runtime_put(&adev->dev);
> >  	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
> >  		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
> > @@ -1536,10 +1554,6 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
> >  	}
> >  
> >  	return 0;
> > -
> > -err_arch_supported:
> > -	etmdrvdata[drvdata->cpu] = NULL;
> > -	return ret;
> >  }
> >  
> >  static struct amba_cs_uci_id uci_id_etm4[] = {
> > @@ -1551,6 +1565,22 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
> >  	}
> >  };
> >  
> > +static int __exit etm4_remove(struct amba_device *adev)
> > +{
> > +	struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > +
> > +	etm_perf_symlink(drvdata->csdev, false);
> > +
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +	etmdrvdata[drvdata->cpu] = NULL;
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +
> > +	coresight_unregister(drvdata->csdev);
> > +
> > +	return 0;
> > +}
> > +
> > +
> 
> Extra line
> 

Will fix in next revision.

> >  static const struct amba_id etm4_ids[] = {
> >  	CS_AMBA_ID(0x000bb95d),			/* Cortex-A53 */
> >  	CS_AMBA_ID(0x000bb95e),			/* Cortex-A57 */
> > @@ -1568,18 +1598,26 @@ static const struct amba_id etm4_ids[] = {
> >  	{},
> >  };
> >  
> > +MODULE_DEVICE_TABLE(amba, etm4_ids);
> > +
> >  static struct amba_driver etm4x_driver = {
> >  	.drv = {
> >  		.name   = "coresight-etm4x",
> > +		.owner  = THIS_MODULE,
> >  		.suppress_bind_attrs = true,
> >  	},
> >  	.probe		= etm4_probe,
> > +	.remove         = etm4_remove,
> >  	.id_table	= etm4_ids,
> >  };
> >  
> >  static int __init etm4x_init(void)
> >  {
> >  	int ret;
> > +	int cpu;
> > +
> > +	for_each_possible_cpu(cpu)
> > +		mutex_init(&per_cpu(etmdrvdata_lock, cpu));
> >  
> >  	ret = etm4_pm_setup();
> >  
> > @@ -1595,4 +1633,20 @@ static int __init etm4x_init(void)
> >  
> >  	return ret;
> >  }
> > -device_initcall(etm4x_init);
> > +
> > +static void __exit etm4x_exit(void)
> > +{
> > +	int cpu;
> > +
> > +	amba_driver_unregister(&etm4x_driver);
> > +	etm4_pm_clear();
> > +	for_each_possible_cpu(cpu)
> > +		mutex_destroy(&per_cpu(etmdrvdata_lock, cpu));
> > +}
> > +module_init(etm4x_init);
> > +module_exit(etm4x_exit);
> > +
> > +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> > +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> > +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
> > +MODULE_LICENSE("GPL v2");
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-13 19:40   ` Mathieu Poirier
@ 2020-08-13 23:58     ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-13 23:58 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Suzuki K Poulose,
	Alexander Shishkin, Greg Kroah-Hartman, coresight, Mao Jinlong,
	Mian Yousaf Kaukab, Russell King, Randy Dunlap, Tingwei Zhang,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 14, 2020 at 03:40:57AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> > From: Kim Phillips <kim.phillips@arm.com>
> > 
> > Allow to build coresight-etm4x as a module, for ease of development.
> > 
> > - Kconfig becomes a tristate, to allow =m
> > - append -core to source file name to allow module to
> >   be called coresight-etm4x by the Makefile
> > - add an etm4_remove function, for module unload
> > - add a MODULE_DEVICE_TABLE for autoloading on boot
> > - protect etmdrvdata[] with mutex lock from racing
> >   between module unload and CPU hotplug
> > 
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Leo Yan <leo.yan@linaro.org>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Randy Dunlap <rdunlap@infradead.org>
> > Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Russell King <linux@armlinux.org.uk>
> > Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Tested-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  drivers/hwtracing/coresight/Kconfig           |   5 +-
> >  drivers/hwtracing/coresight/Makefile          |   4 +-
> >  ...resight-etm4x.c => coresight-etm4x-core.c} | 118 +++++++++++++-----
> >  3 files changed, 92 insertions(+), 35 deletions(-)
> >  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> coresight-etm4x-core.c} (95%)
> > 
> > diff --git a/drivers/hwtracing/coresight/Kconfig
> b/drivers/hwtracing/coresight/Kconfig
> > index 8fd9fd139cf3..d6e107bbd30b 100644
> > --- a/drivers/hwtracing/coresight/Kconfig
> > +++ b/drivers/hwtracing/coresight/Kconfig
> > @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
> >  	  module will be called coresight-etm3x.
> >  
> >  config CORESIGHT_SOURCE_ETM4X
> > -	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> > +	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
> >  	depends on ARM64
> >  	select CORESIGHT_LINKS_AND_SINKS
> >  	select PID_IN_CONTEXTIDR
> > @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
> >  	  for instruction level tracing. Depending on the implemented
> version
> >  	  data tracing may also be available.
> >  
> > +	  To compile this driver as a module, choose M here: the
> > +	  module will be called coresight-etm4x.
> > +
> >  config CORESIGHT_STM
> >  	tristate "CoreSight System Trace Macrocell driver"
> >  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> > diff --git a/drivers/hwtracing/coresight/Makefile
> b/drivers/hwtracing/coresight/Makefile
> > index d619cfd0abd8..271dc255454f 100644
> > --- a/drivers/hwtracing/coresight/Makefile
> > +++ b/drivers/hwtracing/coresight/Makefile
> > @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> coresight-funnel.o \
> >  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> >  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> >  					coresight-etm3x-sysfs.o
> > -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> > -					coresight-etm4x-sysfs.o
> > +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> > +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> >  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> >  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> >  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> > diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > similarity index 95%
> > rename from drivers/hwtracing/coresight/coresight-etm4x.c
> > rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> > index fddfd93b9a7b..ae9847e194a3 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > @@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
> >  MODULE_PARM_DESC(pm_save_enable,
> >  	"Save/restore state on power down: 1 = never, 2 = self-hosted");
> >  
> > +static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
> >  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
> >  static void etm4_set_default_config(struct etmv4_config *config);
> >  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> > @@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config
> *config)
> >  
> >  static int etm4_online_cpu(unsigned int cpu)
> >  {
> > -	if (!etmdrvdata[cpu])
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > +	if (!etmdrvdata[cpu]) {
> > +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  		return 0;
> > +	}
> >  
> >  	if (etmdrvdata[cpu]->boot_enable &&
> !etmdrvdata[cpu]->sticky_enable)
> >  		coresight_enable(etmdrvdata[cpu]->csdev);
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  	return 0;
> >  }
> >  
> >  static int etm4_starting_cpu(unsigned int cpu)
> >  {
> > -	if (!etmdrvdata[cpu])
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > +	if (!etmdrvdata[cpu]) {
> > +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  		return 0;
> > +	}
> >  
> >  	spin_lock(&etmdrvdata[cpu]->spinlock);
> >  	if (!etmdrvdata[cpu]->os_unlock)
> > @@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
> >  	if (local_read(&etmdrvdata[cpu]->mode))
> >  		etm4_enable_hw(etmdrvdata[cpu]);
> >  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  	return 0;
> >  }
> >  
> >  static int etm4_dying_cpu(unsigned int cpu)
> >  {
> > -	if (!etmdrvdata[cpu])
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > +	if (!etmdrvdata[cpu]) {
> > +		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  		return 0;
> > +	}
> >  
> >  	spin_lock(&etmdrvdata[cpu]->spinlock);
> >  	if (local_read(&etmdrvdata[cpu]->mode))
> >  		etm4_disable_hw(etmdrvdata[cpu]);
> >  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >  	return 0;
> >  }
> >  
> > @@ -1360,24 +1373,30 @@ static int etm4_cpu_pm_notify(struct
> notifier_block *nb, unsigned long cmd,
> >  {
> >  	struct etmv4_drvdata *drvdata;
> >  	unsigned int cpu = smp_processor_id();
> > +	int ret = NOTIFY_OK;
> >  
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> >  	if (!etmdrvdata[cpu])
> > -		return NOTIFY_OK;
> > +		goto out;
> >  
> >  	drvdata = etmdrvdata[cpu];
> >  
> >  	if (!drvdata->save_state)
> > -		return NOTIFY_OK;
> > +		goto out;
> >  
> > -	if (WARN_ON_ONCE(drvdata->cpu != cpu))
> > -		return NOTIFY_BAD;
> > +	if (WARN_ON_ONCE(drvdata->cpu != cpu)) {
> > +		ret = NOTIFY_BAD;
> > +		goto out;
> > +	}
> >  
> >  	switch (cmd) {
> >  	case CPU_PM_ENTER:
> >  		/* save the state if self-hosted coresight is in use */
> >  		if (local_read(&drvdata->mode))
> > -			if (etm4_cpu_save(drvdata))
> > -				return NOTIFY_BAD;
> > +			if (etm4_cpu_save(drvdata)) {
> > +				ret = NOTIFY_BAD;
> > +				goto out;
> > +			}
> >  		break;
> >  	case CPU_PM_EXIT:
> >  		/* fallthrough */
> > @@ -1386,10 +1405,12 @@ static int etm4_cpu_pm_notify(struct
> notifier_block *nb, unsigned long cmd,
> >  			etm4_cpu_restore(drvdata);
> >  		break;
> >  	default:
> > -		return NOTIFY_DONE;
> > +		goto out;
> >  	}
> >  
> > -	return NOTIFY_OK;
> > +out:
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > +	return ret;
> >  }
> >  
> >  static struct notifier_block etm4_cpu_pm_nb = {
> > @@ -1430,7 +1451,7 @@ static int __init etm4_pm_setup(void)
> >  	return ret;
> >  }
> >  
> > -static void __init etm4_pm_clear(void)
> > +static void etm4_pm_clear(void)
> >  {
> >  	cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
> >  	cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> > @@ -1487,25 +1508,20 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
> >  	if (!desc.name)
> >  		return -ENOMEM;
> >  
> > -	etmdrvdata[drvdata->cpu] = drvdata;
> > -
> >  	if (smp_call_function_single(drvdata->cpu,
> >  				etm4_init_arch_data,  drvdata, 1))
> >  		dev_err(dev, "ETM arch init failed\n");
> >  
> > -	if (etm4_arch_supported(drvdata->arch) == false) {
> > -		ret = -EINVAL;
> > -		goto err_arch_supported;
> > -	}
> > +	if (etm4_arch_supported(drvdata->arch) == false)
> > +		return -EINVAL;
> >  
> >  	etm4_init_trace_id(drvdata);
> >  	etm4_set_default(&drvdata->config);
> >  
> >  	pdata = coresight_get_platform_data(dev);
> > -	if (IS_ERR(pdata)) {
> > -		ret = PTR_ERR(pdata);
> > -		goto err_arch_supported;
> > -	}
> > +	if (IS_ERR(pdata))
> > +		return PTR_ERR(pdata);
> > +
> >  	adev->dev.platform_data = pdata;
> >  
> >  	desc.type = CORESIGHT_DEV_TYPE_SOURCE;
> > @@ -1515,17 +1531,19 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
> >  	desc.dev = dev;
> >  	desc.groups = coresight_etmv4_groups;
> >  	drvdata->csdev = coresight_register(&desc);
> > -	if (IS_ERR(drvdata->csdev)) {
> > -		ret = PTR_ERR(drvdata->csdev);
> > -		goto err_arch_supported;
> > -	}
> > +	if (IS_ERR(drvdata->csdev))
> > +		return PTR_ERR(drvdata->csdev);
> >  
> >  	ret = etm_perf_symlink(drvdata->csdev, true);
> >  	if (ret) {
> >  		coresight_unregister(drvdata->csdev);
> > -		goto err_arch_supported;
> > +		return ret;
> >  	}
> >  
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +	etmdrvdata[drvdata->cpu] = drvdata;
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +
> >  	pm_runtime_put(&adev->dev);
> >  	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
> >  		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
> > @@ -1536,10 +1554,6 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
> >  	}
> >  
> >  	return 0;
> > -
> > -err_arch_supported:
> > -	etmdrvdata[drvdata->cpu] = NULL;
> > -	return ret;
> >  }
> >  
> >  static struct amba_cs_uci_id uci_id_etm4[] = {
> > @@ -1551,6 +1565,22 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
> >  	}
> >  };
> >  
> > +static int __exit etm4_remove(struct amba_device *adev)
> > +{
> > +	struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > +
> > +	etm_perf_symlink(drvdata->csdev, false);
> > +
> > +	mutex_lock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +	etmdrvdata[drvdata->cpu] = NULL;
> > +	mutex_unlock(&per_cpu(etmdrvdata_lock, drvdata->cpu));
> > +
> > +	coresight_unregister(drvdata->csdev);
> > +
> > +	return 0;
> > +}
> > +
> > +
> >  static const struct amba_id etm4_ids[] = {
> >  	CS_AMBA_ID(0x000bb95d),			/* Cortex-A53 */
> >  	CS_AMBA_ID(0x000bb95e),			/* Cortex-A57 */
> > @@ -1568,18 +1598,26 @@ static const struct amba_id etm4_ids[] = {
> >  	{},
> >  };
> >  
> > +MODULE_DEVICE_TABLE(amba, etm4_ids);
> > +
> >  static struct amba_driver etm4x_driver = {
> >  	.drv = {
> >  		.name   = "coresight-etm4x",
> > +		.owner  = THIS_MODULE,
> >  		.suppress_bind_attrs = true,
> >  	},
> >  	.probe		= etm4_probe,
> > +	.remove         = etm4_remove,
> >  	.id_table	= etm4_ids,
> >  };
> >  
> >  static int __init etm4x_init(void)
> >  {
> >  	int ret;
> > +	int cpu;
> > +
> > +	for_each_possible_cpu(cpu)
> > +		mutex_init(&per_cpu(etmdrvdata_lock, cpu));
> >  
> >  	ret = etm4_pm_setup();
> >  
> > @@ -1595,4 +1633,20 @@ static int __init etm4x_init(void)
> >  
> >  	return ret;
> >  }
> > -device_initcall(etm4x_init);
> > +
> > +static void __exit etm4x_exit(void)
> > +{
> > +	int cpu;
> > +
> > +	amba_driver_unregister(&etm4x_driver);
> > +	etm4_pm_clear();
> > +	for_each_possible_cpu(cpu)
> > +		mutex_destroy(&per_cpu(etmdrvdata_lock, cpu));
> > +}
> > +module_init(etm4x_init);
> > +module_exit(etm4x_exit);
> > +
> > +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> > +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> > +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
> 
> ... And this should be "Arm CoreSight Embedded Trace Macrocell 4.x
> driver".
> 
This will be fixed in v9.

> > +MODULE_LICENSE("GPL v2");
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 15/24] coresight: allow replicator driver to be built as module
  2020-08-13 20:35   ` Mathieu Poirier
@ 2020-08-14  0:08     ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-14  0:08 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 14, 2020 at 04:35:11AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:44PM +0800, Tingwei Zhang wrote:
> > From: Kim Phillips <kim.phillips@arm.com>
> > 
> > Allow to build coresight-replicator as modules, for ease of development.
> > 
> > - Kconfig becomes a tristate, to allow =m
> > - combine static and dynamic replicator init into single
> >   module_init/exit call
> > - add replicator_remove functions, for module unload
> > - add a MODULE_DEVICE_TABLE for autoloading on boot
> > 
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Leo Yan <leo.yan@linaro.org>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Randy Dunlap <rdunlap@infradead.org>
> > Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Russell King <linux@armlinux.org.uk>
> > Co-developed-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> > Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> > Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Tested-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  drivers/hwtracing/coresight/Kconfig           |  5 +-
> >  .../coresight/coresight-replicator.c          | 63 ++++++++++++++++++-
> >  2 files changed, 65 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/Kconfig
> b/drivers/hwtracing/coresight/Kconfig
> > index fc48ae086746..f31778dd0b5d 100644
> > --- a/drivers/hwtracing/coresight/Kconfig
> > +++ b/drivers/hwtracing/coresight/Kconfig
> > @@ -17,13 +17,16 @@ menuconfig CORESIGHT
> >  
> >  if CORESIGHT
> >  config CORESIGHT_LINKS_AND_SINKS
> > -	bool "CoreSight Link and Sink drivers"
> > +	tristate "CoreSight Link and Sink drivers"
> >  	help
> >  	  This enables support for CoreSight link and sink drivers that
> are
> >  	  responsible for transporting and collecting the trace data
> >  	  respectively.  Link and sinks are dynamically aggregated with a
> trace
> >  	  entity at run time to form a complete trace path.
> 
> With the passage of time and the refinement of the supported components,
> the
> CONFIG_ and description are no longer valid.  I'll leave it up to you to
> decide
> if you want to fix it as part of this set, the choice is entirely up to
> you.
> 

I'll leave that to another patch and focus this patch set to make driver
as module.

> >  
> > +	  To compile these drivers as modules, choose M here: the
> > +	  modules will be called coresight-funnel and
> coresight-replicator.
> > +
> >  config CORESIGHT_LINK_AND_SINK_TMC
> >  	tristate "Coresight generic TMC driver"
> >  
> > diff --git a/drivers/hwtracing/coresight/coresight-replicator.c
> b/drivers/hwtracing/coresight/coresight-replicator.c
> > index 78acf29c49ca..05db434c79d0 100644
> > --- a/drivers/hwtracing/coresight/coresight-replicator.c
> > +++ b/drivers/hwtracing/coresight/coresight-replicator.c
> > @@ -291,6 +291,14 @@ static int replicator_probe(struct device *dev,
> struct resource *res)
> >  	return ret;
> >  }
> >  
> > +static int __exit replicator_remove(struct device *dev)
> > +{
> > +	struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
> > +
> > +	coresight_unregister(drvdata->csdev);
> > +	return 0;
> > +}
> > +
> >  static int static_replicator_probe(struct platform_device *pdev)
> >  {
> >  	int ret;
> > @@ -310,6 +318,13 @@ static int static_replicator_probe(struct
> platform_device *pdev)
> >  	return ret;
> >  }
> >  
> > +static int __exit static_replicator_remove(struct platform_device
> *pdev)
> > +{
> > +	replicator_remove(&pdev->dev);
> > +	pm_runtime_disable(&pdev->dev);
> > +	return 0;
> > +}
> > +
> >  #ifdef CONFIG_PM
> >  static int replicator_runtime_suspend(struct device *dev)
> >  {
> > @@ -342,25 +357,28 @@ static const struct of_device_id
> static_replicator_match[] = {
> >  	{.compatible = "arm,coresight-static-replicator"},
> >  	{}
> >  };
> > +MODULE_DEVICE_TABLE(of, static_replicator_match);
> 
> Pick a way to do this, a newline or not, but stick with it for _all_ the
> drivers
> in this set.
>
 
I will add a new line and check all the coresight drivers.

> >  
> >  #ifdef CONFIG_ACPI
> >  static const struct acpi_device_id static_replicator_acpi_ids[] = {
> >  	{"ARMHC985", 0}, /* ARM CoreSight Static Replicator */
> >  	{}
> >  };
> > +MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids);
> 
> Same as above
> 

I will add a new line.

> >  #endif
> >  
> >  static struct platform_driver static_replicator_driver = {
> >  	.probe          = static_replicator_probe,
> > +	.remove         = static_replicator_remove,
> >  	.driver         = {
> >  		.name   = "coresight-static-replicator",
> > +		.owner	= THIS_MODULE,
> >  		.of_match_table = of_match_ptr(static_replicator_match),
> >  		.acpi_match_table = ACPI_PTR(static_replicator_acpi_ids),
> >  		.pm	= &replicator_dev_pm_ops,
> >  		.suppress_bind_attrs = true,
> >  	},
> >  };
> > -builtin_platform_driver(static_replicator_driver);
> >  
> >  static int dynamic_replicator_probe(struct amba_device *adev,
> >  				    const struct amba_id *id)
> > @@ -368,19 +386,60 @@ static int dynamic_replicator_probe(struct
> amba_device *adev,
> >  	return replicator_probe(&adev->dev, &adev->res);
> >  }
> >  
> > +static int __exit dynamic_replicator_remove(struct amba_device *adev)
> > +{
> > +	return replicator_remove(&adev->dev);
> > +}
> > +
> >  static const struct amba_id dynamic_replicator_ids[] = {
> >  	CS_AMBA_ID(0x000bb909),
> >  	CS_AMBA_ID(0x000bb9ec),		/* Coresight SoC-600 */
> >  	{},
> >  };
> >  
> > +MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
> > +
> >  static struct amba_driver dynamic_replicator_driver = {
> >  	.drv = {
> >  		.name	= "coresight-dynamic-replicator",
> >  		.pm	= &replicator_dev_pm_ops,
> > +		.owner	= THIS_MODULE,
> >  		.suppress_bind_attrs = true,
> >  	},
> >  	.probe		= dynamic_replicator_probe,
> > +	.remove         = dynamic_replicator_remove,
> >  	.id_table	= dynamic_replicator_ids,
> >  };
> > -builtin_amba_driver(dynamic_replicator_driver);
> > +
> > +static int __init replicator_init(void)
> > +{
> > +	int ret;
> > +
> > +	ret = platform_driver_register(&static_replicator_driver);
> > +	if (ret) {
> > +		pr_info("Error registering platform driver\n");
> > +		return ret;
> > +	}
> > +
> > +	ret = amba_driver_register(&dynamic_replicator_driver);
> > +	if (ret) {
> > +		pr_info("Error registering amba driver\n");
> > +		platform_driver_unregister(&static_replicator_driver);
> > +	}
> > +
> > +	return ret;
> > +}
> > +
> > +static void __exit replicator_exit(void)
> > +{
> > +	platform_driver_unregister(&static_replicator_driver);
> > +	amba_driver_unregister(&dynamic_replicator_driver);
> > +}
> > +
> 
> Same here, choose to add a newline or not but stay consistent for all the
> drives.
>

Sure. 

> > +module_init(replicator_init);
> > +module_exit(replicator_exit);
> > +
> > +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> 
> Pratik should also be mentioned in the funnel driver.
>
 
I'll add Pratik in v9.

> > +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> > +MODULE_DESCRIPTION("Arm CoreSight Replicator Driver");
> > +MODULE_LICENSE("GPL v2");
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-13 23:46     ` Suzuki K Poulose
@ 2020-08-14  9:52       ` Tingwei Zhang
  2020-08-14 10:42         ` Suzuki K Poulose
  0 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-14  9:52 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: tsoni, saiprakash.ranjan, kim.phillips, mathieu.poirier,
	alexander.shishkin, gregkh, coresight, jinlmao, ykaukab, linux,
	rdunlap, tingwei, leo.yan, linux-arm-kernel, mike.leach

On Fri, Aug 14, 2020 at 07:46:12AM +0800, Suzuki K Poulose wrote:
> On 08/13/2020 08:39 PM, Mathieu Poirier wrote:
> >On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> >>From: Kim Phillips <kim.phillips@arm.com>
> >>
> >>Allow to build coresight-etm4x as a module, for ease of development.
> >>
> >>- Kconfig becomes a tristate, to allow =m
> >>- append -core to source file name to allow module to
> >>   be called coresight-etm4x by the Makefile
> >>- add an etm4_remove function, for module unload
> >>- add a MODULE_DEVICE_TABLE for autoloading on boot
> >>- protect etmdrvdata[] with mutex lock from racing
> >>   between module unload and CPU hotplug
> >>
> >>Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> >>Cc: Leo Yan <leo.yan@linaro.org>
> >>Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> >>Cc: Randy Dunlap <rdunlap@infradead.org>
> >>Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> >>Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >>Cc: Russell King <linux@armlinux.org.uk>
> >>Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> >>Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> >>Tested-by: Mike Leach <mike.leach@linaro.org>
> >>---
> >>  drivers/hwtracing/coresight/Kconfig           |   5 +-
> >>  drivers/hwtracing/coresight/Makefile          |   4 +-
> >>  ...resight-etm4x.c => coresight-etm4x-core.c} | 118
> +++++++++++++-----
> >>  3 files changed, 92 insertions(+), 35 deletions(-)
> >>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> coresight-etm4x-core.c} (95%)
> >>
> >>diff --git a/drivers/hwtracing/coresight/Kconfig
> b/drivers/hwtracing/coresight/Kconfig
> >>index 8fd9fd139cf3..d6e107bbd30b 100644
> >>--- a/drivers/hwtracing/coresight/Kconfig
> >>+++ b/drivers/hwtracing/coresight/Kconfig
> >>@@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
> >>  	  module will be called coresight-etm3x.
> >>  config CORESIGHT_SOURCE_ETM4X
> >>-	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> >>+	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
> >>  	depends on ARM64
> >>  	select CORESIGHT_LINKS_AND_SINKS
> >>  	select PID_IN_CONTEXTIDR
> >>@@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
> >>  	  for instruction level tracing. Depending on the implemented
> version
> >>  	  data tracing may also be available.
> >>+	  To compile this driver as a module, choose M here: the
> >>+	  module will be called coresight-etm4x.
> >>+
> >>  config CORESIGHT_STM
> >>  	tristate "CoreSight System Trace Macrocell driver"
> >>  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> >>diff --git a/drivers/hwtracing/coresight/Makefile
> b/drivers/hwtracing/coresight/Makefile
> >>index d619cfd0abd8..271dc255454f 100644
> >>--- a/drivers/hwtracing/coresight/Makefile
> >>+++ b/drivers/hwtracing/coresight/Makefile
> >>@@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> coresight-funnel.o \
> >>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> >>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> >>  					coresight-etm3x-sysfs.o
> >>-obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> >>-					coresight-etm4x-sysfs.o
> >>+obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> >>+coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> >>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> >>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> >>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> >>diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>similarity index 95%
> >>rename from drivers/hwtracing/coresight/coresight-etm4x.c
> >>rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>index fddfd93b9a7b..ae9847e194a3 100644
> >>--- a/drivers/hwtracing/coresight/coresight-etm4x.c
> >>+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >>@@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
> >>  MODULE_PARM_DESC(pm_save_enable,
> >>  	"Save/restore state on power down: 1 = never, 2 = self-hosted");
> >>+static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
> >>  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
> >>  static void etm4_set_default_config(struct etmv4_config *config);
> >>  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> >>@@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config
> *config)
> >>  static int etm4_online_cpu(unsigned int cpu)
> >>  {
> >>-	if (!etmdrvdata[cpu])
> >>+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> >>+	if (!etmdrvdata[cpu]) {
> >>+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >>  		return 0;
> >>+	}
> >>  	if (etmdrvdata[cpu]->boot_enable &&
> !etmdrvdata[cpu]->sticky_enable)
> >>  		coresight_enable(etmdrvdata[cpu]->csdev);
> >>+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >>  	return 0;
> >>  }
> >>  static int etm4_starting_cpu(unsigned int cpu)
> >>  {
> >>-	if (!etmdrvdata[cpu])
> >>+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> >>+	if (!etmdrvdata[cpu]) {
> >>+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >>  		return 0;
> >>+	}
> >>  	spin_lock(&etmdrvdata[cpu]->spinlock);
> >>  	if (!etmdrvdata[cpu]->os_unlock)
> >>@@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
> >>  	if (local_read(&etmdrvdata[cpu]->mode))
> >>  		etm4_enable_hw(etmdrvdata[cpu]);
> >>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> >>+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> >
> >Ouch!
> >
> >A mutex wrapping a spinlock to protect the exact same drvdata structure.
> 
> Actually this mutex is for "protecting" etmdrvdata[cpu], not the
> drvdata struct as such. But as you said, it becomes like a double lock.
> 
> Having mutex is an overkill for sure and can't be used replace
> spin_lock, especially if needed from atomic context. Having looked
> at the code, we only ever access/modify the etmdrvdata[cpu] on a
> different CPU is when we probe and there are chances of races.
> One of such is described here
> 
> http://lists.infradead.org/pipermail/linux-arm-kernel/2020-July/589941.htm
> l
> 
> I will see if I can spin a couple of patches to address these.
> Once we make sure that the etmdrvdata[cpu] is only modified by "cpu"
> then we don't need this mutex and stick with what we have.
> 
> Suzuki
> 

With Suzuki's idea, I made some change to remove mutex lock and change
etmdrvdata[i] on CPU i. I didn't change the part in probe to assign
drvdata to etmdrvdata. That's after all drvdata is prepared and
coresight device is registered. Once hotplug/PM call back see the
value, it can use it directly. If we have racing in probe and these
call backs, the worse case is call backs finds out etmdrvdata is NULL
and return immediately. Does this make sense?


static void __exit clear_etmdrvdata(void *info)
{
        int cpu = *(int *)info;
        etmdrvdata[cpu] = NULL;
}

static int __exit etm4_remove(struct amba_device *adev)
{
        struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);

        etm_perf_symlink(drvdata->csdev, false);

        /*
         * Taking hotplug lock here to avoid racing between etm4_remove and
         * CPU hotplug call backs.
         */
        cpus_read_lock();
        if (cpu_online(drvdata->cpu))
                /*
                 * The readers for etmdrvdata[] are CPU hotplug call backs
                 * and PM notification call backs. Change etmdrvdata[i] on
                 * CPU i ensures these call backs has consistent view
                 * inside one call back function.
                 */
                smp_call_function_single(drvdata->cpu, clear_etmdrvdata, &drvdata->cpu, 1);
        else
                etmdrvdata[drvdata->cpu] = NULL;

        cpus_read_unlock();

        coresight_unregister(drvdata->csdev);

        return 0;
}

Thanks,
Tingwei
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-14  9:52       ` Tingwei Zhang
@ 2020-08-14 10:42         ` Suzuki K Poulose
  2020-08-14 11:00           ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Suzuki K Poulose @ 2020-08-14 10:42 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, saiprakash.ranjan, kim.phillips, mathieu.poirier,
	suzuki.poulose, alexander.shishkin, gregkh, coresight, jinlmao,
	ykaukab, linux, rdunlap, tingwei, leo.yan, linux-arm-kernel,
	mike.leach

On Fri, Aug 14, 2020 at 05:52:24PM +0800, Tingwei Zhang wrote:
> On Fri, Aug 14, 2020 at 07:46:12AM +0800, Suzuki K Poulose wrote:
> > On 08/13/2020 08:39 PM, Mathieu Poirier wrote:
> > >On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> > >>From: Kim Phillips <kim.phillips@arm.com>
> > >>
> > >>Allow to build coresight-etm4x as a module, for ease of development.
> > >>
> > >>- Kconfig becomes a tristate, to allow =m
> > >>- append -core to source file name to allow module to
> > >>   be called coresight-etm4x by the Makefile
> > >>- add an etm4_remove function, for module unload
> > >>- add a MODULE_DEVICE_TABLE for autoloading on boot
> > >>- protect etmdrvdata[] with mutex lock from racing
> > >>   between module unload and CPU hotplug
> > >>
> > >>Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > >>Cc: Leo Yan <leo.yan@linaro.org>
> > >>Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > >>Cc: Randy Dunlap <rdunlap@infradead.org>
> > >>Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > >>Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > >>Cc: Russell King <linux@armlinux.org.uk>
> > >>Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > >>Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > >>Tested-by: Mike Leach <mike.leach@linaro.org>
> > >>---
> > >>  drivers/hwtracing/coresight/Kconfig           |   5 +-
> > >>  drivers/hwtracing/coresight/Makefile          |   4 +-
> > >>  ...resight-etm4x.c => coresight-etm4x-core.c} | 118
> > +++++++++++++-----
> > >>  3 files changed, 92 insertions(+), 35 deletions(-)
> > >>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> > coresight-etm4x-core.c} (95%)
> > >>
> > >>diff --git a/drivers/hwtracing/coresight/Kconfig
> > b/drivers/hwtracing/coresight/Kconfig
> > >>index 8fd9fd139cf3..d6e107bbd30b 100644
> > >>--- a/drivers/hwtracing/coresight/Kconfig
> > >>+++ b/drivers/hwtracing/coresight/Kconfig
> > >>@@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
> > >>  	  module will be called coresight-etm3x.
> > >>  config CORESIGHT_SOURCE_ETM4X
> > >>-	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> > >>+	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
> > >>  	depends on ARM64
> > >>  	select CORESIGHT_LINKS_AND_SINKS
> > >>  	select PID_IN_CONTEXTIDR
> > >>@@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
> > >>  	  for instruction level tracing. Depending on the implemented
> > version
> > >>  	  data tracing may also be available.
> > >>+	  To compile this driver as a module, choose M here: the
> > >>+	  module will be called coresight-etm4x.
> > >>+
> > >>  config CORESIGHT_STM
> > >>  	tristate "CoreSight System Trace Macrocell driver"
> > >>  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> > >>diff --git a/drivers/hwtracing/coresight/Makefile
> > b/drivers/hwtracing/coresight/Makefile
> > >>index d619cfd0abd8..271dc255454f 100644
> > >>--- a/drivers/hwtracing/coresight/Makefile
> > >>+++ b/drivers/hwtracing/coresight/Makefile
> > >>@@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> > coresight-funnel.o \
> > >>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > >>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> > >>  					coresight-etm3x-sysfs.o
> > >>-obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> > >>-					coresight-etm4x-sysfs.o
> > >>+obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> > >>+coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> > >>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> > >>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> > >>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> > >>diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> > b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > >>similarity index 95%
> > >>rename from drivers/hwtracing/coresight/coresight-etm4x.c
> > >>rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> > >>index fddfd93b9a7b..ae9847e194a3 100644
> > >>--- a/drivers/hwtracing/coresight/coresight-etm4x.c
> > >>+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > >>@@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
> > >>  MODULE_PARM_DESC(pm_save_enable,
> > >>  	"Save/restore state on power down: 1 = never, 2 = self-hosted");
> > >>+static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
> > >>  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
> > >>  static void etm4_set_default_config(struct etmv4_config *config);
> > >>  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> > >>@@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct etmv4_config
> > *config)
> > >>  static int etm4_online_cpu(unsigned int cpu)
> > >>  {
> > >>-	if (!etmdrvdata[cpu])
> > >>+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > >>+	if (!etmdrvdata[cpu]) {
> > >>+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > >>  		return 0;
> > >>+	}
> > >>  	if (etmdrvdata[cpu]->boot_enable &&
> > !etmdrvdata[cpu]->sticky_enable)
> > >>  		coresight_enable(etmdrvdata[cpu]->csdev);
> > >>+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > >>  	return 0;
> > >>  }
> > >>  static int etm4_starting_cpu(unsigned int cpu)
> > >>  {
> > >>-	if (!etmdrvdata[cpu])
> > >>+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > >>+	if (!etmdrvdata[cpu]) {
> > >>+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > >>  		return 0;
> > >>+	}
> > >>  	spin_lock(&etmdrvdata[cpu]->spinlock);
> > >>  	if (!etmdrvdata[cpu]->os_unlock)
> > >>@@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int cpu)
> > >>  	if (local_read(&etmdrvdata[cpu]->mode))
> > >>  		etm4_enable_hw(etmdrvdata[cpu]);
> > >>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> > >>+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > >
> > >Ouch!
> > >
> > >A mutex wrapping a spinlock to protect the exact same drvdata structure.
> > 
> > Actually this mutex is for "protecting" etmdrvdata[cpu], not the
> > drvdata struct as such. But as you said, it becomes like a double lock.
> > 
> > Having mutex is an overkill for sure and can't be used replace
> > spin_lock, especially if needed from atomic context. Having looked
> > at the code, we only ever access/modify the etmdrvdata[cpu] on a
> > different CPU is when we probe and there are chances of races.
> > One of such is described here
> > 
> > http://lists.infradead.org/pipermail/linux-arm-kernel/2020-July/589941.htm
> > l
> > 
> > I will see if I can spin a couple of patches to address these.
> > Once we make sure that the etmdrvdata[cpu] is only modified by "cpu"
> > then we don't need this mutex and stick with what we have.
> > 
> > Suzuki
> > 
> 
> With Suzuki's idea, I made some change to remove mutex lock and change
> etmdrvdata[i] on CPU i. I didn't change the part in probe to assign
> drvdata to etmdrvdata. That's after all drvdata is prepared and
> coresight device is registered. Once hotplug/PM call back see the
> value, it can use it directly. If we have racing in probe and these
> call backs, the worse case is call backs finds out etmdrvdata is NULL
> and return immediately. Does this make sense?
> 
> 
> static void __exit clear_etmdrvdata(void *info)
> {
>         int cpu = *(int *)info;
>         etmdrvdata[cpu] = NULL;
> }
> 
> static int __exit etm4_remove(struct amba_device *adev)
> {
>         struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> 
>         etm_perf_symlink(drvdata->csdev, false);
> 
>         /*
>          * Taking hotplug lock here to avoid racing between etm4_remove and
>          * CPU hotplug call backs.
>          */
>         cpus_read_lock();
>         if (cpu_online(drvdata->cpu))
>                 /*
>                  * The readers for etmdrvdata[] are CPU hotplug call backs
>                  * and PM notification call backs. Change etmdrvdata[i] on
>                  * CPU i ensures these call backs has consistent view
>                  * inside one call back function.
>                  */
>                 smp_call_function_single(drvdata->cpu, clear_etmdrvdata, &drvdata->cpu, 1);

You should check the error here to confirm if this was really complete. Otherwise,
fallback to the manual clearing here.

>         else
>                 etmdrvdata[drvdata->cpu] = NULL;
> 
>         cpus_read_unlock();
> 
>         coresight_unregister(drvdata->csdev);
> 
>         return 0;
> }

Yes, this is exactly what I was looking for. Additionally we should
fix the races mentioned in the link above. I believe, we can solve
that by the following :

---8>---

coresight: etm4x: Delay advertising per-cpu drvdata

Delay advertising the per-cpu etmdrvdata until we have
successfully initialised. This is to avoid races and
unnecessary save/restore of the ETM state, before the
device is properly setup.

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/hwtracing/coresight/coresight-etm4x.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c
index 6d7d2169bfb2..30f7ffa07eb6 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x.c
@@ -1499,8 +1499,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 		return -ENOMEM;
 
 	cpus_read_lock();
-	etmdrvdata[drvdata->cpu] = drvdata;
-
 	if (smp_call_function_single(drvdata->cpu,
 				etm4_init_arch_data,  drvdata, 1))
 		dev_err(dev, "ETM arch init failed\n");
@@ -1509,10 +1507,8 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	cpus_read_unlock();
 
 	/* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error */
-	if (ret) {
-		etmdrvdata[drvdata->cpu] = NULL;
+	if (ret)
 		return ret;
-	}
 
 	if (etm4_arch_supported(drvdata->arch) == false) {
 		ret = -EINVAL;
@@ -1547,6 +1543,8 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 		goto err_arch_supported;
 	}
 
+	/* Advertise this after we have successfully initialised */
+	etmdrvdata[drvdata->cpu] = drvdata;
 	pm_runtime_put(&adev->dev);
 	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
 		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
@@ -1559,7 +1557,6 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	return 0;
 
 err_arch_supported:
-	etmdrvdata[drvdata->cpu] = NULL;
 	etm4_pm_clear();
 	return ret;
 }
-- 
2.24.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-14 10:42         ` Suzuki K Poulose
@ 2020-08-14 11:00           ` Tingwei Zhang
  2020-08-14 11:18             ` Suzuki K Poulose
  0 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-14 11:00 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: tsoni, saiprakash.ranjan, kim.phillips, mathieu.poirier,
	alexander.shishkin, gregkh, coresight, jinlmao, ykaukab, linux,
	rdunlap, tingwei, leo.yan, linux-arm-kernel, mike.leach

On Fri, Aug 14, 2020 at 06:42:01PM +0800, Suzuki K Poulose wrote:
> On Fri, Aug 14, 2020 at 05:52:24PM +0800, Tingwei Zhang wrote:
> > On Fri, Aug 14, 2020 at 07:46:12AM +0800, Suzuki K Poulose wrote:
> > > On 08/13/2020 08:39 PM, Mathieu Poirier wrote:
> > > >On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
> > > >>From: Kim Phillips <kim.phillips@arm.com>
> > > >>
> > > >>Allow to build coresight-etm4x as a module, for ease of development.
> > > >>
> > > >>- Kconfig becomes a tristate, to allow =m
> > > >>- append -core to source file name to allow module to
> > > >>   be called coresight-etm4x by the Makefile
> > > >>- add an etm4_remove function, for module unload
> > > >>- add a MODULE_DEVICE_TABLE for autoloading on boot
> > > >>- protect etmdrvdata[] with mutex lock from racing
> > > >>   between module unload and CPU hotplug
> > > >>
> > > >>Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > > >>Cc: Leo Yan <leo.yan@linaro.org>
> > > >>Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > > >>Cc: Randy Dunlap <rdunlap@infradead.org>
> > > >>Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > > >>Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > >>Cc: Russell King <linux@armlinux.org.uk>
> > > >>Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > > >>Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > > >>Tested-by: Mike Leach <mike.leach@linaro.org>
> > > >>---
> > > >>  drivers/hwtracing/coresight/Kconfig           |   5 +-
> > > >>  drivers/hwtracing/coresight/Makefile          |   4 +-
> > > >>  ...resight-etm4x.c => coresight-etm4x-core.c} | 118
> > > +++++++++++++-----
> > > >>  3 files changed, 92 insertions(+), 35 deletions(-)
> > > >>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> > > coresight-etm4x-core.c} (95%)
> > > >>
> > > >>diff --git a/drivers/hwtracing/coresight/Kconfig
> > > b/drivers/hwtracing/coresight/Kconfig
> > > >>index 8fd9fd139cf3..d6e107bbd30b 100644
> > > >>--- a/drivers/hwtracing/coresight/Kconfig
> > > >>+++ b/drivers/hwtracing/coresight/Kconfig
> > > >>@@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
> > > >>  	  module will be called coresight-etm3x.
> > > >>  config CORESIGHT_SOURCE_ETM4X
> > > >>-	bool "CoreSight Embedded Trace Macrocell 4.x driver"
> > > >>+	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
> > > >>  	depends on ARM64
> > > >>  	select CORESIGHT_LINKS_AND_SINKS
> > > >>  	select PID_IN_CONTEXTIDR
> > > >>@@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
> > > >>  	  for instruction level tracing. Depending on the
> implemented
> > > version
> > > >>  	  data tracing may also be available.
> > > >>+	  To compile this driver as a module, choose M here: the
> > > >>+	  module will be called coresight-etm4x.
> > > >>+
> > > >>  config CORESIGHT_STM
> > > >>  	tristate "CoreSight System Trace Macrocell driver"
> > > >>  	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T))
> || ARM64
> > > >>diff --git a/drivers/hwtracing/coresight/Makefile
> > > b/drivers/hwtracing/coresight/Makefile
> > > >>index d619cfd0abd8..271dc255454f 100644
> > > >>--- a/drivers/hwtracing/coresight/Makefile
> > > >>+++ b/drivers/hwtracing/coresight/Makefile
> > > >>@@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> > > coresight-funnel.o \
> > > >>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > > >>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> > > >>  					coresight-etm3x-sysfs.o
> > > >>-obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> > > >>-					coresight-etm4x-sysfs.o
> > > >>+obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> > > >>+coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> > > >>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> > > >>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> > > >>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> > > >>diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> > > b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > > >>similarity index 95%
> > > >>rename from drivers/hwtracing/coresight/coresight-etm4x.c
> > > >>rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> > > >>index fddfd93b9a7b..ae9847e194a3 100644
> > > >>--- a/drivers/hwtracing/coresight/coresight-etm4x.c
> > > >>+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > > >>@@ -48,6 +48,7 @@ module_param(pm_save_enable, int, 0444);
> > > >>  MODULE_PARM_DESC(pm_save_enable,
> > > >>  	"Save/restore state on power down: 1 = never, 2 =
> self-hosted");
> > > >>+static DEFINE_PER_CPU(struct mutex, etmdrvdata_lock);
> > > >>  static struct etmv4_drvdata *etmdrvdata[NR_CPUS];
> > > >>  static void etm4_set_default_config(struct etmv4_config *config);
> > > >>  static int etm4_set_event_filters(struct etmv4_drvdata *drvdata,
> > > >>@@ -1089,18 +1090,25 @@ void etm4_config_trace_mode(struct
> etmv4_config
> > > *config)
> > > >>  static int etm4_online_cpu(unsigned int cpu)
> > > >>  {
> > > >>-	if (!etmdrvdata[cpu])
> > > >>+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > > >>+	if (!etmdrvdata[cpu]) {
> > > >>+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > > >>  		return 0;
> > > >>+	}
> > > >>  	if (etmdrvdata[cpu]->boot_enable &&
> > > !etmdrvdata[cpu]->sticky_enable)
> > > >>  		coresight_enable(etmdrvdata[cpu]->csdev);
> > > >>+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > > >>  	return 0;
> > > >>  }
> > > >>  static int etm4_starting_cpu(unsigned int cpu)
> > > >>  {
> > > >>-	if (!etmdrvdata[cpu])
> > > >>+	mutex_lock(&per_cpu(etmdrvdata_lock, cpu));
> > > >>+	if (!etmdrvdata[cpu]) {
> > > >>+		mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > > >>  		return 0;
> > > >>+	}
> > > >>  	spin_lock(&etmdrvdata[cpu]->spinlock);
> > > >>  	if (!etmdrvdata[cpu]->os_unlock)
> > > >>@@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int
> cpu)
> > > >>  	if (local_read(&etmdrvdata[cpu]->mode))
> > > >>  		etm4_enable_hw(etmdrvdata[cpu]);
> > > >>  	spin_unlock(&etmdrvdata[cpu]->spinlock);
> > > >>+	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
> > > >
> > > >Ouch!
> > > >
> > > >A mutex wrapping a spinlock to protect the exact same drvdata
> structure.
> > > 
> > > Actually this mutex is for "protecting" etmdrvdata[cpu], not the
> > > drvdata struct as such. But as you said, it becomes like a double
> lock.
> > > 
> > > Having mutex is an overkill for sure and can't be used replace
> > > spin_lock, especially if needed from atomic context. Having looked
> > > at the code, we only ever access/modify the etmdrvdata[cpu] on a
> > > different CPU is when we probe and there are chances of races.
> > > One of such is described here
> > > 
> > >
> http://lists.infradead.org/pipermail/linux-arm-kernel/2020-July/589941.htm
> > > l
> > > 
> > > I will see if I can spin a couple of patches to address these.
> > > Once we make sure that the etmdrvdata[cpu] is only modified by "cpu"
> > > then we don't need this mutex and stick with what we have.
> > > 
> > > Suzuki
> > > 
> > 
> > With Suzuki's idea, I made some change to remove mutex lock and change
> > etmdrvdata[i] on CPU i. I didn't change the part in probe to assign
> > drvdata to etmdrvdata. That's after all drvdata is prepared and
> > coresight device is registered. Once hotplug/PM call back see the
> > value, it can use it directly. If we have racing in probe and these
> > call backs, the worse case is call backs finds out etmdrvdata is NULL
> > and return immediately. Does this make sense?
> > 
> > 
> > static void __exit clear_etmdrvdata(void *info)
> > {
> >         int cpu = *(int *)info;
> >         etmdrvdata[cpu] = NULL;
> > }
> > 
> > static int __exit etm4_remove(struct amba_device *adev)
> > {
> >         struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > 
> >         etm_perf_symlink(drvdata->csdev, false);
> > 
> >         /*
> >          * Taking hotplug lock here to avoid racing between etm4_remove
> and
> >          * CPU hotplug call backs.
> >          */
> >         cpus_read_lock();
> >         if (cpu_online(drvdata->cpu))
> >                 /*
> >                  * The readers for etmdrvdata[] are CPU hotplug call
> backs
> >                  * and PM notification call backs. Change etmdrvdata[i]
> on
> >                  * CPU i ensures these call backs has consistent view
> >                  * inside one call back function.
> >                  */
> >                 smp_call_function_single(drvdata->cpu, clear_etmdrvdata,
> &drvdata->cpu, 1);
> 
> You should check the error here to confirm if this was really complete.
> Otherwise,
> fallback to the manual clearing here.
> 
Yes. I don't need to check cpu_online since it's checked in
smp_call_function_single(). I can just check return value and
fallback to manual clearing.

> >         else
> >                 etmdrvdata[drvdata->cpu] = NULL;
> > 
> >         cpus_read_unlock();
> > 
> >         coresight_unregister(drvdata->csdev);
> > 
> >         return 0;
> > }
> 
> Yes, this is exactly what I was looking for. Additionally we should
> fix the races mentioned in the link above. I believe, we can solve
> that by the following :
>
I already did the same thing in this patch if you ignore the mutex
part. :)

Thanks,
Tingwei 
> ---8>---
> 
> coresight: etm4x: Delay advertising per-cpu drvdata
> 
> Delay advertising the per-cpu etmdrvdata until we have
> successfully initialised. This is to avoid races and
> unnecessary save/restore of the ETM state, before the
> device is properly setup.
> 
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-etm4x.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> b/drivers/hwtracing/coresight/coresight-etm4x.c
> index 6d7d2169bfb2..30f7ffa07eb6 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x.c
> @@ -1499,8 +1499,6 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
>  		return -ENOMEM;
>  
>  	cpus_read_lock();
> -	etmdrvdata[drvdata->cpu] = drvdata;
> -
>  	if (smp_call_function_single(drvdata->cpu,
>  				etm4_init_arch_data,  drvdata, 1))
>  		dev_err(dev, "ETM arch init failed\n");
> @@ -1509,10 +1507,8 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
>  	cpus_read_unlock();
>  
>  	/* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error
> */
> -	if (ret) {
> -		etmdrvdata[drvdata->cpu] = NULL;
> +	if (ret)
>  		return ret;
> -	}
>  
>  	if (etm4_arch_supported(drvdata->arch) == false) {
>  		ret = -EINVAL;
> @@ -1547,6 +1543,8 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
>  		goto err_arch_supported;
>  	}
>  
> +	/* Advertise this after we have successfully initialised */
> +	etmdrvdata[drvdata->cpu] = drvdata;
>  	pm_runtime_put(&adev->dev);
>  	dev_info(&drvdata->csdev->dev, "CPU%d: ETM v%d.%d initialized\n",
>  		 drvdata->cpu, drvdata->arch >> 4, drvdata->arch & 0xf);
> @@ -1559,7 +1557,6 @@ static int etm4_probe(struct amba_device *adev,
> const struct amba_id *id)
>  	return 0;
>  
>  err_arch_supported:
> -	etmdrvdata[drvdata->cpu] = NULL;
>  	etm4_pm_clear();
>  	return ret;
>  }
> -- 
> 2.24.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 10/24] coresight: etm4x: allow etm4x to be built as a module
  2020-08-14 11:00           ` Tingwei Zhang
@ 2020-08-14 11:18             ` Suzuki K Poulose
  0 siblings, 0 replies; 68+ messages in thread
From: Suzuki K Poulose @ 2020-08-14 11:18 UTC (permalink / raw)
  To: tingweiz
  Cc: tsoni, saiprakash.ranjan, kim.phillips, mathieu.poirier,
	alexander.shishkin, gregkh, coresight, jinlmao, ykaukab, linux,
	rdunlap, tingwei, leo.yan, linux-arm-kernel, mike.leach

On 08/14/2020 12:00 PM, Tingwei Zhang wrote:
> On Fri, Aug 14, 2020 at 06:42:01PM +0800, Suzuki K Poulose wrote:
>> On Fri, Aug 14, 2020 at 05:52:24PM +0800, Tingwei Zhang wrote:
>>> On Fri, Aug 14, 2020 at 07:46:12AM +0800, Suzuki K Poulose wrote:
>>>> On 08/13/2020 08:39 PM, Mathieu Poirier wrote:
>>>>> On Fri, Aug 07, 2020 at 07:11:39PM +0800, Tingwei Zhang wrote:
>>>>>> From: Kim Phillips <kim.phillips@arm.com>


>>>>>> @@ -1109,18 +1117,23 @@ static int etm4_starting_cpu(unsigned int
>> cpu)
>>>>>>   	if (local_read(&etmdrvdata[cpu]->mode))
>>>>>>   		etm4_enable_hw(etmdrvdata[cpu]);
>>>>>>   	spin_unlock(&etmdrvdata[cpu]->spinlock);
>>>>>> +	mutex_unlock(&per_cpu(etmdrvdata_lock, cpu));
>>>>>
>>>>> Ouch!
>>>>>
>>>>> A mutex wrapping a spinlock to protect the exact same drvdata
>> structure.
>>>>
>>>> Actually this mutex is for "protecting" etmdrvdata[cpu], not the
>>>> drvdata struct as such. But as you said, it becomes like a double
>> lock.
>>>>
>>>> Having mutex is an overkill for sure and can't be used replace
>>>> spin_lock, especially if needed from atomic context. Having looked
>>>> at the code, we only ever access/modify the etmdrvdata[cpu] on a
>>>> different CPU is when we probe and there are chances of races.
>>>> One of such is described here
>>>>
>>>>
>> http://lists.infradead.org/pipermail/linux-arm-kernel/2020-July/589941.htm
>>>> l
>>>>
>>>> I will see if I can spin a couple of patches to address these.
>>>> Once we make sure that the etmdrvdata[cpu] is only modified by "cpu"
>>>> then we don't need this mutex and stick with what we have.
>>>>
>>>> Suzuki
>>>>
>>>
>>> With Suzuki's idea, I made some change to remove mutex lock and change
>>> etmdrvdata[i] on CPU i. I didn't change the part in probe to assign
>>> drvdata to etmdrvdata. That's after all drvdata is prepared and
>>> coresight device is registered. Once hotplug/PM call back see the
>>> value, it can use it directly. If we have racing in probe and these
>>> call backs, the worse case is call backs finds out etmdrvdata is NULL
>>> and return immediately. Does this make sense?
>>>
>>>
>>> static void __exit clear_etmdrvdata(void *info)
>>> {
>>>          int cpu = *(int *)info;
>>>          etmdrvdata[cpu] = NULL;
>>> }
>>>
>>> static int __exit etm4_remove(struct amba_device *adev)
>>> {
>>>          struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
>>>
>>>          etm_perf_symlink(drvdata->csdev, false);
>>>
>>>          /*
>>>           * Taking hotplug lock here to avoid racing between etm4_remove
>> and
>>>           * CPU hotplug call backs.
>>>           */
>>>          cpus_read_lock();
>>>          if (cpu_online(drvdata->cpu))
>>>                  /*
>>>                   * The readers for etmdrvdata[] are CPU hotplug call
>> backs
>>>                   * and PM notification call backs. Change etmdrvdata[i]
>> on
>>>                   * CPU i ensures these call backs has consistent view
>>>                   * inside one call back function.
>>>                   */
>>>                  smp_call_function_single(drvdata->cpu, clear_etmdrvdata,
>> &drvdata->cpu, 1);
>>
>> You should check the error here to confirm if this was really complete.
>> Otherwise,
>> fallback to the manual clearing here.
>>
> Yes. I don't need to check cpu_online since it's checked in
> smp_call_function_single(). I can just check return value and
> fallback to manual clearing.
> 
>>>          else
>>>                  etmdrvdata[drvdata->cpu] = NULL;
>>>
>>>          cpus_read_unlock();
>>>
>>>          coresight_unregister(drvdata->csdev);
>>>
>>>          return 0;
>>> }
>>
>> Yes, this is exactly what I was looking for. Additionally we should
>> fix the races mentioned in the link above. I believe, we can solve
>> that by the following :
>>
> I already did the same thing in this patch if you ignore the mutex
> part. :)

Oh, yes. I see that now :-)

Cheers
Suzuki

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 16/24] coresight: cti: add function to register cti associate ops
  2020-08-07 11:11 ` [PATCH v8 16/24] coresight: cti: add function to register cti associate ops Tingwei Zhang
@ 2020-08-17 16:02   ` Mathieu Poirier
  2020-08-17 18:49     ` Mike Leach
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-17 16:02 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:45PM +0800, Tingwei Zhang wrote:
> Add static cti_assoc_ops to coresight core driver. Let cti
> driver register the add_assoc and remove_assoc call back.
> Avoid coresight core driver to depend on cti driver.
> 
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/coresight-cti.c  | 32 ++++++++++++++++++--
>  drivers/hwtracing/coresight/coresight-priv.h | 14 ++++-----
>  drivers/hwtracing/coresight/coresight.c      | 21 +++++++++++--
>  3 files changed, 53 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
> index 3ccc703dc940..1f470c47ba70 100644
> --- a/drivers/hwtracing/coresight/coresight-cti.c
> +++ b/drivers/hwtracing/coresight/coresight-cti.c
> @@ -589,7 +589,6 @@ void cti_add_assoc_to_csdev(struct coresight_device *csdev)
>  cti_add_done:
>  	mutex_unlock(&ect_mutex);
>  }
> -EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
>  
>  /*
>   * Removing the associated devices is easier.
> @@ -616,7 +615,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
>  	}
>  	mutex_unlock(&ect_mutex);
>  }
> -EXPORT_SYMBOL_GPL(cti_remove_assoc_from_csdev);

Mike and Tingwei,

It seems to me that functions cti_add_assoc_to_csdev() and
cti_remote_assoc_from_csdev() don't have to be exported.  They could be called
in cti_probe() and cti_device_release() with the ect_mutex held, the same way
cti_update_conn_xrefs() and cti_remove_conn_xrefs() are.

If my assessment is correct this patch would be simpler.

Thanks,
Mathieu


> +
> +/*
> + * Operations to add and remove associated CTI.
> + * Register to coresight core driver as call back function.
> + */
> +static struct cti_assoc_op cti_assoc_ops = {
> +	.add = cti_add_assoc_to_csdev,
> +	.remove = cti_remove_assoc_from_csdev
> +};
>  
>  /*
>   * Update the cross references where the associated device was found
> @@ -972,4 +979,23 @@ static struct amba_driver cti_driver = {
>  	.probe		= cti_probe,
>  	.id_table	= cti_ids,
>  };
> -builtin_amba_driver(cti_driver);
> +
> +static int __init cti_init(void)
> +{
> +	int ret;
> +
> +	ret = amba_driver_register(&cti_driver);
> +	if (ret)
> +		pr_info("Error registering cti driver\n");
> +	coresight_set_cti_ops(&cti_assoc_ops);
> +	return ret;
> +}
> +
> +static void __exit cti_exit(void)
> +{
> +	coresight_remove_cti_ops();
> +	amba_driver_unregister(&cti_driver);
> +}
> +
> +module_init(cti_init);
> +module_exit(cti_exit);
> diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> index dcb8aeb6af62..6cde6cf42554 100644
> --- a/drivers/hwtracing/coresight/coresight-priv.h
> +++ b/drivers/hwtracing/coresight/coresight-priv.h
> @@ -173,15 +173,13 @@ static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
>  static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
>  #endif
>  
> -#ifdef CONFIG_CORESIGHT_CTI
> -extern void cti_add_assoc_to_csdev(struct coresight_device *csdev);
> -extern void cti_remove_assoc_from_csdev(struct coresight_device *csdev);
> +struct cti_assoc_op {
> +	void (*add)(struct coresight_device *csdev);
> +	void (*remove)(struct coresight_device *csdev);
> +};
>  
> -#else
> -static inline void cti_add_assoc_to_csdev(struct coresight_device *csdev) {}
> -static inline void
> -cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}
> -#endif
> +extern void coresight_set_cti_ops(const struct cti_assoc_op *cti_op);
> +extern void coresight_remove_cti_ops(void);
>  
>  /*
>   * Macros and inline functions to handle CoreSight UCI data and driver
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 0b0e31577b9b..31b9ec8d3b9c 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -57,6 +57,20 @@ const u32 coresight_barrier_pkt[4] = {
>  		0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
>  EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
>  
> +static const struct cti_assoc_op *cti_assoc_ops;
> +
> +void coresight_set_cti_ops(const struct cti_assoc_op *cti_op)
> +{
> +	cti_assoc_ops = cti_op;
> +}
> +EXPORT_SYMBOL_GPL(coresight_set_cti_ops);
> +
> +void coresight_remove_cti_ops(void)
> +{
> +	cti_assoc_ops = NULL;
> +}
> +EXPORT_SYMBOL_GPL(coresight_remove_cti_ops);
> +
>  static int coresight_id_match(struct device *dev, void *data)
>  {
>  	int trace_id, i_trace_id;
> @@ -1242,7 +1256,8 @@ static void coresight_device_release(struct device *dev)
>  {
>  	struct coresight_device *csdev = to_coresight_device(dev);
>  
> -	cti_remove_assoc_from_csdev(csdev);
> +	if (cti_assoc_ops && cti_assoc_ops->remove)
> +		cti_assoc_ops->remove(csdev);
>  	fwnode_handle_put(csdev->dev.fwnode);
>  	kfree(csdev->refcnt);
>  	kfree(csdev);
> @@ -1553,8 +1568,8 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
>  		ret = coresight_fixup_device_conns(csdev);
>  	if (!ret)
>  		ret = coresight_fixup_orphan_conns(csdev);
> -	if (!ret)
> -		cti_add_assoc_to_csdev(csdev);
> +	if (!ret && cti_assoc_ops && cti_assoc_ops->add)
> +		cti_assoc_ops->add(csdev);
>  
>  	mutex_unlock(&coresight_mutex);
>  	if (ret) {
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 17/24] coresight: cti: Fix remove sysfs link error
  2020-08-07 11:11 ` [PATCH v8 17/24] coresight: cti: Fix remove sysfs link error Tingwei Zhang
@ 2020-08-17 16:15   ` Mathieu Poirier
  2020-08-17 22:48     ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-17 16:15 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:46PM +0800, Tingwei Zhang wrote:
> From: Mike Leach <mike.leach@linaro.org>
> 
> CTI code to remove sysfs link to other devices on shutdown, incorrectly
> tries to remove a single ended link when these are all double ended. This
> implementation leaves elements in the link info structure undefined which
> results in a crash in recent tests for driver module unload.
> 
> This patch corrects the link removal code.
> 
> Fixes: 73274abb6557 (coresight: cti: Add in sysfs links to other coresight devices)

This should be:

Fixes: 73274abb6557 ("coresight: cti: Add in sysfs links to other coresight devices")

> Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
> Signed-off-by: Mike Leach <mike.leach@linaro.org>
> ---
>  drivers/hwtracing/coresight/coresight-cti.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
> index 1f470c47ba70..1c34db7d1b1b 100644
> --- a/drivers/hwtracing/coresight/coresight-cti.c
> +++ b/drivers/hwtracing/coresight/coresight-cti.c
> @@ -511,12 +511,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata *drvdata,
>  	return !link_err;
>  }
>  
> -static void cti_remove_sysfs_link(struct cti_trig_con *tc)
> +static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
> +				  struct cti_trig_con *tc)
>  {
>  	struct coresight_sysfs_link link_info;
>  
> +	link_info.orig = drvdata->csdev;
>  	link_info.orig_name = tc->con_dev_name;
>  	link_info.target = tc->con_dev;
> +	link_info.target_name = dev_name(&drvdata->csdev->dev);
>  	coresight_remove_sysfs_link(&link_info);
>  }
>  
> @@ -606,7 +609,7 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
>  		ctidev = &ctidrv->ctidev;
>  		list_for_each_entry(tc, &ctidev->trig_cons, node) {
>  			if (tc->con_dev == csdev->ect_dev) {
> -				cti_remove_sysfs_link(tc);
> +				cti_remove_sysfs_link(ctidrv, tc);
>  				tc->con_dev = NULL;
>  				break;
>  			}
> @@ -658,7 +661,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata *drvdata)
>  		if (tc->con_dev) {
>  			coresight_set_assoc_ectdev_mutex(tc->con_dev,
>  							 NULL);
> -			cti_remove_sysfs_link(tc);
> +			cti_remove_sysfs_link(drvdata, tc);

With the above:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  			tc->con_dev = NULL;
>  		}
>  	}
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 18/24] coresight: cti: Fix bug clearing sysfs links on callback
  2020-08-07 11:11 ` [PATCH v8 18/24] coresight: cti: Fix bug clearing sysfs links on callback Tingwei Zhang
@ 2020-08-17 16:21   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-17 16:21 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:47PM +0800, Tingwei Zhang wrote:
> From: Mike Leach <mike.leach@linaro.org>
> 
> During module unload, a coresight driver module will call back into
> the CTI driver to remove any links between the two devices.
> 
> The current code has 2 issues:-
> 1) in the CTI driver the matching code is matching to the wrong device
> so misses all the links.
> 2) The callback is called too late in the unload process resulting in a
> crash.
> 
> This fixes both the issues.

This patch may no longer be required if my recommendation from patch 16 is
followed.

> 
> Fixes: 177af8285b59 (coresight: cti: Enable CTI associated with devices)

Same comment as in my previous patch, we need a set of double quotes for the
title.

> Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
> Signed-off-by: Mike Leach <mike.leach@linaro.org>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Acked-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/coresight-cti.c | 2 +-
>  drivers/hwtracing/coresight/coresight.c     | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
> index 1c34db7d1b1b..6bb06c5715db 100644
> --- a/drivers/hwtracing/coresight/coresight-cti.c
> +++ b/drivers/hwtracing/coresight/coresight-cti.c
> @@ -608,7 +608,7 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
>  		ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
>  		ctidev = &ctidrv->ctidev;
>  		list_for_each_entry(tc, &ctidev->trig_cons, node) {
> -			if (tc->con_dev == csdev->ect_dev) {
> +			if (tc->con_dev == csdev) {
>  				cti_remove_sysfs_link(ctidrv, tc);
>  				tc->con_dev = NULL;
>  				break;
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 31b9ec8d3b9c..d066411aa794 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -1256,8 +1256,6 @@ static void coresight_device_release(struct device *dev)
>  {
>  	struct coresight_device *csdev = to_coresight_device(dev);
>  
> -	if (cti_assoc_ops && cti_assoc_ops->remove)
> -		cti_assoc_ops->remove(csdev);
>  	fwnode_handle_put(csdev->dev.fwnode);
>  	kfree(csdev->refcnt);
>  	kfree(csdev);
> @@ -1592,6 +1590,8 @@ void coresight_unregister(struct coresight_device *csdev)
>  {
>  	etm_perf_del_symlink_sink(csdev);
>  	/* Remove references of that device in the topology */
> +	if (cti_assoc_ops && cti_assoc_ops->remove)
> +		cti_assoc_ops->remove(csdev);
>  	coresight_remove_conns(csdev);
>  	coresight_clear_default_sink(csdev);
>  	coresight_release_platform_data(csdev, csdev->pdata);
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled
  2020-08-07 11:11 ` [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled Tingwei Zhang
@ 2020-08-17 16:38   ` Mathieu Poirier
  2020-08-17 19:04     ` Mike Leach
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-17 16:38 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:48PM +0800, Tingwei Zhang wrote:
> If associated ect device is not enabled at first place, disable
> routine should not be called. Add ect_enabled flag to check whether
> ect device is enabled. Fix the issue in below case.  Ect device is
> not available when associated coresight device enabled and the
> association is established after coresight device is enabled.
> 
> Signed-off-by: Mike Leach <mike.leach@linaro.org>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> ---
>  drivers/hwtracing/coresight/coresight.c | 11 ++++++++---
>  include/linux/coresight.h               |  1 +
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index d066411aa794..27ad8317e3cf 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -245,13 +245,18 @@ coresight_control_assoc_ectdev(struct coresight_device *csdev, bool enable)
>  
>  	if (!ect_csdev)
>  		return 0;
> +	if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
> +		return 0;
>  
>  	if (enable) {
> -		if (ect_ops(ect_csdev)->enable)
> -			ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> +		ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> +		if (!ect_ret)
> +			csdev->ect_enabled = true;
>  	} else {
> -		if (ect_ops(ect_csdev)->disable)
> +		if (csdev->ect_enabled) {
>  			ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
> +			csdev->ect_enabled = false;
> +		}
>  	}
>  
>  	/* output warning if ECT enable is preventing trace operation */
> diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> index 3bb738f9a326..7d3c87e5b97c 100644
> --- a/include/linux/coresight.h
> +++ b/include/linux/coresight.h
> @@ -208,6 +208,7 @@ struct coresight_device {
>  	/* sysfs links between components */
>  	int nr_links;
>  	bool has_conns_grp;
> +	bool ect_enabled; /* true only if associated ect device is enabled */

We have cti_config::enable_req_count and cti_config::hw_enabled, both used in
cti_enable_hw() and cti_disable_hw().  I would have thought they'd be sufficient
to address the counting problems.  If they are not I would much rather see a
solution confined to the cti driver than in the core itself. 

Thanks,
Mathieu

>  };
>  
>  /*
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 21/24] coresight: cti: allow cti to be built as a module
  2020-08-07 11:11 ` [PATCH v8 21/24] coresight: cti: allow cti to be built as a module Tingwei Zhang
@ 2020-08-17 17:13   ` Mathieu Poirier
  2020-08-17 19:14     ` Mike Leach
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-17 17:13 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:50PM +0800, Tingwei Zhang wrote:
> Allow to build coresight-cti as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-cti by the Makefile
> - add an cti_remove function, for module unload
> - move cti_remove_conn_xrefs to cti_remove
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>

Mike, 

Please add a "Reviewed-by" tag once you have reviewed this patch.

> ---
>  drivers/hwtracing/coresight/Kconfig           |  5 ++++-
>  drivers/hwtracing/coresight/Makefile          |  4 ++--
>  .../{coresight-cti.c => coresight-cti-core.c} | 19 ++++++++++++++++++-
>  .../hwtracing/coresight/coresight-platform.c  |  1 +
>  drivers/hwtracing/coresight/coresight.c       |  1 +
>  5 files changed, 26 insertions(+), 4 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} (98%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index f31778dd0b5d..b04aae2ceecc 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -136,7 +136,7 @@ config CORESIGHT_CPU_DEBUG
>  	  module will be called coresight-cpu-debug.
>  
>  config CORESIGHT_CTI
> -	bool "CoreSight Cross Trigger Interface (CTI) driver"
> +	tristate "CoreSight Cross Trigger Interface (CTI) driver"
>  	depends on ARM || ARM64
>  	help
>  	  This driver provides support for CoreSight CTI and CTM components.
> @@ -147,6 +147,9 @@ config CORESIGHT_CTI
>  	  halt compared to disabling sources and sinks normally in driver
>  	  software.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight-cti.
> +
>  config CORESIGHT_CTI_INTEGRATION_REGS
>  	bool "Access CTI CoreSight Integration Registers"
>  	depends on CORESIGHT_CTI
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index f2a568b969c4..0359d5a1588f 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -19,6 +19,6 @@ coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> -obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o \
> -				coresight-cti-platform.o \
> +obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
> +coresight-cti-y := coresight-cti-core.o	coresight-cti-platform.o \
>  				coresight-cti-sysfs.o

Please align "coresight-cti-sysfs.o" with "coresight-cti-core.o".  The same
should be done for the etm3x driver.

> diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti-core.c
> similarity index 98%
> rename from drivers/hwtracing/coresight/coresight-cti.c
> rename to drivers/hwtracing/coresight/coresight-cti-core.c
> index 6bb06c5715db..ca31da6cf1c0 100644
> --- a/drivers/hwtracing/coresight/coresight-cti.c
> +++ b/drivers/hwtracing/coresight/coresight-cti-core.c
> @@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
>  	struct cti_drvdata *ect_item, *ect_tmp;
>  
>  	mutex_lock(&ect_mutex);
> -	cti_remove_conn_xrefs(drvdata);
>  	cti_pm_release(drvdata);
>  
>  	/* remove from the list */
> @@ -853,6 +852,18 @@ static void cti_device_release(struct device *dev)
>  	if (drvdata->csdev_release)
>  		drvdata->csdev_release(dev);
>  }
> +static int __exit cti_remove(struct amba_device *adev)
> +{
> +	struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	mutex_lock(&ect_mutex);
> +	cti_remove_conn_xrefs(drvdata);
> +	mutex_unlock(&ect_mutex);

The changelog point out this change but now _why_ it is done - please revise.

> +
> +	coresight_unregister(drvdata->csdev);
> +
> +	return 0;
> +}
>  
>  static int cti_probe(struct amba_device *adev, const struct amba_id *id)
>  {
> @@ -972,6 +983,7 @@ static const struct amba_id cti_ids[] = {
>  	CS_AMBA_UCI_ID(0x000bb9ed, uci_id_cti), /* Coresight CTI (SoC 600) */
>  	{ 0, 0},
>  };
> +MODULE_DEVICE_TABLE(amba, cti_ids);
>  
>  static struct amba_driver cti_driver = {
>  	.drv = {
> @@ -980,6 +992,7 @@ static struct amba_driver cti_driver = {
>  		.suppress_bind_attrs = true,
>  	},
>  	.probe		= cti_probe,
> +	.remove		= cti_remove,
>  	.id_table	= cti_ids,
>  };
>  
> @@ -1002,3 +1015,7 @@ static void __exit cti_exit(void)
>  
>  module_init(cti_init);
>  module_exit(cti_exit);
> +
> +MODULE_AUTHOR("Mike Leach <mike.leach@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index bfd44231d7ad..635d55c1d580 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -75,6 +75,7 @@ coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode)
>  	}
>  	return csdev;
>  }
> +EXPORT_SYMBOL_GPL(coresight_find_csdev_by_fwnode);
>  
>  #ifdef CONFIG_OF
>  static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep)
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> index 8dcd73ea33b4..f9566d667261 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight.c
> @@ -289,6 +289,7 @@ void coresight_set_assoc_ectdev_mutex(struct coresight_device *csdev,
>  	csdev->ect_dev = ect_csdev;
>  	mutex_unlock(&coresight_mutex);
>  }
> +EXPORT_SYMBOL_GPL(coresight_set_assoc_ectdev_mutex);
>  
>  static int coresight_enable_sink(struct coresight_device *csdev,
>  				 u32 mode, void *data)
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 23/24] coresight: catu: allow catu drivers to be built as modules
  2020-08-07 11:11 ` [PATCH v8 23/24] coresight: catu: allow catu drivers to be built as modules Tingwei Zhang
@ 2020-08-17 17:39   ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-17 17:39 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:52PM +0800, Tingwei Zhang wrote:
> Allow to build coresight-catu as modules, for ease of development.
> - Kconfig becomes a tristate, to allow =m
> - add catu_remove functions, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Reviewed-by: Mike Leach <mike.leach@linaro.org>
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>

For patches 22 and 23:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> ---
>  drivers/hwtracing/coresight/Kconfig          |  5 ++++-
>  drivers/hwtracing/coresight/coresight-catu.c | 15 +++++++++++++++
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index b04aae2ceecc..dfe407cde262 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -42,7 +42,7 @@ config CORESIGHT_LINK_AND_SINK_TMC
>  	  module will be called coresight-tmc.
>  
>  config CORESIGHT_CATU
> -	bool "Coresight Address Translation Unit (CATU) driver"
> +	tristate "Coresight Address Translation Unit (CATU) driver"
>  	depends on CORESIGHT_LINK_AND_SINK_TMC
>  	help
>  	   Enable support for the Coresight Address Translation Unit (CATU).
> @@ -52,6 +52,9 @@ config CORESIGHT_CATU
>  	   by looking up the provided table. CATU can also be used in pass-through
>  	   mode where the address is not translated.
>  
> +	   To compile this driver as a module, choose M here: the
> +	   module will be called coresight-catu.
> +
>  config CORESIGHT_SINK_TPIU
>  	tristate "Coresight generic TPIU driver"
>  	depends on CORESIGHT_LINKS_AND_SINKS
> diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c
> index 47696a7d24a7..99430f6cf5a5 100644
> --- a/drivers/hwtracing/coresight/coresight-catu.c
> +++ b/drivers/hwtracing/coresight/coresight-catu.c
> @@ -567,11 +567,21 @@ static int catu_probe(struct amba_device *adev, const struct amba_id *id)
>  	return ret;
>  }
>  
> +static int __exit catu_remove(struct amba_device *adev)
> +{
> +	struct catu_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +	coresight_unregister(drvdata->csdev);
> +	return 0;
> +}
> +
>  static struct amba_id catu_ids[] = {
>  	CS_AMBA_ID(0x000bb9ee),
>  	{},
>  };
>  
> +MODULE_DEVICE_TABLE(amba, catu_ids);
> +
>  static struct amba_driver catu_driver = {
>  	.drv = {
>  		.name			= "coresight-catu",
> @@ -579,6 +589,7 @@ static struct amba_driver catu_driver = {
>  		.suppress_bind_attrs	= true,
>  	},
>  	.probe				= catu_probe,
> +	.remove				= catu_remove,
>  	.id_table			= catu_ids,
>  };
>  
> @@ -601,3 +612,7 @@ static void __exit catu_exit(void)
>  
>  module_init(catu_init);
>  module_exit(catu_exit);
> +
> +MODULE_AUTHOR("Suzuki K Poulose <suzuki.poulose@arm.com>");
> +MODULE_DESCRIPTION("Arm CoreSight Address Translation Unit (CATU) Driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 24/24] coresight: allow the coresight core driver to be built as a module
  2020-08-07 11:11 ` [PATCH v8 24/24] coresight: allow the coresight core driver to be built as a module Tingwei Zhang
@ 2020-08-17 17:47   ` Mathieu Poirier
  2020-08-17 22:56     ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-17 17:47 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Leo Yan, linux-arm-kernel, Mike Leach

On Fri, Aug 07, 2020 at 07:11:53PM +0800, Tingwei Zhang wrote:
> Enhance coresight developer's efficiency to debug coresight drivers.
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight by the Makefile
> - modules can have only one init/exit, so we add the etm_perf
>   register/unregister function calls to the core init/exit
>   functions.
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> Tested-by: Mike Leach <mike.leach@linaro.org>
> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
>  drivers/hwtracing/coresight/Makefile          |  5 ++-
>  .../{coresight.c => coresight-core.c}         | 42 ++++++++++++++-----
>  .../hwtracing/coresight/coresight-etm-perf.c  |  8 +++-
>  .../hwtracing/coresight/coresight-etm-perf.h  |  3 ++
>  5 files changed, 48 insertions(+), 15 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight.c => coresight-core.c} (98%)
> 
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index dfe407cde262..c1198245461d 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -3,7 +3,7 @@
>  # Coresight configuration
>  #
>  menuconfig CORESIGHT
> -	bool "CoreSight Tracing Support"
> +	tristate "CoreSight Tracing Support"
>  	depends on ARM || ARM64
>  	depends on OF || ACPI
>  	select ARM_AMBA
> @@ -15,6 +15,9 @@ menuconfig CORESIGHT
>  	  specification and configure the right series of components when a
>  	  trace source gets enabled.
>  
> +	  To compile this driver as a module, choose M here: the
> +	  module will be called coresight.
> +
>  if CORESIGHT
>  config CORESIGHT_LINKS_AND_SINKS
>  	tristate "CoreSight Link and Sink drivers"
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index 0359d5a1588f..1b35b55bd420 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -2,8 +2,9 @@
>  #
>  # Makefile for CoreSight drivers.
>  #
> -obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
> -			   coresight-platform.o coresight-sysfs.o
> +obj-$(CONFIG_CORESIGHT) += coresight.o
> +coresight-y := coresight-core.o  coresight-etm-perf.o coresight-platform.o \
> +		coresight-sysfs.o
>  obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
>  coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
>  		      coresight-tmc-etr.o
> diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight-core.c
> similarity index 98%
> rename from drivers/hwtracing/coresight/coresight.c
> rename to drivers/hwtracing/coresight/coresight-core.c
> index f9566d667261..045416ac962f 100644
> --- a/drivers/hwtracing/coresight/coresight.c
> +++ b/drivers/hwtracing/coresight/coresight-core.c
> @@ -1462,16 +1462,6 @@ int coresight_timeout(void __iomem *addr, u32 offset, int position, int value)
>  }
>  EXPORT_SYMBOL_GPL(coresight_timeout);
>  
> -struct bus_type coresight_bustype = {
> -	.name	= "coresight",
> -};
> -
> -static int __init coresight_init(void)
> -{
> -	return bus_register(&coresight_bustype);
> -}
> -postcore_initcall(coresight_init);
> -
>  /*
>   * coresight_release_platform_data: Release references to the devices connected
>   * to the output port of this device.
> @@ -1680,3 +1670,35 @@ char *coresight_alloc_device_name(struct coresight_dev_list *dict,
>  	return name;
>  }
>  EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
> +
> +struct bus_type coresight_bustype = {
> +	.name	= "coresight",
> +};
> +
> +static int __init coresight_init(void)
> +{
> +	int ret;
> +
> +	ret = bus_register(&coresight_bustype);
> +	if (ret)
> +		return ret;
> +
> +	ret = etm_perf_init();
> +	if (ret)
> +		bus_unregister(&coresight_bustype);
> +
> +	return ret;
> +}
> +
> +static void __exit coresight_exit(void)
> +{
> +	etm_perf_exit();
> +	bus_unregister(&coresight_bustype);
> +}
> +
> +module_init(coresight_init);
> +module_exit(coresight_exit);
> +
> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");

Pratik deserves credit too.

With that:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

I am done reviewing this set.

Thank you for the patience,
Mathieu

> +MODULE_DESCRIPTION("Arm CoreSight tracer driver");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
> index 3728c44e5763..668b3ff11576 100644
> --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> @@ -591,7 +591,7 @@ void etm_perf_del_symlink_sink(struct coresight_device *csdev)
>  	csdev->ea = NULL;
>  }
>  
> -static int __init etm_perf_init(void)
> +int __init etm_perf_init(void)
>  {
>  	int ret;
>  
> @@ -618,4 +618,8 @@ static int __init etm_perf_init(void)
>  
>  	return ret;
>  }
> -device_initcall(etm_perf_init);
> +
> +void __exit etm_perf_exit(void)
> +{
> +	perf_pmu_unregister(&etm_pmu);
> +}
> diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
> index 05f89723e282..3e4f2ad5e193 100644
> --- a/drivers/hwtracing/coresight/coresight-etm-perf.h
> +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
> @@ -82,4 +82,7 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
>  
>  #endif /* CONFIG_CORESIGHT */
>  
> +int __init etm_perf_init(void);
> +void __exit etm_perf_exit(void);
> +
>  #endif
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 16/24] coresight: cti: add function to register cti associate ops
  2020-08-17 16:02   ` Mathieu Poirier
@ 2020-08-17 18:49     ` Mike Leach
  2020-08-18 17:16       ` Mathieu Poirier
  0 siblings, 1 reply; 68+ messages in thread
From: Mike Leach @ 2020-08-17 18:49 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	Coresight ML, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel

Hi Mathieu,

On Mon, 17 Aug 2020 at 17:02, Mathieu Poirier
<mathieu.poirier@linaro.org> wrote:
>
> On Fri, Aug 07, 2020 at 07:11:45PM +0800, Tingwei Zhang wrote:
> > Add static cti_assoc_ops to coresight core driver. Let cti
> > driver register the add_assoc and remove_assoc call back.
> > Avoid coresight core driver to depend on cti driver.
> >
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Tested-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  drivers/hwtracing/coresight/coresight-cti.c  | 32 ++++++++++++++++++--
> >  drivers/hwtracing/coresight/coresight-priv.h | 14 ++++-----
> >  drivers/hwtracing/coresight/coresight.c      | 21 +++++++++++--
> >  3 files changed, 53 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
> > index 3ccc703dc940..1f470c47ba70 100644
> > --- a/drivers/hwtracing/coresight/coresight-cti.c
> > +++ b/drivers/hwtracing/coresight/coresight-cti.c
> > @@ -589,7 +589,6 @@ void cti_add_assoc_to_csdev(struct coresight_device *csdev)
> >  cti_add_done:
> >       mutex_unlock(&ect_mutex);
> >  }
> > -EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
> >
> >  /*
> >   * Removing the associated devices is easier.
> > @@ -616,7 +615,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
> >       }
> >       mutex_unlock(&ect_mutex);
> >  }
> > -EXPORT_SYMBOL_GPL(cti_remove_assoc_from_csdev);
>
> Mike and Tingwei,
>
> It seems to me that functions cti_add_assoc_to_csdev() and
> cti_remote_assoc_from_csdev() don't have to be exported.  They could be called
> in cti_probe() and cti_device_release() with the ect_mutex held, the same way
> cti_update_conn_xrefs() and cti_remove_conn_xrefs() are.
>

The different functions handle two different initialisation & two
different teardown ordering scenarios
a) csdev - e.g. ETM is discovered & initialised before the associated
CTI. Therefore the CTI has to establish interconnections on creation -
calls cti_update_conn_xrefs() .
b) CTI is discovered before csdev - therefore the csdev calls
cti_add_assoc_to_csdev().
c) csdev is torn down before CTI - therefore csdev calls
cti_remove_assoc_from_csdev()
d) CTI is torn down before csdev - therefore calls cti_remove_conn_xrefs()

We can't call cti_add_assoc_to_csdev() in cti probe as the csdev does
not exist yet. Bear in mind that one CTI can actually be associated
with multiple different csdev devices - especially in the none CPU
bound infrastructure such as funnels and sinks.
This has always been the case since the first CTI set - but is even
more important now the modules can be removed / added as required.

Regards

Mike


> If my assessment is correct this patch would be simpler.
>
> Thanks,
> Mathieu
>
>
> > +
> > +/*
> > + * Operations to add and remove associated CTI.
> > + * Register to coresight core driver as call back function.
> > + */
> > +static struct cti_assoc_op cti_assoc_ops = {
> > +     .add = cti_add_assoc_to_csdev,
> > +     .remove = cti_remove_assoc_from_csdev
> > +};
> >
> >  /*
> >   * Update the cross references where the associated device was found
> > @@ -972,4 +979,23 @@ static struct amba_driver cti_driver = {
> >       .probe          = cti_probe,
> >       .id_table       = cti_ids,
> >  };
> > -builtin_amba_driver(cti_driver);
> > +
> > +static int __init cti_init(void)
> > +{
> > +     int ret;
> > +
> > +     ret = amba_driver_register(&cti_driver);
> > +     if (ret)
> > +             pr_info("Error registering cti driver\n");
> > +     coresight_set_cti_ops(&cti_assoc_ops);
> > +     return ret;
> > +}
> > +
> > +static void __exit cti_exit(void)
> > +{
> > +     coresight_remove_cti_ops();
> > +     amba_driver_unregister(&cti_driver);
> > +}
> > +
> > +module_init(cti_init);
> > +module_exit(cti_exit);
> > diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> > index dcb8aeb6af62..6cde6cf42554 100644
> > --- a/drivers/hwtracing/coresight/coresight-priv.h
> > +++ b/drivers/hwtracing/coresight/coresight-priv.h
> > @@ -173,15 +173,13 @@ static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
> >  static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
> >  #endif
> >
> > -#ifdef CONFIG_CORESIGHT_CTI
> > -extern void cti_add_assoc_to_csdev(struct coresight_device *csdev);
> > -extern void cti_remove_assoc_from_csdev(struct coresight_device *csdev);
> > +struct cti_assoc_op {
> > +     void (*add)(struct coresight_device *csdev);
> > +     void (*remove)(struct coresight_device *csdev);
> > +};
> >
> > -#else
> > -static inline void cti_add_assoc_to_csdev(struct coresight_device *csdev) {}
> > -static inline void
> > -cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}
> > -#endif
> > +extern void coresight_set_cti_ops(const struct cti_assoc_op *cti_op);
> > +extern void coresight_remove_cti_ops(void);
> >
> >  /*
> >   * Macros and inline functions to handle CoreSight UCI data and driver
> > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> > index 0b0e31577b9b..31b9ec8d3b9c 100644
> > --- a/drivers/hwtracing/coresight/coresight.c
> > +++ b/drivers/hwtracing/coresight/coresight.c
> > @@ -57,6 +57,20 @@ const u32 coresight_barrier_pkt[4] = {
> >               0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
> >  EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
> >
> > +static const struct cti_assoc_op *cti_assoc_ops;
> > +
> > +void coresight_set_cti_ops(const struct cti_assoc_op *cti_op)
> > +{
> > +     cti_assoc_ops = cti_op;
> > +}
> > +EXPORT_SYMBOL_GPL(coresight_set_cti_ops);
> > +
> > +void coresight_remove_cti_ops(void)
> > +{
> > +     cti_assoc_ops = NULL;
> > +}
> > +EXPORT_SYMBOL_GPL(coresight_remove_cti_ops);
> > +
> >  static int coresight_id_match(struct device *dev, void *data)
> >  {
> >       int trace_id, i_trace_id;
> > @@ -1242,7 +1256,8 @@ static void coresight_device_release(struct device *dev)
> >  {
> >       struct coresight_device *csdev = to_coresight_device(dev);
> >
> > -     cti_remove_assoc_from_csdev(csdev);
> > +     if (cti_assoc_ops && cti_assoc_ops->remove)
> > +             cti_assoc_ops->remove(csdev);
> >       fwnode_handle_put(csdev->dev.fwnode);
> >       kfree(csdev->refcnt);
> >       kfree(csdev);
> > @@ -1553,8 +1568,8 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
> >               ret = coresight_fixup_device_conns(csdev);
> >       if (!ret)
> >               ret = coresight_fixup_orphan_conns(csdev);
> > -     if (!ret)
> > -             cti_add_assoc_to_csdev(csdev);
> > +     if (!ret && cti_assoc_ops && cti_assoc_ops->add)
> > +             cti_assoc_ops->add(csdev);
> >
> >       mutex_unlock(&coresight_mutex);
> >       if (ret) {
> > --
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> > a Linux Foundation Collaborative Project
> >



-- 
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled
  2020-08-17 16:38   ` Mathieu Poirier
@ 2020-08-17 19:04     ` Mike Leach
  2020-08-18 17:39       ` Mathieu Poirier
  0 siblings, 1 reply; 68+ messages in thread
From: Mike Leach @ 2020-08-17 19:04 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	Coresight ML, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel

Hi Mathieu,

On Mon, 17 Aug 2020 at 17:38, Mathieu Poirier
<mathieu.poirier@linaro.org> wrote:
>
> On Fri, Aug 07, 2020 at 07:11:48PM +0800, Tingwei Zhang wrote:
> > If associated ect device is not enabled at first place, disable
> > routine should not be called. Add ect_enabled flag to check whether
> > ect device is enabled. Fix the issue in below case.  Ect device is
> > not available when associated coresight device enabled and the
> > association is established after coresight device is enabled.
> >
> > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > ---
> >  drivers/hwtracing/coresight/coresight.c | 11 ++++++++---
> >  include/linux/coresight.h               |  1 +
> >  2 files changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> > index d066411aa794..27ad8317e3cf 100644
> > --- a/drivers/hwtracing/coresight/coresight.c
> > +++ b/drivers/hwtracing/coresight/coresight.c
> > @@ -245,13 +245,18 @@ coresight_control_assoc_ectdev(struct coresight_device *csdev, bool enable)
> >
> >       if (!ect_csdev)
> >               return 0;
> > +     if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
> > +             return 0;
> >
> >       if (enable) {
> > -             if (ect_ops(ect_csdev)->enable)
> > -                     ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> > +             ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> > +             if (!ect_ret)
> > +                     csdev->ect_enabled = true;
> >       } else {
> > -             if (ect_ops(ect_csdev)->disable)
> > +             if (csdev->ect_enabled) {
> >                       ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
> > +                     csdev->ect_enabled = false;
> > +             }
> >       }
> >
> >       /* output warning if ECT enable is preventing trace operation */
> > diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> > index 3bb738f9a326..7d3c87e5b97c 100644
> > --- a/include/linux/coresight.h
> > +++ b/include/linux/coresight.h
> > @@ -208,6 +208,7 @@ struct coresight_device {
> >       /* sysfs links between components */
> >       int nr_links;
> >       bool has_conns_grp;
> > +     bool ect_enabled; /* true only if associated ect device is enabled */
>
> We have cti_config::enable_req_count and cti_config::hw_enabled, both used in
> cti_enable_hw() and cti_disable_hw().  I would have thought they'd be sufficient
> to address the counting problems.  If they are not I would much rather see a
> solution confined to the cti driver than in the core itself.
>

This is related to the fact that under sysfs it is possible under
sysfs to enable an etm e.g. etm1 without the cti module present, then
insert the CTI module, then enable another ETM e.g etm2.
This is an issue that is caused by the possibility of module load and
unload, and though inadvisable from a system usage point of view -
Tingwei correctly points out that it could happen.

At the point that the first ETM is enabled, the associated ect pointer
would be NULL, and thus no attempt to enable the ect/CTI is made. The
CTI module on load will set the ect pointers on all registered csdev
devices, including ones that are already enabled - etm1.
So when we come to disable etm1, it will try to disable a CTI that it
did not enable - a fact that cannot be counted in the CTI driver as it
was not there when the etm was enabled. So we have a flag in csdev to
record if this csdev did in fact enable the associated device, so it
is clear to disable it on shutdown.

Regards

Mike



> Thanks,
> Mathieu
>
> >  };
> >
> >  /*
> > --
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> > a Linux Foundation Collaborative Project
> >



-- 
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 21/24] coresight: cti: allow cti to be built as a module
  2020-08-17 17:13   ` Mathieu Poirier
@ 2020-08-17 19:14     ` Mike Leach
  2020-08-18 17:42       ` Mathieu Poirier
  0 siblings, 1 reply; 68+ messages in thread
From: Mike Leach @ 2020-08-17 19:14 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	Coresight ML, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel

Hi,

On Mon, 17 Aug 2020 at 18:13, Mathieu Poirier
<mathieu.poirier@linaro.org> wrote:
>
> On Fri, Aug 07, 2020 at 07:11:50PM +0800, Tingwei Zhang wrote:
> > Allow to build coresight-cti as a module, for ease of development.
> >
> > - Kconfig becomes a tristate, to allow =m
> > - append -core to source file name to allow module to
> >   be called coresight-cti by the Makefile
> > - add an cti_remove function, for module unload
> > - move cti_remove_conn_xrefs to cti_remove
> > - add a MODULE_DEVICE_TABLE for autoloading on boot
> >
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Tested-by: Mike Leach <mike.leach@linaro.org>
>
> Mike,
>
> Please add a "Reviewed-by" tag once you have reviewed this patch.
>

Sorry - not sure of the protocol - assumed that my tested-by implied
reviewed by.

Anyway...

Reviewed-by Mike Leach <mike.leach@linaro.org>

> > ---
> >  drivers/hwtracing/coresight/Kconfig           |  5 ++++-
> >  drivers/hwtracing/coresight/Makefile          |  4 ++--
> >  .../{coresight-cti.c => coresight-cti-core.c} | 19 ++++++++++++++++++-
> >  .../hwtracing/coresight/coresight-platform.c  |  1 +
> >  drivers/hwtracing/coresight/coresight.c       |  1 +
> >  5 files changed, 26 insertions(+), 4 deletions(-)
> >  rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} (98%)
> >
> > diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> > index f31778dd0b5d..b04aae2ceecc 100644
> > --- a/drivers/hwtracing/coresight/Kconfig
> > +++ b/drivers/hwtracing/coresight/Kconfig
> > @@ -136,7 +136,7 @@ config CORESIGHT_CPU_DEBUG
> >         module will be called coresight-cpu-debug.
> >
> >  config CORESIGHT_CTI
> > -     bool "CoreSight Cross Trigger Interface (CTI) driver"
> > +     tristate "CoreSight Cross Trigger Interface (CTI) driver"
> >       depends on ARM || ARM64
> >       help
> >         This driver provides support for CoreSight CTI and CTM components.
> > @@ -147,6 +147,9 @@ config CORESIGHT_CTI
> >         halt compared to disabling sources and sinks normally in driver
> >         software.
> >
> > +       To compile this driver as a module, choose M here: the
> > +       module will be called coresight-cti.
> > +
> >  config CORESIGHT_CTI_INTEGRATION_REGS
> >       bool "Access CTI CoreSight Integration Registers"
> >       depends on CORESIGHT_CTI
> > diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> > index f2a568b969c4..0359d5a1588f 100644
> > --- a/drivers/hwtracing/coresight/Makefile
> > +++ b/drivers/hwtracing/coresight/Makefile
> > @@ -19,6 +19,6 @@ coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> >  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> >  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> >  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> > -obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o \
> > -                             coresight-cti-platform.o \
> > +obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
> > +coresight-cti-y := coresight-cti-core.o      coresight-cti-platform.o \
> >                               coresight-cti-sysfs.o
>
> Please align "coresight-cti-sysfs.o" with "coresight-cti-core.o".  The same
> should be done for the etm3x driver.
>
> > diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti-core.c
> > similarity index 98%
> > rename from drivers/hwtracing/coresight/coresight-cti.c
> > rename to drivers/hwtracing/coresight/coresight-cti-core.c
> > index 6bb06c5715db..ca31da6cf1c0 100644
> > --- a/drivers/hwtracing/coresight/coresight-cti.c
> > +++ b/drivers/hwtracing/coresight/coresight-cti-core.c
> > @@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
> >       struct cti_drvdata *ect_item, *ect_tmp;
> >
> >       mutex_lock(&ect_mutex);
> > -     cti_remove_conn_xrefs(drvdata);
> >       cti_pm_release(drvdata);
> >
> >       /* remove from the list */
> > @@ -853,6 +852,18 @@ static void cti_device_release(struct device *dev)
> >       if (drvdata->csdev_release)
> >               drvdata->csdev_release(dev);
> >  }
> > +static int __exit cti_remove(struct amba_device *adev)
> > +{
> > +     struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > +
> > +     mutex_lock(&ect_mutex);
> > +     cti_remove_conn_xrefs(drvdata);
> > +     mutex_unlock(&ect_mutex);
>
> The changelog point out this change but now _why_ it is done - please revise.
>

By the time the system calls device_release, all the sysfs links have
gone so trying to remove them results in errors / crash. Not obvious
when the drivers were built in as this would be called while the
system was powering down, but very much noticeable when removing the
CTI moduie from a running system.

Regards

Mike

> > +
> > +     coresight_unregister(drvdata->csdev);
> > +
> > +     return 0;
> > +}
> >
> >  static int cti_probe(struct amba_device *adev, const struct amba_id *id)
> >  {
> > @@ -972,6 +983,7 @@ static const struct amba_id cti_ids[] = {
> >       CS_AMBA_UCI_ID(0x000bb9ed, uci_id_cti), /* Coresight CTI (SoC 600) */
> >       { 0, 0},
> >  };
> > +MODULE_DEVICE_TABLE(amba, cti_ids);
> >
> >  static struct amba_driver cti_driver = {
> >       .drv = {
> > @@ -980,6 +992,7 @@ static struct amba_driver cti_driver = {
> >               .suppress_bind_attrs = true,
> >       },
> >       .probe          = cti_probe,
> > +     .remove         = cti_remove,
> >       .id_table       = cti_ids,
> >  };
> >
> > @@ -1002,3 +1015,7 @@ static void __exit cti_exit(void)
> >
> >  module_init(cti_init);
> >  module_exit(cti_exit);
> > +
> > +MODULE_AUTHOR("Mike Leach <mike.leach@linaro.org>");
> > +MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
> > +MODULE_LICENSE("GPL v2");
> > diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> > index bfd44231d7ad..635d55c1d580 100644
> > --- a/drivers/hwtracing/coresight/coresight-platform.c
> > +++ b/drivers/hwtracing/coresight/coresight-platform.c
> > @@ -75,6 +75,7 @@ coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode)
> >       }
> >       return csdev;
> >  }
> > +EXPORT_SYMBOL_GPL(coresight_find_csdev_by_fwnode);
> >
> >  #ifdef CONFIG_OF
> >  static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep)
> > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> > index 8dcd73ea33b4..f9566d667261 100644
> > --- a/drivers/hwtracing/coresight/coresight.c
> > +++ b/drivers/hwtracing/coresight/coresight.c
> > @@ -289,6 +289,7 @@ void coresight_set_assoc_ectdev_mutex(struct coresight_device *csdev,
> >       csdev->ect_dev = ect_csdev;
> >       mutex_unlock(&coresight_mutex);
> >  }
> > +EXPORT_SYMBOL_GPL(coresight_set_assoc_ectdev_mutex);
> >
> >  static int coresight_enable_sink(struct coresight_device *csdev,
> >                                u32 mode, void *data)
> > --
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> > a Linux Foundation Collaborative Project
> >



-- 
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 17/24] coresight: cti: Fix remove sysfs link error
  2020-08-17 16:15   ` Mathieu Poirier
@ 2020-08-17 22:48     ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-17 22:48 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Tue, Aug 18, 2020 at 12:15:31AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:46PM +0800, Tingwei Zhang wrote:
> > From: Mike Leach <mike.leach@linaro.org>
> > 
> > CTI code to remove sysfs link to other devices on shutdown, incorrectly
> > tries to remove a single ended link when these are all double ended.
> This
> > implementation leaves elements in the link info structure undefined
> which
> > results in a crash in recent tests for driver module unload.
> > 
> > This patch corrects the link removal code.
> > 
> > Fixes: 73274abb6557 (coresight: cti: Add in sysfs links to other
> coresight devices)
> 
> This should be:
> 
> Fixes: 73274abb6557 ("coresight: cti: Add in sysfs links to other
> coresight devices")
> 

Sure. I'll put this into v9.

Thanks,
Tingwei
> > Reported-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  drivers/hwtracing/coresight/coresight-cti.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight-cti.c
> b/drivers/hwtracing/coresight/coresight-cti.c
> > index 1f470c47ba70..1c34db7d1b1b 100644
> > --- a/drivers/hwtracing/coresight/coresight-cti.c
> > +++ b/drivers/hwtracing/coresight/coresight-cti.c
> > @@ -511,12 +511,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata
> *drvdata,
> >  	return !link_err;
> >  }
> >  
> > -static void cti_remove_sysfs_link(struct cti_trig_con *tc)
> > +static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
> > +				  struct cti_trig_con *tc)
> >  {
> >  	struct coresight_sysfs_link link_info;
> >  
> > +	link_info.orig = drvdata->csdev;
> >  	link_info.orig_name = tc->con_dev_name;
> >  	link_info.target = tc->con_dev;
> > +	link_info.target_name = dev_name(&drvdata->csdev->dev);
> >  	coresight_remove_sysfs_link(&link_info);
> >  }
> >  
> > @@ -606,7 +609,7 @@ void cti_remove_assoc_from_csdev(struct
> coresight_device *csdev)
> >  		ctidev = &ctidrv->ctidev;
> >  		list_for_each_entry(tc, &ctidev->trig_cons, node) {
> >  			if (tc->con_dev == csdev->ect_dev) {
> > -				cti_remove_sysfs_link(tc);
> > +				cti_remove_sysfs_link(ctidrv, tc);
> >  				tc->con_dev = NULL;
> >  				break;
> >  			}
> > @@ -658,7 +661,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata
> *drvdata)
> >  		if (tc->con_dev) {
> >  			coresight_set_assoc_ectdev_mutex(tc->con_dev,
> >  							 NULL);
> > -			cti_remove_sysfs_link(tc);
> > +			cti_remove_sysfs_link(drvdata, tc);
> 
> With the above:
> 
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> >  			tc->con_dev = NULL;
> >  		}
> >  	}
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 24/24] coresight: allow the coresight core driver to be built as a module
  2020-08-17 17:47   ` Mathieu Poirier
@ 2020-08-17 22:56     ` Tingwei Zhang
  0 siblings, 0 replies; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-17 22:56 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	coresight, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Tue, Aug 18, 2020 at 01:47:22AM +0800, Mathieu Poirier wrote:
> On Fri, Aug 07, 2020 at 07:11:53PM +0800, Tingwei Zhang wrote:
> > Enhance coresight developer's efficiency to debug coresight drivers.
> > - Kconfig becomes a tristate, to allow =m
> > - append -core to source file name to allow module to
> >   be called coresight by the Makefile
> > - modules can have only one init/exit, so we add the etm_perf
> >   register/unregister function calls to the core init/exit
> >   functions.
> > - add a MODULE_DEVICE_TABLE for autoloading on boot
> > 
> > Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > Cc: Leo Yan <leo.yan@linaro.org>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Randy Dunlap <rdunlap@infradead.org>
> > Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Russell King <linux@armlinux.org.uk>
> > Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > Tested-by: Mike Leach <mike.leach@linaro.org>
> > Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> > ---
> >  drivers/hwtracing/coresight/Kconfig           |  5 ++-
> >  drivers/hwtracing/coresight/Makefile          |  5 ++-
> >  .../{coresight.c => coresight-core.c}         | 42 ++++++++++++++-----
> >  .../hwtracing/coresight/coresight-etm-perf.c  |  8 +++-
> >  .../hwtracing/coresight/coresight-etm-perf.h  |  3 ++
> >  5 files changed, 48 insertions(+), 15 deletions(-)
> >  rename drivers/hwtracing/coresight/{coresight.c => coresight-core.c}
> (98%)
> > 
> > diff --git a/drivers/hwtracing/coresight/Kconfig
> b/drivers/hwtracing/coresight/Kconfig
> > index dfe407cde262..c1198245461d 100644
> > --- a/drivers/hwtracing/coresight/Kconfig
> > +++ b/drivers/hwtracing/coresight/Kconfig
> > @@ -3,7 +3,7 @@
> >  # Coresight configuration
> >  #
> >  menuconfig CORESIGHT
> > -	bool "CoreSight Tracing Support"
> > +	tristate "CoreSight Tracing Support"
> >  	depends on ARM || ARM64
> >  	depends on OF || ACPI
> >  	select ARM_AMBA
> > @@ -15,6 +15,9 @@ menuconfig CORESIGHT
> >  	  specification and configure the right series of components when
> a
> >  	  trace source gets enabled.
> >  
> > +	  To compile this driver as a module, choose M here: the
> > +	  module will be called coresight.
> > +
> >  if CORESIGHT
> >  config CORESIGHT_LINKS_AND_SINKS
> >  	tristate "CoreSight Link and Sink drivers"
> > diff --git a/drivers/hwtracing/coresight/Makefile
> b/drivers/hwtracing/coresight/Makefile
> > index 0359d5a1588f..1b35b55bd420 100644
> > --- a/drivers/hwtracing/coresight/Makefile
> > +++ b/drivers/hwtracing/coresight/Makefile
> > @@ -2,8 +2,9 @@
> >  #
> >  # Makefile for CoreSight drivers.
> >  #
> > -obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
> > -			   coresight-platform.o coresight-sysfs.o
> > +obj-$(CONFIG_CORESIGHT) += coresight.o
> > +coresight-y := coresight-core.o  coresight-etm-perf.o
> coresight-platform.o \
> > +		coresight-sysfs.o
> >  obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
> >  coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
> >  		      coresight-tmc-etr.o
> > diff --git a/drivers/hwtracing/coresight/coresight.c
> b/drivers/hwtracing/coresight/coresight-core.c
> > similarity index 98%
> > rename from drivers/hwtracing/coresight/coresight.c
> > rename to drivers/hwtracing/coresight/coresight-core.c
> > index f9566d667261..045416ac962f 100644
> > --- a/drivers/hwtracing/coresight/coresight.c
> > +++ b/drivers/hwtracing/coresight/coresight-core.c
> > @@ -1462,16 +1462,6 @@ int coresight_timeout(void __iomem *addr, u32
> offset, int position, int value)
> >  }
> >  EXPORT_SYMBOL_GPL(coresight_timeout);
> >  
> > -struct bus_type coresight_bustype = {
> > -	.name	= "coresight",
> > -};
> > -
> > -static int __init coresight_init(void)
> > -{
> > -	return bus_register(&coresight_bustype);
> > -}
> > -postcore_initcall(coresight_init);
> > -
> >  /*
> >   * coresight_release_platform_data: Release references to the devices
> connected
> >   * to the output port of this device.
> > @@ -1680,3 +1670,35 @@ char *coresight_alloc_device_name(struct
> coresight_dev_list *dict,
> >  	return name;
> >  }
> >  EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
> > +
> > +struct bus_type coresight_bustype = {
> > +	.name	= "coresight",
> > +};
> > +
> > +static int __init coresight_init(void)
> > +{
> > +	int ret;
> > +
> > +	ret = bus_register(&coresight_bustype);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = etm_perf_init();
> > +	if (ret)
> > +		bus_unregister(&coresight_bustype);
> > +
> > +	return ret;
> > +}
> > +
> > +static void __exit coresight_exit(void)
> > +{
> > +	etm_perf_exit();
> > +	bus_unregister(&coresight_bustype);
> > +}
> > +
> > +module_init(coresight_init);
> > +module_exit(coresight_exit);
> > +
> > +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> 
> Pratik deserves credit too.
> 
> With that:
> 
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> I am done reviewing this set.
> 
> Thank you for the patience,
> Mathieu
> 

Thanks for the review of this big patchset, Mathieu.
Sorry for some silly mistakes.

Thanks,
Tingwei

> > +MODULE_DESCRIPTION("Arm CoreSight tracer driver");
> > +MODULE_LICENSE("GPL v2");
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c
> b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > index 3728c44e5763..668b3ff11576 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > @@ -591,7 +591,7 @@ void etm_perf_del_symlink_sink(struct
> coresight_device *csdev)
> >  	csdev->ea = NULL;
> >  }
> >  
> > -static int __init etm_perf_init(void)
> > +int __init etm_perf_init(void)
> >  {
> >  	int ret;
> >  
> > @@ -618,4 +618,8 @@ static int __init etm_perf_init(void)
> >  
> >  	return ret;
> >  }
> > -device_initcall(etm_perf_init);
> > +
> > +void __exit etm_perf_exit(void)
> > +{
> > +	perf_pmu_unregister(&etm_pmu);
> > +}
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h
> b/drivers/hwtracing/coresight/coresight-etm-perf.h
> > index 05f89723e282..3e4f2ad5e193 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.h
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
> > @@ -82,4 +82,7 @@ static inline void *etm_perf_sink_config(struct
> perf_output_handle *handle)
> >  
> >  #endif /* CONFIG_CORESIGHT */
> >  
> > +int __init etm_perf_init(void);
> > +void __exit etm_perf_exit(void);
> > +
> >  #endif
> > -- 
> > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > a Linux Foundation Collaborative Project
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 16/24] coresight: cti: add function to register cti associate ops
  2020-08-17 18:49     ` Mike Leach
@ 2020-08-18 17:16       ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-18 17:16 UTC (permalink / raw)
  To: Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	Coresight ML, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel

Good day,

On Mon, Aug 17, 2020 at 07:49:16PM +0100, Mike Leach wrote:
> Hi Mathieu,
> 
> On Mon, 17 Aug 2020 at 17:02, Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> >
> > On Fri, Aug 07, 2020 at 07:11:45PM +0800, Tingwei Zhang wrote:
> > > Add static cti_assoc_ops to coresight core driver. Let cti
> > > driver register the add_assoc and remove_assoc call back.
> > > Avoid coresight core driver to depend on cti driver.
> > >
> > > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > > Tested-by: Mike Leach <mike.leach@linaro.org>
> > > ---
> > >  drivers/hwtracing/coresight/coresight-cti.c  | 32 ++++++++++++++++++--
> > >  drivers/hwtracing/coresight/coresight-priv.h | 14 ++++-----
> > >  drivers/hwtracing/coresight/coresight.c      | 21 +++++++++++--
> > >  3 files changed, 53 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti.c
> > > index 3ccc703dc940..1f470c47ba70 100644
> > > --- a/drivers/hwtracing/coresight/coresight-cti.c
> > > +++ b/drivers/hwtracing/coresight/coresight-cti.c
> > > @@ -589,7 +589,6 @@ void cti_add_assoc_to_csdev(struct coresight_device *csdev)
> > >  cti_add_done:
> > >       mutex_unlock(&ect_mutex);
> > >  }
> > > -EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
> > >
> > >  /*
> > >   * Removing the associated devices is easier.
> > > @@ -616,7 +615,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
> > >       }
> > >       mutex_unlock(&ect_mutex);
> > >  }
> > > -EXPORT_SYMBOL_GPL(cti_remove_assoc_from_csdev);
> >
> > Mike and Tingwei,
> >
> > It seems to me that functions cti_add_assoc_to_csdev() and
> > cti_remote_assoc_from_csdev() don't have to be exported.  They could be called
> > in cti_probe() and cti_device_release() with the ect_mutex held, the same way
> > cti_update_conn_xrefs() and cti_remove_conn_xrefs() are.
> >
> 
> The different functions handle two different initialisation & two
> different teardown ordering scenarios
> a) csdev - e.g. ETM is discovered & initialised before the associated
> CTI. Therefore the CTI has to establish interconnections on creation -
> calls cti_update_conn_xrefs() .
> b) CTI is discovered before csdev - therefore the csdev calls
> cti_add_assoc_to_csdev().
> c) csdev is torn down before CTI - therefore csdev calls
> cti_remove_assoc_from_csdev()
> d) CTI is torn down before csdev - therefore calls cti_remove_conn_xrefs()
> 
> We can't call cti_add_assoc_to_csdev() in cti probe as the csdev does
> not exist yet. Bear in mind that one CTI can actually be associated
> with multiple different csdev devices - especially in the none CPU
> bound infrastructure such as funnels and sinks.

Yes, I see your point now.  The problem needs to be viewed from other devices'
(than CTI) perspective.  And that part is done in
coresight_register/unregister().

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

> This has always been the case since the first CTI set - but is even
> more important now the modules can be removed / added as required.
> 
> Regards
> 
> Mike
> 
> 
> > If my assessment is correct this patch would be simpler.
> >
> > Thanks,
> > Mathieu
> >
> >
> > > +
> > > +/*
> > > + * Operations to add and remove associated CTI.
> > > + * Register to coresight core driver as call back function.
> > > + */
> > > +static struct cti_assoc_op cti_assoc_ops = {
> > > +     .add = cti_add_assoc_to_csdev,
> > > +     .remove = cti_remove_assoc_from_csdev
> > > +};
> > >
> > >  /*
> > >   * Update the cross references where the associated device was found
> > > @@ -972,4 +979,23 @@ static struct amba_driver cti_driver = {
> > >       .probe          = cti_probe,
> > >       .id_table       = cti_ids,
> > >  };
> > > -builtin_amba_driver(cti_driver);
> > > +
> > > +static int __init cti_init(void)
> > > +{
> > > +     int ret;
> > > +
> > > +     ret = amba_driver_register(&cti_driver);
> > > +     if (ret)
> > > +             pr_info("Error registering cti driver\n");
> > > +     coresight_set_cti_ops(&cti_assoc_ops);
> > > +     return ret;
> > > +}
> > > +
> > > +static void __exit cti_exit(void)
> > > +{
> > > +     coresight_remove_cti_ops();
> > > +     amba_driver_unregister(&cti_driver);
> > > +}
> > > +
> > > +module_init(cti_init);
> > > +module_exit(cti_exit);
> > > diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h
> > > index dcb8aeb6af62..6cde6cf42554 100644
> > > --- a/drivers/hwtracing/coresight/coresight-priv.h
> > > +++ b/drivers/hwtracing/coresight/coresight-priv.h
> > > @@ -173,15 +173,13 @@ static inline int etm_readl_cp14(u32 off, unsigned int *val) { return 0; }
> > >  static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
> > >  #endif
> > >
> > > -#ifdef CONFIG_CORESIGHT_CTI
> > > -extern void cti_add_assoc_to_csdev(struct coresight_device *csdev);
> > > -extern void cti_remove_assoc_from_csdev(struct coresight_device *csdev);
> > > +struct cti_assoc_op {
> > > +     void (*add)(struct coresight_device *csdev);
> > > +     void (*remove)(struct coresight_device *csdev);
> > > +};
> > >
> > > -#else
> > > -static inline void cti_add_assoc_to_csdev(struct coresight_device *csdev) {}
> > > -static inline void
> > > -cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}
> > > -#endif
> > > +extern void coresight_set_cti_ops(const struct cti_assoc_op *cti_op);
> > > +extern void coresight_remove_cti_ops(void);
> > >
> > >  /*
> > >   * Macros and inline functions to handle CoreSight UCI data and driver
> > > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> > > index 0b0e31577b9b..31b9ec8d3b9c 100644
> > > --- a/drivers/hwtracing/coresight/coresight.c
> > > +++ b/drivers/hwtracing/coresight/coresight.c
> > > @@ -57,6 +57,20 @@ const u32 coresight_barrier_pkt[4] = {
> > >               0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
> > >  EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
> > >
> > > +static const struct cti_assoc_op *cti_assoc_ops;
> > > +
> > > +void coresight_set_cti_ops(const struct cti_assoc_op *cti_op)
> > > +{
> > > +     cti_assoc_ops = cti_op;
> > > +}
> > > +EXPORT_SYMBOL_GPL(coresight_set_cti_ops);
> > > +
> > > +void coresight_remove_cti_ops(void)
> > > +{
> > > +     cti_assoc_ops = NULL;
> > > +}
> > > +EXPORT_SYMBOL_GPL(coresight_remove_cti_ops);
> > > +
> > >  static int coresight_id_match(struct device *dev, void *data)
> > >  {
> > >       int trace_id, i_trace_id;
> > > @@ -1242,7 +1256,8 @@ static void coresight_device_release(struct device *dev)
> > >  {
> > >       struct coresight_device *csdev = to_coresight_device(dev);
> > >
> > > -     cti_remove_assoc_from_csdev(csdev);
> > > +     if (cti_assoc_ops && cti_assoc_ops->remove)
> > > +             cti_assoc_ops->remove(csdev);
> > >       fwnode_handle_put(csdev->dev.fwnode);
> > >       kfree(csdev->refcnt);
> > >       kfree(csdev);
> > > @@ -1553,8 +1568,8 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
> > >               ret = coresight_fixup_device_conns(csdev);
> > >       if (!ret)
> > >               ret = coresight_fixup_orphan_conns(csdev);
> > > -     if (!ret)
> > > -             cti_add_assoc_to_csdev(csdev);
> > > +     if (!ret && cti_assoc_ops && cti_assoc_ops->add)
> > > +             cti_assoc_ops->add(csdev);
> > >
> > >       mutex_unlock(&coresight_mutex);
> > >       if (ret) {
> > > --
> > > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> > > a Linux Foundation Collaborative Project
> > >
> 
> 
> 
> -- 
> Mike Leach
> Principal Engineer, ARM Ltd.
> Manchester Design Centre. UK

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled
  2020-08-17 19:04     ` Mike Leach
@ 2020-08-18 17:39       ` Mathieu Poirier
  2020-08-19  1:55         ` Tingwei Zhang
  0 siblings, 1 reply; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-18 17:39 UTC (permalink / raw)
  To: Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	Coresight ML, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel

On Mon, Aug 17, 2020 at 08:04:06PM +0100, Mike Leach wrote:
> Hi Mathieu,
> 
> On Mon, 17 Aug 2020 at 17:38, Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> >
> > On Fri, Aug 07, 2020 at 07:11:48PM +0800, Tingwei Zhang wrote:
> > > If associated ect device is not enabled at first place, disable
> > > routine should not be called. Add ect_enabled flag to check whether
> > > ect device is enabled. Fix the issue in below case.  Ect device is
> > > not available when associated coresight device enabled and the
> > > association is established after coresight device is enabled.
> > >
> > > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > > ---
> > >  drivers/hwtracing/coresight/coresight.c | 11 ++++++++---
> > >  include/linux/coresight.h               |  1 +
> > >  2 files changed, 9 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> > > index d066411aa794..27ad8317e3cf 100644
> > > --- a/drivers/hwtracing/coresight/coresight.c
> > > +++ b/drivers/hwtracing/coresight/coresight.c
> > > @@ -245,13 +245,18 @@ coresight_control_assoc_ectdev(struct coresight_device *csdev, bool enable)
> > >
> > >       if (!ect_csdev)
> > >               return 0;
> > > +     if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
> > > +             return 0;
> > >
> > >       if (enable) {
> > > -             if (ect_ops(ect_csdev)->enable)
> > > -                     ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> > > +             ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> > > +             if (!ect_ret)
> > > +                     csdev->ect_enabled = true;
> > >       } else {
> > > -             if (ect_ops(ect_csdev)->disable)
> > > +             if (csdev->ect_enabled) {
> > >                       ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
> > > +                     csdev->ect_enabled = false;
> > > +             }
> > >       }
> > >
> > >       /* output warning if ECT enable is preventing trace operation */
> > > diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> > > index 3bb738f9a326..7d3c87e5b97c 100644
> > > --- a/include/linux/coresight.h
> > > +++ b/include/linux/coresight.h
> > > @@ -208,6 +208,7 @@ struct coresight_device {
> > >       /* sysfs links between components */
> > >       int nr_links;
> > >       bool has_conns_grp;
> > > +     bool ect_enabled; /* true only if associated ect device is enabled */
> >
> > We have cti_config::enable_req_count and cti_config::hw_enabled, both used in
> > cti_enable_hw() and cti_disable_hw().  I would have thought they'd be sufficient
> > to address the counting problems.  If they are not I would much rather see a
> > solution confined to the cti driver than in the core itself.
> >
> 
> This is related to the fact that under sysfs it is possible under
> sysfs to enable an etm e.g. etm1 without the cti module present, then
> insert the CTI module, then enable another ETM e.g etm2.
> This is an issue that is caused by the possibility of module load and
> unload, and though inadvisable from a system usage point of view -
> Tingwei correctly points out that it could happen.
> 
> At the point that the first ETM is enabled, the associated ect pointer
> would be NULL, and thus no attempt to enable the ect/CTI is made. The
> CTI module on load will set the ect pointers on all registered csdev
> devices, including ones that are already enabled - etm1.
> So when we come to disable etm1, it will try to disable a CTI that it
> did not enable - a fact that cannot be counted in the CTI driver as it
> was not there when the etm was enabled. So we have a flag in csdev to
> record if this csdev did in fact enable the associated device, so it
> is clear to disable it on shutdown.

In the above example the csdev structures associated with ETM1 and ETM2 will
have different csdev->ect_dev pointers, one for each CTI it is assocated with.
And I would think the reference count for CTI1 would not have been incremented
since it was never enabled.

What am I missing?

> 
> Regards
> 
> Mike
> 
> 
> 
> > Thanks,
> > Mathieu
> >
> > >  };
> > >
> > >  /*
> > > --
> > > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> > > a Linux Foundation Collaborative Project
> > >
> 
> 
> 
> -- 
> Mike Leach
> Principal Engineer, ARM Ltd.
> Manchester Design Centre. UK

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 21/24] coresight: cti: allow cti to be built as a module
  2020-08-17 19:14     ` Mike Leach
@ 2020-08-18 17:42       ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-18 17:42 UTC (permalink / raw)
  To: Mike Leach
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Mao Jinlong,
	Suzuki K Poulose, Alexander Shishkin, Greg Kroah-Hartman,
	Coresight ML, Randy Dunlap, Mian Yousaf Kaukab, Russell King,
	Tingwei Zhang, Leo Yan, linux-arm-kernel

On Mon, Aug 17, 2020 at 08:14:29PM +0100, Mike Leach wrote:
> Hi,
> 
> On Mon, 17 Aug 2020 at 18:13, Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> >
> > On Fri, Aug 07, 2020 at 07:11:50PM +0800, Tingwei Zhang wrote:
> > > Allow to build coresight-cti as a module, for ease of development.
> > >
> > > - Kconfig becomes a tristate, to allow =m
> > > - append -core to source file name to allow module to
> > >   be called coresight-cti by the Makefile
> > > - add an cti_remove function, for module unload
> > > - move cti_remove_conn_xrefs to cti_remove
> > > - add a MODULE_DEVICE_TABLE for autoloading on boot
> > >
> > > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > > Tested-by: Mike Leach <mike.leach@linaro.org>
> >
> > Mike,
> >
> > Please add a "Reviewed-by" tag once you have reviewed this patch.
> >
> 
> Sorry - not sure of the protocol - assumed that my tested-by implied
> reviewed by.

One does not imply the other - in fact many people keep to testing patches
only.  

> 
> Anyway...
> 
> Reviewed-by Mike Leach <mike.leach@linaro.org>
> 
> > > ---
> > >  drivers/hwtracing/coresight/Kconfig           |  5 ++++-
> > >  drivers/hwtracing/coresight/Makefile          |  4 ++--
> > >  .../{coresight-cti.c => coresight-cti-core.c} | 19 ++++++++++++++++++-
> > >  .../hwtracing/coresight/coresight-platform.c  |  1 +
> > >  drivers/hwtracing/coresight/coresight.c       |  1 +
> > >  5 files changed, 26 insertions(+), 4 deletions(-)
> > >  rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} (98%)
> > >
> > > diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> > > index f31778dd0b5d..b04aae2ceecc 100644
> > > --- a/drivers/hwtracing/coresight/Kconfig
> > > +++ b/drivers/hwtracing/coresight/Kconfig
> > > @@ -136,7 +136,7 @@ config CORESIGHT_CPU_DEBUG
> > >         module will be called coresight-cpu-debug.
> > >
> > >  config CORESIGHT_CTI
> > > -     bool "CoreSight Cross Trigger Interface (CTI) driver"
> > > +     tristate "CoreSight Cross Trigger Interface (CTI) driver"
> > >       depends on ARM || ARM64
> > >       help
> > >         This driver provides support for CoreSight CTI and CTM components.
> > > @@ -147,6 +147,9 @@ config CORESIGHT_CTI
> > >         halt compared to disabling sources and sinks normally in driver
> > >         software.
> > >
> > > +       To compile this driver as a module, choose M here: the
> > > +       module will be called coresight-cti.
> > > +
> > >  config CORESIGHT_CTI_INTEGRATION_REGS
> > >       bool "Access CTI CoreSight Integration Registers"
> > >       depends on CORESIGHT_CTI
> > > diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> > > index f2a568b969c4..0359d5a1588f 100644
> > > --- a/drivers/hwtracing/coresight/Makefile
> > > +++ b/drivers/hwtracing/coresight/Makefile
> > > @@ -19,6 +19,6 @@ coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> > >  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> > >  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> > >  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> > > -obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o \
> > > -                             coresight-cti-platform.o \
> > > +obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
> > > +coresight-cti-y := coresight-cti-core.o      coresight-cti-platform.o \
> > >                               coresight-cti-sysfs.o
> >
> > Please align "coresight-cti-sysfs.o" with "coresight-cti-core.o".  The same
> > should be done for the etm3x driver.
> >
> > > diff --git a/drivers/hwtracing/coresight/coresight-cti.c b/drivers/hwtracing/coresight/coresight-cti-core.c
> > > similarity index 98%
> > > rename from drivers/hwtracing/coresight/coresight-cti.c
> > > rename to drivers/hwtracing/coresight/coresight-cti-core.c
> > > index 6bb06c5715db..ca31da6cf1c0 100644
> > > --- a/drivers/hwtracing/coresight/coresight-cti.c
> > > +++ b/drivers/hwtracing/coresight/coresight-cti-core.c
> > > @@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
> > >       struct cti_drvdata *ect_item, *ect_tmp;
> > >
> > >       mutex_lock(&ect_mutex);
> > > -     cti_remove_conn_xrefs(drvdata);
> > >       cti_pm_release(drvdata);
> > >
> > >       /* remove from the list */
> > > @@ -853,6 +852,18 @@ static void cti_device_release(struct device *dev)
> > >       if (drvdata->csdev_release)
> > >               drvdata->csdev_release(dev);
> > >  }
> > > +static int __exit cti_remove(struct amba_device *adev)
> > > +{
> > > +     struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > > +
> > > +     mutex_lock(&ect_mutex);
> > > +     cti_remove_conn_xrefs(drvdata);
> > > +     mutex_unlock(&ect_mutex);
> >
> > The changelog point out this change but now _why_ it is done - please revise.
> >
> 
> By the time the system calls device_release, all the sysfs links have
> gone so trying to remove them results in errors / crash. Not obvious
> when the drivers were built in as this would be called while the
> system was powering down, but very much noticeable when removing the
> CTI moduie from a running system.
> 
> Regards
> 
> Mike
> 
> > > +
> > > +     coresight_unregister(drvdata->csdev);
> > > +
> > > +     return 0;
> > > +}
> > >
> > >  static int cti_probe(struct amba_device *adev, const struct amba_id *id)
> > >  {
> > > @@ -972,6 +983,7 @@ static const struct amba_id cti_ids[] = {
> > >       CS_AMBA_UCI_ID(0x000bb9ed, uci_id_cti), /* Coresight CTI (SoC 600) */
> > >       { 0, 0},
> > >  };
> > > +MODULE_DEVICE_TABLE(amba, cti_ids);
> > >
> > >  static struct amba_driver cti_driver = {
> > >       .drv = {
> > > @@ -980,6 +992,7 @@ static struct amba_driver cti_driver = {
> > >               .suppress_bind_attrs = true,
> > >       },
> > >       .probe          = cti_probe,
> > > +     .remove         = cti_remove,
> > >       .id_table       = cti_ids,
> > >  };
> > >
> > > @@ -1002,3 +1015,7 @@ static void __exit cti_exit(void)
> > >
> > >  module_init(cti_init);
> > >  module_exit(cti_exit);
> > > +
> > > +MODULE_AUTHOR("Mike Leach <mike.leach@linaro.org>");
> > > +MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
> > > +MODULE_LICENSE("GPL v2");
> > > diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> > > index bfd44231d7ad..635d55c1d580 100644
> > > --- a/drivers/hwtracing/coresight/coresight-platform.c
> > > +++ b/drivers/hwtracing/coresight/coresight-platform.c
> > > @@ -75,6 +75,7 @@ coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode)
> > >       }
> > >       return csdev;
> > >  }
> > > +EXPORT_SYMBOL_GPL(coresight_find_csdev_by_fwnode);
> > >
> > >  #ifdef CONFIG_OF
> > >  static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep)
> > > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c
> > > index 8dcd73ea33b4..f9566d667261 100644
> > > --- a/drivers/hwtracing/coresight/coresight.c
> > > +++ b/drivers/hwtracing/coresight/coresight.c
> > > @@ -289,6 +289,7 @@ void coresight_set_assoc_ectdev_mutex(struct coresight_device *csdev,
> > >       csdev->ect_dev = ect_csdev;
> > >       mutex_unlock(&coresight_mutex);
> > >  }
> > > +EXPORT_SYMBOL_GPL(coresight_set_assoc_ectdev_mutex);
> > >
> > >  static int coresight_enable_sink(struct coresight_device *csdev,
> > >                                u32 mode, void *data)
> > > --
> > > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> > > a Linux Foundation Collaborative Project
> > >
> 
> 
> 
> -- 
> Mike Leach
> Principal Engineer, ARM Ltd.
> Manchester Design Centre. UK

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled
  2020-08-18 17:39       ` Mathieu Poirier
@ 2020-08-19  1:55         ` Tingwei Zhang
  2020-08-19 19:50           ` Mathieu Poirier
  0 siblings, 1 reply; 68+ messages in thread
From: Tingwei Zhang @ 2020-08-19  1:55 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Suzuki K Poulose,
	Alexander Shishkin, Greg Kroah-Hartman, Coresight ML,
	Mao Jinlong, Mian Yousaf Kaukab, Russell King, Randy Dunlap,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Wed, Aug 19, 2020 at 01:39:09AM +0800, Mathieu Poirier wrote:
> On Mon, Aug 17, 2020 at 08:04:06PM +0100, Mike Leach wrote:
> > Hi Mathieu,
> > 
> > On Mon, 17 Aug 2020 at 17:38, Mathieu Poirier
> > <mathieu.poirier@linaro.org> wrote:
> > >
> > > On Fri, Aug 07, 2020 at 07:11:48PM +0800, Tingwei Zhang wrote:
> > > > If associated ect device is not enabled at first place, disable
> > > > routine should not be called. Add ect_enabled flag to check whether
> > > > ect device is enabled. Fix the issue in below case.  Ect device is
> > > > not available when associated coresight device enabled and the
> > > > association is established after coresight device is enabled.
> > > >
> > > > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > > > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > > > ---
> > > >  drivers/hwtracing/coresight/coresight.c | 11 ++++++++---
> > > >  include/linux/coresight.h               |  1 +
> > > >  2 files changed, 9 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/drivers/hwtracing/coresight/coresight.c
> b/drivers/hwtracing/coresight/coresight.c
> > > > index d066411aa794..27ad8317e3cf 100644
> > > > --- a/drivers/hwtracing/coresight/coresight.c
> > > > +++ b/drivers/hwtracing/coresight/coresight.c
> > > > @@ -245,13 +245,18 @@ coresight_control_assoc_ectdev(struct
> coresight_device *csdev, bool enable)
> > > >
> > > >       if (!ect_csdev)
> > > >               return 0;
> > > > +     if ((!ect_ops(ect_csdev)->enable) ||
> (!ect_ops(ect_csdev)->disable))
> > > > +             return 0;
> > > >
> > > >       if (enable) {
> > > > -             if (ect_ops(ect_csdev)->enable)
> > > > -                     ect_ret =
> ect_ops(ect_csdev)->enable(ect_csdev);
> > > > +             ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> > > > +             if (!ect_ret)
> > > > +                     csdev->ect_enabled = true;
> > > >       } else {
> > > > -             if (ect_ops(ect_csdev)->disable)
> > > > +             if (csdev->ect_enabled) {
> > > >                       ect_ret =
> ect_ops(ect_csdev)->disable(ect_csdev);
> > > > +                     csdev->ect_enabled = false;
> > > > +             }
> > > >       }
> > > >
> > > >       /* output warning if ECT enable is preventing trace operation
> */
> > > > diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> > > > index 3bb738f9a326..7d3c87e5b97c 100644
> > > > --- a/include/linux/coresight.h
> > > > +++ b/include/linux/coresight.h
> > > > @@ -208,6 +208,7 @@ struct coresight_device {
> > > >       /* sysfs links between components */
> > > >       int nr_links;
> > > >       bool has_conns_grp;
> > > > +     bool ect_enabled; /* true only if associated ect device is
> enabled */
> > >
> > > We have cti_config::enable_req_count and cti_config::hw_enabled, both
> used in
> > > cti_enable_hw() and cti_disable_hw().  I would have thought they'd be
> sufficient
> > > to address the counting problems.  If they are not I would much rather
> see a
> > > solution confined to the cti driver than in the core itself.
> > >
> > 
> > This is related to the fact that under sysfs it is possible under
> > sysfs to enable an etm e.g. etm1 without the cti module present, then
> > insert the CTI module, then enable another ETM e.g etm2.
> > This is an issue that is caused by the possibility of module load and
> > unload, and though inadvisable from a system usage point of view -
> > Tingwei correctly points out that it could happen.
> > 
> > At the point that the first ETM is enabled, the associated ect pointer
> > would be NULL, and thus no attempt to enable the ect/CTI is made. The
> > CTI module on load will set the ect pointers on all registered csdev
> > devices, including ones that are already enabled - etm1.
> > So when we come to disable etm1, it will try to disable a CTI that it
> > did not enable - a fact that cannot be counted in the CTI driver as it
> > was not there when the etm was enabled. So we have a flag in csdev to
> > record if this csdev did in fact enable the associated device, so it
> > is clear to disable it on shutdown.
> 
> In the above example the csdev structures associated with ETM1 and ETM2
> will
> have different csdev->ect_dev pointers, one for each CTI it is assocated
> with.
> And I would think the reference count for CTI1 would not have been
> incremented
> since it was never enabled.
> 
> What am I missing?
> 

The issue here is we could have two or more coresght devices associated
to single CTI device, especially for sys cti case. For example, we have
coresight devcie A and B. They are assocaited to CTI device C. CTI module
is not loaded at first. Device A is enabled. CTI C is not enabled. Then
CTI module is loaded. Device B is enabled. CTI C is enabled with
enable_req_count = 1. Device A is disabled. It decrease enable_req_count
to 0, so CTI C is disabled. It's kinda weird to me that CTI C is enabled
with device B and disabled by device A.

The point is we need some flag in coresight device structure to save the
status of associated CTI enablement when CTI module is not loaded yet.

Thanks,
Tingwei

> > 
> > Regards
> > 
> > Mike
> > 
> > 
> > 
> > > Thanks,
> > > Mathieu
> > >
> > > >  };
> > > >
> > > >  /*
> > > > --
> > > > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
> > > > a Linux Foundation Collaborative Project
> > > >
> > 
> > 
> > 
> > -- 
> > Mike Leach
> > Principal Engineer, ARM Ltd.
> > Manchester Design Centre. UK
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled
  2020-08-19  1:55         ` Tingwei Zhang
@ 2020-08-19 19:50           ` Mathieu Poirier
  0 siblings, 0 replies; 68+ messages in thread
From: Mathieu Poirier @ 2020-08-19 19:50 UTC (permalink / raw)
  To: Tingwei Zhang
  Cc: tsoni, Sai Prakash Ranjan, Kim Phillips, Suzuki K Poulose,
	Alexander Shishkin, Greg Kroah-Hartman, Coresight ML,
	Mao Jinlong, Mian Yousaf Kaukab, Russell King, Randy Dunlap,
	Tingwei Zhang, Leo Yan, linux-arm-kernel, Mike Leach

On Wed, Aug 19, 2020 at 09:55:33AM +0800, Tingwei Zhang wrote:
> On Wed, Aug 19, 2020 at 01:39:09AM +0800, Mathieu Poirier wrote:
> > On Mon, Aug 17, 2020 at 08:04:06PM +0100, Mike Leach wrote:
> > > Hi Mathieu,
> > > 
> > > On Mon, 17 Aug 2020 at 17:38, Mathieu Poirier
> > > <mathieu.poirier@linaro.org> wrote:
> > > >
> > > > On Fri, Aug 07, 2020 at 07:11:48PM +0800, Tingwei Zhang wrote:
> > > > > If associated ect device is not enabled at first place, disable
> > > > > routine should not be called. Add ect_enabled flag to check whether
> > > > > ect device is enabled. Fix the issue in below case.  Ect device is
> > > > > not available when associated coresight device enabled and the
> > > > > association is established after coresight device is enabled.
> > > > >
> > > > > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > > > > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > > > > ---
> > > > >  drivers/hwtracing/coresight/coresight.c | 11 ++++++++---
> > > > >  include/linux/coresight.h               |  1 +
> > > > >  2 files changed, 9 insertions(+), 3 deletions(-)
> > > > >
> > > > > diff --git a/drivers/hwtracing/coresight/coresight.c
> > b/drivers/hwtracing/coresight/coresight.c
> > > > > index d066411aa794..27ad8317e3cf 100644
> > > > > --- a/drivers/hwtracing/coresight/coresight.c
> > > > > +++ b/drivers/hwtracing/coresight/coresight.c
> > > > > @@ -245,13 +245,18 @@ coresight_control_assoc_ectdev(struct
> > coresight_device *csdev, bool enable)
> > > > >
> > > > >       if (!ect_csdev)
> > > > >               return 0;
> > > > > +     if ((!ect_ops(ect_csdev)->enable) ||
> > (!ect_ops(ect_csdev)->disable))
> > > > > +             return 0;
> > > > >
> > > > >       if (enable) {
> > > > > -             if (ect_ops(ect_csdev)->enable)
> > > > > -                     ect_ret =
> > ect_ops(ect_csdev)->enable(ect_csdev);
> > > > > +             ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
> > > > > +             if (!ect_ret)
> > > > > +                     csdev->ect_enabled = true;
> > > > >       } else {
> > > > > -             if (ect_ops(ect_csdev)->disable)
> > > > > +             if (csdev->ect_enabled) {
> > > > >                       ect_ret =
> > ect_ops(ect_csdev)->disable(ect_csdev);
> > > > > +                     csdev->ect_enabled = false;
> > > > > +             }
> > > > >       }
> > > > >
> > > > >       /* output warning if ECT enable is preventing trace operation
> > */
> > > > > diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> > > > > index 3bb738f9a326..7d3c87e5b97c 100644
> > > > > --- a/include/linux/coresight.h
> > > > > +++ b/include/linux/coresight.h
> > > > > @@ -208,6 +208,7 @@ struct coresight_device {
> > > > >       /* sysfs links between components */
> > > > >       int nr_links;
> > > > >       bool has_conns_grp;
> > > > > +     bool ect_enabled; /* true only if associated ect device is
> > enabled */
> > > >
> > > > We have cti_config::enable_req_count and cti_config::hw_enabled, both
> > used in
> > > > cti_enable_hw() and cti_disable_hw().  I would have thought they'd be
> > sufficient
> > > > to address the counting problems.  If they are not I would much rather
> > see a
> > > > solution confined to the cti driver than in the core itself.
> > > >
> > > 
> > > This is related to the fact that under sysfs it is possible under
> > > sysfs to enable an etm e.g. etm1 without the cti module present, then
> > > insert the CTI module, then enable another ETM e.g etm2.
> > > This is an issue that is caused by the possibility of module load and
> > > unload, and though inadvisable from a system usage point of view -
> > > Tingwei correctly points out that it could happen.
> > > 
> > > At the point that the first ETM is enabled, the associated ect pointer
> > > would be NULL, and thus no attempt to enable the ect/CTI is made. The
> > > CTI module on load will set the ect pointers on all registered csdev
> > > devices, including ones that are already enabled - etm1.
> > > So when we come to disable etm1, it will try to disable a CTI that it
> > > did not enable - a fact that cannot be counted in the CTI driver as it
> > > was not there when the etm was enabled. So we have a flag in csdev to
> > > record if this csdev did in fact enable the associated device, so it
> > > is clear to disable it on shutdown.
> > 
> > In the above example the csdev structures associated with ETM1 and ETM2
> > will
> > have different csdev->ect_dev pointers, one for each CTI it is assocated
> > with.
> > And I would think the reference count for CTI1 would not have been
> > incremented
> > since it was never enabled.
> > 
> > What am I missing?
> > 
> 
> The issue here is we could have two or more coresght devices associated
> to single CTI device, especially for sys cti case. For example, we have
> coresight devcie A and B. They are assocaited to CTI device C. CTI module
> is not loaded at first. Device A is enabled. CTI C is not enabled. Then
> CTI module is loaded. Device B is enabled. CTI C is enabled with
> enable_req_count = 1. Device A is disabled. It decrease enable_req_count
> to 0, so CTI C is disabled. It's kinda weird to me that CTI C is enabled
> with device B and disabled by device A.

Thanks for taking the time to write this out, I now have a better understanding
of the problem.  On the flip side I hope to find a better solution, something I
will have to think about.  No need to wait on me though, resubmit a new revision
when ready and I'll see then.

> 
> The point is we need some flag in coresight device structure to save the
> status of associated CTI enablement when CTI module is not loaded yet.
> 
> Thanks,
> Tingwei
> 
> > > 
> > > Regards
> > > 
> > > Mike
> > > 
> > > 
> > > 
> > > > Thanks,
> > > > Mathieu
> > > >
> > > > >  };
> > > > >
> > > > >  /*
> > > > > --
> > > > > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> > Forum,
> > > > > a Linux Foundation Collaborative Project
> > > > >
> > > 
> > > 
> > > 
> > > -- 
> > > Mike Leach
> > > Principal Engineer, ARM Ltd.
> > > Manchester Design Centre. UK
> > 
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-08-19 19:51 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 11:11 [PATCH v8 00/24] coresight: allow to build coresight as modules Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 01/24] coresight: cpu_debug: add module name in Kconfig Tingwei Zhang
2020-08-12 17:16   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 02/24] coresight: cpu_debug: define MODULE_DEVICE_TABLE Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules Tingwei Zhang
2020-08-12 17:54   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 04/24] coresight: add coresight prefix to barrier_pkt Tingwei Zhang
2020-08-12 17:58   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 05/24] coresight: export global symbols Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 06/24] coresight: add try_get_module() in coresight_grab_device() Tingwei Zhang
2020-08-12 19:36   ` Mathieu Poirier
2020-08-13  7:37     ` Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 07/24] coresight: stm: allow to build coresight-stm as a module Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure Tingwei Zhang
2020-08-12 20:48   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 09/24] coresight: etm3x: allow etm3x to be built as a module Tingwei Zhang
2020-08-12 20:47   ` Mathieu Poirier
2020-08-13  2:16     ` Tingwei Zhang
2020-08-13  9:47   ` Suzuki K Poulose
2020-08-13 10:56     ` Tingwei Zhang
2020-08-13 17:00       ` Mathieu Poirier
2020-08-13 23:44         ` Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 10/24] coresight: etm4x: allow etm4x " Tingwei Zhang
2020-08-13 19:39   ` Mathieu Poirier
2020-08-13 23:46     ` Suzuki K Poulose
2020-08-14  9:52       ` Tingwei Zhang
2020-08-14 10:42         ` Suzuki K Poulose
2020-08-14 11:00           ` Tingwei Zhang
2020-08-14 11:18             ` Suzuki K Poulose
2020-08-13 19:40   ` Mathieu Poirier
2020-08-13 23:58     ` Tingwei Zhang
2020-08-13 19:45   ` Mathieu Poirier
2020-08-13 23:57     ` Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 11/24] coresight: etb: allow etb " Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 12/24] coresight: tpiu: allow tpiu " Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 13/24] coresight: tmc: allow tmc " Tingwei Zhang
2020-08-13 20:36   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 14/24] coresight: allow funnel driver to be built as module Tingwei Zhang
2020-08-13 20:15   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 15/24] coresight: allow replicator " Tingwei Zhang
2020-08-13 20:35   ` Mathieu Poirier
2020-08-14  0:08     ` Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 16/24] coresight: cti: add function to register cti associate ops Tingwei Zhang
2020-08-17 16:02   ` Mathieu Poirier
2020-08-17 18:49     ` Mike Leach
2020-08-18 17:16       ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 17/24] coresight: cti: Fix remove sysfs link error Tingwei Zhang
2020-08-17 16:15   ` Mathieu Poirier
2020-08-17 22:48     ` Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 18/24] coresight: cti: Fix bug clearing sysfs links on callback Tingwei Zhang
2020-08-17 16:21   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 19/24] coresight: cti: don't disable ect device if it's not enabled Tingwei Zhang
2020-08-17 16:38   ` Mathieu Poirier
2020-08-17 19:04     ` Mike Leach
2020-08-18 17:39       ` Mathieu Poirier
2020-08-19  1:55         ` Tingwei Zhang
2020-08-19 19:50           ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 20/24] coresight: cti: increase reference count when enabling cti Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 21/24] coresight: cti: allow cti to be built as a module Tingwei Zhang
2020-08-17 17:13   ` Mathieu Poirier
2020-08-17 19:14     ` Mike Leach
2020-08-18 17:42       ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 22/24] coresight: tmc-etr: add function to register catu ops Tingwei Zhang
2020-08-07 11:11 ` [PATCH v8 23/24] coresight: catu: allow catu drivers to be built as modules Tingwei Zhang
2020-08-17 17:39   ` Mathieu Poirier
2020-08-07 11:11 ` [PATCH v8 24/24] coresight: allow the coresight core driver to be built as a module Tingwei Zhang
2020-08-17 17:47   ` Mathieu Poirier
2020-08-17 22:56     ` Tingwei Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).