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

From: Paul E. McKenney

Date: Mon Nov 30 2026 - 14:55:44 EST


On Mon, Nov 30, 2026 at 06:17:41PM +0000, Ravindran, Binoy wrote:
>
> On Mon, Nov 30, 2026, Paul E. McKenney wrote:
> > OK, I will bite...
> >
> > Why not simply invoke synchronize_rcu_tasks(), after which any of the
> > tasks that were missed will have already exited?
>
> That was our first attempt, and it is not enough, for two reasons.
>
> First, the task we miss can be in a quiescent state as far as RCU Tasks
> is concerned. It is sleeping voluntarily in do_exit() after
> exit_notify(), with a return address into the old patch's code on its
> stack. A voluntary context switch is an RCU Tasks quiescent state, and
> check_holdout_task() drops a holdout as soon as its nvcsw has changed,
> so the grace period can end while the task is still asleep there. When
> it wakes, it returns into freed text. With synchronize_rcu_tasks()
> before the free of the replaced patch and a 2 s sleep injected after
> exit_notify(), 5 of 6 runs still crashed.
>
> Second, the problem is not only the free. The transition must not
> switch a task while one of its frames is in a function being patched.
> The invisible task is never checked, so klp_try_complete_transition()
> can finish while the task still runs the old function, and the
> consistency model is broken whether or not anything is freed. A wait
> at free cannot repair that, since it runs after the transition has
> already completed.
>
> So the transition itself has to see these tasks and check their
> stacks, which is what the rest of this series does. In v5, which I
> plan to post this week, the two helpers in this patch are replaced by
> a single walk of the exit lists that can drop the list lock, using the
> same cursor scheme as rcu_tasks_postscan(). If you would prefer a
> different interface on the RCU side, I am happy to rework it.

I suspect that we are talking past each other. ;-)

I am *not* suggesting replacing your overall algorithm with a single
call to synchronize_rcu_tasks(), just the piece of it that uses the
RCU-Tasks helper functions.

I instead suggest keeping your overall algorithm, including your walk
of the tasks list, and replacing the call to your Tasks-RCU helper
function with synchronize_rcu_tasks(). This does not wait for tasks
with preemption disabled that are working towards their last call
to schedule(), but those can be handled with a subsequent call to
synchronize_rcu_tasks_rude().

Does that make sense, or am I still missing something?

Thanx, Paul