From: "Zhu, Yi" <chuyee@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>,
Wilson Felipe Pereira <wfelipe@google.com>,
Dylan Hatch <dylanbhatch@google.com>
Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 0/2] livepatch: make the transition stack check scale with patch size
Date: Fri, 4 Dec 2026 00:35:05 +0000 [thread overview]
Message-ID: <cover.1796344045.git.chuyee@google.com> (raw)
During a patching transition, every task's stack is checked against
every patched function. Two things make that expensive for large
cumulative livepatches:
- klp_check_stack_func() calls klp_find_ops(), a walk of a global list
with one entry per patched function, for every patched function.
The per-task check is therefore O(N^2) in the number of patched
functions N.
- Even without that lookup, each task repeats the same O(N * D) scan
(D = stack depth), although the forbidden address ranges are the
same for all tasks.
The first transition pass runs under read_lock(&tasklist_lock), so on
large patches this stalls fork() and exit() machine-wide for seconds to
minutes.
Patch 1 keys klp_ops on the patched function in an RCU hash table.
Patch 2 builds a sorted, RCU-published table of the patched address
ranges once per transition state change, and looks up each stack entry
with bsearch(). The per-task cost drops to O(D log N). If the table
can't be built, the existing per-function check is used.
Testing, on livepatching/for-next (2c3787447317) with and without the
series, in a 32-vCPU QEMU/KVM guest (Intel Xeon @ 2.60GHz host,
CONFIG_PREEMPT_LAZY):
- livepatch kselftests, with lockdep, PROVE_RCU and DEBUG_LIST: 39
passed, 4 skipped (legacy replace attribute not present), 0 failed on
both kernels; no lockdep, RCU or WARN splats.
- A synthetic target module with N noinline functions and a livepatch
replacing all of them; idle threads added to reach the task counts
below. The first klp_try_complete_transition() pass, timed with a
kprobe, and the time from insmod until the transition completes:
first pass insmod -> patched
N tasks base patched base patched
100 ~1.9k 19.6 ms 1.7 ms 1.9 s 1.9 s
1,000 ~1.9k 3.41 s 1.9 ms 4.9 s 2.9 s
2,000 ~1.9k 14.5 s 1.7 ms 17.9 s 4.8 s
3,000 ~1.9k 30.7 s 2.2 ms 36.1 s 6.9 s
5,000 ~1.9k 156 s 1.8 ms 167 s 11.8 s
10,000 ~1.9k 1,069 s 1.8 ms 1,096 s 27.2 s
2,000 ~3.4k 25.9 s 3.0 ms 29.3 s 5.0 s
2,000 ~50.4k - 35.5 ms - 5.5 s
10,000 ~50.4k - 37.5 ms - 27.8 s
On base, the first pass triggers soft lockups from 3,000 functions
on; with ~3.4k tasks, udev-worker tasks on other CPUs report soft
lockups too. The patched kernel shows no soft lockups or RCU stalls
in any run. Its remaining insmod time is module loading, symbol
resolution and ftrace registration, which this series does not
change.
Disabling a large patch has a separate cost: two synchronize_rcu()
calls per function in the ftrace unregister path. That will be
addressed separately.
Zhu, Yi (2):
livepatch: look up klp_ops in a hash table
livepatch: check task stacks against a sorted range table
kernel/livepatch/core.c | 10 ++
kernel/livepatch/patch.c | 38 ++++---
kernel/livepatch/patch.h | 8 +-
kernel/livepatch/transition.c | 190 +++++++++++++++++++++++++++++++---
kernel/livepatch/transition.h | 1 +
5 files changed, 221 insertions(+), 26 deletions(-)
base-commit: 2c37874473176739f4107c70739a930501d619c8
--
2.56.1.987.g2ec0ab4260-goog
next reply other threads:[~2026-12-04 0:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:35 Zhu, Yi [this message]
2026-12-04 0:35 ` [PATCH 1/2] livepatch: look up klp_ops in a hash table Zhu, Yi
2026-12-04 0:51 ` sashiko-bot
2026-12-04 0:35 ` [PATCH 2/2] livepatch: check task stacks against a sorted range table Zhu, Yi
2026-12-04 0:59 ` 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=cover.1796344045.git.chuyee@google.com \
--to=chuyee@google.com \
--cc=dylanbhatch@google.com \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--cc=song@kernel.org \
--cc=wfelipe@google.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