From: Yafang Shao <laoar.shao@gmail.com>
To: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz,
pmladek@suse.com, joe.lawrence@redhat.com, song@kernel.org
Cc: live-patching@vger.kernel.org, Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH v7 for-next 0/8] livepatch: Introduce replace set support
Date: Tue, 25 Aug 2026 19:46:33 +0800 [thread overview]
Message-ID: <20260825114641.80452-1-laoar.shao@gmail.com> (raw)
We previously proposed a BPF+livepatch method to enable rapid
experimentation with new kernel features without interrupting production
workloads:
https://lore.kernel.org/live-patching/20260402092607.96430-1-laoar.shao@gmail.com/
In the resulting discussion, Song and Petr suggested adding a "replace set"
to support scenarios where specific livepatches can be selectively replaced
or skipped.
This patchset introduces a more flexible model using two new fields in
struct klp_patch:
- provides: an unsigned int id identifying the patch replace set.
By default (provides=0), any livepatch replaces any other livepatch.
- obsoletes: an optional array of unsigned int ids specifying
additional provides ids to be replaced. This allows a new patch
to explicitly obsolete patches from different replace sets.
A new livepatch atomically replaces any existing livepatch whose
provides id matches either:
1. The new patch provides id (same replace set), or
2. Any id in the new patch obsoletes list
Additionally, this design deprecates the traditional non-atomic-replace
model. Previously, setting 'replace' to 0 was the only way to keep
certain livepatches persistent on the system, forcing developers to
disable atomic replacement entirely. With the introduction of replace set,
developers now have a selective option to keep specific livepatches
persistent while maintaining atomic replacement capabilities elsewhere.
At present, KLP state, shadow variables, and callbacks are not integrated
with the new replace_set mechanism in this patchset. Support for these
features is deferred until Petr's klp-state-transfer infrastructure is
completed and merged:
https://github.com/pmladek/linux/tree/klp-state-transfer-v1-iter12
Future Work
===========
- Allow `provides` and `obsoletes` to be configured dynamically at
module load time, rather than being fixed at build time.
Notes for sashiko-bot
=====================
In your review of v5, you found the following issues:
- A malformed livepatch module with a missing `old_name` triggers a NULL
pointer dereference in `klp_find_func()`.
This has already been addressed by commit 1a921fd13c31e
("livepatch: Fix NULL pointer dereference in klp_find_func()").
- When CONFIG_DEBUG_KOBJECT_RELEASE is enabled, an error during patch
initialization causes a use-after-free during module unload due to the
delayed kobject release.
This is addressed by the patch posted at
https://lore.kernel.org/live-patching/20260821031648.48195-1-laoar.shao@gmail.com/
- Other review issues are addressed in this version; details in the changes
section.
It is based on livepatching tree's for-next branch.
Changes
=======
v6->v7:
- rebase it to livepatching's for-next branch
- rename klp_patch_replaceable() to klp_patch_replaces() (Song)
- remove "[]" around --obsoletes (Song)
v6: https://lore.kernel.org/live-patching/20260607131659.29281-1-laoar.shao@gmail.com/
v5->v6:
- Check `--provides` argument in `klp-build (sashiko)
- Fix the 'replace' feature detection for OOT kernel builds (sashiko)
- Fix race condition in sysfs polling (sashiko)
v5: https://lore.kernel.org/live-patching/20260809091954.22930-1-laoar.shao@gmail.com
v4(RFC)->v5:
- Add selftests and Remove the RFC
- Fmprove klp_has_function_conflict() (Song)
- Fix a pre-exisiting bug
- Fix bugs reported by sashiko
v4 (RFC): https://lore.kernel.org/live-patching/20260804065010.44922-1-laoar.shao@gmail.com/
v3->v4(RFC):
- Allow a livepatch to replace livepatches with different provides IDs.
Replace the single `replace_set` field with two separate fields,
`provides` and `obsoletes`, for more flexible replacement semantics.
(Petr, Joe)
v3: https://lore.kernel.org/live-patching/20260607131659.29281-1-laoar.shao@gmail.com/
v2->v3:
- Address the feedback from Sachiko AI
- Fix the pre-existing NULL pointer dereference issue
- Move klp_find_func into core.h
- Don't deprecate stack_order completely
v2: https://lore.kernel.org/live-patching/20260529034542.68766-1-laoar.shao@gmail.com/
v1->v2:
- Incorporate feedback from Petr:
- Initialize replace_set to 0 by default
- Improve documentation
- Enforce that livepatches in different replace_sets cannot use the same
state->id.
- Enforce that livepatches in different replace_sets cannot modify the
same function.
- Ensure consistent capitalization and naming usage of KLP_REPLACE_SET.
- Incorporate feedback from Sachiko AI:
- Skip the klp_transition patch during klp_force_transition().
v1 (RFC): https://lore.kernel.org/live-patching/20260513143321.26185-1-laoar.shao@gmail.com/
Yafang Shao (8):
livepatch: Make klp_find_func() non static
livepatch: Call klp_init_patch_early() earlier
livepatch: Implement replace set for scoped atomic replace
livepatch: Deprecate stack_order
selftests/livepatch: Adapt atomic replace tests to provides/obsoletes
selftests/livepatch: Add provides/obsoletes test scenarios
selftests/livepatch: Add test for state ID conflict across provides
selftests/livepatch: Add test for function conflict across provides
.../ABI/removed/sysfs-kernel-livepatch | 16 +
.../ABI/testing/sysfs-kernel-livepatch | 27 +-
.../livepatch/cumulative-patches.rst | 93 +++--
Documentation/livepatch/livepatch.rst | 23 +-
include/linux/livepatch.h | 7 +-
kernel/livepatch/core.c | 114 +++---
kernel/livepatch/core.h | 2 +
kernel/livepatch/state.c | 57 ++-
kernel/livepatch/transition.c | 11 +-
scripts/livepatch/init.c | 71 +++-
scripts/livepatch/klp-build | 78 +++-
tools/testing/selftests/livepatch/Makefile | 3 +-
.../testing/selftests/livepatch/functions.sh | 15 +
.../selftests/livepatch/test-callbacks.sh | 6 +
.../selftests/livepatch/test-livepatch.sh | 6 +
.../livepatch/test-provides-obsoletes.sh | 370 ++++++++++++++++++
.../selftests/livepatch/test_modules/Makefile | 15 +
.../test_modules/test_klp_atomic_replace.c | 22 ++
.../test_modules/test_klp_callbacks_demo2.c | 12 +
.../test_modules/test_klp_livepatch.c | 9 +
.../test_modules/test_klp_provides.c | 72 ++++
.../livepatch/test_modules/test_klp_state.c | 13 +
.../livepatch/test_modules/test_klp_state2.c | 23 ++
23 files changed, 942 insertions(+), 123 deletions(-)
create mode 100644 Documentation/ABI/removed/sysfs-kernel-livepatch
create mode 100755 tools/testing/selftests/livepatch/test-provides-obsoletes.sh
create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_provides.c
--
2.52.0
next reply other threads:[~2026-08-25 11:46 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 11:46 Yafang Shao [this message]
2026-08-25 11:46 ` [PATCH v7 for-next 1/8] livepatch: Make klp_find_func() non static Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 2/8] livepatch: Call klp_init_patch_early() earlier Yafang Shao
2026-08-25 12:06 ` sashiko-bot
2026-08-25 12:11 ` Yafang Shao
2026-08-27 23:57 ` Josh Poimboeuf
2026-08-28 2:24 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 3/8] livepatch: Implement replace set for scoped atomic replace Yafang Shao
2026-08-25 11:59 ` sashiko-bot
2026-08-25 12:10 ` Yafang Shao
2026-08-28 0:26 ` Josh Poimboeuf
2026-08-28 3:03 ` Yafang Shao
2026-08-28 3:39 ` Josh Poimboeuf
2026-08-28 5:42 ` Yafang Shao
2026-09-02 7:31 ` Replace rules: was: " Petr Mladek
2026-09-02 9:40 ` Yafang Shao
2026-09-02 11:50 ` Yafang Shao
2026-09-03 10:01 ` Petr Mladek
2026-09-06 2:58 ` Yafang Shao
2026-09-03 9:27 ` Petr Mladek
2026-09-03 21:18 ` Song Liu
2026-09-06 8:34 ` Yafang Shao
2026-09-02 7:34 ` documentation: " Petr Mladek
2026-09-02 9:50 ` Yafang Shao
2026-09-03 7:30 ` Petr Mladek
2026-09-02 7:37 ` code cleanup: " Petr Mladek
2026-09-02 9:52 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 4/8] livepatch: Deprecate stack_order Yafang Shao
2026-08-28 0:29 ` Josh Poimboeuf
2026-08-28 3:14 ` Yafang Shao
2026-09-02 12:01 ` Petr Mladek
2026-09-02 12:20 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 5/8] selftests/livepatch: Adapt atomic replace tests to provides/obsoletes Yafang Shao
2026-08-28 0:31 ` Josh Poimboeuf
2026-08-28 3:56 ` Yafang Shao
2026-09-02 13:45 ` Petr Mladek
2026-09-03 3:23 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 6/8] selftests/livepatch: Add provides/obsoletes test scenarios Yafang Shao
2026-09-02 15:15 ` Petr Mladek
2026-09-03 5:43 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 7/8] selftests/livepatch: Add test for state ID conflict across provides Yafang Shao
2026-09-02 15:25 ` Petr Mladek
2026-09-03 5:44 ` Yafang Shao
2026-08-25 11:46 ` [PATCH v7 for-next 8/8] selftests/livepatch: Add test for function " Yafang Shao
2026-09-02 15:51 ` Petr Mladek
2026-09-03 5:48 ` 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=20260825114641.80452-1-laoar.shao@gmail.com \
--to=laoar.shao@gmail.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=pmladek@suse.com \
--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