Re: [PATCH v3 2/7] srcu: Rule for using synchronize_srcu_atomic() from interrupt handlers

From: Frederic Weisbecker

Date: Thu Nov 12 2026 - 13:21:37 EST


Le Thu, Nov 12, 2026 at 08:37:26AM -0500, Mathieu Desnoyers a écrit :
> This is about the update side. A user that calls
> synchronize_srcu_atomic() from an interrupt handler must disable
> interrupts around all its calls on that srcu_struct, task context
> included. Document this rule, and warn when it is broken. The rules
> for readers are unchanged.
>
> synchronize_srcu_atomic() spins rather than sleeps, so it may be called
> from atomic context, interrupt handlers included. Its callers on one
> srcu_struct exclude each other with ->srcu_atomic_gp_flag. One of them
> drives the grace period. The others spin until a grace period ends.
>
> The flag owner disables only preemption. So an interrupt can arrive on
> its CPU while it holds the flag. If that interrupt handler calls
> synchronize_srcu_atomic() on the same srcu_struct, it spins forever:
>
> CPU 0, task CPU 0, hardirq
> synchronize_srcu_atomic()
> takes ->srcu_atomic_gp_flag
> synchronize_srcu_atomic()
> spins until a grace period ends
> it never ends: its driver is the
> task this interrupt interrupted
>
> Nothing reports it. lockdep cannot, because lock_sync() records no
> interrupt state.
>
> synchronize_srcu_atomic() cannot disable interrupts itself. A reader
> that disables only preemption may wait for an IPI to the waiter's CPU.
> That IPI never runs while the waiter spins with interrupts disabled.
> The kernel-doc already lets the caller choose the waiter's context.
> It then asks the readers to run in that context, or a stricter one.
>
> So the caller disables interrupts. The existing reader rule then
> requires the readers of that srcu_struct to disable interrupts too.
>
> Also store the owner's CPU number plus one in the flag, instead of 1.
> A waiter that finds its own CPU as the owner warns once. It still
> hangs, but no longer silently.
>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
> Reviewed-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
> Tested-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
> Reviewed-by: Kunwu Chan <chentao@xxxxxxxxxx>

Reviewed-by: Frederic Weisbecker <frederic@xxxxxxxxxx>

--
Frederic Weisbecker
SUSE Labs