diff mbox series

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

Message ID 49d6554536047b9f5526c4ea33990b7c904673d3.1561037262.git.saiprakash.ranjan@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series coresight: Set affinity to invalid for missing CPU phandle | expand

Commit Message

Sai Prakash Ranjan June 20, 2019, 1:45 p.m. UTC
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.

Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
---
 drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Suzuki K Poulose June 20, 2019, 1:55 p.m. UTC | #1
Sai,

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

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

On 20/06/2019 14:45, Sai Prakash Ranjan wrote:
> 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.


> coresight platform for such cases and then handle it
> in the coresight drivers.
> 
> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
> ---
>   drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index 3c5ceda8db24..b1ea60c210e1 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -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.

>   	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
Sai Prakash Ranjan June 20, 2019, 2:54 p.m. UTC | #2
Hi Suzuki,

Thanks for the review.

On 6/20/2019 7:25 PM, Suzuki K Poulose wrote:
> 
> Sai,
> 
> Thanks for the patch. Please could you change the subject to :
> 
> "coresight: Do not default to CPU0 for missing CPU phandle"
> 

Sure.

> On 20/06/2019 14:45, Sai Prakash Ranjan wrote:
>> 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.
> 
> 

Sure will do it and repost.

>> coresight platform for such cases and then handle it
>> in the coresight drivers.
>>
>> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
>> ---
>>   drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
>>   1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-platform.c 
>> b/drivers/hwtracing/coresight/coresight-platform.c
>> index 3c5ceda8db24..b1ea60c210e1 100644
>> --- a/drivers/hwtracing/coresight/coresight-platform.c
>> +++ b/drivers/hwtracing/coresight/coresight-platform.c
>> @@ -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.

>>       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

-Sai
Mathieu Poirier June 20, 2019, 5:39 p.m. UTC | #3
Hi Sai,

On Thu, Jun 20, 2019 at 07:15:46PM +0530, Sai Prakash Ranjan wrote:
> 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.
> 
> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
> ---
>  drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> index 3c5ceda8db24..b1ea60c210e1 100644
> --- a/drivers/hwtracing/coresight/coresight-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-platform.c
> @@ -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.  

> +

Spurious newline

>  	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;
>  }
>  
>  /*
> -- 
> QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
> of Code Aurora Forum, hosted by The Linux Foundation
>
Sai Prakash Ranjan June 20, 2019, 6:05 p.m. UTC | #4
Hi Mathieu,

Thanks for the review comments.

On 6/20/2019 11:09 PM, Mathieu Poirier wrote:
> Hi Sai,
> 
> On Thu, Jun 20, 2019 at 07:15:46PM +0530, Sai Prakash Ranjan wrote:
>> 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.
>>
>> Signed-off-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
>> ---
>>   drivers/hwtracing/coresight/coresight-platform.c | 10 ++++++----
>>   1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
>> index 3c5ceda8db24..b1ea60c210e1 100644
>> --- a/drivers/hwtracing/coresight/coresight-platform.c
>> +++ b/drivers/hwtracing/coresight/coresight-platform.c
>> @@ -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.
> 

Will do it, thanks.

>> +
> 
> Spurious newline
> 

This was on purpose, the code looks much cleaner.

-Sai
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
index 3c5ceda8db24..b1ea60c210e1 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -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;
 }
 
 /*