Re: [PATCH v2] irqchip/riscv-aplic: fix asynchronous probing
From: sashiko-bot
Date: Mon Oct 12 2026 - 04:42:25 EST
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@xxxxxxxxxxxx>
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@xxxxxxxxxxxx
> 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@xxxxxxxxxxxx?part=1