diff mbox series

[v3,1/2] irqchip/loongson-eiointc: Fix return value checking of eiointc_index

Message ID 20230711120807.1805186-2-maobibo@loongson.cn (mailing list archive)
State Superseded
Headers show
Series irqchip/loongson-eiointc: Add simple irq routing method | expand

Commit Message

bibo mao July 11, 2023, 12:08 p.m. UTC
Return value of function eiointc_index is int, however it is converted
into uint32_t and then compared smaller than zero. This causes logic
problem. There is eioint initialization problem on qemu virt-machine
where there is only one eioint node and more than 4 vcpus. Nodemap of
eioint is 1, and external device intr can only be routed to vcpu 0-3, the
other vcpus can not response any external device interrupts and only local
processor interrupts like ipi/timer can work.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 drivers/irqchip/irq-loongson-eiointc.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Philippe Mathieu-Daudé July 11, 2023, 1:18 p.m. UTC | #1
On 11/7/23 14:08, Bibo Mao wrote:
> Return value of function eiointc_index is int, however it is converted
> into uint32_t and then compared smaller than zero. This causes logic
> problem. There is eioint initialization problem on qemu virt-machine
> where there is only one eioint node and more than 4 vcpus. Nodemap of
> eioint is 1, and external device intr can only be routed to vcpu 0-3, the
> other vcpus can not response any external device interrupts and only local
> processor interrupts like ipi/timer can work.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   drivers/irqchip/irq-loongson-eiointc.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)

Fixes: dd281e1a1a93 ("irqchip: Add Loongson Extended I/O interrupt 
controller support")

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Huacai Chen July 11, 2023, 3:06 p.m. UTC | #2
On Tue, Jul 11, 2023 at 8:08 PM Bibo Mao <maobibo@loongson.cn> wrote:
>
> Return value of function eiointc_index is int, however it is converted
> into uint32_t and then compared smaller than zero. This causes logic
> problem. There is eioint initialization problem on qemu virt-machine
> where there is only one eioint node and more than 4 vcpus. Nodemap of
> eioint is 1, and external device intr can only be routed to vcpu 0-3, the
> other vcpus can not response any external device interrupts and only local
> processor interrupts like ipi/timer can work.
I'm sorry but there are still spelling problems...
"eio", "eio intc", "eioint" should all be "eiointc".

Huacai

>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>  drivers/irqchip/irq-loongson-eiointc.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
> index 92d8aa28bdf5..1c5a5b59f199 100644
> --- a/drivers/irqchip/irq-loongson-eiointc.c
> +++ b/drivers/irqchip/irq-loongson-eiointc.c
> @@ -144,12 +144,14 @@ static int eiointc_router_init(unsigned int cpu)
>         int i, bit;
>         uint32_t data;
>         uint32_t node = cpu_to_eio_node(cpu);
> -       uint32_t index = eiointc_index(node);
> +       int index = eiointc_index(node);
>
> -       if (index < 0) {
> -               pr_err("Error: invalid nodemap!\n");
> -               return -1;
> -       }
> +       /*
> +        * qemu virt-machine has only one eio intc and more than four cpus
> +        * irq from eio can only be routed to cpu 0-3 on virt machine
> +        */
> +       if (index < 0)
> +               return 0;
>
>         if ((cpu_logical_map(cpu) % CORES_PER_EIO_NODE) == 0) {
>                 eiointc_enable();
> --
> 2.27.0
>
bibo mao July 12, 2023, 1:03 a.m. UTC | #3
在 2023/7/11 23:06, Huacai Chen 写道:
> On Tue, Jul 11, 2023 at 8:08 PM Bibo Mao <maobibo@loongson.cn> wrote:
>>
>> Return value of function eiointc_index is int, however it is converted
>> into uint32_t and then compared smaller than zero. This causes logic
>> problem. There is eioint initialization problem on qemu virt-machine
>> where there is only one eioint node and more than 4 vcpus. Nodemap of
>> eioint is 1, and external device intr can only be routed to vcpu 0-3, the
>> other vcpus can not response any external device interrupts and only local
>> processor interrupts like ipi/timer can work.
> I'm sorry but there are still spelling problems...
> "eio", "eio intc", "eioint" should all be "eiointc".
Sure, thanks for pointing it out, will modify in next version.

Regards
Bibo Mao
> 
> Huacai
> 
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> ---
>>  drivers/irqchip/irq-loongson-eiointc.c | 12 +++++++-----
>>  1 file changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
>> index 92d8aa28bdf5..1c5a5b59f199 100644
>> --- a/drivers/irqchip/irq-loongson-eiointc.c
>> +++ b/drivers/irqchip/irq-loongson-eiointc.c
>> @@ -144,12 +144,14 @@ static int eiointc_router_init(unsigned int cpu)
>>         int i, bit;
>>         uint32_t data;
>>         uint32_t node = cpu_to_eio_node(cpu);
>> -       uint32_t index = eiointc_index(node);
>> +       int index = eiointc_index(node);
>>
>> -       if (index < 0) {
>> -               pr_err("Error: invalid nodemap!\n");
>> -               return -1;
>> -       }
>> +       /*
>> +        * qemu virt-machine has only one eio intc and more than four cpus
>> +        * irq from eio can only be routed to cpu 0-3 on virt machine
>> +        */
>> +       if (index < 0)
>> +               return 0;
>>
>>         if ((cpu_logical_map(cpu) % CORES_PER_EIO_NODE) == 0) {
>>                 eiointc_enable();
>> --
>> 2.27.0
>>
Marc Zyngier July 12, 2023, 8:56 a.m. UTC | #4
On Tue, 11 Jul 2023 13:08:06 +0100,
Bibo Mao <maobibo@loongson.cn> wrote:
> 
> Return value of function eiointc_index is int, however it is converted
> into uint32_t and then compared smaller than zero. This causes logic
> problem. There is eioint initialization problem on qemu virt-machine
> where there is only one eioint node and more than 4 vcpus. Nodemap of
> eioint is 1, and external device intr can only be routed to vcpu 0-3, the
> other vcpus can not response any external device interrupts and only local
> processor interrupts like ipi/timer can work.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>  drivers/irqchip/irq-loongson-eiointc.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
> index 92d8aa28bdf5..1c5a5b59f199 100644
> --- a/drivers/irqchip/irq-loongson-eiointc.c
> +++ b/drivers/irqchip/irq-loongson-eiointc.c
> @@ -144,12 +144,14 @@ static int eiointc_router_init(unsigned int cpu)
>  	int i, bit;
>  	uint32_t data;
>  	uint32_t node = cpu_to_eio_node(cpu);
> -	uint32_t index = eiointc_index(node);
> +	int index = eiointc_index(node);
>  
> -	if (index < 0) {
> -		pr_err("Error: invalid nodemap!\n");
> -		return -1;
> -	}
> +	/*
> +	 * qemu virt-machine has only one eio intc and more than four cpus
> +	 * irq from eio can only be routed to cpu 0-3 on virt machine
> +	 */
> +	if (index < 0)
> +		return 0;
>  
>  	if ((cpu_logical_map(cpu) % CORES_PER_EIO_NODE) == 0) {
>  		eiointc_enable();

This sort of thing really needs a Fixes: tag.

Thanks,

	M.
bibo mao July 12, 2023, 9:14 a.m. UTC | #5
在 2023/7/12 16:56, Marc Zyngier 写道:
> On Tue, 11 Jul 2023 13:08:06 +0100,
> Bibo Mao <maobibo@loongson.cn> wrote:
>>
>> Return value of function eiointc_index is int, however it is converted
>> into uint32_t and then compared smaller than zero. This causes logic
>> problem. There is eioint initialization problem on qemu virt-machine
>> where there is only one eioint node and more than 4 vcpus. Nodemap of
>> eioint is 1, and external device intr can only be routed to vcpu 0-3, the
>> other vcpus can not response any external device interrupts and only local
>> processor interrupts like ipi/timer can work.
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> ---
>>  drivers/irqchip/irq-loongson-eiointc.c | 12 +++++++-----
>>  1 file changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
>> index 92d8aa28bdf5..1c5a5b59f199 100644
>> --- a/drivers/irqchip/irq-loongson-eiointc.c
>> +++ b/drivers/irqchip/irq-loongson-eiointc.c
>> @@ -144,12 +144,14 @@ static int eiointc_router_init(unsigned int cpu)
>>  	int i, bit;
>>  	uint32_t data;
>>  	uint32_t node = cpu_to_eio_node(cpu);
>> -	uint32_t index = eiointc_index(node);
>> +	int index = eiointc_index(node);
>>  
>> -	if (index < 0) {
>> -		pr_err("Error: invalid nodemap!\n");
>> -		return -1;
>> -	}
>> +	/*
>> +	 * qemu virt-machine has only one eio intc and more than four cpus
>> +	 * irq from eio can only be routed to cpu 0-3 on virt machine
>> +	 */
>> +	if (index < 0)
>> +		return 0;
>>  
>>  	if ((cpu_logical_map(cpu) % CORES_PER_EIO_NODE) == 0) {
>>  		eiointc_enable();
> 
> This sort of thing really needs a Fixes: tag.
Sure, will add Fixes tag.

I am a newbie to lkml, thanks for kindly pointing it out :)

Regards
Bibo Mao

> 
> Thanks,
> 
> 	M.
>
diff mbox series

Patch

diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
index 92d8aa28bdf5..1c5a5b59f199 100644
--- a/drivers/irqchip/irq-loongson-eiointc.c
+++ b/drivers/irqchip/irq-loongson-eiointc.c
@@ -144,12 +144,14 @@  static int eiointc_router_init(unsigned int cpu)
 	int i, bit;
 	uint32_t data;
 	uint32_t node = cpu_to_eio_node(cpu);
-	uint32_t index = eiointc_index(node);
+	int index = eiointc_index(node);
 
-	if (index < 0) {
-		pr_err("Error: invalid nodemap!\n");
-		return -1;
-	}
+	/*
+	 * qemu virt-machine has only one eio intc and more than four cpus
+	 * irq from eio can only be routed to cpu 0-3 on virt machine
+	 */
+	if (index < 0)
+		return 0;
 
 	if ((cpu_logical_map(cpu) % CORES_PER_EIO_NODE) == 0) {
 		eiointc_enable();