Re: [PATCH v4 1/3] rcu-tasks: Add helpers to visit tasks on the exit lists

From: Ravindran, Binoy

Date: Wed Dec 02 2026 - 01:16:49 EST



On Mon, Nov 30, 2026, Paul E. McKenney wrote:
> Apologies for my confusion, but so many RCU versions! ;-)

No apology needed, and thank you.

> Would it work to add those __srcu_read_lock() and __srcu_read_unlock()
> calls to exit_tasks_rcu_start() and exit_tasks_rcu_finish(),
> respectively, then have your code do synchronize_srcu() instead of
> synchronize_rcu_tasks(), presumably by invoking a helper function in
> kernel/rcu/tasks.h?

Yes, it works in our tests.

I built it on v7.4-rc2 with our series. exit_tasks_rcu_start() enters an
SRCU read-side critical section on a static SRCU domain, and keeps the
index in a new task_struct field. exit_tasks_rcu_finish() leaves it. A
helper in kernel/rcu/tasks.h calls synchronize_srcu().
klp_try_complete_transition() calls it after every task on the task
list has switched, before the cleanup.

> Some thought and/or experiment maybe required to come up with the optimal
> variant of __srcu_read_lock() and __srcu_read_unlock(), but those are
> good places to start.

I used plain __srcu_read_lock() and __srcu_read_unlock(). I have not
tried other variants yet.

> This assumes that your code would not be holding mutexes across my
> proposed synchronize_srcu() that are also acquired by do_exit() between
> its calls to exit_tasks_rcu_start() and exit_tasks_rcu_finish(). See
> here for more details:
>
> 1612160b9127 ("rcu-tasks: Eliminate deadlocks involving do_exit() and RCU tasks")
>
> If your code does need to hold such mutexes, back to the drawing board.

Our code does hold klp_mutex across synchronize_srcu(). I checked
against 1612160b9127, and as far as I can see, nothing between
exit_tasks_rcu_start() and exit_tasks_rcu_finish() takes klp_mutex. No
test deadlocked.

The test is the same as before. A test-only hook makes exiting tasks
sleep after exit_notify(), and two livepatches that both replace
do_exit() replace each other in a loop.

Safety: 120 runs and 1,440 cycles, with no sleep and with sleeps from
20 ms to 2 s, had no crash. 42 of those runs used your SRCU change
without our exit-list walks, and they also had no warnings. I did not
test forced transitions with SRCU.

Lockdep: I ran three kernels under PROVE_LOCKING, PROVE_RCU and
DEBUG_ATOMIC_SLEEP: your SRCU change without our walks, your SRCU
change with the rest of our series, and our current series. Each
kernel ran 16 runs, with a 2 s sleep, a 200 ms sleep and no sleep.
There were no lockdep or sleep-in-atomic reports, no hung tasks and no
crashes. The only warning was the reschedule IPI warning at
arch/x86/kernel/apic/ipi.c:71, which we also see without either change.

Latency: here the two designs differ. The SRCU wait covers every task
in the exit window, even one that never runs patched code. Our walk
waits only for exiting tasks that still run patched code. To show this,
I used two livepatches that change getpid(), so no exiting task runs
patched code. Transition times, from "starting patching transition" to
"patching complete", as p90 / p99, from 36 runs per exit sleep (18 for
no sleep):

no sleep: our walk 1.68 / 1.79 s, SRCU 1.68 / 1.78 s
500 ms: our walk 1.73 / 1.84 s, SRCU 1.89 / 2.26 s
1 s: our walk 1.75 / 1.91 s, SRCU 2.48 / 2.80 s
2 s: our walk 1.84 / 2.03 s, SRCU 3.60 / 3.86 s

Both designs retry the transition once a second, which accounts for
most of the time with no sleep.

With no injected sleep, I also ran 24 runs per design while the guests
tore down PID namespaces, about 430,000 for each design. The p99 was
1.78 s with our walk and 1.76 s with SRCU. The longest transition was
1.94 s with our walk and 3.97 s with SRCU.

Slow exits do happen without an injected sleep. We traced exits while
PID namespaces were torn down in a loop. The longest voluntary sleep in
the exit window was 146 ms on an arm64 host and 2 ms on an x86-64 host.
Every voluntary sleep of 1 ms or more was a namespace's init waiting
for its children.

So in these runs, SRCU cost little when no exit was slow, and it added
the length of a slow exit when there was one. It is also simpler and
needs no new walker interface on the RCU side. Which would you and the
livepatch maintainers prefer? I am happy to rework the series around
SRCU if that is the better fit.

Thanks,
Binoy