From: sashiko-bot@kernel.org
To: "Yafang Shao" <laoar.shao@gmail.com>,
jpoimboe@kernel.org, mbenes@suse.cz, pmladek@suse.com,
joe.lawrence@redhat.com, song@kernel.org
Cc: live-patching@vger.kernel.org
Subject: Re: [PATCH v2] livepatch: Avoid blocking tasklist_lock too long
Date: Mon, 23 Nov 2026 02:52:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-228569@kernel.org> (raw)
In-Reply-To: <20261123024119.16154-1-laoar.shao@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] livepatch: broken current handling in
klp_try_complete_transition()
--
commit 9627aa0e09bd9a194e83552843dfca92987dfda2
Author: Yafang Shao <laoar.shao@gmail.com>
livepatch: Avoid blocking tasklist_lock too long
This commit splits the task iteration in klp_try_complete_transition() into
a first pass under rcu_read_lock() and a conditional second pass under
tasklist_lock to reduce tasklist_lock hold times during livepatch
transitions.
Link: https://github.com/redis/redis [0]
Link: https://lore.kernel.org/all/20250227024733.16989-1-laoar.shao@gmail.com/ [1]
Link: https://lore.kernel.org/all/Z8CRXxfI24E9_IHC@pathway.suse.cz/ [2]
Link: https://lore.kernel.org/all/20250213013603.i6uxtjvc3qxlsqwc@jpoimboe/ [3]
> diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
> index ef70ff582da18..e5df13fa6fbde 100644
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c
> @@ -444,12 +444,38 @@ void klp_try_complete_transition(void)
> *
> * Usually this will transition most (or all) of the tasks on a system
> * unless the patch includes changes to a very common function.
> + *
> + * To avoid holding the tasklist_lock for too long, we iterate over the
> + * tasks in two passes. In the first pass, we use the lightweight RCU
> + * read lock to iterate through most tasks. This pass will cover the
> + * majority of tasks, except for some newly forked tasks which may be
> + * added into the tasklist concurrently. In the second pass, we acquire
> + * the tasklist_lock to handle the tasks missed in the first pass.
> */
> - read_lock(&tasklist_lock);
> - for_each_process_thread(g, task)
> +
> + /* First pass: Iterate over tasks using the lightweight RCU read lock. */
> + rcu_read_lock();
> + for_each_process_thread(g, task) {
> + /* klp_check_stack() requires preemption to be disabled */
> + if (task == current)
> + continue;
> +
> if (!klp_try_switch_task(task))
> complete = false;
> - read_unlock(&tasklist_lock);
> + }
> + rcu_read_unlock();
> +
> + /*
> + * If the first pass succeeded, grab the more heavyweight tasklist lock
> + * to check current and any newly forked tasks.
> + */
> + if (complete) {
> + read_lock(&tasklist_lock);
> + for_each_process_thread(g, task)
> + if (!klp_try_switch_task(task))
> + complete = false;
> + read_unlock(&tasklist_lock);
> + }
[Severity: Medium]
Does deferring current to the second pass still call klp_check_stack() with
preemption enabled on CONFIG_PREEMPT_RT?
As the new comment in klp_copy_process() notes, tasklist_lock is a sleeping
lock on CONFIG_PREEMPT_RT, so read_lock(&tasklist_lock) does not disable
preemption. When task == current, klp_try_switch_task() calls
klp_check_and_switch_task() directly instead of going through
task_call_func(), so klp_check_stack() triggers
lockdep_assert_preemption_disabled() and leaves the per-CPU klp_stack_entries
array unprotected if current is preempted by a task that runs
__klp_sched_try_switch().
Skipping current in the first pass also leaves current unswitched whenever
any other task fails to switch (complete == false), and forces an
unnecessary second pass under tasklist_lock when current itself cannot
switch. Disabling preemption around klp_check_and_switch_task(current, ...)
in klp_try_switch_task() would avoid both issues and allow current to be
handled in the RCU pass.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123024119.16154-1-laoar.shao@gmail.com?part=1
next prev parent reply other threads:[~2026-11-23 2:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 2:41 [PATCH v2] livepatch: Avoid blocking tasklist_lock too long Yafang Shao
2026-11-23 2:52 ` sashiko-bot [this message]
2026-11-23 3:56 ` Yafang Shao
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-228569@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=song@kernel.org \
/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