[V1,2/5] irqchip/loongson-eiointc: Fix incorrect use of acpi_get_vec_parent

Message ID 20230324060854.29375-3-lvjianmin@loongson.cn
State New
Headers
Series Fix some issues of irq controllers for dual-bridges scenario |

Commit Message

吕建民 March 24, 2023, 6:08 a.m. UTC
  In eiointc_acpi_init(), a *eiointc* node is passed into
acpi_get_vec_parent() instead of a required *NUMA* node (on some chip
like 3C5000L, a *NUMA* node means a *eiointc* node, but on some chip
like 3C5000, a *NUMA* node contains 4 *eiointc* nodes), and node in
struct acpi_vector_group is essentially a *NUMA* node, which will
lead to no parent matched for passed *eiointc* node. so the patch
adjusts code to use *NUMA* node for parameter node of
acpi_set_vec_parent/acpi_get_vec_parent.

Change-Id: Iddd8423f9694cadc1ce28ee290c2e98ca17dfccc
Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
---
 drivers/irqchip/irq-loongson-eiointc.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
  

Comments

Marc Zyngier March 24, 2023, 3:34 p.m. UTC | #1
On Fri, 24 Mar 2023 06:08:51 +0000,
Jianmin Lv <lvjianmin@loongson.cn> wrote:
> 
> In eiointc_acpi_init(), a *eiointc* node is passed into
> acpi_get_vec_parent() instead of a required *NUMA* node (on some chip
> like 3C5000L, a *NUMA* node means a *eiointc* node, but on some chip
> like 3C5000, a *NUMA* node contains 4 *eiointc* nodes), and node in
> struct acpi_vector_group is essentially a *NUMA* node, which will
> lead to no parent matched for passed *eiointc* node. so the patch
> adjusts code to use *NUMA* node for parameter node of
> acpi_set_vec_parent/acpi_get_vec_parent.
> 
> Change-Id: Iddd8423f9694cadc1ce28ee290c2e98ca17dfccc
> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
> ---
>  drivers/irqchip/irq-loongson-eiointc.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
> index 62a632d73991..b165c27a3609 100644
> --- a/drivers/irqchip/irq-loongson-eiointc.c
> +++ b/drivers/irqchip/irq-loongson-eiointc.c
> @@ -280,9 +280,6 @@ static void acpi_set_vec_parent(int node, struct irq_domain *parent, struct acpi
>  {
>  	int i;
>  
> -	if (cpu_has_flatmode)
> -		node = cpu_to_node(node * CORES_PER_EIO_NODE);
> -
>  	for (i = 0; i < MAX_IO_PICS; i++) {
>  		if (node == vec_group[i].node) {
>  			vec_group[i].parent = parent;
> @@ -349,8 +346,13 @@ static int __init pch_pic_parse_madt(union acpi_subtable_headers *header,
>  static int __init pch_msi_parse_madt(union acpi_subtable_headers *header,
>  					const unsigned long end)
>  {
> +	struct irq_domain *parent;
>  	struct acpi_madt_msi_pic *pchmsi_entry = (struct acpi_madt_msi_pic *)header;
> -	struct irq_domain *parent = acpi_get_vec_parent(eiointc_priv[nr_pics - 1]->node, msi_group);
> +	int node = eiointc_priv[nr_pics - 1]->node;
> +
> +	if (cpu_has_flatmode)
> +		node = cpu_to_node(node * CORES_PER_EIO_NODE);

This is a bit unreadable. I'd rather see:

	int node;

	if (cpu_has_flatmode)
		node = ....;
	else
		node = ....;

which makes it easy to detect the use of an uninitialised 'node'
rather than using the wrong default variable.

> +	parent = acpi_get_vec_parent(node, msi_group);
>  
>  	if (parent)
>  		return pch_msi_acpi_init(parent, pchmsi_entry);
> @@ -379,6 +381,7 @@ int __init eiointc_acpi_init(struct irq_domain *parent,
>  	int i, ret, parent_irq;
>  	unsigned long node_map;
>  	struct eiointc_priv *priv;
> +	int node = acpi_eiointc->node;
>  
>  	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>  	if (!priv)
> @@ -421,8 +424,10 @@ int __init eiointc_acpi_init(struct irq_domain *parent,
>  				  "irqchip/loongarch/intc:starting",
>  				  eiointc_router_init, NULL);
>  
> -	acpi_set_vec_parent(acpi_eiointc->node, priv->eiointc_domain, pch_group);
> -	acpi_set_vec_parent(acpi_eiointc->node, priv->eiointc_domain, msi_group);
> +	if (cpu_has_flatmode)
> +		node = cpu_to_node(node * CORES_PER_EIO_NODE);
> +	acpi_set_vec_parent(node, priv->eiointc_domain, pch_group);
> +	acpi_set_vec_parent(node, priv->eiointc_domain, msi_group);
>  	ret = acpi_cascade_irqdomain_init();
>  
>  	return ret;

Same thing here.

	M.
  
吕建民 March 27, 2023, 4 a.m. UTC | #2
On 2023/3/24 下午11:34, Marc Zyngier wrote:
> On Fri, 24 Mar 2023 06:08:51 +0000,
> Jianmin Lv <lvjianmin@loongson.cn> wrote:
>>
>> In eiointc_acpi_init(), a *eiointc* node is passed into
>> acpi_get_vec_parent() instead of a required *NUMA* node (on some chip
>> like 3C5000L, a *NUMA* node means a *eiointc* node, but on some chip
>> like 3C5000, a *NUMA* node contains 4 *eiointc* nodes), and node in
>> struct acpi_vector_group is essentially a *NUMA* node, which will
>> lead to no parent matched for passed *eiointc* node. so the patch
>> adjusts code to use *NUMA* node for parameter node of
>> acpi_set_vec_parent/acpi_get_vec_parent.
>>
>> Change-Id: Iddd8423f9694cadc1ce28ee290c2e98ca17dfccc
>> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
>> ---
>>   drivers/irqchip/irq-loongson-eiointc.c | 17 +++++++++++------
>>   1 file changed, 11 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
>> index 62a632d73991..b165c27a3609 100644
>> --- a/drivers/irqchip/irq-loongson-eiointc.c
>> +++ b/drivers/irqchip/irq-loongson-eiointc.c
>> @@ -280,9 +280,6 @@ static void acpi_set_vec_parent(int node, struct irq_domain *parent, struct acpi
>>   {
>>   	int i;
>>   
>> -	if (cpu_has_flatmode)
>> -		node = cpu_to_node(node * CORES_PER_EIO_NODE);
>> -
>>   	for (i = 0; i < MAX_IO_PICS; i++) {
>>   		if (node == vec_group[i].node) {
>>   			vec_group[i].parent = parent;
>> @@ -349,8 +346,13 @@ static int __init pch_pic_parse_madt(union acpi_subtable_headers *header,
>>   static int __init pch_msi_parse_madt(union acpi_subtable_headers *header,
>>   					const unsigned long end)
>>   {
>> +	struct irq_domain *parent;
>>   	struct acpi_madt_msi_pic *pchmsi_entry = (struct acpi_madt_msi_pic *)header;
>> -	struct irq_domain *parent = acpi_get_vec_parent(eiointc_priv[nr_pics - 1]->node, msi_group);
>> +	int node = eiointc_priv[nr_pics - 1]->node;
>> +
>> +	if (cpu_has_flatmode)
>> +		node = cpu_to_node(node * CORES_PER_EIO_NODE);
> 
> This is a bit unreadable. I'd rather see:
> 
> 	int node;
> 
> 	if (cpu_has_flatmode)
> 		node = ....;
> 	else
> 		node = ....;
> 
> which makes it easy to detect the use of an uninitialised 'node'
> rather than using the wrong default variable.
> 
>> +	parent = acpi_get_vec_parent(node, msi_group);
>>   
>>   	if (parent)
>>   		return pch_msi_acpi_init(parent, pchmsi_entry);
>> @@ -379,6 +381,7 @@ int __init eiointc_acpi_init(struct irq_domain *parent,
>>   	int i, ret, parent_irq;
>>   	unsigned long node_map;
>>   	struct eiointc_priv *priv;
>> +	int node = acpi_eiointc->node;
>>   
>>   	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>>   	if (!priv)
>> @@ -421,8 +424,10 @@ int __init eiointc_acpi_init(struct irq_domain *parent,
>>   				  "irqchip/loongarch/intc:starting",
>>   				  eiointc_router_init, NULL);
>>   
>> -	acpi_set_vec_parent(acpi_eiointc->node, priv->eiointc_domain, pch_group);
>> -	acpi_set_vec_parent(acpi_eiointc->node, priv->eiointc_domain, msi_group);
>> +	if (cpu_has_flatmode)
>> +		node = cpu_to_node(node * CORES_PER_EIO_NODE);
>> +	acpi_set_vec_parent(node, priv->eiointc_domain, pch_group);
>> +	acpi_set_vec_parent(node, priv->eiointc_domain, msi_group);
>>   	ret = acpi_cascade_irqdomain_init();
>>   
>>   	return ret;
> 
> Same thing here.
> 

Ok, I'll change them  in next version.

Thanks!

> 	M.
>
  

Patch

diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
index 62a632d73991..b165c27a3609 100644
--- a/drivers/irqchip/irq-loongson-eiointc.c
+++ b/drivers/irqchip/irq-loongson-eiointc.c
@@ -280,9 +280,6 @@  static void acpi_set_vec_parent(int node, struct irq_domain *parent, struct acpi
 {
 	int i;
 
-	if (cpu_has_flatmode)
-		node = cpu_to_node(node * CORES_PER_EIO_NODE);
-
 	for (i = 0; i < MAX_IO_PICS; i++) {
 		if (node == vec_group[i].node) {
 			vec_group[i].parent = parent;
@@ -349,8 +346,13 @@  static int __init pch_pic_parse_madt(union acpi_subtable_headers *header,
 static int __init pch_msi_parse_madt(union acpi_subtable_headers *header,
 					const unsigned long end)
 {
+	struct irq_domain *parent;
 	struct acpi_madt_msi_pic *pchmsi_entry = (struct acpi_madt_msi_pic *)header;
-	struct irq_domain *parent = acpi_get_vec_parent(eiointc_priv[nr_pics - 1]->node, msi_group);
+	int node = eiointc_priv[nr_pics - 1]->node;
+
+	if (cpu_has_flatmode)
+		node = cpu_to_node(node * CORES_PER_EIO_NODE);
+	parent = acpi_get_vec_parent(node, msi_group);
 
 	if (parent)
 		return pch_msi_acpi_init(parent, pchmsi_entry);
@@ -379,6 +381,7 @@  int __init eiointc_acpi_init(struct irq_domain *parent,
 	int i, ret, parent_irq;
 	unsigned long node_map;
 	struct eiointc_priv *priv;
+	int node = acpi_eiointc->node;
 
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -421,8 +424,10 @@  int __init eiointc_acpi_init(struct irq_domain *parent,
 				  "irqchip/loongarch/intc:starting",
 				  eiointc_router_init, NULL);
 
-	acpi_set_vec_parent(acpi_eiointc->node, priv->eiointc_domain, pch_group);
-	acpi_set_vec_parent(acpi_eiointc->node, priv->eiointc_domain, msi_group);
+	if (cpu_has_flatmode)
+		node = cpu_to_node(node * CORES_PER_EIO_NODE);
+	acpi_set_vec_parent(node, priv->eiointc_domain, pch_group);
+	acpi_set_vec_parent(node, priv->eiointc_domain, msi_group);
 	ret = acpi_cascade_irqdomain_init();
 
 	return ret;