Live Patching
 help / color / mirror / Atom feed
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>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>
Cc: live-patching@vger.kernel.org,
	"Yafang Shao" <laoar.shao@gmail.com>,
	"Jaidev Shastri" <jaidevshastri@vt.edu>
Subject: Re: [PATCH v5 2/4] livepatch: Retry klp_synchronize_transition() if it fails
Date: Sat, 05 Dec 2026 18:22:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-251787@kernel.org> (raw)
In-Reply-To: <20261205-klp-series-v3-v5-2-3d60c8ea9316@vt.edu>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] livepatch: unbounded uninterruptible retry in
  klp_synchronize_transition()
- [Low] livepatch: missing Fixes tag for klp_synchronize_transition()
  bug fix
--

commit f48adcf8ba6e941661b90ee57576b67c0772ba78
Author: Binoy Ravindran <binoy@vt.edu>

> livepatch: Retry klp_synchronize_transition() if it fails
>
> schedule_on_each_cpu() returns -ENOMEM when it cannot allocate its work
> items, before it queues any of them. klp_synchronize_transition() ignores
> the error, so it can return without waiting. The transition relies on the
> wait in several places, including the two that the following patches add
> before func->transition is set and before the transition completes.
>
> Retry until the wait succeeds. The callers can sleep, since
> schedule_on_each_cpu() itself sleeps.
>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Binoy Ravindran <binoy@vt.edu>

[Severity: Low]
This fixes the unchecked schedule_on_each_cpu() call introduced in
klp_synchronize_transition().  Should this include:

  Fixes: 842c08846420 ("livepatch: Fix stacking of patches with respect to RCU")

> diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
> index 2351a19ac2a9e..33095e888e10c 100644
> --- a/kernel/livepatch/transition.c
> +++ b/kernel/livepatch/transition.c

[ ... ]

> @@ -71,7 +72,13 @@ static void klp_sync(struct work_struct *work)
>   */
>  static void klp_synchronize_transition(void)
>  {
> -	schedule_on_each_cpu(klp_sync);
> +	/*
> +	 * schedule_on_each_cpu() fails only when it cannot allocate its work
> +	 * items, before it queues any of them.  The callers rely on the wait,
> +	 * so retry until it succeeds.
> +	 */
> +	while (schedule_on_each_cpu(klp_sync))
> +		msleep(20);
>  }

[Severity: Medium]
Can this loop livelock forever while holding klp_mutex?

schedule_on_each_cpu() calls alloc_percpu(), which takes
pcpu_alloc_mutex with mutex_lock_killable().  Under OOM, another caller
holding pcpu_alloc_mutex can loop in GFP_NOIO page allocation, while a
killed livepatch caller gets -ENOMEM from alloc_percpu() on every retry.

Even without contention, an OOM victim that cannot satisfy
pcpu_alloc_pages() from OOM reserves fails with -ENOMEM and loops
forever.  Because msleep(20) is uninterruptible, the task cannot exit to
free memory and holds klp_mutex indefinitely, stalling module loading.

Since every caller of klp_synchronize_transition() already holds
klp_mutex, a static DEFINE_PER_CPU(struct work_struct, ...) driven with
cpus_read_lock(), schedule_work_on(), and flush_work() would avoid
dynamic allocation and the retry loop altogether.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-klp-series-v3-v5-0-3d60c8ea9316@vt.edu?part=2

  reply	other threads:[~2026-12-05 18:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 18:08 [PATCH v5 0/4] livepatch: Do not lose exiting tasks during a transition Binoy Ravindran via B4 Relay
2026-12-05 18:08 ` [PATCH v5 1/4] rcu-tasks: Make the exit window an SRCU read-side critical section Binoy Ravindran via B4 Relay
2026-12-05 18:28   ` sashiko-bot
2026-12-05 18:08 ` [PATCH v5 2/4] livepatch: Retry klp_synchronize_transition() if it fails Binoy Ravindran via B4 Relay
2026-12-05 18:22   ` sashiko-bot [this message]
2026-12-05 18:08 ` [PATCH v5 3/4] livepatch: Select TASKS_RCU Binoy Ravindran via B4 Relay
2026-12-05 18:08 ` [PATCH v5 4/4] livepatch: Wait for exiting tasks around a transition Binoy Ravindran via B4 Relay
2026-12-05 18:27   ` sashiko-bot

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-251787@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=binoy@vt.edu \
    --cc=boqun@kernel.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --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=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=laoar.shao@gmail.com \
    --cc=live-patching@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mbenes@suse.cz \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.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 \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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