Re: [PATCH v3 2/3] livepatch: Include exiting tasks in the transition
From: Petr Mladek
Date: Fri Nov 27 2026 - 09:40:50 EST
On Thu 2026-11-26 11:12:27, Yafang Shao wrote:
> On Thu, Nov 26, 2026 at 8:58 AM Ravindran, Binoy <binoy@xxxxxx> wrote:
> >
> >
> > Thanks, this is right. A dying task reports its quiescent state in
> > rcu_note_context_switch(), early in __schedule(), and then still runs
> > traceable code, such as update_rq_clock() and pick_next_task(), until
> > switch_to(). RCU does not promise to wait for code after that point, and
> > with expedited grace periods the quiescent state is reported right
> > there, so synchronize_rcu() can return too early.
> > klp_synchronize_transition(), which v2 used, does not have this
> > problem: schedule_on_each_cpu() completes only after the work item has
> > run on every CPU, which on the dying task's CPU happens only after
> > switch_to().
> >
> > v4 goes back to klp_synchronize_transition() for both waits and keeps
> > klp_try_switch_exiting_tasks() from v3. I will send it after rerunning
> > the tests.
> >
> > Yafang, this reverses your second suggestion; I hope the reason above
> > makes sense. It also brings back the v2 transition times.
>
> Agreed. I missed the point that the quiescent state is reported early
> in __schedule(), and that the code from there until switch_to() is not
> covered by synchronize_rcu(). Thanks for pointing that out.
Honestly, I think that synchronize_srcu() should work. Otherwise,
the comment in rcu_tasks_postgp() would be wrong.
IMHO, the trick is that there are two interlacing rcu_read() periods
in do_exit() and synchronize_rcu(), see the comment in
rcu_tasks_postscan() and the commit e4e1e8089c5fd9 ("rcu-tasks:
Improve comments explaining tasks_rcu_exit_srcu purpose").
Best Regards,
Petr