From: "Ravindran, Binoy" <binoy@vt.edu>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
Joel Fernandes <joelagnelf@nvidia.com>,
Josh Triplett <josh@joshtriplett.org>,
Boqun Feng <boqun@kernel.org>,
Uladzislau Rezki <urezki@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang@linux.dev>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Miroslav Benes <mbenes@suse.cz>,
"live-patching@vger.kernel.org" <live-patching@vger.kernel.org>,
Petr Mladek <pmladek@suse.com>,
Joe Lawrence <joe.lawrence@redhat.com>,
Song Liu <song@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Jiri Kosina <jikos@kernel.org>,
"rcu@vger.kernel.org" <rcu@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"live-patching@vger.kernel.org" <live-patching@vger.kernel.org>,
"Shastri, Jaidev" <jaidevshastri@vt.edu>
Subject: Re: [PATCH 0/2] livepatch: Do not lose exiting tasks during a transition
Date: Tue, 24 Nov 2026 04:57:23 +0000 [thread overview]
Message-ID: <DM6PR05MB41377901DA5182DDFAD6E3D4D1442@DM6PR05MB4137.namprd05.prod.outlook.com> (raw)
In-Reply-To: <CALOAHbDu5NmVowk4SHzeUDxASaxKkbL_w1dModFWzdi8yK9tBw@mail.gmail.com>
Hi Yafang,
Thanks for the pointers to the earlier thread and to Josh's
suggestion.
> I did not take it for the same reason Sashiko raised in issue 2: the
> RCU exit list narrows the race window but does not close it.
> I could not see how klp_synchronize_transition(), as you describe
> below, completely resolves it. Could you please explain that in
> detail?
The exit list alone does not close it, and v2 does not rely on it
alone. The exit list covers the part of the exit path that can sleep.
The part it misses cannot sleep or be preempted, and
klp_synchronize_transition() waits it out. In detail:
1. Where the gap is. An exiting task is on an exit list from
exit_tasks_rcu_start() to exit_tasks_rcu_finish(). exit_notify()
runs inside that range, and the task is unhashed no earlier than
exit_notify(). So until exit_tasks_rcu_finish() the task is on the
task list, an exit list, or both. After exit_tasks_rcu_finish() it
may be on neither, if it has already been unhashed. That is the
gap in issue 2.
2. What the task can do in the gap. do_exit() calls preempt_disable()
before exit_rcu() and exit_tasks_rcu_finish(). After that the task
runs only lockdep_free_task() and do_task_dead(), whose __schedule()
is its last. From preempt_disable() on, the task stays on its CPU:
it cannot sleep, be preempted, or migrate. So once a task is in the
gap, the next context switch on its CPU is the task's final one.
3. What klp_synchronize_transition() guarantees. It calls
schedule_on_each_cpu() and returns only after a work item has run
on every online CPU, so every CPU has switched context since the
call began. Any task that was in the gap when the call began has
reached its final __schedule() and will never run again.
4. Where v2 calls it.
a. In klp_init_transition(), after patch_state has been set on
every task (the task list and the exit lists, walked under
tasklist_lock) and before func->transition is set. A task that
the walk did not visit had left the exit lists before or during
the walk, so it was in the gap when the sync began, and it is
dead before any function enters the transition. So when
func->transition is set, every task that can still run has a
valid patch_state.
b. In klp_try_complete_transition(), before it calls
klp_complete_transition(). A task in the gap can still be
running code reached through the old function, and the switch
check cannot see it. The sync makes it dead before
func->transition is cleared and before the old patch can be
freed. A task that leaves the exit lists after this sync was
already counted as switched, so it runs the new code.
So there is no point at which a task that can still run patched code
is invisible to the transition: before exit_tasks_rcu_finish() it is
on a list the transition walks, and after it, the sync waits for it to
die.
One limit: the exit lists exist only with CONFIG_TASKS_RCU. Without
it, the helpers are empty and only the final non-preemptible stretch
is covered.
I tested v2 on v7.4-rc2 with two klp-build livepatches that each
replace do_exit() and replace each other ten times per run while
short-lived tasks exit, with a test-only 2 s delay after
exit_notify(). Without the series, 9 of 12 runs crashed: the last
transition finished in about 2 ms, the old patch's module was
unloaded, and the delayed task then faulted executing freed module
memory. With the series, all 12 runs completed their 120 replace
cycles without a fault. I will put this argument in the v2 changelog.
Thanks,
Binoy
prev parent reply other threads:[~2026-11-24 4:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 20:52 Binoy Ravindran via B4 Relay
2026-11-23 20:52 ` [PATCH 1/2] rcu-tasks: Add helpers to visit tasks on the exit lists Binoy Ravindran via B4 Relay
2026-11-23 20:52 ` [PATCH 2/2] livepatch: Include exiting tasks in the transition Binoy Ravindran via B4 Relay
2026-11-23 22:40 ` [PATCH 0/2] livepatch: Do not lose exiting tasks during a transition Ravindran, Binoy
2026-11-24 4:00 ` Yafang Shao
2026-11-24 4:57 ` Ravindran, Binoy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM6PR05MB41377901DA5182DDFAD6E3D4D1442@DM6PR05MB4137.namprd05.prod.outlook.com \
--to=binoy@vt.edu \
--cc=boqun@kernel.org \
--cc=frederic@kernel.org \
--cc=jaidevshastri@vt.edu \
--cc=jiangshanlai@gmail.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=joelagnelf@nvidia.com \
--cc=josh@joshtriplett.org \
--cc=jpoimboe@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mbenes@suse.cz \
--cc=mingo@kernel.org \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=pmladek@suse.com \
--cc=qiang.zhang@linux.dev \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=song@kernel.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®