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 2/2] livepatch: Include exiting tasks in the transition
Date: Mon, 23 Nov 2026 21:12:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-230067@kernel.org> (raw)
In-Reply-To: <20261123-klp-series-v3-v1-2-427c95811d9b@vt.edu>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] livepatch: race in klp_start_transition() re-sets
TIF_PATCH_PENDING
- [Medium] livepatch: per-task consistency race after
exit_tasks_rcu_finish()
--
commit 82efb900438952dc8b24689159b1d649ddb674e7
Author: Binoy Ravindran <binoy@vt.edu>
livepatch: Include exiting tasks in the transition
This commit extends each livepatch transition step to walk the RCU-tasks
exit lists so that unhashed tasks still executing in do_exit() are covered
by the transition.
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..cab167417190f 100644
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c
[ ... ]
> @@ -527,6 +595,7 @@ void klp_start_transition(void)
> if (task->patch_state != klp_target_state)
> set_tsk_thread_flag(task, TIF_PATCH_PENDING);
> read_unlock(&tasklist_lock);
> + rcu_tasks_visit_exiting(klp_exiting_start, NULL);
[Severity: Medium]
Can klp_exiting_start() re-set TIF_PATCH_PENDING on a task that has already
switched to klp_target_state during the first loop?
Between exit_tasks_rcu_start() and unhashing in release_task(), an exiting
task is on both tasklist and rtp_exit_list (for example, a PID namespace
child reaper sleeping with TASK_FREEZABLE set in zap_pid_ns_processes()).
When klp_reverse_transition() calls klp_start_transition(),
klp_sched_try_switch_key is already enabled from the initial
klp_start_transition(), so the task can switch in schedule() between the two
walks:
CPU0 CPU1 (exiting task)
klp_reverse_transition()
klp_start_transition()
for_each_process_thread()
set_tsk_thread_flag(t,
TIF_PATCH_PENDING)
schedule()
__klp_sched_try_switch()
...
klp_check_and_switch_task()
clear_tsk_thread_flag(t,
TIF_PATCH_PENDING)
rcu_tasks_visit_exiting()
klp_exiting_start()
if (t->patch_state !=
klp_target_state)
set_tsk_thread_flag(t,
TIF_PATCH_PENDING)
t->patch_state = klp_target_state
Subsequent klp_try_switch_task() calls see t->patch_state == klp_target_state
and return true without clearing TIF_PATCH_PENDING. When
klp_complete_transition() runs, its for_each_process_thread() loop executes
before rcu_tasks_visit_exiting(klp_exiting_complete, NULL) and hits
WARN_ON_ONCE(test_tsk_thread_flag(task, TIF_PATCH_PENDING)) if the task is
still on tasklist (or is an EXIT_ZOMBIE task that has already passed
exit_tasks_rcu_finish()).
[ ... ]
> @@ -580,6 +649,7 @@ void klp_init_transition(struct klp_patch *patch, int state)
> task->patch_state = initial_state;
> }
> read_unlock(&tasklist_lock);
> + rcu_tasks_visit_exiting(klp_exiting_init, &initial_state);
[Severity: Medium]
Can an unhashed task that has already called exit_tasks_rcu_finish() be
missed by both walks here and in klp_try_complete_transition()?
In do_exit(), exit_tasks_rcu_finish() removes the task from rtp_exit_list
with interrupts enabled while the task continues executing as current
through lockdep_free_task(), do_task_dead(), and __schedule(SM_NONE) up to
context_switch():
CPU0 CPU1 (self-reaping task)
do_exit()
exit_notify() (unhashed)
preempt_disable()
exit_tasks_rcu_finish()
klp_init_transition()
for_each_process_thread()
rcu_tasks_visit_exiting()
func->transition = true
do_task_dead() / <hardirq>
klp_ftrace_handler()
patch_state == KLP_TRANSITION_IDLE
<-- WARN_ON_ONCE and wrong func
Because the task is on neither list after exit_tasks_rcu_finish() and
klp_init_transition() does not call klp_synchronize_transition() before
setting func->transition = true, any patched function called before
context_switch() (or from an IRQ before local_irq_disable() in __schedule())
observes KLP_TRANSITION_IDLE (or a stale patch_state if an earlier
klp_complete_transition() also missed the task), triggers WARN_ON_ONCE(),
and selects func->new_func regardless of initial_state.
Likewise, if an unswitched exiting task passes exit_tasks_rcu_finish() just
before klp_try_complete_transition() snapshots the exit lists, the
transition completes and klp_complete_transition() runs
klp_unpatch_replaced_patches(), klp_discard_nops(), klp_unpatch_objects(),
and clears func->transition = false before klp_synchronize_transition()
waits for the non-preemptible tail of do_exit() to switch out.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-klp-series-v3-v1-0-427c95811d9b@vt.edu?part=2
next prev parent reply other threads:[~2026-11-23 21:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 20:52 [PATCH 0/2] livepatch: Do not lose exiting tasks during a transition 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 21:03 ` sashiko-bot
2026-11-23 20:52 ` [PATCH 2/2] livepatch: Include exiting tasks in the transition Binoy Ravindran via B4 Relay
2026-11-23 21:12 ` sashiko-bot [this message]
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
2026-11-24 6:47 ` Yafang Shao
2026-11-24 15:15 ` Ravindran, Binoy
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-230067@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