[PATCH 1/1] irqchip/loongson-pch-pic: Fix vec_count reading for 32-bit and 64-bit

George Guo
2026-04-10T01:31:07Z

From: George Guo <guodongtai@kylinos.cn>

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.

Fixes: 0370a5e740f2 ("irqchip/loongson-pch-pic: Adjust irqchip driver for 32BIT/64BIT")
Cc: stable@vger.kernel.org
Tested-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
drivers/irqchip/irq-loongson-pch-pic.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-loongson-pch-pic.c b/drivers/irqchip/irq-loongson-pch-pic.c
index 98fc1770e2a5..eb25d482a4c5 100644
--- a/drivers/irqchip/irq-loongson-pch-pic.c
+++ b/drivers/irqchip/irq-loongson-pch-pic.c
@@ -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,
--
2.43.0