From: Dylan Hatch <dylanbhatch@google.com>
To: 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, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Dylan Hatch <dylanbhatch@google.com>
Subject: [PATCH 0/2] sched, livepatch: Fix transition stall for CPU-bound tasks
Date: Tue, 17 Nov 2026 04:52:52 +0000 [thread overview]
Message-ID: <20261117045254.1048298-1-dylanbhatch@google.com> (raw)
Commit 676e8cf70cb0 ("sched,livepatch: Untangle cond_resched() and
live-patching") moved klp_sched_try_switch() from _cond_resched() into
__schedule() and gated it on READ_ONCE(curr->__state) & TASK_FREEZABLE.
This causes livepatch transitions to stall when CPU-bound kthreads or
PF_USER_WORKER threads (such as vhost-<pid>) spin in a kernel loop with
cond_resched():
1. A sole runnable task on a CPU (cfs_rq->nr_queued == 1) never has
TIF_NEED_RESCHED set during sched_tick(), and wake_up_state(task,
TASK_INTERRUPTIBLE) in klp_send_signals() is a no-op for a
TASK_RUNNING task. Because _cond_resched() is a no-op under
CONFIG_PREEMPTION=y, the task only enters __schedule(SM_PREEMPT) on
return from interrupts via irqentry_exit_cond_resched() when
TIF_NEED_RESCHED is set.
2. Even when __schedule() is entered via preemption or an unfreezable
sleep (such as PF_NOFREEZE kthreads or PF_USER_WORKER threads
sleeping in TASK_INTERRUPTIBLE), curr->__state does not have
TASK_FREEZABLE set, so klp_sched_try_switch() skips the task.
Patch 1 fixes both issues by dropping the TASK_FREEZABLE check from
klp_sched_try_switch() (relying on stack_trace_save_tsk_reliable() in
klp_check_stack()) and calling resched_curr(rq) in sched_tick() when
klp_sched_need_resched() is true for the current task.
Patch 2 adds a livepatch kselftest (test-cond-resched.sh) that spawns
kthreads spinning in a cpu_relax() + cond_resched_tasks_rcu_qs() loop
and verifies that livepatch transitions complete without stalling.
Note on reliable stacktraces across exception boundaries:
Because _cond_resched() is a no-op under CONFIG_PREEMPTION=y, a sole
runnable spinning kthread enters __schedule(SM_PREEMPT) from
preempt_schedule_irq() with an in-kernel interrupt pt_regs frame on the
stack. Switching the task in klp_sched_try_switch() therefore requires
arch_stack_walk_reliable() to support unwinding across in-kernel
exception frames. This works on x86_64 with CONFIG_UNWINDER_ORC=y, where
test-cond-resched.sh passes with this series.
On architectures or configurations where arch_stack_walk_reliable()
currently rejects in-kernel exception frames (arm64, powerpc, s390, or
x86 with CONFIG_FRAME_POINTER=y), test-cond-resched.sh exposes this
limitation and will fail until exception-boundary unwinding is
supported. On arm64, the test passes when combined with the proposed
kernel SFrame unwinder series [1] or equivalent .eh_frame-derived
unwind tables [2].
This series is available on github: [3].
Ref:
[1]: https://lore.kernel.org/all/20261117020648.323464-1-dylanbhatch@google.com/
[2]: https://lore.kernel.org/all/20261117043504.1021063-1-dylanbhatch@google.com/
[3]: https://github.com/dylanbhatch/linux/tree/stall
Dylan Hatch (2):
sched, livepatch: Fix transition stall for CPU-bound tasks
selftests/livepatch: Add cond_resched() kthread transition test
include/linux/livepatch_sched.h | 13 ++-
kernel/sched/core.c | 3 +-
tools/testing/selftests/livepatch/Makefile | 3 +-
.../selftests/livepatch/test-cond-resched.sh | 73 ++++++++++++++
.../selftests/livepatch/test_modules/Makefile | 1 +
.../test_modules/test_klp_cond_resched.c | 94 +++++++++++++++++++
6 files changed, 183 insertions(+), 4 deletions(-)
create mode 100755 tools/testing/selftests/livepatch/test-cond-resched.sh
create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_cond_resched.c
--
2.56.0.679.gc527c65306-goog
next reply other threads:[~2026-11-17 4:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 4:52 Dylan Hatch [this message]
2026-11-17 4:52 ` [PATCH 1/2] sched, livepatch: Fix transition stall for CPU-bound tasks Dylan Hatch
2026-11-17 4:52 ` [PATCH 2/2] selftests/livepatch: Add cond_resched() kthread transition test 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=20261117045254.1048298-1-dylanbhatch@google.com \
--to=dylanbhatch@google.com \
--cc=bigeasy@linutronix.de \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--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=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