* [PATCH v2] irqchip/riscv-aplic: fix asynchronous probing
@ 2026-10-12 8:33 Vladimir Kondratiev
2026-10-12 8:41 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Kondratiev @ 2026-10-12 8:33 UTC (permalink / raw)
To: Anup Patel, Thomas Gleixner, Radu Rendec, Paul Walmsley,
Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Jessica Liu
Cc: linux-riscv, linux-kernel, linux-rt-devel, Vladimir Kondratiev
boolean flag don't protect from race when probing several instances
asynchronously. On system with multiple APLICs, if probed asynchronously,
warning triggered as below.
[ 0.227210] riscv-aplic 67560000.interrupt-controller: 257 interrupts directly connected to 8 CPUs
[ 0.227210] riscv-aplic 674e0000.interrupt-controller: 257 interrupts directly connected to 8 CPUs
[ 0.227224] ------------[ cut here ]------------
[ 0.227227] list_add double add: new=ffffffff8130ced0, prev=ffffffff8130ced0, next=ffffffff81316d40.
[ 0.227302] WARNING: lib/list_debug.c:35 at __list_add_valid_or_report+0xe0/0xe6, CPU#4: kworker/u97:0/211
[ 0.227322] Modules linked in:
[ 0.227333] CPU: 4 UID: 0 PID: 211 Comm: kworker/u97:0 Not tainted 7.3.0-rc6 #1 PREEMPT_RT
[ 0.227341] Hardware name: EyeQ7H evaluation board (DT)
[ 0.227346] Workqueue: async async_run_entry_fn
[ 0.227358] epc : __list_add_valid_or_report+0xe0/0xe6
[ 0.227366] ra : __list_add_valid_or_report+0xe0/0xe6
[ 0.227375] epc : ffffffff804a08a0 ra : ffffffff804a08a0 sp : ffffffc600823b90
[ 0.227379] gp : ffffffff81389e70 tp : ffffffd60135ee00 t0 : 0000000000000000
[ 0.227383] t1 : 3fffffffffffffff t2 : 0000000000000000 s0 : ffffffc600823bb0
[ 0.227387] s1 : ffffffff8130ced0 a0 : 0000000000000058 a1 : ffffffd9efc9e5c0
[ 0.227391] a2 : ffffffd9efd5c510 a3 : 0000000000000000 a4 : 0000000000000000
[ 0.227395] a5 : 0000000000000000 a6 : ffffffd9efc6e5c0 a7 : bfffffffffffe000
[ 0.227399] s2 : 0000000000000000 s3 : ffffffff8130ce28 s4 : 0000000000000000
[ 0.227402] s5 : ffffffd6018b65c8 s6 : 0000000000000000 s7 : ffffffd6012fd605
[ 0.227406] s8 : ffffffd6010c3400 s9 : 0000000000000000 s10: 0000000000000000
[ 0.227409] s11: 0000000000000000 t3 : 3fffffffffffe000 t4 : 0000000000000020
[ 0.227413] t5 : 0000000000000000 t6 : ffffffc6008238f8 ssp : 0000000000000000
[ 0.227417] status: 0000000200000120 badaddr: ffffffff804a08a0 cause: 0000000000000003
[ 0.227422] [<ffffffff804a08a0>] __list_add_valid_or_report+0xe0/0xe6
[ 0.227432] [<ffffffff80558226>] register_syscore+0x30/0x60
[ 0.227444] [<ffffffff804ca0fe>] aplic_probe+0xd2/0xfa
[ 0.227453] [<ffffffff80559b2e>] platform_probe+0x3e/0x7a
[ 0.227461] [<ffffffff8055731a>] really_probe+0x88/0x35c
[ 0.227469] [<ffffffff805576ae>] __driver_probe_device+0xc0/0x13a
[ 0.227478] [<ffffffff805577f4>] driver_probe_device+0x38/0xb2
[ 0.227486] [<ffffffff80557ba6>] __driver_attach_async_helper+0x3c/0xc4
[ 0.227493] [<ffffffff80054a0e>] async_run_entry_fn+0x28/0x154
[ 0.227500] [<ffffffff8004482a>] process_one_work+0x14e/0x3d2
[ 0.227509] [<ffffffff800452fe>] worker_thread+0x144/0x286
[ 0.227516] [<ffffffff8004ca3e>] kthread+0xee/0x10e
[ 0.227524] [<ffffffff8001050a>] ret_from_fork_kernel+0x18/0x14e
[ 0.227532] [<ffffffff807bef36>] ret_from_fork_kernel_asm+0x16/0x18
[ 0.227542] ---[ end trace 0000000000000000 ]---
[ 0.228475] pinctrl-single 48508000.pinctrl: 512 pins, size 2048
[ 0.228500] pinctrl-single 53838000.pinctrl: 512 pins, size 2048
[ 0.228723] pinctrl-single 67107000.pinctrl: 512 pins, size 2048
[ 0.227210] riscv-aplic 674e0000.interrupt-controller: 257 interrupts directly connected to 8 CPUs
[ 0.227224] ------------[ cut here ]------------
[ 0.227227] list_add double add: new=ffffffff8130ced0, prev=ffffffff8130ced0, next=ffffffff81316d40.
[ 0.227302] WARNING: lib/list_debug.c:35 at __list_add_valid_or_report+0xe0/0xe6, CPU#4: kworker/u97:0/211
[ 0.227322] Modules linked in:
[ 0.227333] CPU: 4 UID: 0 PID: 211 Comm: kworker/u97:0 Not tainted 7.3.0-rc6 #1 PREEMPT_RT
[ 0.227341] Hardware name: EyeQ7H evaluation board (DT)
[ 0.227346] Workqueue: async async_run_entry_fn
[ 0.227358] epc : __list_add_valid_or_report+0xe0/0xe6
[ 0.227366] ra : __list_add_valid_or_report+0xe0/0xe6
[ 0.227375] epc : ffffffff804a08a0 ra : ffffffff804a08a0 sp : ffffffc600823b90
[ 0.227379] gp : ffffffff81389e70 tp : ffffffd60135ee00 t0 : 0000000000000000
[ 0.227383] t1 : 3fffffffffffffff t2 : 0000000000000000 s0 : ffffffc600823bb0
[ 0.227387] s1 : ffffffff8130ced0 a0 : 0000000000000058 a1 : ffffffd9efc9e5c0
[ 0.227391] a2 : ffffffd9efd5c510 a3 : 0000000000000000 a4 : 0000000000000000
[ 0.227395] a5 : 0000000000000000 a6 : ffffffd9efc6e5c0 a7 : bfffffffffffe000
[ 0.227399] s2 : 0000000000000000 s3 : ffffffff8130ce28 s4 : 0000000000000000
[ 0.227402] s5 : ffffffd6018b65c8 s6 : 0000000000000000 s7 : ffffffd6012fd605
[ 0.227406] s8 : ffffffd6010c3400 s9 : 0000000000000000 s10: 0000000000000000
[ 0.227409] s11: 0000000000000000 t3 : 3fffffffffffe000 t4 : 0000000000000020
[ 0.227413] t5 : 0000000000000000 t6 : ffffffc6008238f8 ssp : 0000000000000000
[ 0.227417] status: 0000000200000120 badaddr: ffffffff804a08a0 cause: 0000000000000003
[ 0.227422] [<ffffffff804a08a0>] __list_add_valid_or_report+0xe0/0xe6
[ 0.227432] [<ffffffff80558226>] register_syscore+0x30/0x60
[ 0.227444] [<ffffffff804ca0fe>] aplic_probe+0xd2/0xfa
[ 0.227453] [<ffffffff80559b2e>] platform_probe+0x3e/0x7a
[ 0.227461] [<ffffffff8055731a>] really_probe+0x88/0x35c
[ 0.227469] [<ffffffff805576ae>] __driver_probe_device+0xc0/0x13a
[ 0.227478] [<ffffffff805577f4>] driver_probe_device+0x38/0xb2
[ 0.227486] [<ffffffff80557ba6>] __driver_attach_async_helper+0x3c/0xc4
[ 0.227493] [<ffffffff80054a0e>] async_run_entry_fn+0x28/0x154
[ 0.227500] [<ffffffff8004482a>] process_one_work+0x14e/0x3d2
[ 0.227509] [<ffffffff800452fe>] worker_thread+0x144/0x286
[ 0.227516] [<ffffffff8004ca3e>] kthread+0xee/0x10e
[ 0.227524] [<ffffffff8001050a>] ret_from_fork_kernel+0x18/0x14e
[ 0.227532] [<ffffffff807bef36>] ret_from_fork_kernel_asm+0x16/0x18
[ 0.227542] ---[ end trace 0000000000000000 ]---
Fixes: b330fbfd34d7 ("irqchip/riscv-aplic: Register syscore operations only once")
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
Changes in v2:
- fixed potential access to read-only page
- Link to v1: https://lore.kernel.org/r/20261012-aplic-async-probe-v1-1-4c2c4f5b0916@mobileye.com
---
drivers/irqchip/irq-riscv-aplic-main.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/irqchip/irq-riscv-aplic-main.c b/drivers/irqchip/irq-riscv-aplic-main.c
index d9afb6ae98cf56d6fd9f858c31a3d23546c3b450..788b9f855cb7e5340a28e5b6acb5e9185a587717 100644
--- a/drivers/irqchip/irq-riscv-aplic-main.c
+++ b/drivers/irqchip/irq-riscv-aplic-main.c
@@ -116,14 +116,12 @@ static struct syscore aplic_syscore = {
.ops = &aplic_syscore_ops,
};
-static bool aplic_syscore_registered __ro_after_init;
+static atomic_t aplic_syscore_registered __ro_after_init = ATOMIC_INIT(0);
static void aplic_syscore_init(void)
{
- if (!aplic_syscore_registered) {
+ if (!atomic_cmpxchg(&aplic_syscore_registered, 0, 1))
register_syscore(&aplic_syscore);
- aplic_syscore_registered = true;
- }
}
static int aplic_pm_notifier(struct notifier_block *nb, unsigned long action, void *data)
---
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
change-id: 20261012-aplic-async-probe-81624e035607
Best regards,
--
Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] irqchip/riscv-aplic: fix asynchronous probing
2026-10-12 8:33 [PATCH v2] irqchip/riscv-aplic: fix asynchronous probing Vladimir Kondratiev
@ 2026-10-12 8:41 ` sashiko-bot
2026-10-12 9:05 ` Vladimir Kondratiev
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-10-12 8:41 UTC (permalink / raw)
To: Vladimir Kondratiev; +Cc: linux-kernel, linux-rt-devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] irqchip/riscv-aplic: panic on writing __ro_after_init atomic variable during late probe
--
commit 85f19d2af252a4bd94c9b2ae22ff4a1c3d7ce27f
Author: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
irqchip/riscv-aplic: fix asynchronous probing
This commit replaces the boolean flag with an atomic counter to prevent a
double-add race condition when probing multiple APLIC instances
asynchronously.
Link: https://lore.kernel.org/r/20261012-aplic-async-probe-v1-1-4c2c4f5b0916@mobileye.com
> diff --git a/drivers/irqchip/irq-riscv-aplic-main.c b/drivers/irqchip/irq-riscv-aplic-main.c
> --- a/drivers/irqchip/irq-riscv-aplic-main.c
> +++ b/drivers/irqchip/irq-riscv-aplic-main.c
> @@ -116,14 +116,12 @@ static struct syscore aplic_syscore = {
> .ops = &aplic_syscore_ops,
> };
>
> -static bool aplic_syscore_registered __ro_after_init;
> +static atomic_t aplic_syscore_registered __ro_after_init = ATOMIC_INIT(0);
>
> static void aplic_syscore_init(void)
> {
> - if (!aplic_syscore_registered) {
> + if (!atomic_cmpxchg(&aplic_syscore_registered, 0, 1))
[Severity: High]
Will this trigger a fatal page fault if the probe is deferred?
The aplic_syscore_registered variable retains the __ro_after_init attribute,
which places it in a memory section that becomes strictly read-only after
the kernel initialization phase completes.
Platform driver probes can be deferred (for instance, waiting for an MSI
domain) and run in a workqueue after the init phase is done.
If a late probe calls aplic_syscore_init(), atomic_cmpxchg() will attempt
to write 1 to this read-only memory page, which causes a store fault (or
AMO fault on RISC-V).
Does the __ro_after_init attribute need to be removed here to safely
support late and deferred probing?
> register_syscore(&aplic_syscore);
> - aplic_syscore_registered = true;
> - }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012-aplic-async-probe-v2-1-868d7684c9d6@mobileye.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] irqchip/riscv-aplic: fix asynchronous probing
2026-10-12 8:41 ` sashiko-bot
@ 2026-10-12 9:05 ` Vladimir Kondratiev
0 siblings, 0 replies; 3+ messages in thread
From: Vladimir Kondratiev @ 2026-10-12 9:05 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-kernel, linux-rt-devel
On 10/12/26 11:41, sashiko-bot@kernel.org wrote:
> Does the __ro_after_init attribute need to be removed here to safely
> support late and deferred probing?
To be honest, not sure. This patch retains same behavior,
the `aplic_syscore_registered` is written only once by first probe.
If __ro_after_init is not appropriate here, it need be removed from the
original code as well.
Anyway, removing __ro_after_init
Thanks, Vladimir
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-12 9:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12 8:33 [PATCH v2] irqchip/riscv-aplic: fix asynchronous probing Vladimir Kondratiev
2026-10-12 8:41 ` sashiko-bot
2026-10-12 9:05 ` Vladimir Kondratiev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®