[RFC PATCH v4 0/4] livepatch: Introduce replace set support
Yafang Shao <[email protected]>
| Newsgroups | org.kernel.vger.live-patching |
|---|---|
| Message-ID | <[email protected]> |
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/[email protected]/ 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. 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/[email protected]/ 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/[email protected]/ 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/[email protected]/ Yafang Shao (4): 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 .../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 | 101 +++++++++++------- kernel/livepatch/core.h | 2 + kernel/livepatch/state.c | 56 ++++++++-- kernel/livepatch/transition.c | 11 +- scripts/livepatch/init.c | 71 +++++++++++- scripts/livepatch/klp-build | 87 +++++++++++++-- 11 files changed, 380 insertions(+), 114 deletions(-) create mode 100644 Documentation/ABI/removed/sysfs-kernel-livepatch -- 2.52.0