From: sashiko-bot@kernel.org
To: "Binoy Ravindran" <binoy@vt.edu>,
"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>,
"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>
Cc: live-patching@vger.kernel.org,
"Yafang Shao" <laoar.shao@gmail.com>,
"Jaidev Shastri" <jaidevshastri@vt.edu>
Subject: Re: [PATCH v3 2/3] livepatch: Include exiting tasks in the transition
Date: Wed, 25 Nov 2026 23:33:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-234405@kernel.org> (raw)
In-Reply-To: <20261125-klp-series-v3-v3-2-b1e0f79af331@vt.edu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] livepatch: synchronize_rcu() returns before dying task
finishes __schedule()
--
commit 92ba6cc4a8d2e1bcb38ce05b46cd777e11fa7ede
Author: Binoy Ravindran <binoy@vt.edu>
livepatch: Include exiting tasks in the transition
This commit extends livepatch transitions to visit exiting tasks on the
RCU-tasks exit lists and uses synchronize_rcu() to wait for tasks that
have already left the exit lists to finish their final context switch.
Link: https://lore.kernel.org/all/20250127063526.76687-1-laoar.shao@gmail.com/
> diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
> index 2351a19ac2a9e..0edcb9f9c663b 100644
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c
[ ... ]
> @@ -489,6 +570,12 @@ void klp_try_complete_transition(void)
> /* Done! Now cleanup the data structures. */
> klp_resched_disable();
> patch = klp_transition_patch;
> + /*
> + * A task can leave the exit lists unswitched after the snapshot. It
> + * runs with preemption disabled until its final switch, so
> + * synchronize_rcu() waits it out, as in rcu_tasks_postgp().
> + */
> + synchronize_rcu();
> klp_complete_transition();
>
> /*
[ ... ]
> @@ -590,6 +679,14 @@ void klp_init_transition(struct klp_patch *patch, int state)
> task->patch_state = initial_state;
> }
>
> + /*
> + * A task that has passed exit_tasks_rcu_finish() is on neither list but
> + * may still call patched code until its final switch. It runs with
> + * preemption disabled, so synchronize_rcu() returns only after every
> + * such task is gone, as in rcu_tasks_postgp().
> + */
> + synchronize_rcu();
> +
> /*
> * Enforce the order of the task->patch_state initializations and the
> * func->transition updates to ensure that klp_ftrace_handler() doesn't
[Severity: Medium]
Can synchronize_rcu() in klp_try_complete_transition() and
klp_init_transition() return while a dying task is still executing
__schedule() before switch_to()?
When do_exit() reaches do_task_dead() -> __schedule(),
klp_sched_try_switch() is a no-op because curr->__state is TASK_DEAD
rather than TASK_FREEZABLE, and rcu_note_context_switch() reports the RCU
quiescent state near the start of __schedule() while current is still the
dying task:
CPU0 (dying task) CPU1 (livepatch transition)
do_exit()
preempt_disable()
exit_tasks_rcu_finish()
klp_init_transition()
/* walks miss CPU0's task */
synchronize_rcu()
do_task_dead()
__schedule()
klp_sched_try_switch(prev)
rcu_note_context_switch()
/* synchronize_rcu() returns */
func->transition = true
pick_next_task()
klp_ftrace_handler()
<-- sees patch_state == KLP_TRANSITION_IDLE
context_switch()
switch_to()
If a livepatch patches any function called in __schedule() between
rcu_note_context_switch() and switch_to() (such as update_rq_clock(),
try_to_block_task(), pick_next_task(), or psi_sched_switch()),
klp_ftrace_handler() can hit WARN_ON_ONCE(patch_state ==
KLP_TRANSITION_IDLE) on the uninitialized task during
klp_init_transition(), or klp_complete_transition() can unpatch replaced
patches and clear func->transition while an unswitched dying task is
still running inside __schedule().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-klp-series-v3-v3-0-b1e0f79af331@vt.edu?part=2
next prev parent reply other threads:[~2026-11-25 23:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 23:11 [PATCH v3 0/3] livepatch: Do not lose exiting tasks during a transition Binoy Ravindran via B4 Relay
2026-11-25 23:11 ` [PATCH v3 1/3] rcu-tasks: Add helpers to visit tasks on the exit lists Binoy Ravindran via B4 Relay
2026-11-25 23:11 ` [PATCH v3 2/3] livepatch: Include exiting tasks in the transition Binoy Ravindran via B4 Relay
2026-11-25 23:33 ` sashiko-bot [this message]
2026-11-26 0:58 ` Ravindran, Binoy
2026-11-26 3:12 ` Yafang Shao
2026-11-27 14:39 ` Petr Mladek
2026-11-27 15:10 ` Petr Mladek
2026-11-27 19:13 ` Ravindran, Binoy
2026-11-25 23:11 ` [PATCH v3 3/3] livepatch: Select TASKS_RCU Binoy Ravindran via B4 Relay
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=sashiko-outbox-234405@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=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=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=rostedt@goodmis.org \
--cc=sashiko-reviews@lists.linux.dev \
--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