irqchip/loongson-pch-pic: Fix vec_count reading for 32-bit and 64-bit
Subsystems (3)
PATCH 1/1 irqchip/loongson-pch-pic: Fix vec_count reading for 32-bit and 64-bit
From: George Guo <[email protected]>
Commit 0370a5e740f2 ("irqchip/loongson-pch-pic: Adjust irqchip driver for 32BIT/64BIT") changed vec_count reading from readq() to readl() to support both 32-bit and 64-bit platforms. However, on virtual 64-bit platforms (QEMU 8.2.0) this causes incorrect vec_count value, leading to panic:
WARNING: drivers/acpi/irq.c:63 at acpi_register_gsi+0xe8/0x108 Call Trace: [<900000000024c634>] show_stack+0x64/0x188 [<9000000000245154>] dump_stack_lvl+0x6c/0x9c [<900000000026cb38>] __warn+0x98/0x200 [<90000000016dc900>] __report_bug+0xa8/0x1c0 [<90000000016dcb0c>] report_bug+0x3c/0xc0 [<90000000017170b0>] do_bp+0x270/0x3c0 [<900000000024aba8>] handle_bp+0x128/0x1e0 [<9000000000def7a0>] acpi_register_gsi+0xe8/0x108 [<9000000000ddcc5c>] acpi_dev_resource_interrupt+0x2f4/0x348 [<9000000000e43ad0>] pnpacpi_allocated_resource+0xc8/0x398 [<9000000000e1d608>] acpi_walk_resource_buffer+0x88/0x168 [<9000000000e1dbec>] acpi_walk_resources+0x13c/0x178 [<9000000000e43df0>] pnpacpi_parse_allocated_resource+0x50/0xc8 [<9000000001778b00>] pnpacpi_add_device.isra.0+0x208/0x2e4 [<9000000001778c10>] pnpacpi_add_device_handler+0x34/0x54 [<9000000000e14fac>] acpi_ns_get_device_callback+0x15c/0x2c8 [<9000000000e14bc4>] acpi_ns_walk_namespace+0x134/0x2d0 [<9000000000e14e28>] acpi_get_devices+0xc8/0xf0 [<9000000001778878>] pnpacpi_init+0x68/0x9c [<9000000000248e7c>] do_one_initcall+0x6c/0x4b0 [<9000000001731aa0>] do_initcalls+0x118/0x160 [<9000000001731ca4>] kernel_init_freeable+0x148/0x1a4 [<900000000171a294>] kernel_init+0x24/0x130 [<9000000001717358>] ret_from_kernel_thread+0x28/0x150 [<900000000024a24c>] ret_from_kernel_thread_asm+0xc/0xa0
GSI: No registered irqchip, giving up
Fix this by using readq() on 64-bit and readl() on 32-bit platforms.
--- drivers/irqchip/irq-loongson-pch-pic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/irqchip/irq-loongson-pch-pic.c +6 -1
@@ -343,7 +343,12 @@ static int pch_pic_init(phys_addr_t addr, unsigned long size, int vec_base, priv->table[i] =PIC_UNDEF_VECTOR ; priv->ht_vec_base = vec_base; - priv->vec_count = ((readl (priv->base +4 ) >>16 ) &0xff ) +1 ; + +if (IS_ENABLED (CONFIG_64BIT )) + priv->vec_count = ((readq (priv->base) >>48 ) &0xff ) +1 ; +else + priv->vec_count = ((readl (priv->base +4 ) >>16 ) &0xff ) +1 ; + priv->gsi_base = gsi_base; priv->pic_domain = irq_domain_create_hierarchy(parent_domain, 0,
Signature · 1 line
2.43.0
Thomas Gleixner
maintainerQuoted 6 lines · George Guo
From: George Guo <[email protected]>
Commit
0370a5e740f2("irqchip/loongson-pch-pic: Adjust irqchip driver for 32BIT/64BIT") changedvec_countreading fromreadq()toreadl()to support both 32-bit and 64-bit platforms. However, on virtual 64-bit platforms (QEMU 8.2.0) this causes incorrectvec_countvalue, leading to panic:
Is this problem limited to qemu?
Quoted 4 lines
WARNING: drivers/acpi/irq.c:63 at acpi_register_gsi+0xe8/0x108 Call Trace: [<900000000024c634>] show_stack+0x64/0x188 [<9000000000245154>] dump_stack_lvl+0x6c/0x9c
Please trim your backtrace as documented:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces
drivers/irqchip/irq-loongson-pch-pic.c static int pch_pic_init(phys_addr_t addr, unsigned long size, int vec_base, · line 350
Quoted 10 lines
drivers/irqchip/irq-loongson-pch-pic.c +5
-1@@ -343,7 +343,12 @@ static int pch_pic_init(phys_addr_t addr, unsigned long size, int vec_base, priv->table[i] =PIC_UNDEF_VECTOR ; priv->ht_vec_base = vec_base; - priv->vec_count = ((readl (priv->base +4 ) >>16 ) &0xff ) +1 ; + +if (IS_ENABLED (CONFIG_64BIT )) + priv->vec_count = ((readq (priv->base) >>48 ) &0xff ) +1 ; +else + priv->vec_count = ((readl (priv->base +4 ) >>16 ) &0xff ) +1 ;
This does not make sense at all.
readl(base + 4) >> 16
is fully equivalent to
readq(base) >> 48
on a little endian machine, no?
This needs a better explanation in the change log about the root cause and why this is the correct solution to fix the problem.
If there is no other solution then this needs a big fat comment in the code explaining the reason. Otherwise the next AI agent will notice the equivalence and people will send cleanup patches....
Thanks,
tglx
Huacai Chen
maintainerQuoted 10 lines · Thomas Gleixner
Quoted 6 lines · George Guo
From: George Guo <[email protected]>
Commit
0370a5e740f2("irqchip/loongson-pch-pic: Adjust irqchip driver for 32BIT/64BIT") changedvec_countreading fromreadq()toreadl()to support both 32-bit and 64-bit platforms. However, on virtual 64-bit platforms (QEMU 8.2.0) this causes incorrectvec_countvalue, leading to panic:Is this problem limited to qemu?
I think it is a qemu bug rather than a kernel bug. Since qemu 8.2.0 is old, I suggest use qemu 10.2.0 to test.
Huacai
Quoted 41 lines
Quoted 5 lines
WARNING: drivers/acpi/irq.c:63 at acpi_register_gsi+0xe8/0x108 Call Trace: [<900000000024c634>] show_stack+0x64/0x188 [<9000000000245154>] dump_stack_lvl+0x6c/0x9cPlease trim your backtrace as documented:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces
drivers/irqchip/irq-loongson-pch-pic.c static int pch_pic_init(phys_addr_t addr, unsigned long size, int vec_base, · line 350
Quoted 10 lines
drivers/irqchip/irq-loongson-pch-pic.c +5
-1@@ -343,7 +343,12 @@ static int pch_pic_init(phys_addr_t addr, unsigned long size, int vec_base, priv->table[i] =PIC_UNDEF_VECTOR ; priv->ht_vec_base = vec_base; - priv->vec_count = ((readl (priv->base +4 ) >>16 ) &0xff ) +1 ; + +if (IS_ENABLED (CONFIG_64BIT )) + priv->vec_count = ((readq (priv->base) >>48 ) &0xff ) +1 ; +else + priv->vec_count = ((readl (priv->base +4 ) >>16 ) &0xff ) +1 ;This does not make sense at all.
readl(base + 4) >> 16is fully equivalent to
readq(base) >> 48on a little endian machine, no?
This needs a better explanation in the change log about the root cause and why this is the correct solution to fix the problem.
If there is no other solution then this needs a big fat comment in the code explaining the reason. Otherwise the next AI agent will notice the equivalence and people will send cleanup patches....
Thanks,
tglx