Skip to contentSkip to conversation

coresight: Set affinity to invalid for missing CPU phandle

PATCH In review Sai Prakash Ranjan 3 participants 13 messages Jun 20, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover coresight: Set affinity to invalid for missing CPU phandle

In case of missing CPU phandle, the affinity is set default to CPU0 which is not a correct assumption and leads to crashes in few cases. Fix this by returning -ENODEV in coresight platform and abort the probe in coresight etm and cpu-debug drivers.

Sai Prakash Ranjan (2):
coresight: Set affinity to invalid for missing CPU phandle
coresight: Abort probe for missing CPU phandle

 drivers/hwtracing/coresight/coresight-cpu-debug.c |  3 +++
 drivers/hwtracing/coresight/coresight-etm3x.c     |  3 +++
 drivers/hwtracing/coresight/coresight-etm4x.c     |  3 +++
 drivers/hwtracing/coresight/coresight-platform.c  | 10 ++++++----
 4 files changed, 15 insertions(+), 4 deletions(-)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH 1/2 coresight: Set affinity to invalid for missing CPU phandle

Affinity defaults to CPU0 in case of missing CPU phandle and this leads to crashes in some cases because of such wrong assumption. Fix this by returning -ENODEV in coresight platform for such cases and then handle it in the coresight drivers.

---
 drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-platform.c +6 -4
index 3c5ceda8db24..b1ea60c210e1 100644
@@ -160,15 +160,17 @@ static int of_coresight_get_cpu(struct device *dev)
 
 	if (!dev->of_node)
 		return 0;
+
 	dn = of_parse_phandle(dev->of_node, "cpu", 0);
-	/* Affinity defaults to CPU0 */
+
+	/* Affinity defaults to invalid if no cpu nodes are found*/
 	if (!dn)
-		return 0;
+		return -ENODEV;
+
 	cpu = of_cpu_node_to_id(dn);
 	of_node_put(dn);
 
-	/* Affinity to CPU0 if no cpu nodes are found */
-	return (cpu < 0) ? 0 : cpu;
+	return cpu;
 }
 
 /*
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
maintainer
#2 lore raw

Sai,

Thanks for the patch. Please could you change the subject to :

"coresight: Do not default to CPU0 for missing CPU phandle"

Quoted 3 lines · Sai Prakash Ranjan

Affinity defaults to CPU0 in case of missing CPU phandle and this leads to crashes in some cases because of such wrong assumption. Fix this by returning -ENODEV in

Thats not the right justification. Causing crashes is due to bad DT/firmware. I would be happy with something like :

"Coresight platform support assumes that a missing \"cpu\" phandle defaults to CPU0. This could be problematic and unnecessarily binds components to CPU0, where they may not be. Let us make the DT binding rules a bit stricter by not defaulting to CPU0 for missing "cpu" affinity information."

Also, you must

1) update the devicetree/bindings document to reflect the same.
2) update the drivers to take appropriate action on the missing CPU where they are expected (e.g, CPU-debug, etm*), to prevent breaking a bisect.

Quoted 13 lines

coresight platform for such cases and then handle it in the coresight drivers.

---
  drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-platform.c +0 -0
index 3c5ceda8db24..b1ea60c210e1 100644

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 166

Quoted 8 lines
drivers/hwtracing/coresight/coresight-platform.c +3 -1
@@ -160,15 +160,17 @@ static int of_coresight_get_cpu(struct device *dev)
 
  	if (!dev->of_node)
  		return 0;
+
  	dn = of_parse_phandle(dev->of_node, "cpu", 0);
-	/* Affinity defaults to CPU0 */
+
+	/* Affinity defaults to invalid if no cpu nodes are found*/

The code is self explanatory here. You could drop the comment.

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 175

Quoted 12 lines
drivers/hwtracing/coresight/coresight-platform.c +3 -3
  	if (!dn)
-		return 0;
+		return -ENODEV;
+
  	cpu = of_cpu_node_to_id(dn);
  	of_node_put(dn);
 
-	/* Affinity to CPU0 if no cpu nodes are found */
-	return (cpu < 0) ? 0 : cpu;
+	return cpu;
  }
 

Suzuki

#3 lore raw

Hi Suzuki,

Thanks for the review.

Quoted 7 lines · Suzuki K Poulose

Sai,

Thanks for the patch. Please could you change the subject to :

"coresight: Do not default to CPU0 for missing CPU phandle"

Sure.

Quoted 14 lines · Sai Prakash Ranjan
Quoted 3 lines

Affinity defaults to CPU0 in case of missing CPU phandle and this leads to crashes in some cases because of such wrong assumption. Fix this by returning -ENODEV in

Thats not the right justification. Causing crashes is due to bad DT/firmware. I would be happy with something like :

"Coresight platform support assumes that a missing \"cpu\" phandle defaults to CPU0. This could be problematic and unnecessarily binds components to CPU0, where they may not be. Let us make the DT binding rules a bit stricter by not defaulting to CPU0 for missing "cpu" affinity information."

Quoted 8 lines

Also, you must

1) update the devicetree/bindings document to reflect the same.
2) update the drivers to take appropriate action on the missing CPU where they are expected (e.g, CPU-debug, etm*), to prevent breaking a bisect.

Sure will do it and repost.

Quoted 8 lines
Quoted 8 lines

coresight platform for such cases and then handle it in the coresight drivers.

---
  drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----

  1 file changed, 6 insertions(+), 4 deletions(-)
Quoted 15 lines

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 165

Quoted 12 lines
drivers/hwtracing/coresight/coresight-platform.c +3 -1
index 3c5ceda8db24..b1ea60c210e1 100644
@@ -160,15 +160,17 @@ static int of_coresight_get_cpu(struct device *dev)
       if (!dev->of_node)
           return 0;
+
       dn = of_parse_phandle(dev->of_node, "cpu", 0);
-    /* Affinity defaults to CPU0 */
+
+    /* Affinity defaults to invalid if no cpu nodes are found*/

The code is self explanatory here. You could drop the comment.

Sure.

Quoted 11 lines

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 174

Quoted 10 lines
drivers/hwtracing/coresight/coresight-platform.c +3 -3
       if (!dn)
-        return 0;
+        return -ENODEV;
+
       cpu = of_cpu_node_to_id(dn);
       of_node_put(dn);
-    /* Affinity to CPU0 if no cpu nodes are found */
-    return (cpu < 0) ? 0 : cpu;
+    return cpu;
   }
Quoted 1 line

Suzuki

-Sai

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#4 lore raw
In reply to Sai Prakash Ranjan

Hi Sai,

Quoted 16 lines · Sai Prakash Ranjan

Affinity defaults to CPU0 in case of missing CPU phandle and this leads to crashes in some cases because of such wrong assumption. Fix this by returning -ENODEV in coresight platform for such cases and then handle it in the coresight drivers.

---
 drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-platform.c +0 -0
index 3c5ceda8db24..b1ea60c210e1 100644

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 162

Quoted 3 lines
drivers/hwtracing/coresight/coresight-platform.c +0 -0
@@ -160,15 +160,17 @@ static int of_coresight_get_cpu(struct device *dev)
 
 	if (!dev->of_node)
 		return 0;

An error should be returned if the above condition is true.

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 163

Quoted 1 line
drivers/hwtracing/coresight/coresight-platform.c +1 -0
+

Spurious newline

Quoted 21 lines
drivers/hwtracing/coresight/coresight-platform.c +5 -4
 	dn = of_parse_phandle(dev->of_node, "cpu", 0);
-	/* Affinity defaults to CPU0 */
+
+	/* Affinity defaults to invalid if no cpu nodes are found*/
 	if (!dn)
-		return 0;
+		return -ENODEV;
+
 	cpu = of_cpu_node_to_id(dn);
 	of_node_put(dn);
 
-	/* Affinity to CPU0 if no cpu nodes are found */
-	return (cpu < 0) ? 0 : cpu;
+	return cpu;
 }
 
 /*
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#5 lore raw

Hi Mathieu,

Thanks for the review comments.

Quoted 20 lines · Mathieu Poirier

Hi Sai,

Quoted 17 lines · Sai Prakash Ranjan

Affinity defaults to CPU0 in case of missing CPU phandle and this leads to crashes in some cases because of such wrong assumption. Fix this by returning -ENODEV in coresight platform for such cases and then handle it in the coresight drivers.

---
  drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-platform.c +0 -0
index 3c5ceda8db24..b1ea60c210e1 100644
@@ -160,15 +160,17 @@ static int of_coresight_get_cpu(struct device *dev)
 
Quoted 5 lines

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 162

Quoted 2 lines
drivers/hwtracing/coresight/coresight-platform.c +0 -0
  	if (!dev->of_node)
  		return 0;

An error should be returned if the above condition is true.

Will do it, thanks.

Quoted 4 lines

drivers/hwtracing/coresight/coresight-platform.c static int of_coresight_get_cpu(struct device *dev) · line 163

Quoted 1 line
drivers/hwtracing/coresight/coresight-platform.c +1 -0
+

Spurious newline

This was on purpose, the code looks much cleaner.

-Sai

Signature · 7 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#6 lore raw

PATCH 2/2 coresight: Abort probe for missing CPU phandle

In reply to Sai Prakash Ranjan

Currently the coresight etm and cpu-debug drivers assume the affinity to CPU0 returned by coresight platform and continue the probe in case of missing CPU phandle. This is not true and leads to crash in some cases, so abort the probe in case of missing CPU phandle.

---
 drivers/hwtracing/coresight/coresight-cpu-debug.c | 3 +++
 drivers/hwtracing/coresight/coresight-etm3x.c     | 3 +++
 drivers/hwtracing/coresight/coresight-etm4x.c     | 3 +++
 3 files changed, 9 insertions(+)
drivers/hwtracing/coresight/coresight-cpu-debug.c +3 -0
index 07a1367c733f..43f32fa71ff9 100644
@@ -579,6 +579,9 @@ static int debug_probe(struct amba_device *adev, const struct amba_id *id)
 		return -ENOMEM;
 
 	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;
+
 	if (per_cpu(debug_drvdata, drvdata->cpu)) {
 		dev_err(dev, "CPU%d drvdata has already been initialized\n",
 			drvdata->cpu);
drivers/hwtracing/coresight/coresight-etm3x.c +3 -0
index 225c2982e4fe..882e2751746c 100644
@@ -816,6 +816,9 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
 	}
 
 	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;
+
 	desc.name  = devm_kasprintf(dev, GFP_KERNEL, "etm%d", drvdata->cpu);
 	if (!desc.name)
 		return -ENOMEM;
drivers/hwtracing/coresight/coresight-etm4x.c +3 -0
index 7fe266194ab5..97d71dbbeb19 100644
@@ -1101,6 +1101,9 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	spin_lock_init(&drvdata->spinlock);
 
 	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;
+
 	desc.name = devm_kasprintf(dev, GFP_KERNEL, "etm%d", drvdata->cpu);
 	if (!desc.name)
 		return -ENOMEM;
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
maintainer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] coresight: Abort probe for missing CPU phandle

Quoted 19 lines · Sai Prakash Ranjan

Currently the coresight etm and cpu-debug drivers assume the affinity to CPU0 returned by coresight platform and continue the probe in case of missing CPU phandle. This is not true and leads to crash in some cases, so abort the probe in case of missing CPU phandle.

---
  drivers/hwtracing/coresight/coresight-cpu-debug.c | 3 +++
  drivers/hwtracing/coresight/coresight-etm3x.c     | 3 +++
  drivers/hwtracing/coresight/coresight-etm4x.c     | 3 +++
  3 files changed, 9 insertions(+)
drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
index 07a1367c733f..43f32fa71ff9 100644

drivers/hwtracing/coresight/coresight-cpu-debug.c static int debug_probe(struct amba_device *adev, const struct amba_id *id) · line 583

Quoted 5 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -0
@@ -579,6 +579,9 @@ static int debug_probe(struct amba_device *adev, const struct amba_id *id)
  		return -ENOMEM;
 
  	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;

if (drvdata->cpu < 0)

	return drvdata->cpu;

Same everywhere below ?

Also, I would like to hear Mathieu's thoughts on this change. If he's OK with it:

#8 lore raw

Re: [PATCH 2/2] coresight: Abort probe for missing CPU phandle

Quoted 31 lines · Suzuki K Poulose
Quoted 19 lines · Sai Prakash Ranjan

Currently the coresight etm and cpu-debug drivers assume the affinity to CPU0 returned by coresight platform and continue the probe in case of missing CPU phandle. This is not true and leads to crash in some cases, so abort the probe in case of missing CPU phandle.

---
  drivers/hwtracing/coresight/coresight-cpu-debug.c | 3 +++ drivers/hwtracing/coresight/coresight-etm3x.c     | 3 +++ drivers/hwtracing/coresight/coresight-etm4x.c     | 3 +++

  3 files changed, 9 insertions(+)
drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
index 07a1367c733f..43f32fa71ff9 100644

drivers/hwtracing/coresight/coresight-cpu-debug.c static int debug_probe(struct amba_device *adev, · line 583

Quoted 5 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -0
@@ -579,6 +579,9 @@ static int debug_probe(struct amba_device *adev, 
 const struct amba_id *id)
           return -ENOMEM;
       drvdata->cpu = coresight_get_cpu(dev);
+    if (drvdata->cpu == -ENODEV)
+        return -ENODEV;

if (drvdata->cpu < 0)
    return drvdata->cpu;

Quoted 8 lines

Same everywhere below ?

Also, I would like to hear Mathieu's thoughts on this change. If he's OK with it:

Thanks, I will make the change and repost.

-Sai

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
maintainer
#9 lore raw

Re: [PATCH 2/2] coresight: Abort probe for missing CPU phandle

Quoted 38 lines · Sai Prakash Ranjan
Quoted 37 lines · Suzuki K Poulose
Quoted 20 lines · Sai Prakash Ranjan

Currently the coresight etm and cpu-debug drivers assume the affinity to CPU0 returned by coresight platform and continue the probe in case of missing CPU phandle. This is not true and leads to crash in some cases, so abort the probe in case of missing CPU phandle.

---
   drivers/hwtracing/coresight/coresight-cpu-debug.c | 3 +++
   drivers/hwtracing/coresight/coresight-etm3x.c     | 3 +++
   drivers/hwtracing/coresight/coresight-etm4x.c     | 3 +++
   3 files changed, 9 insertions(+)
drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
index 07a1367c733f..43f32fa71ff9 100644

drivers/hwtracing/coresight/coresight-cpu-debug.c static int debug_probe(struct amba_device *adev, · line 583

Quoted 5 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -0
@@ -579,6 +579,9 @@ static int debug_probe(struct amba_device *adev,
 const struct amba_id *id)
           return -ENOMEM;
       drvdata->cpu = coresight_get_cpu(dev);
+    if (drvdata->cpu == -ENODEV)
+        return -ENODEV;

if (drvdata->cpu < 0)
    return drvdata->cpu;

Same everywhere below ?

Also, I would like to hear Mathieu's thoughts on this change. If he's OK with it:

Quoted 6 lines
Quoted 4 lines

above.

Thanks, I will make the change and repost.

Please wait for Mathieu's thoughts on it. And in general I would wait for feedback from the people in a version, before posting another one, to reduce the number of respins.

Cheers
Suzuki

#10 lore raw

Re: [PATCH 2/2] coresight: Abort probe for missing CPU phandle

Quoted 7 lines · Suzuki K Poulose

Please wait for Mathieu's thoughts on it. And in general I would wait for feedback from the people in a version, before posting another one, to reduce the number of respins.

Mathieu already said he was OK in the other thread, but I will wait for some more feedbacks.

Thanks,
Sai

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#11 lore raw

Re: [PATCH 2/2] coresight: Abort probe for missing CPU phandle

In reply to Sai Prakash Ranjan
Quoted 19 lines · Sai Prakash Ranjan

Currently the coresight etm and cpu-debug drivers assume the affinity to CPU0 returned by coresight platform and continue the probe in case of missing CPU phandle. This is not true and leads to crash in some cases, so abort the probe in case of missing CPU phandle.

---
 drivers/hwtracing/coresight/coresight-cpu-debug.c | 3 +++
 drivers/hwtracing/coresight/coresight-etm3x.c     | 3 +++
 drivers/hwtracing/coresight/coresight-etm4x.c     | 3 +++
 3 files changed, 9 insertions(+)
drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
index 07a1367c733f..43f32fa71ff9 100644

drivers/hwtracing/coresight/coresight-cpu-debug.c static int debug_probe(struct amba_device *adev, const struct amba_id *id) · line 583

Quoted 5 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -0
@@ -579,6 +579,9 @@ static int debug_probe(struct amba_device *adev, const struct amba_id *id)
 		return -ENOMEM;
 
 	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;

As Suzuki pointed out, simply return the error message conveyed by coresight_get_cpu().

Also please merge both patches together to avoid bisect nightmare.

Thank you for the contribution,
Mathieu

Quoted 36 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +1 -0
+
 	if (per_cpu(debug_drvdata, drvdata->cpu)) {
 		dev_err(dev, "CPU%d drvdata has already been initialized\n",
 			drvdata->cpu);
drivers/hwtracing/coresight/coresight-etm3x.c +3 -0
index 225c2982e4fe..882e2751746c 100644
@@ -816,6 +816,9 @@ static int etm_probe(struct amba_device *adev, const struct amba_id *id)
 	}
 
 	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;
+
 	desc.name  = devm_kasprintf(dev, GFP_KERNEL, "etm%d", drvdata->cpu);
 	if (!desc.name)
 		return -ENOMEM;
drivers/hwtracing/coresight/coresight-etm4x.c +3 -0
index 7fe266194ab5..97d71dbbeb19 100644
@@ -1101,6 +1101,9 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
 	spin_lock_init(&drvdata->spinlock);
 
 	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;
+
 	desc.name = devm_kasprintf(dev, GFP_KERNEL, "etm%d", drvdata->cpu);
 	if (!desc.name)
 		return -ENOMEM;
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#12 lore raw

Re: [PATCH 2/2] coresight: Abort probe for missing CPU phandle

Hi Mathieu,

Thanks for the review comments.

Quoted 8 lines · Mathieu Poirier
Quoted 7 lines · Sai Prakash Ranjan
drivers/hwtracing/coresight/coresight-cpu-debug.c +0 -0
index 07a1367c733f..43f32fa71ff9 100644
@@ -579,6 +579,9 @@ static int debug_probe(struct amba_device *adev, const struct amba_id *id)
  		return -ENOMEM;
 
Quoted 8 lines

drivers/hwtracing/coresight/coresight-cpu-debug.c static int debug_probe(struct amba_device *adev, const struct amba_id *id) · line 583

Quoted 3 lines
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -0
  	drvdata->cpu = coresight_get_cpu(dev);
+	if (drvdata->cpu == -ENODEV)
+		return -ENODEV;

As Suzuki pointed out, simply return the error message conveyed by coresight_get_cpu().

Also please merge both patches together to avoid bisect nightmare.

Sure, will do it.

Signature · 7 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel