Skip to contentSkip to conversation

coresight: Fixes device's owner field for registered using coresight_init_driver()

PATCH Applied Junhao He 2 participants 6 messages Sep 18, 2024 – Apr 29, 2025

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Junhao He

author
#0 lore raw

PATCH 1/1 coresight: Fixes device's owner field for registered using coresight_init_driver()

The coresight_init_driver() of the coresight-core module is called from the sub coresgiht device (such as tmc/stm/funnle/...) module. It calls amba_driver_register() and Platform_driver_register(), which are macro functions that use the coresight-core's module to initialize the caller's owner field. Therefore, when the sub coresight device calls coresight_init_driver(), an incorrect THIS_MODULE value is captured.

The sub coesgiht modules can be removed while their callbacks are running, resulting in a general protection failure.

Add module parameter to coresight_init_driver() so can be called with the module of the callback.

Fixes 075b7cd7ad7d ("coresight: Add helpers registering/removing both AMBA and platform drivers")
---
 drivers/hwtracing/coresight/coresight-catu.c       | 2 +-
 drivers/hwtracing/coresight/coresight-core.c       | 6 +++---
 drivers/hwtracing/coresight/coresight-cpu-debug.c  | 3 ++-
 drivers/hwtracing/coresight/coresight-funnel.c     | 3 ++-
 drivers/hwtracing/coresight/coresight-replicator.c | 3 ++-
 drivers/hwtracing/coresight/coresight-stm.c        | 2 +-
 drivers/hwtracing/coresight/coresight-tmc-core.c   | 2 +-
 drivers/hwtracing/coresight/coresight-tpiu.c       | 2 +-
 include/linux/coresight.h                          | 2 +-
 9 files changed, 14 insertions(+), 11 deletions(-)
drivers/hwtracing/coresight/coresight-catu.c +1 -1
index bfea880d6dfb..337668f9cfd4 100644
@@ -702,7 +702,7 @@ static int __init catu_init(void)
 {
 	int ret;
 
-	ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver);
+	ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver, THIS_MODULE);
 	tmc_etr_set_catu_ops(&etr_catu_buf_ops);
 	return ret;
 }
drivers/hwtracing/coresight/coresight-core.c +3 -3
index 9fc6f6b863e0..c546a417836c 100644
@@ -1399,17 +1399,17 @@ module_init(coresight_init);
 module_exit(coresight_exit);
 
 int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-			  struct platform_driver *pdev_drv)
+			  struct platform_driver *pdev_drv, struct module *owner)
 {
 	int ret;
 
-	ret = amba_driver_register(amba_drv);
+	ret = __amba_driver_register(amba_drv, owner);
 	if (ret) {
 		pr_err("%s: error registering AMBA driver\n", drv);
 		return ret;
 	}
 
-	ret = platform_driver_register(pdev_drv);
+	ret = __platform_driver_register(pdev_drv, owner);
 	if (!ret)
 		return 0;
 
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -1
index 75962dae9aa1..cc599c5ef4b2 100644
@@ -774,7 +774,8 @@ static struct platform_driver debug_platform_driver = {
 
 static int __init debug_init(void)
 {
-	return coresight_init_driver("debug", &debug_driver, &debug_platform_driver);
+	return coresight_init_driver("debug", &debug_driver, &debug_platform_driver,
+				     THIS_MODULE);
 }
 
 static void __exit debug_exit(void)
drivers/hwtracing/coresight/coresight-funnel.c +2 -1
index 5a819c8970fb..8f451b051ddc 100644
@@ -433,7 +433,8 @@ static struct amba_driver dynamic_funnel_driver = {
 
 static int __init funnel_init(void)
 {
-	return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver);
+	return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver,
+				     THIS_MODULE);
 }
 
 static void __exit funnel_exit(void)
drivers/hwtracing/coresight/coresight-replicator.c +2 -1
index 3e55be9c8418..f7607c72857c 100644
@@ -438,7 +438,8 @@ static struct amba_driver dynamic_replicator_driver = {
 
 static int __init replicator_init(void)
 {
-	return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver);
+	return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver,
+				     THIS_MODULE);
 }
 
 static void __exit replicator_exit(void)
drivers/hwtracing/coresight/coresight-stm.c +1 -1
index 117dbb484543..403eea8f95d4 100644
@@ -1046,7 +1046,7 @@ static struct platform_driver stm_platform_driver = {
 
 static int __init stm_init(void)
 {
-	return coresight_init_driver("stm", &stm_driver, &stm_platform_driver);
+	return coresight_init_driver("stm", &stm_driver, &stm_platform_driver, THIS_MODULE);
 }
 
 static void __exit stm_exit(void)
drivers/hwtracing/coresight/coresight-tmc-core.c +1 -1
index b54562f392f3..e31e36635394 100644
@@ -742,7 +742,7 @@ static struct platform_driver tmc_platform_driver = {
 
 static int __init tmc_init(void)
 {
-	return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver);
+	return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver, THIS_MODULE);
 }
 
 static void __exit tmc_exit(void)
drivers/hwtracing/coresight/coresight-tpiu.c +1 -1
index b048e146fbb1..f9ecd05cbe5c 100644
@@ -318,7 +318,7 @@ static struct platform_driver tpiu_platform_driver = {
 
 static int __init tpiu_init(void)
 {
-	return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver);
+	return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver, THIS_MODULE);
 }
 
 static void __exit tpiu_exit(void)
include/linux/coresight.h +1 -1
index f09ace92176e..e6c26952ddc2 100644
@@ -660,7 +660,7 @@ coresight_find_output_type(struct coresight_platform_data *pdata,
 			   union coresight_dev_subtype subtype);
 
 int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-			  struct platform_driver *pdev_drv);
+			  struct platform_driver *pdev_drv, struct module *owner);
 
 void coresight_remove_driver(struct amba_driver *amba_drv,
 			     struct platform_driver *pdev_drv);
Signature · 1 line
2.33.0
maintainer
#1 lore raw
Quoted 7 lines · Junhao He

The coresight_init_driver() of the coresight-core module is called from the sub coresgiht device (such as tmc/stm/funnle/...) module. It calls amba_driver_register() and Platform_driver_register(), which are macro functions that use the coresight-core's module to initialize the caller's owner field. Therefore, when the sub coresight device calls coresight_init_driver(), an incorrect THIS_MODULE value is captured.

Quoted 8 lines

The sub coesgiht modules can be removed while their callbacks are running, resulting in a general protection failure.

Add module parameter to coresight_init_driver() so can be called with the module of the callback.

Fixes 075b7cd7ad7d ("coresight: Add helpers registering/removing both AMBA and platform drivers")

Thanks for the fix, looks good to me. I will queue this for v6.13

Suzuki

Quoted 144 lines
---
  drivers/hwtracing/coresight/coresight-catu.c       | 2 +-
  drivers/hwtracing/coresight/coresight-core.c       | 6 +++---
  drivers/hwtracing/coresight/coresight-cpu-debug.c  | 3 ++-
  drivers/hwtracing/coresight/coresight-funnel.c     | 3 ++-
  drivers/hwtracing/coresight/coresight-replicator.c | 3 ++-
  drivers/hwtracing/coresight/coresight-stm.c        | 2 +-
  drivers/hwtracing/coresight/coresight-tmc-core.c   | 2 +-
  drivers/hwtracing/coresight/coresight-tpiu.c       | 2 +-
  include/linux/coresight.h                          | 2 +-
  9 files changed, 14 insertions(+), 11 deletions(-)
drivers/hwtracing/coresight/coresight-catu.c +1 -1
index bfea880d6dfb..337668f9cfd4 100644
@@ -702,7 +702,7 @@ static int __init catu_init(void)
  {
  	int ret;
 
-	ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver);
+	ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver, THIS_MODULE);
  	tmc_etr_set_catu_ops(&etr_catu_buf_ops);
  	return ret;
  }
drivers/hwtracing/coresight/coresight-core.c +3 -3
index 9fc6f6b863e0..c546a417836c 100644
@@ -1399,17 +1399,17 @@ module_init(coresight_init);
  module_exit(coresight_exit);
 
  int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-			  struct platform_driver *pdev_drv)
+			  struct platform_driver *pdev_drv, struct module *owner)
  {
  	int ret;
 
-	ret = amba_driver_register(amba_drv);
+	ret = __amba_driver_register(amba_drv, owner);
  	if (ret) {
  		pr_err("%s: error registering AMBA driver\n", drv);
  		return ret;
  	}
 
-	ret = platform_driver_register(pdev_drv);
+	ret = __platform_driver_register(pdev_drv, owner);
  	if (!ret)
  		return 0;
 
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -1
index 75962dae9aa1..cc599c5ef4b2 100644
@@ -774,7 +774,8 @@ static struct platform_driver debug_platform_driver = {
 
  static int __init debug_init(void)
  {
-	return coresight_init_driver("debug", &debug_driver, &debug_platform_driver);
+	return coresight_init_driver("debug", &debug_driver, &debug_platform_driver,
+				     THIS_MODULE);
  }
 
  static void __exit debug_exit(void)
drivers/hwtracing/coresight/coresight-funnel.c +2 -1
index 5a819c8970fb..8f451b051ddc 100644
@@ -433,7 +433,8 @@ static struct amba_driver dynamic_funnel_driver = {
 
  static int __init funnel_init(void)
  {
-	return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver);
+	return coresight_init_driver("funnel", &dynamic_funnel_driver, &funnel_driver,
+				     THIS_MODULE);
  }
 
  static void __exit funnel_exit(void)
drivers/hwtracing/coresight/coresight-replicator.c +2 -1
index 3e55be9c8418..f7607c72857c 100644
@@ -438,7 +438,8 @@ static struct amba_driver dynamic_replicator_driver = {
 
  static int __init replicator_init(void)
  {
-	return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver);
+	return coresight_init_driver("replicator", &dynamic_replicator_driver, &replicator_driver,
+				     THIS_MODULE);
  }
 
  static void __exit replicator_exit(void)
drivers/hwtracing/coresight/coresight-stm.c +1 -1
index 117dbb484543..403eea8f95d4 100644
@@ -1046,7 +1046,7 @@ static struct platform_driver stm_platform_driver = {
 
  static int __init stm_init(void)
  {
-	return coresight_init_driver("stm", &stm_driver, &stm_platform_driver);
+	return coresight_init_driver("stm", &stm_driver, &stm_platform_driver, THIS_MODULE);
  }
 
  static void __exit stm_exit(void)
drivers/hwtracing/coresight/coresight-tmc-core.c +1 -1
index b54562f392f3..e31e36635394 100644
@@ -742,7 +742,7 @@ static struct platform_driver tmc_platform_driver = {
 
  static int __init tmc_init(void)
  {
-	return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver);
+	return coresight_init_driver("tmc", &tmc_driver, &tmc_platform_driver, THIS_MODULE);
  }
 
  static void __exit tmc_exit(void)
drivers/hwtracing/coresight/coresight-tpiu.c +1 -1
index b048e146fbb1..f9ecd05cbe5c 100644
@@ -318,7 +318,7 @@ static struct platform_driver tpiu_platform_driver = {
 
  static int __init tpiu_init(void)
  {
-	return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver);
+	return coresight_init_driver("tpiu", &tpiu_driver, &tpiu_platform_driver, THIS_MODULE);
  }
 
  static void __exit tpiu_exit(void)
include/linux/coresight.h +1 -1
index f09ace92176e..e6c26952ddc2 100644
@@ -660,7 +660,7 @@ coresight_find_output_type(struct coresight_platform_data *pdata,
  			   union coresight_dev_subtype subtype);
 
  int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-			  struct platform_driver *pdev_drv);
+			  struct platform_driver *pdev_drv, struct module *owner);
 
  void coresight_remove_driver(struct amba_driver *amba_drv,
  			     struct platform_driver *pdev_drv);
author
#2 lore raw

Hi Suzuki,

Could you confirm if this patch was queued in coresight/next or upstream of the mainline?

I couldn't find it in: kernel/git/coresight/linux.git or Kernel v6.14.0-rc4.

Maybe am I missing some information?

Best regards,
Junhao.

Quoted 173 lines · Suzuki K Poulose
Quoted 7 lines · Junhao He

The coresight_init_driver() of the coresight-core module is called from the sub coresgiht device (such as tmc/stm/funnle/...) module. It calls amba_driver_register() and Platform_driver_register(), which are macro functions that use the coresight-core's module to initialize the caller's owner field. Therefore, when the sub coresight device calls coresight_init_driver(), an incorrect THIS_MODULE value is captured.

Quoted 8 lines

The sub coesgiht modules can be removed while their callbacks are running, resulting in a general protection failure.

Add module parameter to coresight_init_driver() so can be called with the module of the callback.

Fixes 075b7cd7ad7d ("coresight: Add helpers registering/removing both AMBA and platform drivers")

Thanks for the fix, looks good to me. I will queue this for v6.13

Suzuki

Quoted 140 lines
---
  drivers/hwtracing/coresight/coresight-catu.c       | 2 +-
  drivers/hwtracing/coresight/coresight-core.c       | 6 +++---
  drivers/hwtracing/coresight/coresight-cpu-debug.c  | 3 ++-
  drivers/hwtracing/coresight/coresight-funnel.c     | 3 ++-
  drivers/hwtracing/coresight/coresight-replicator.c | 3 ++-
  drivers/hwtracing/coresight/coresight-stm.c        | 2 +-
  drivers/hwtracing/coresight/coresight-tmc-core.c   | 2 +-
  drivers/hwtracing/coresight/coresight-tpiu.c       | 2 +-
  include/linux/coresight.h                          | 2 +-
  9 files changed, 14 insertions(+), 11 deletions(-)
drivers/hwtracing/coresight/coresight-catu.c +1 -0
index bfea880d6dfb..337668f9cfd4 100644
@@ -702,7 +702,7 @@ static int __init catu_init(void)
  {
      int ret;
  -    ret = coresight_init_driver("catu", &catu_driver, 
 &catu_platform_driver);
+    ret = coresight_init_driver("catu", &catu_driver, 
 &catu_platform_driver, THIS_MODULE);
      tmc_etr_set_catu_ops(&etr_catu_buf_ops);
      return ret;
  }
drivers/hwtracing/coresight/coresight-core.c +3 -1
index 9fc6f6b863e0..c546a417836c 100644
@@ -1399,17 +1399,17 @@ module_init(coresight_init);
  module_exit(coresight_exit);
    int coresight_init_driver(const char *drv, struct amba_driver 
 *amba_drv,
-              struct platform_driver *pdev_drv)
+              struct platform_driver *pdev_drv, struct module *owner)
  {
      int ret;
  -    ret = amba_driver_register(amba_drv);
+    ret = __amba_driver_register(amba_drv, owner);
      if (ret) {
          pr_err("%s: error registering AMBA driver\n", drv);
          return ret;
      }
  -    ret = platform_driver_register(pdev_drv);
+    ret = __platform_driver_register(pdev_drv, owner);
      if (!ret)
          return 0;
  diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c 

b/drivers/hwtracing/coresight/coresight-cpu-debug.c index 75962dae9aa1..cc599c5ef4b2 100644

drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -1
@@ -774,7 +774,8 @@ static struct platform_driver 
 debug_platform_driver = {
    static int __init debug_init(void)
  {
-    return coresight_init_driver("debug", &debug_driver, 
 &debug_platform_driver);
+    return coresight_init_driver("debug", &debug_driver, 
 &debug_platform_driver,
+                     THIS_MODULE);
  }

static void __exit debug_exit(void)

drivers/hwtracing/coresight/coresight-funnel.c +2 -1
index 5a819c8970fb..8f451b051ddc 100644
@@ -433,7 +433,8 @@ static struct amba_driver dynamic_funnel_driver = {
    static int __init funnel_init(void)
  {
-    return coresight_init_driver("funnel", &dynamic_funnel_driver, 
 &funnel_driver);
+    return coresight_init_driver("funnel", &dynamic_funnel_driver, 
 &funnel_driver,
+                     THIS_MODULE);
  }
    static void __exit funnel_exit(void)
drivers/hwtracing/coresight/coresight-replicator.c +2 -1
index 3e55be9c8418..f7607c72857c 100644
@@ -438,7 +438,8 @@ static struct amba_driver 
 dynamic_replicator_driver = {
    static int __init replicator_init(void)
  {
-    return coresight_init_driver("replicator", 
 &dynamic_replicator_driver, &replicator_driver);
+    return coresight_init_driver("replicator", 
 &dynamic_replicator_driver, &replicator_driver,
+                     THIS_MODULE);
  }

static void __exit replicator_exit(void)

drivers/hwtracing/coresight/coresight-stm.c +1 -1
index 117dbb484543..403eea8f95d4 100644
@@ -1046,7 +1046,7 @@ static struct platform_driver 
 stm_platform_driver = {
    static int __init stm_init(void)
  {
-    return coresight_init_driver("stm", &stm_driver, 
 &stm_platform_driver);
+    return coresight_init_driver("stm", &stm_driver, 
 &stm_platform_driver, THIS_MODULE);
  }

static void __exit stm_exit(void)

drivers/hwtracing/coresight/coresight-tmc-core.c +1 -1
index b54562f392f3..e31e36635394 100644
@@ -742,7 +742,7 @@ static struct platform_driver tmc_platform_driver 
 = {
    static int __init tmc_init(void)
  {
-    return coresight_init_driver("tmc", &tmc_driver, 
 &tmc_platform_driver);
+    return coresight_init_driver("tmc", &tmc_driver, 
 &tmc_platform_driver, THIS_MODULE);
  }

static void __exit tmc_exit(void)

drivers/hwtracing/coresight/coresight-tpiu.c +1 -1
index b048e146fbb1..f9ecd05cbe5c 100644
@@ -318,7 +318,7 @@ static struct platform_driver 
 tpiu_platform_driver = {
    static int __init tpiu_init(void)
  {
-    return coresight_init_driver("tpiu", &tpiu_driver, 
 &tpiu_platform_driver);
+    return coresight_init_driver("tpiu", &tpiu_driver, 
 &tpiu_platform_driver, THIS_MODULE);
  }

static void __exit tpiu_exit(void)

include/linux/coresight.h +0 -0
index f09ace92176e..e6c26952ddc2 100644

include/linux/coresight.h coresight_find_output_type(struct · line 666

Quoted 8 lines
include/linux/coresight.h +1 -1
@@ -660,7 +660,7 @@ coresight_find_output_type(struct 
 coresight_platform_data *pdata,
                 union coresight_dev_subtype subtype);
    int coresight_init_driver(const char *drv, struct amba_driver 
 *amba_drv,
-              struct platform_driver *pdev_drv);
+              struct platform_driver *pdev_drv, struct module *owner);
    void coresight_remove_driver(struct amba_driver *amba_drv,
                   struct platform_driver *pdev_drv);

.

maintainer
#3 lore raw

Hi

Quoted 7 lines · hejunhao

Hi Suzuki,

Could you confirm if this patch was queued in coresight/next or upstream of the mainline?

I couldn't find it in: kernel/git/coresight/linux.git or Kernel v6.14.0- rc4.

Maybe am I missing some information?

Apologies, I missed queueing this. That said, I have a minor comment on the patch below.

Quoted 78 lines

Best regards,
Junhao.

Quoted 72 lines · Suzuki K Poulose
Quoted 7 lines · Junhao He

The coresight_init_driver() of the coresight-core module is called from the sub coresgiht device (such as tmc/stm/funnle/...) module. It calls amba_driver_register() and Platform_driver_register(), which are macro functions that use the coresight-core's module to initialize the caller's owner field.  Therefore, when the sub coresight device calls coresight_init_driver(), an incorrect THIS_MODULE value is captured.

Quoted 8 lines

The sub coesgiht modules can be removed while their callbacks are running, resulting in a general protection failure.

Add module parameter to coresight_init_driver() so can be called with the module of the callback.

Fixes 075b7cd7ad7d ("coresight: Add helpers registering/removing both AMBA and platform drivers")

Thanks for the fix, looks good to me. I will queue this for v6.13

Suzuki

Quoted 51 lines

---
  drivers/hwtracing/coresight/coresight-catu.c       | 2 +- drivers/hwtracing/coresight/coresight-core.c       | 6 +++--- drivers/hwtracing/coresight/coresight-cpu-debug.c  | 3 ++- drivers/hwtracing/coresight/coresight-funnel.c     | 3 ++- drivers/hwtracing/coresight/coresight-replicator.c | 3 ++- drivers/hwtracing/coresight/coresight-stm.c        | 2 +- drivers/hwtracing/coresight/coresight-tmc-core.c   | 2 +- drivers/hwtracing/coresight/coresight-tpiu.c       | 2 +- include/linux/coresight.h                          | 2 +-

  9 files changed, 14 insertions(+), 11 deletions(-)
drivers/hwtracing/coresight/coresight-catu.c +1 -0
index bfea880d6dfb..337668f9cfd4 100644
@@ -702,7 +702,7 @@ static int __init catu_init(void)
   {
       int ret;
   -    ret = coresight_init_driver("catu", &catu_driver, &catu_platform_driver);
+    ret = coresight_init_driver("catu", &catu_driver, 
 &catu_platform_driver, THIS_MODULE);
       tmc_etr_set_catu_ops(&etr_catu_buf_ops);
       return ret;

  }

drivers/hwtracing/coresight/coresight-core.c +3 -1
index 9fc6f6b863e0..c546a417836c 100644
@@ -1399,17 +1399,17 @@ module_init(coresight_init);
   module_exit(coresight_exit);
     int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-              struct platform_driver *pdev_drv)
+              struct platform_driver *pdev_drv, struct module *owner)
   {
       int ret;
   -    ret = amba_driver_register(amba_drv);
+    ret = __amba_driver_register(amba_drv, owner);
       if (ret) {
           pr_err("%s: error registering AMBA driver\n", drv);
           return ret;
       }
   -    ret = platform_driver_register(pdev_drv);
+    ret = __platform_driver_register(pdev_drv, owner);
       if (!ret)
           return 0;

  diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/ drivers/hwtracing/coresight/coresight-cpu-debug.c index 75962dae9aa1..cc599c5ef4b2 100644

drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
@@ -774,7 +774,8 @@ static struct platform_driver 
Quoted 8 lines
Quoted 8 lines

drivers/hwtracing/coresight/coresight-cpu-debug.c static struct platform_driver · line 780

Quoted 8 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -1
 debug_platform_driver = {
     static int __init debug_init(void)
   {
-    return coresight_init_driver("debug", &debug_driver, 
 &debug_platform_driver);
+    return coresight_init_driver("debug", &debug_driver, 
 &debug_platform_driver,
+                     THIS_MODULE);

minor nit:

Could we make the coresight_init_driver() a static inline or even a macro to automatically add the THIS_MODULE param ?

Something like:

#define coresight_init_driver(name, amba_drv, pdev_drv)
coresight_init_driver_owner(name, amba_drv, pdev_drv, THIS_MODULE)

I could respin this and queue the change.

Suzuki

Quoted 90 lines
Quoted 89 lines
Quoted 78 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
   }

    static void __exit debug_exit(void)

drivers/hwtracing/coresight/coresight-funnel.c +2 -1
index 5a819c8970fb..8f451b051ddc 100644
@@ -433,7 +433,8 @@ static struct amba_driver dynamic_funnel_driver = {
     static int __init funnel_init(void)
   {
-    return coresight_init_driver("funnel", &dynamic_funnel_driver, 
 &funnel_driver);
+    return coresight_init_driver("funnel", &dynamic_funnel_driver, 
 &funnel_driver,
+                     THIS_MODULE);
   }
     static void __exit funnel_exit(void)
drivers/hwtracing/coresight/coresight-replicator.c +2 -1
index 3e55be9c8418..f7607c72857c 100644
@@ -438,7 +438,8 @@ static struct amba_driver 
 dynamic_replicator_driver = {
     static int __init replicator_init(void)
   {
-    return coresight_init_driver("replicator", 
 &dynamic_replicator_driver, &replicator_driver);
+    return coresight_init_driver("replicator", 
 &dynamic_replicator_driver, &replicator_driver,
+                     THIS_MODULE);
   }

    static void __exit replicator_exit(void)

drivers/hwtracing/coresight/coresight-stm.c +1 -1
index 117dbb484543..403eea8f95d4 100644
@@ -1046,7 +1046,7 @@ static struct platform_driver 
 stm_platform_driver = {
     static int __init stm_init(void)
   {
-    return coresight_init_driver("stm", &stm_driver, 
 &stm_platform_driver);
+    return coresight_init_driver("stm", &stm_driver, 
 &stm_platform_driver, THIS_MODULE);
   }

    static void __exit stm_exit(void)

drivers/hwtracing/coresight/coresight-tmc-core.c +1 -1
index b54562f392f3..e31e36635394 100644
@@ -742,7 +742,7 @@ static struct platform_driver tmc_platform_driver 
 = {
     static int __init tmc_init(void)
   {
-    return coresight_init_driver("tmc", &tmc_driver, 
 &tmc_platform_driver);
+    return coresight_init_driver("tmc", &tmc_driver, 
 &tmc_platform_driver, THIS_MODULE);
   }

    static void __exit tmc_exit(void)

drivers/hwtracing/coresight/coresight-tpiu.c +1 -1
index b048e146fbb1..f9ecd05cbe5c 100644
@@ -318,7 +318,7 @@ static struct platform_driver 
 tpiu_platform_driver = {
     static int __init tpiu_init(void)
   {
-    return coresight_init_driver("tpiu", &tpiu_driver, 
 &tpiu_platform_driver);
+    return coresight_init_driver("tpiu", &tpiu_driver, 
 &tpiu_platform_driver, THIS_MODULE);
   }

    static void __exit tpiu_exit(void)

include/linux/coresight.h +0 -0
index f09ace92176e..e6c26952ddc2 100644

include/linux/coresight.h coresight_find_output_type(struct · line 665

Quoted 7 lines
include/linux/coresight.h +1 -1
@@ -660,7 +660,7 @@ coresight_find_output_type(struct 
 coresight_platform_data *pdata,
                  union coresight_dev_subtype subtype);
     int coresight_init_driver(const char *drv, struct amba_driver *amba_drv,
-              struct platform_driver *pdev_drv);
+              struct platform_driver *pdev_drv, struct module *owner);
     void coresight_remove_driver(struct amba_driver *amba_drv,
                    struct platform_driver *pdev_drv);

.

author
#4 lore raw

Hi Suzuki,

Quoted 108 lines · Suzuki K Poulose

Hi

Quoted 7 lines · hejunhao

Hi Suzuki,

Could you confirm if this patch was queued in coresight/next or upstream of the mainline?

I couldn't find it in: kernel/git/coresight/linux.git or Kernel v6.14.0- rc4.

Maybe am I missing some information?

Apologies, I missed queueing this. That said, I have a minor comment on the patch below.

Quoted 81 lines

Best regards,
Junhao.

Quoted 75 lines · Suzuki K Poulose
Quoted 7 lines · Junhao He

The coresight_init_driver() of the coresight-core module is called from the sub coresgiht device (such as tmc/stm/funnle/...) module. It calls amba_driver_register() and Platform_driver_register(), which are macro functions that use the coresight-core's module to initialize the caller's owner field. Therefore, when the sub coresight device calls coresight_init_driver(), an incorrect THIS_MODULE value is captured.

Quoted 8 lines

The sub coesgiht modules can be removed while their callbacks are running, resulting in a general protection failure.

Add module parameter to coresight_init_driver() so can be called with the module of the callback.

Fixes 075b7cd7ad7d ("coresight: Add helpers registering/removing both AMBA and platform drivers")

Thanks for the fix, looks good to me. I will queue this for v6.13

Suzuki

Quoted 54 lines
---
  drivers/hwtracing/coresight/coresight-catu.c       | 2 +-
  drivers/hwtracing/coresight/coresight-core.c       | 6 +++---
  drivers/hwtracing/coresight/coresight-cpu-debug.c  | 3 ++-
  drivers/hwtracing/coresight/coresight-funnel.c     | 3 ++-
  drivers/hwtracing/coresight/coresight-replicator.c | 3 ++-
  drivers/hwtracing/coresight/coresight-stm.c        | 2 +-
  drivers/hwtracing/coresight/coresight-tmc-core.c   | 2 +-
  drivers/hwtracing/coresight/coresight-tpiu.c       | 2 +-
  include/linux/coresight.h                          | 2 +-
  9 files changed, 14 insertions(+), 11 deletions(-)
drivers/hwtracing/coresight/coresight-catu.c +1 -0
index bfea880d6dfb..337668f9cfd4 100644
@@ -702,7 +702,7 @@ static int __init catu_init(void)
  {
      int ret;
  -    ret = coresight_init_driver("catu", &catu_driver, 
 &catu_platform_driver);
+    ret = coresight_init_driver("catu", &catu_driver, 
 &catu_platform_driver, THIS_MODULE);
      tmc_etr_set_catu_ops(&etr_catu_buf_ops);
      return ret;
  }
drivers/hwtracing/coresight/coresight-core.c +3 -1
index 9fc6f6b863e0..c546a417836c 100644
@@ -1399,17 +1399,17 @@ module_init(coresight_init);
  module_exit(coresight_exit);
    int coresight_init_driver(const char *drv, struct amba_driver 
 *amba_drv,
-              struct platform_driver *pdev_drv)
+              struct platform_driver *pdev_drv, struct module *owner)
  {
      int ret;
  -    ret = amba_driver_register(amba_drv);
+    ret = __amba_driver_register(amba_drv, owner);
      if (ret) {
          pr_err("%s: error registering AMBA driver\n", drv);
          return ret;
      }
  -    ret = platform_driver_register(pdev_drv);
+    ret = __platform_driver_register(pdev_drv, owner);
      if (!ret)
          return 0;
  diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/ 

drivers/hwtracing/coresight/coresight-cpu-debug.c
index 75962dae9aa1..cc599c5ef4b2 100644

drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
@@ -774,7 +774,8 @@ static struct platform_driver 
Quoted 8 lines
Quoted 8 lines

drivers/hwtracing/coresight/coresight-cpu-debug.c static struct platform_driver · line 780

Quoted 8 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -1
 debug_platform_driver = {
    static int __init debug_init(void)
  {
-    return coresight_init_driver("debug", &debug_driver, 
 &debug_platform_driver);
+    return coresight_init_driver("debug", &debug_driver, 
 &debug_platform_driver,
+                     THIS_MODULE);

minor nit:

Could we make the coresight_init_driver() a static inline or even a macro to automatically add the THIS_MODULE param ?

Quoted 8 lines

Something like:

#define coresight_init_driver(name, amba_drv, pdev_drv)
coresight_init_driver_owner(name, amba_drv, pdev_drv, THIS_MODULE)

I could respin this and queue the change.

Yes, thanks for the review. Will fix in next version.

Quoted 99 lines
Quoted 86 lines
Quoted 86 lines
Quoted 86 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
  }

static void __exit debug_exit(void)

drivers/hwtracing/coresight/coresight-funnel.c +2 -1
index 5a819c8970fb..8f451b051ddc 100644
@@ -433,7 +433,8 @@ static struct amba_driver dynamic_funnel_driver 
 = {
    static int __init funnel_init(void)
  {
-    return coresight_init_driver("funnel", &dynamic_funnel_driver, 
 &funnel_driver);
+    return coresight_init_driver("funnel", &dynamic_funnel_driver, 
 &funnel_driver,
+                     THIS_MODULE);
  }

static void __exit funnel_exit(void)

drivers/hwtracing/coresight/coresight-replicator.c +2 -1
index 3e55be9c8418..f7607c72857c 100644
@@ -438,7 +438,8 @@ static struct amba_driver 
 dynamic_replicator_driver = {
    static int __init replicator_init(void)
  {
-    return coresight_init_driver("replicator", 
 &dynamic_replicator_driver, &replicator_driver);
+    return coresight_init_driver("replicator", 
 &dynamic_replicator_driver, &replicator_driver,
+                     THIS_MODULE);
  }

static void __exit replicator_exit(void)

drivers/hwtracing/coresight/coresight-stm.c +1 -1
index 117dbb484543..403eea8f95d4 100644
@@ -1046,7 +1046,7 @@ static struct platform_driver 
 stm_platform_driver = {
    static int __init stm_init(void)
  {
-    return coresight_init_driver("stm", &stm_driver, 
 &stm_platform_driver);
+    return coresight_init_driver("stm", &stm_driver, 
 &stm_platform_driver, THIS_MODULE);
  }

static void __exit stm_exit(void)

drivers/hwtracing/coresight/coresight-tmc-core.c +1 -1
index b54562f392f3..e31e36635394 100644
@@ -742,7 +742,7 @@ static struct platform_driver 
 tmc_platform_driver = {
    static int __init tmc_init(void)
  {
-    return coresight_init_driver("tmc", &tmc_driver, 
 &tmc_platform_driver);
+    return coresight_init_driver("tmc", &tmc_driver, 
 &tmc_platform_driver, THIS_MODULE);
  }

static void __exit tmc_exit(void)

drivers/hwtracing/coresight/coresight-tpiu.c +1 -1
index b048e146fbb1..f9ecd05cbe5c 100644
@@ -318,7 +318,7 @@ static struct platform_driver 
 tpiu_platform_driver = {
    static int __init tpiu_init(void)
  {
-    return coresight_init_driver("tpiu", &tpiu_driver, 
 &tpiu_platform_driver);
+    return coresight_init_driver("tpiu", &tpiu_driver, 
 &tpiu_platform_driver, THIS_MODULE);
  }

static void __exit tpiu_exit(void)

include/linux/coresight.h +0 -1
index f09ace92176e..e6c26952ddc2 100644
@@ -660,7 +660,7 @@ coresight_find_output_type(struct 
 coresight_platform_data *pdata,
                 union coresight_dev_subtype subtype);
    int coresight_init_driver(const char *drv, struct amba_driver 
 *amba_drv,
-              struct platform_driver *pdev_drv);
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
include/linux/coresight.h +1 -0
+              struct platform_driver *pdev_drv, struct module 
 *owner);
    void coresight_remove_driver(struct amba_driver *amba_drv,
                   struct platform_driver *pdev_drv);

.

.

maintainer Applied
#5 lore raw
In reply to Junhao He
Quoted 8 lines · Junhao He

The coresight_init_driver() of the coresight-core module is called from the sub coresgiht device (such as tmc/stm/funnle/...) module. It calls amba_driver_register() and Platform_driver_register(), which are macro functions that use the coresight-core's module to initialize the caller's owner field. Therefore, when the sub coresight device calls coresight_init_driver(), an incorrect THIS_MODULE value is captured.

[...]

Applied, thanks!

[1/1] coresight: Fixes device's owner field for registered using coresight_init_driver()

      https://git.kernel.org/coresight/c/9f52aecc

Best regards,

Signature · 1 line
Suzuki K Poulose <[email protected]>