Live Patching
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dylan Hatch" <dylanbhatch@google.com>,
	"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@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Shuah Khan" <shuah@kernel.org>
Cc: "Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Thomas Gleixner" <tglx@kernel.org>,
	live-patching@vger.kernel.org
Subject: Re: [PATCH v2 1/2] sched, livepatch: Fix transition stall for CPU-bound tasks
Date: Wed, 25 Nov 2026 04:46:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-232592@kernel.org> (raw)
In-Reply-To: <20261125041900.3243569-2-dylanbhatch@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] livepatch: klp_sched_try_switch() transitions task inside
  klp_ftrace_handler()
--

commit 838d28a5585cbc1f5e4b8cf8405e19da19b1f60d
Author: Dylan Hatch <dylanbhatch@google.com>

sched, livepatch: Fix transition stall for CPU-bound tasks

This commit removes the TASK_FREEZABLE check from klp_sched_try_switch() and
updates klp_send_signals() to wake PF_USER_WORKER threads and call
resched_cpu() on running tasks with pending livepatch transitions.

> diff --git a/include/linux/livepatch_sched.h b/include/linux/livepatch_sched.h
> index 065c185f27638..533b754f10da4 100644
> --- a/include/linux/livepatch_sched.h
> +++ b/include/linux/livepatch_sched.h
> @@ -14,7 +14,7 @@ DECLARE_STATIC_KEY_FALSE(klp_sched_try_switch_key);
>  static __always_inline void klp_sched_try_switch(struct task_struct *curr)
>  {
>  	if (static_branch_unlikely(&klp_sched_try_switch_key) &&
> -	    READ_ONCE(curr->__state) & TASK_FREEZABLE)
> +	    unlikely(test_tsk_thread_flag(curr, TIF_PATCH_PENDING)))
>  		__klp_sched_try_switch();
>  }

[Severity: High]
Can removing the TASK_FREEZABLE check switch a task while it is preempted
at the end of klp_ftrace_handler(), after the handler has already redirected
ftrace_regs to the previous patch state's function?

During an unpatch transition (or a stacked/replace patch transition), a task
with current->patch_state == KLP_TRANSITION_PATCHED calling a patched
function can be preempted before ftrace_caller transfers control to the
selected target:

ftrace_caller
  klp_ftrace_handler()
    ftrace_test_recursion_trylock()       /* disables preemption */
    ftrace_regs_set_instruction_pointer(fregs, func->new_func)
    ftrace_test_recursion_unlock()
      preempt_enable_notrace()
        preempt_schedule_notrace()
          __schedule(SM_PREEMPT)
            klp_sched_try_switch()
              klp_check_stack()           /* sees only func->old_func */
              klp_update_patch_state()    /* sets KLP_TRANSITION_UNPATCHED */
  /* returns to func->new_func while task is KLP_TRANSITION_UNPATCHED */

ftrace_regs_set_instruction_pointer() only updates the saved IP inside
ftrace_regs; the return address slot unwound by arch_stack_walk_reliable()
still holds func->old_func + MCOUNT_INSN_SIZE until klp_ftrace_handler()
returns to ftrace_caller.  When klp_target_state is KLP_TRANSITION_UNPATCHED
(or when patching over a stacked patch), klp_check_stack_func() checks the
stack against func->new_func (or prev->new_func), so klp_check_stack()
succeeds and transitions the task.

When __schedule() returns, ftrace_caller jumps into func->new_func even
though the task's patch_state is now KLP_TRANSITION_UNPATCHED, breaking
per-task consistency.  If __schedule() context-switches the task out after
klp_sched_try_switch() marks it unpatched, klp_complete_transition() and
klp_synchronize_transition() can also finish unpatching and allow the
livepatch module to be unloaded before the task is scheduled back in and
jumps to the freed func->new_func address.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125041900.3243569-1-dylanbhatch@google.com?part=1

  reply	other threads:[~2026-11-25  4:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  4:18 [PATCH v2 0/2] sched, livepatch: Fix transition stall for CPU-bound tasks Dylan Hatch
2026-11-25  4:18 ` [PATCH v2 1/2] " Dylan Hatch
2026-11-25  4:46   ` sashiko-bot [this message]
2026-11-25  4:19 ` [PATCH v2 2/2] selftests/livepatch: Add cond_resched() transition tests Dylan Hatch

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-232592@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=dylanbhatch@google.com \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tglx@kernel.org \
    --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