livepatch: Introduce replace set support
Subsystems (3)
v3 cover livepatch: Introduce replace set support
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 patch introduces 'replace_set' to provide finer-grained control over livepatch management. The core rules and behaviors of a replace_set are defined as follows:
- Livepatches sharing the same replace_set can mutually replace each other.
- Only one livepatch within a given replace_set can be active at a time.
- Livepatches belonging to different replace_sets can coexist on the system.
- Livepatches in different replace_sets are prohibited from modifying the same function.
- Livepatches in different replace_sets cannot use the same state ID.
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
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 (7):
livepatch: Fix NULL pointer dereference in klp_find_func()
livepatch: Move klp_find_func() into core.h
livepatch: Support scoped atomic replace using replace_set
livepatch: Deprecate stack_order selftests/livepatch: Update tests for replace_set selftests/livepatch: Add test for state ID conflict across
replace_sets
selftests/livepatch: Add test for function conflict across
replace_sets
.../ABI/removed/sysfs-kernel-livepatch | 9 + .../ABI/testing/sysfs-kernel-livepatch | 14 +- .../livepatch/cumulative-patches.rst | 23 ++- Documentation/livepatch/livepatch.rst | 21 ++- include/linux/livepatch.h | 5 +- kernel/livepatch/core.c | 65 ++----- kernel/livepatch/core.h | 21 +++ kernel/livepatch/state.c | 51 ++++-- kernel/livepatch/transition.c | 11 +- scripts/livepatch/init.c | 6 +- scripts/livepatch/klp-build | 16 +- .../selftests/livepatch/test-callbacks.sh | 33 ++-- .../selftests/livepatch/test-livepatch.sh | 159 +++++++---------- .../testing/selftests/livepatch/test-state.sh | 34 ++++ .../testing/selftests/livepatch/test-sysfs.sh | 91 ++-------- .../selftests/livepatch/test_modules/Makefile | 2 + .../test_modules/test_klp_atomic_replace.c | 10 +- .../test_modules/test_klp_atomic_replace2.c | 55 ++++++ .../test_modules/test_klp_callbacks_demo.c | 6 + .../test_modules/test_klp_callbacks_demo2.c | 10 +- .../test_modules/test_klp_livepatch.c | 6 + .../livepatch/test_modules/test_klp_state.c | 4 +- .../livepatch/test_modules/test_klp_state2.c | 4 +- .../livepatch/test_modules/test_klp_state4.c | 163 ++++++++++++++++++ 24 files changed, 507 insertions(+), 312 deletions(-) create mode 100644 Documentation/ABI/removed/sysfs-kernel-livepatch create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace2.c create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_state4.c
Signature · 1 line
2.52.0
PATCH v3 1/7 livepatch: Fix NULL pointer dereference in klp_find_func()
If a newly loaded livepatch provides a function entry with a NULL old_name, func->old_name will be NULL when evaluated in strcmp():
klp_init_patch()
klp_add_nops()
klp_find_func()
strcmp(old_func->old_name, func->old_name)--- kernel/livepatch/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/livepatch/core.c +1 -1
@@ -92,7 +92,7 @@ static struct klp_func *klp_find_func(struct klp_object *obj,* Besides identical old_sympos, also consider old_sympos * of 0 and 1 are identical. */ -if ((strcmp (old_func->old_name, func->old_name) ==0 ) && +if ((func->old_name &&strcmp (old_func->old_name, func->old_name) ==0 ) && ((old_func->old_sympos == func->old_sympos) || (old_func->old_sympos ==0 && func->old_sympos ==1 ) || (old_func->old_sympos ==1 && func->old_sympos ==0 ))) {
Signature · 1 line
2.52.0
Petr Mladek
maintainerRe: [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func()
Quoted 11 lines · Yafang Shao
If a newly loaded livepatch provides a function entry with a NULL
old_name,func->old_namewill be NULL when evaluated instrcmp():
klp_init_patch()klp_add_nops() klp_find_func() strcmp(old_func->old_name, func->old_name)
kernel/livepatch/core.c static struct klp_func *klp_find_func(struct klp_object *obj, · line 95
Quoted 5 lines
kernel/livepatch/core.c +1
-1@@ -92,7 +92,7 @@ static struct klp_func *klp_find_func(struct klp_object *obj,* Besides identical old_sympos, also consider old_sympos * of 0 and 1 are identical. */ - if ((strcmp(old_func->old_name, func->old_name) == 0) && + if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&
I do not have a good feeling about this solution because it quietly ignores a problem. As a result, klp_add_object_nops() would call klp_alloc_func_nop() even though it does not make much sense.
A livepatch where any func->oldname is not defined should get rejected. It will actually happen but _later_ in:
+ klp_init_patch()
+ klp_init_object()
+ klp_init_func()
I see three better possibilities.
1. We could move/add the sanity checks into klp_init_patch_early() and return broken livepatches earlier.
2. We could move/add the sanity check into a new klp_check_patch() which will be called even before klp_init_patch_early().
3. We could allow klp_find_func() to return ERR_PTR(-EINVAL). klp_add_object_nops() should then return the error as well.
My preference:
I would do the 3rd variant because it is much easier than adding/moving all consistency checks between klp_init_*() and klp_init_*_early() or klp_check_*() functions.
kernel/livepatch/core.c static struct klp_func *klp_find_func(struct klp_object *obj, · line 98
Quoted 3 lines
kernel/livepatch/core.c +0
-0((old_func->old_sympos == func->old_sympos) || (old_func->old_sympos == 0 && func->old_sympos == 1) || (old_func->old_sympos == 1 && func->old_sympos == 0))) {
Best Regards,
Petr
Re: [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func()
Quoted 38 lines · Petr Mladek
Quoted 11 lines · Yafang Shao
If a newly loaded livepatch provides a function entry with a NULL
old_name,func->old_namewill be NULL when evaluated instrcmp():
klp_init_patch()klp_add_nops() klp_find_func() strcmp(old_func->old_name, func->old_name)kernel/livepatch/core.c static struct klp_func *klp_find_func(struct klp_object *obj, · line 95
Quoted 5 lines
kernel/livepatch/core.c +1
-1@@ -92,7 +92,7 @@ static struct klp_func *klp_find_func(struct klp_object *obj,* Besides identical old_sympos, also consider old_sympos * of 0 and 1 are identical. */ - if ((strcmp(old_func->old_name, func->old_name) == 0) && + if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&I do not have a good feeling about this solution because it quietly ignores a problem. As a result,
klp_add_object_nops()would callklp_alloc_func_nop()even though it does not make much sense.A livepatch where any
func->oldnameis not defined should get rejected. It will actually happen but _later_ in:+
klp_init_patch()
+klp_init_object()
+klp_init_func()I see three better possibilities.
1. We could move/add the sanity checks into
klp_init_patch_early()and return broken livepatches earlier.2. We could move/add the sanity check into a new
klp_check_patch()which will be called even beforeklp_init_patch_early().
Quoted 8 lines
3. We could allow
klp_find_func()to returnERR_PTR(-EINVAL).klp_add_object_nops()should then return the error as well.My preference:
I would do the 3rd variant because it is much easier than adding/moving all consistency checks between klp_init_*() and klp_init_*_early() or klp_check_*() functions.
Thanks for the suggestion. I will update it.
Signature · 2 lines
Regards Yafang
Miroslav Benes
maintainerRe: [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func()
In reply to Petr MladekQuoted 32 lines · Petr Mladek
Quoted 11 lines · Yafang Shao
If a newly loaded livepatch provides a function entry with a NULL
old_name,func->old_namewill be NULL when evaluated instrcmp():
klp_init_patch()klp_add_nops() klp_find_func() strcmp(old_func->old_name, func->old_name)kernel/livepatch/core.c static struct klp_func *klp_find_func(struct klp_object *obj, · line 95
Quoted 5 lines
kernel/livepatch/core.c +1
-1@@ -92,7 +92,7 @@ static struct klp_func *klp_find_func(struct klp_object *obj,* Besides identical old_sympos, also consider old_sympos * of 0 and 1 are identical. */ - if ((strcmp(old_func->old_name, func->old_name) == 0) && + if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&I do not have a good feeling about this solution because it quietly ignores a problem. As a result,
klp_add_object_nops()would callklp_alloc_func_nop()even though it does not make much sense.A livepatch where any
func->oldnameis not defined should get rejected. It will actually happen but _later_ in:+
klp_init_patch()
+klp_init_object()
+klp_init_func()I see three better possibilities.
Quoted 8 lines
1. We could move/add the sanity checks into
klp_init_patch_early()and return broken livepatches earlier.2. We could move/add the sanity check into a new
klp_check_patch()which will be called even beforeklp_init_patch_early().3. We could allow
klp_find_func()to returnERR_PTR(-EINVAL).klp_add_object_nops()should then return the error as well.
If you change it to do so.
Quoted 5 lines
My preference:
I would do the 3rd variant because it is much easier than adding/moving all consistency checks between klp_init_*() and klp_init_*_early() or klp_check_*() functions.
Interesting issue. If I remember correctly, klp_init_*() path is meant for the initial checking originally (among others). That is why klp_init_func() has it right at the beginning. It got a lot complicated later. We introduced atomic replace feature which added klp_add_nops() and is called earlier. Then there was the kobject issue which introduced early init path. Both forgot about the check and that is what we have now. I would prefer it to fix cleanly. klp_init_patch_early() is not enough because klp_is_patch_compatible() is called even earlier. So your option 2 sounds best to me. On the other hand, it might be difficult to disentangle it all.
Anyway, could you send the fix separately since it is an existing issue, please?
Re: [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func()
Quoted 62 lines · Miroslav Benes
Quoted 32 lines · Petr Mladek
Quoted 11 lines · Yafang Shao
If a newly loaded livepatch provides a function entry with a NULL
old_name,func->old_namewill be NULL when evaluated instrcmp():
klp_init_patch()klp_add_nops() klp_find_func() strcmp(old_func->old_name, func->old_name)kernel/livepatch/core.c static struct klp_func *klp_find_func(struct klp_object *obj, · line 95
Quoted 5 lines
kernel/livepatch/core.c +1
-1@@ -92,7 +92,7 @@ static struct klp_func *klp_find_func(struct klp_object *obj,* Besides identical old_sympos, also consider old_sympos * of 0 and 1 are identical. */ - if ((strcmp(old_func->old_name, func->old_name) == 0) && + if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&I do not have a good feeling about this solution because it quietly ignores a problem. As a result,
klp_add_object_nops()would callklp_alloc_func_nop()even though it does not make much sense.A livepatch where any
func->oldnameis not defined should get rejected. It will actually happen but _later_ in:+
klp_init_patch()
+klp_init_object()
+klp_init_func()I see three better possibilities.
Quoted 8 lines
1. We could move/add the sanity checks into
klp_init_patch_early()and return broken livepatches earlier.2. We could move/add the sanity check into a new
klp_check_patch()which will be called even beforeklp_init_patch_early().3. We could allow
klp_find_func()to returnERR_PTR(-EINVAL).klp_add_object_nops()should then return the error as well.If you change it to do so.
Quoted 5 lines
My preference:
I would do the 3rd variant because it is much easier than adding/moving all consistency checks between klp_init_*() and klp_init_*_early() or klp_check_*() functions.
Interesting issue. If I remember correctly, klp_init_*() path is meant for the initial checking originally (among others). That is why
klp_init_func()has it right at the beginning. It got a lot complicated later. We introduced atomic replace feature which addedklp_add_nops()and is called earlier. Then there was the kobject issue which introduced early init path. Both forgot about the check and that is what we have now. I would prefer it to fix cleanly.klp_init_patch_early()is not enough becauseklp_is_patch_compatible()is called even earlier. So your option 2 sounds best to me. On the other hand, it might be difficult to disentangle it all.
Quoted 2 lines
Anyway, could you send the fix separately since it is an existing issue, please?
Does the following change look good to you ?
kernel/livepatch/core.c +0 -0
@@ -799,9 +799,6 @@ void klp_free_replaced_patches_async(struct
klp_patch *new_patch)
static int klp_init_func(struct klp_object *obj, struct klp_func *func) {
- if (!func->old_name)
- return -EINVAL;
-
/*
* NOPs get the address later. The patched module must be loaded,
* see klp_init_object_loaded().
@@ -1107,8 +1104,9 @@ static int __klp_enable_patch(struct klp_patch *patch)
*/
int klp_enable_patch(struct klp_patch *patch)
{
- int ret;
struct klp_object *obj;+ struct klp_func *func;
+ int ret;
if (!patch || !patch->mod || !patch->objs)
return -EINVAL;
@@ -1116,9 +1114,12 @@ int klp_enable_patch(struct klp_patch *patch)
klp_for_each_object_static(patch, obj) {
if (!obj->funcs)
return -EINVAL;+ klp_for_each_func_static(obj, func) {
+ if (!func->old_name)
+ return -EINVAL;
+ }
}
-
if (!is_livepatch_module(patch->mod)) {
pr_err("module %s is not marked as a livepatch module\n",
patch->mod->name);Signature · 2 lines
Regards Yafang
Miroslav Benes
maintainerRe: [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func()
Quoted 35 lines
Quoted 2 lines
Anyway, could you send the fix separately since it is an existing issue, please?
Does the following change look good to you ?
kernel/livepatch/core.c +0
-3@@ -799,9 +799,6 @@ void klp_free_replaced_patches_async(struct klp_patch *new_patch)static int klp_init_func (struct klp_object *obj,struct klp_func *func) { -if (!func->old_name) -return -EINVAL ; -/* * NOPs get the address later. The patched module must be loaded, * see
klp_init_object_loaded().kernel/livepatch/core.c +2
-1@@ -1107,8 +1104,9 @@ static int __klp_enable_patch(struct klp_patch *patch)*/ int klp_enable_patch (struct klp_patch *patch) { -int ret;struct klp_object *obj; +struct klp_func *func; +int ret;if (!patch || !patch->mod || !patch->objs)return -EINVAL ;@@ -1116,9 +1114,12 @@ int klp_enable_patch(struct klp_patch *patch)klp_for_each_object_static (patch, obj) {if (!obj->funcs)return -EINVAL ;
kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1125
Quoted 10 lines
kernel/livepatch/core.c +4
-1+klp_for_each_func_static (obj, func) { +if (!func->old_name) +return -EINVAL ; + } } -if (!is_livepatch_module (patch->mod)) {pr_err ("module %s is not marked as a livepatch module\n" , patch->mod->name);
If you wrap it into klp_check_patch() which Petr proposed alongside with all the checks at the beginning of klp_enable_patch() up to is_livepatch_module(), then yes, I think.
Miroslav
Petr Mladek
maintainerRe: [PATCH v3 1/7] livepatch: Fix NULL pointer dereference in klp_find_func()
Quoted 41 lines · Miroslav Benes
Quoted 41 lines
Quoted 2 lines
Anyway, could you send the fix separately since it is an existing issue, please?
Does the following change look good to you ?
kernel/livepatch/core.c +0
-3@@ -799,9 +799,6 @@ void klp_free_replaced_patches_async(struct klp_patch *new_patch)static int klp_init_func (struct klp_object *obj,struct klp_func *func) { -if (!func->old_name) -return -EINVAL ; -/* * NOPs get the address later. The patched module must be loaded, * see
klp_init_object_loaded().kernel/livepatch/core.c +6
-1@@ -1107,8 +1104,9 @@ static int __klp_enable_patch(struct klp_patch *patch)*/ int klp_enable_patch (struct klp_patch *patch) { -int ret;struct klp_object *obj; +struct klp_func *func; +int ret;if (!patch || !patch->mod || !patch->objs)return -EINVAL ;@@ -1116,9 +1114,12 @@ int klp_enable_patch(struct klp_patch *patch)klp_for_each_object_static (patch, obj) {if (!obj->funcs)return -EINVAL ; +klp_for_each_func_static (obj, func) { +if (!func->old_name) +return -EINVAL ; + } }
Quoted 8 lines
kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1125
Quoted 4 lines
kernel/livepatch/core.c +0
-1-if (!is_livepatch_module (patch->mod)) {pr_err ("module %s is not marked as a livepatch module\n" , patch->mod->name);If you wrap it into
klp_check_patch()which Petr proposed alongside with all the checks at the beginning ofklp_enable_patch()up tois_livepatch_module(), then yes, I think.
+1
Best Regards,
Petr
PATCH v3 2/7 livepatch: Move klp_find_func() into core.h
In reply to Yafang ShaoThis function will be used in other source file in the following patch.
--- kernel/livepatch/core.c | 21 --------------------- kernel/livepatch/core.h | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-)
kernel/livepatch/core.c +0 -21
@@ -82,27 +82,6 @@ static bool klp_initialized(void)return !!klp_root_kobj; } -static struct klp_func *klp_find_func (struct klp_object *obj, -struct klp_func *old_func) -{ -struct klp_func *func; - -klp_for_each_func (obj, func) { -/* -* Besides identical old_sympos, also consider old_sympos -* of 0 and 1 are identical. -*/ -if ((func->old_name &&strcmp (old_func->old_name, func->old_name) ==0 ) && - ((old_func->old_sympos == func->old_sympos) || - (old_func->old_sympos ==0 && func->old_sympos ==1 ) || - (old_func->old_sympos ==1 && func->old_sympos ==0 ))) { -return func; - } - } - -return NULL ; -} -static struct klp_object *klp_find_object (struct klp_patch *patch,struct klp_object *old_obj) {
kernel/livepatch/core.h +21 -0
@@ -56,4 +56,25 @@ static inline void klp_post_unpatch_callback(struct klp_object *obj) obj->callbacks.post_unpatch_enabled = false; } +static inline struct klp_func *klp_find_func (struct klp_object *obj, +struct klp_func *old_func) +{ +struct klp_func *func; + +klp_for_each_func (obj, func) { +/* +* Besides identical old_sympos, also consider old_sympos +* of 0 and 1 are identical. +*/ +if ((func->old_name &&strcmp (old_func->old_name, func->old_name) ==0 ) && + ((old_func->old_sympos == func->old_sympos) || + (old_func->old_sympos ==0 && func->old_sympos ==1 ) || + (old_func->old_sympos ==1 && func->old_sympos ==0 ))) { +return func; + } + } + +return NULL ; +} +#endif /* _LIVEPATCH_CORE_H */
Signature · 1 line
2.52.0
Petr Mladek
maintainerRe: [PATCH v3 2/7] livepatch: Move klp_find_func() into core.h
Quoted 58 lines · Yafang Shao
This function will be used in other source file in the following patch.
Signed-off-by Yafang Shao <[email protected]>--- kernel/livepatch/core.c | 21 --------------------- kernel/livepatch/core.h | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-)kernel/livepatch/core.c +0
-21@@ -82,27 +82,6 @@ static bool klp_initialized(void)return !!klp_root_kobj; } -static struct klp_func *klp_find_func (struct klp_object *obj, -struct klp_func *old_func) -{ -struct klp_func *func; - -klp_for_each_func (obj, func) { -/* -* Besides identical old_sympos, also consider old_sympos -* of 0 and 1 are identical. -*/ -if ((func->old_name &&strcmp (old_func->old_name, func->old_name) ==0 ) && - ((old_func->old_sympos == func->old_sympos) || - (old_func->old_sympos ==0 && func->old_sympos ==1 ) || - (old_func->old_sympos ==1 && func->old_sympos ==0 ))) { -return func; - } - } - -return NULL ; -} -static struct klp_object *klp_find_object (struct klp_patch *patch,struct klp_object *old_obj) {kernel/livepatch/core.h +10
-0@@ -56,4 +56,25 @@ static inline void klp_post_unpatch_callback(struct klp_object *obj) obj->callbacks.post_unpatch_enabled = false; } +static inline struct klp_func *klp_find_func (struct klp_object *obj, +struct klp_func *old_func) +{ +struct klp_func *func; + +klp_for_each_func (obj, func) { +/* +* Besides identical old_sympos, also consider old_sympos +* of 0 and 1 are identical. +*/
kernel/livepatch/core.h static inline void klp_post_unpatch_callback(struct klp_object *obj) · line 78
Quoted 10 lines
kernel/livepatch/core.h +10
-0+if ((func->old_name &&strcmp (old_func->old_name, func->old_name) ==0 ) && + ((old_func->old_sympos == func->old_sympos) || + (old_func->old_sympos ==0 && func->old_sympos ==1 ) || + (old_func->old_sympos ==1 && func->old_sympos ==0 ))) { +return func; + } + } + +return NULL ; +}
This is too big for in-lining to my taste. I would prefer to just remove the static and declare it in the header file.
Also it would be nice to add a description of the function when we are going to use it on more locations. Especially, if we allow to pass errors via ERR_PTR.
Best Regards,
Petr
Re: [PATCH v3 2/7] livepatch: Move klp_find_func() into core.h
Quoted 74 lines · Petr Mladek
Quoted 58 lines · Yafang Shao
This function will be used in other source file in the following patch.
Signed-off-by Yafang Shao <[email protected]>--- kernel/livepatch/core.c | 21 --------------------- kernel/livepatch/core.h | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-)kernel/livepatch/core.c +0
-21@@ -82,27 +82,6 @@ static bool klp_initialized(void)return !!klp_root_kobj; } -static struct klp_func *klp_find_func (struct klp_object *obj, -struct klp_func *old_func) -{ -struct klp_func *func; - -klp_for_each_func (obj, func) { -/* -* Besides identical old_sympos, also consider old_sympos -* of 0 and 1 are identical. -*/ -if ((func->old_name &&strcmp (old_func->old_name, func->old_name) ==0 ) && - ((old_func->old_sympos == func->old_sympos) || - (old_func->old_sympos ==0 && func->old_sympos ==1 ) || - (old_func->old_sympos ==1 && func->old_sympos ==0 ))) { -return func; - } - } - -return NULL ; -} -static struct klp_object *klp_find_object (struct klp_patch *patch,struct klp_object *old_obj) {kernel/livepatch/core.h +10
-0@@ -56,4 +56,25 @@ static inline void klp_post_unpatch_callback(struct klp_object *obj) obj->callbacks.post_unpatch_enabled = false; } +static inline struct klp_func *klp_find_func (struct klp_object *obj, +struct klp_func *old_func) +{ +struct klp_func *func; + +klp_for_each_func (obj, func) { +/* +* Besides identical old_sympos, also consider old_sympos +* of 0 and 1 are identical. +*/ kernel/livepatch/core.h static inline void klp_post_unpatch_callback(struct klp_object *obj) · line 78
Quoted 10 lines
kernel/livepatch/core.h +10
-0+if ((func->old_name &&strcmp (old_func->old_name, func->old_name) ==0 ) && + ((old_func->old_sympos == func->old_sympos) || + (old_func->old_sympos ==0 && func->old_sympos ==1 ) || + (old_func->old_sympos ==1 && func->old_sympos ==0 ))) { +return func; + } + } + +return NULL ; +}This is too big for in-lining to my taste. I would prefer to just remove the static and declare it in the header file.
Quoted 3 lines
Also it would be nice to add a description of the function when we are going to use it on more locations. Especially, if we allow to pass errors via
ERR_PTR.
I will update it.
Signature · 2 lines
Regards Yafang
PATCH v3 3/7 livepatch: Support scoped atomic replace using replace_set
In reply to Yafang ShaoConvert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given replace_set number.
This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different replace_set, the loading of the new livepatch will be refused.
Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different replace_set.
For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Support for replace_set compatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].
Other user-visible changes include:
- The non-replace model is now deprecated
- /sys/kernel/livepatch/livepatch_XXX/replace attribute is replaced by /sys/kernel/livepatch/livepatch_XXX/replace_set
--- .../ABI/testing/sysfs-kernel-livepatch | 5 +- .../livepatch/cumulative-patches.rst | 23 ++++++--- Documentation/livepatch/livepatch.rst | 21 ++++---- include/linux/livepatch.h | 5 +- kernel/livepatch/core.c | 24 +++++---- kernel/livepatch/state.c | 51 +++++++++++++++---- kernel/livepatch/transition.c | 11 ++-- scripts/livepatch/init.c | 6 +-- scripts/livepatch/klp-build | 16 +++--- 9 files changed, 104 insertions(+), 58 deletions(-)
Documentation/ABI/testing/sysfs-kernel-livepatch +2 -3
@@ -47,13 +47,12 @@ Description: disabled when the feature is used. See Documentation/livepatch/livepatch.rst for more information. -What: /sys/kernel/livepatch/<patch>/replace +What: /sys/kernel/livepatch/<patch>/replace_set Date: Jun 2024 KernelVersion: 6.11.0 Contact: [email protected] Description: - An attribute which indicates whether the patch supports - atomic-replace. + An attribute to show the replace_set of this livepatch. What: /sys/kernel/livepatch/<patch>/stack_order Date: Jan 2025
Documentation/livepatch/cumulative-patches.rst +15 -8
@@ -17,18 +17,20 @@ from all older livepatches and completely replace them in one transition. Usage ----- -The atomic replace can be enabled by setting "replace" flag in struct klp_patch, -for example:: +The "replace_set" attribute in ``struct klp_patch`` acts as a **replace_set**, +defining the scope of the replacement. By default, the replace_set is 0. + +For example:: static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, - .replace = true, + .replace_set = 0, }; All processes are then migrated to use the code only from the new patch. -Once the transition is finished, all older patches are automatically -disabled. +Once the transition is finished, all older patches with the same replace +set are automatically disabled. Patches with different tags remain active. Ftrace handlers are transparently removed from functions that are no longer modified by the new cumulative patch.
@@ -62,9 +64,14 @@ Limitations: ------------ - Once the operation finishes, there is no straightforward way - to reverse it and restore the replaced patches atomically. - - A good practice is to set .replace flag in any released livepatch. + to reverse it and restore the replaced patches (with the same set) + atomically. + + A good practice is to use only one (default) "replace_set". It + makes sure that there always will be only one enabled livepatch + on the system. The consistency model will ensure a safe update + between two versions. It prevents potential problems with installing + two livepatches doing incompatible functional changes. Then re-adding an older livepatch is equivalent to downgrading to that patch. This is safe as long as the livepatches do _not_ do extra modifications in (un)patching callbacks or in the module_init()
Documentation/livepatch/livepatch.rst +12 -9
@@ -347,15 +347,18 @@ to '0'. 5.3. Replacing -------------- -All enabled patches might get replaced by a cumulative patch that -has the .replace flag set. - -Once the new patch is enabled and the 'transition' finishes then -all the functions (struct klp_func) associated with the replaced -patches are removed from the corresponding struct klp_ops. Also -the ftrace handler is unregistered and the struct klp_ops is -freed when the related function is not modified by the new patch -and func_stack list becomes empty. +There always can be only one livepatch with a given "replace_set" number. +They always replace each other. + +Once the transition is complete, all functions (``struct klp_func``) +associated with the matching replaced patches are removed from the +corresponding ``struct klp_ops``. If a function is no longer modified by +the new patch and its ``func_stack`` list becomes empty, the ftrace +handler is unregistered and the ``struct klp_ops`` is freed. + +Patches with a different replace set are not affected by this process +and remain active. This allows for the independent management and +stacking of multiple, non-conflicting livepatch sets. See Documentation/livepatch/cumulative-patches.rst for more details.
include/linux/livepatch.h +3 -2
@@ -123,7 +123,8 @@ struct klp_state {* @mod: reference to the live patch module * @objs: object entries for kernel objects to be patched * @states: system states that can get modified -* @replace: replace all actively used patches +* @replace_set:Livepatch using the same @replace_set will get atomically +* replaced. * @list: list node for global list of actively used patches * @kobj: kobject for sysfs resources * @obj_list: dynamic list of the object entries
@@ -137,7 +138,7 @@ struct klp_patch {struct module *mod;struct klp_object *objs;struct klp_state *states; -bool replace; +unsigned int replace_set;/* internal */ struct list_head list;
kernel/livepatch/core.c +14 -10
@@ -329,7 +329,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,* /sys/kernel/livepatch/<patch>/enabled * /sys/kernel/livepatch/<patch>/transition * /sys/kernel/livepatch/<patch>/force -* /sys/kernel/livepatch/<patch>/replace +* /sys/kernel/livepatch/<patch>/replace_set * /sys/kernel/livepatch/<patch>/stack_order * /sys/kernel/livepatch/<patch>/<object> * /sys/kernel/livepatch/<patch>/<object>/patched
@@ -427,13 +427,13 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,return count; } -static ssize_t replace_show (struct kobject *kobj, +static ssize_t replace_set_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {struct klp_patch *patch; patch = container_of(kobj, struct klp_patch, kobj); -return sysfs_emit (buf,"%d\n" , patch->replace); +return sysfs_emit (buf,"%u\n" , patch->replace_set); } static ssize_t stack_order_show(struct kobject *kobj,
@@ -460,13 +460,13 @@ static ssize_t stack_order_show(struct kobject *kobj,static struct kobj_attribute enabled_kobj_attr =__ATTR_RW (enabled);static struct kobj_attribute transition_kobj_attr =__ATTR_RO (transition);static struct kobj_attribute force_kobj_attr =__ATTR_WO (force); -static struct kobj_attribute replace_kobj_attr =__ATTR_RO (replace); +static struct kobj_attribute replace_set_kobj_attr =__ATTR_RO (replace_set);static struct kobj_attribute stack_order_kobj_attr =__ATTR_RO (stack_order);static struct attribute *klp_patch_attrs[] = { &enabled_kobj_attr.attr, &transition_kobj_attr.attr, &force_kobj_attr.attr, - &replace_kobj_attr.attr, + &replace_set_kobj_attr.attr, &stack_order_kobj_attr.attr,NULL };
@@ -600,6 +600,8 @@ static int klp_add_nops(struct klp_patch *patch)klp_for_each_object (old_patch, old_obj) {int err; +if (patch->replace_set != old_patch->replace_set) +continue ; err =klp_add_object_nops (patch, old_obj);if (err)return err;
@@ -772,6 +774,8 @@ void klp_free_replaced_patches_async(struct klp_patch *new_patch)klp_for_each_patch_safe (old_patch, tmp_patch) {if (old_patch == new_patch)return ; +if (old_patch->replace_set != new_patch->replace_set) +continue ;klp_free_patch_async (old_patch); } }
@@ -967,11 +971,9 @@ static int klp_init_patch(struct klp_patch *patch)if (ret)return ret; -if (patch->replace) { - ret =klp_add_nops (patch); -if (ret) -return ret; - } + ret =klp_add_nops (patch); +if (ret) +return ret;klp_for_each_object (patch, obj) { ret =klp_init_object (patch, obj);
@@ -1174,6 +1176,8 @@ void klp_unpatch_replaced_patches(struct klp_patch *new_patch)if (old_patch == new_patch)return ; +if (old_patch->replace_set != new_patch->replace_set) +continue ; old_patch->enabled = false;klp_unpatch_objects (old_patch); }
kernel/livepatch/state.c +41 -10
75 lines not on this page · raw message
kernel/livepatch/transition.c +6 -5
@@ -89,7 +89,7 @@ static void klp_complete_transition(void) klp_transition_patch->mod->name, klp_target_state == KLP_TRANSITION_PATCHED ? "patching" : "unpatching"); -if (klp_transition_patch->replace && klp_target_state ==KLP_TRANSITION_PATCHED ) { +if (klp_target_state ==KLP_TRANSITION_PATCHED ) {klp_unpatch_replaced_patches (klp_transition_patch);klp_discard_nops (klp_transition_patch); }
@@ -498,7 +498,7 @@ void klp_try_complete_transition(void)*/ if (!patch->enabled)klp_free_patch_async (patch); -else if (patch->replace) +else klp_free_replaced_patches_async (patch); }
@@ -720,11 +720,12 @@ void klp_force_transition(void)klp_update_patch_state (idle_task (cpu));/* Set forced flag for patches being removed. */ -if (klp_target_state ==KLP_TRANSITION_UNPATCHED ) +if (klp_target_state ==KLP_TRANSITION_UNPATCHED ) { klp_transition_patch->forced = true; -else if (klp_transition_patch->replace) { + }else {klp_for_each_patch (patch) { -if (patch != klp_transition_patch) +if (patch != klp_transition_patch && + patch->replace_set == klp_transition_patch->replace_set) patch->forced = true; } }
scripts/livepatch/init.c +3 -3
@@ -72,10 +72,10 @@ static int __init livepatch_mod_init(void)/* TODO patch->states */ -#ifdef KLP_NO_REPLACE - patch->replace = false; +#ifdef KLP_REPLACE_SET + patch->replace_set =KLP_REPLACE_SET ;#else - patch->replace = true; + patch->replace_set =0 ;#endif return klp_enable_patch (patch);
scripts/livepatch/klp-build +8 -8
@@ -22,7 +22,7 @@ shopt -s lastpipe unset DEBUG_CLONE DIFF_CHECKSUM SKIP_CLEANUP XTRACE -REPLACE=1 +REPLACE_SET=0 SHORT_CIRCUIT=0 JOBS="$(getconf _NPROCESSORS_ONLN)" VERBOSE="-s"
@@ -134,7 +134,7 @@ Options: -f, --show-first-changed Show address of first changed instruction -j, --jobs=<jobs> Build jobs to run simultaneously [default: $JOBS] -o, --output=<file.ko> Output file [default: livepatch-<patch-name>.ko] - --no-replace Disable livepatch atomic replace + -s, --replace-set=<set> Set the atomic replace set for this livepatch -v, --verbose Pass V=1 to kernel/module builds Advanced Options:
@@ -159,8 +159,8 @@ process_args() { local long local args - short="hfj:o:vdS:T" - long="help,show-first-changed,jobs:,output:,no-replace,verbose,debug,short-circuit:,keep-tmp" + short="hfj:o:s:vdS:T" + long="help,show-first-changed,jobs:,output:,replace-set:,verbose,debug,short-circuit:,keep-tmp" args=$(getopt --options "$short" --longoptions "$long" -- "$@") || { echo; usage; exit
@@ -189,9 +189,9 @@ process_args() { NAME="$(module_name_string "$NAME")" shift 2 ;; - --no-replace) - REPLACE=0 - shift + -s | --replace-set) + REPLACE_SET="$2" + shift 2 ;; -v | --verbose) VERBOSE="V=1"
@@ -777,7 +777,7 @@ build_patch_module() { cflags=("-ffunction-sections") cflags+=("-fdata-sections") - [[ $REPLACE -eq 0 ]] && cflags+=("-DKLP_NO_REPLACE") + cflags+=("-DKLP_REPLACE_SET=$REPLACE_SET") cmd=("make") cmd+=("$VERBOSE")
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The newly introduced check in `klp_is_patch_compatible` causes a kernel panic if a livepatch…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The newly introduced check in klp_is_patch_compatible causes a kernel panic if a livepatch module contains a klp_func entry with old_name == NULL. --
commit ed678e88294b650a730cda1a47351fce99677c1e
Author: Yafang Shao <[email protected]>
livepatch: Support scoped atomic replace using replace_set
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set.
[ ... ]
Quoted 2 lines
kernel/livepatch/state.c +0
-0
[ ... ]
Quoted 8 lines
kernel/livepatch/state.c +8
-0+/* +* Refuse loading a livepatch which would want to modify a +* function which is already livepatched with the livepatch +* with another "replace_set". +*/ +klp_for_each_object_static (patch, obj) { +klp_for_each_object (old_patch, old_obj) { +if (!!obj->name != !!old_obj->name)
kernel/livepatch/state.c EXPORT_SYMBOL_GPL(klp_get_prev_state); · line 147
Quoted 10 lines
kernel/livepatch/state.c +9
-0+continue ; +if (obj->name &&strcmp (obj->name, old_obj->name)) +continue ; +klp_for_each_func_static (obj, func) { +if (klp_find_func (old_obj, func)) +return false; + } + } + } }
[Severity: High]
Can passing an unvalidated function to klp_find_func() cause a NULL pointer dereference here?
If a new livepatch module is loaded with an improperly initialized klp_func array (e.g., accidentally missing old_name but providing new_func), klp_for_each_func_static() will still process it because structural validation in klp_init_patch() hasn't occurred yet at this point in the loading process.
When this unvalidated func is passed as the second argument to klp_find_func(old_obj, func), the roles inside klp_find_func() are reversed from its usual context. The old_func parameter represents the new patch's unvalidated function, while the local func iterator represents the already-installed patch.
Inside klp_find_func(), the check evaluates:
if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0)
Since the installed patch's func->old_name is guaranteed to be non-NULL, strcmp() will be called with old_func->old_name. If old_func->old_name is NULL, does this turn what would normally be a graceful -EINVAL module rejection into a system crash?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 55 lines · On Sun, Jun 7, 2026 at 9:33 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The newly introduced check inklp_is_patch_compatiblecauses a kernel panic if a livepatch module contains aklp_funcentry withold_name == NULL. --commit
ed678e88294b650a730cda1a47351fce99677c1e
Author: Yafang Shao <[email protected]>livepatch: Support scoped atomic replace using
replace_setConvert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set.
[ ... ]
Quoted 2 lines
kernel/livepatch/state.c +0
-0[ ... ]
Quoted 8 lines
kernel/livepatch/state.c +8
-0+/* +* Refuse loading a livepatch which would want to modify a +* function which is already livepatched with the livepatch +* with another "replace_set". +*/ +klp_for_each_object_static (patch, obj) { +klp_for_each_object (old_patch, old_obj) { +if (!!obj->name != !!old_obj->name)kernel/livepatch/state.c
Quoted 10 lines
kernel/livepatch/state.c +9
-0+continue ; +if (obj->name &&strcmp (obj->name, old_obj->name)) +continue ; +klp_for_each_func_static (obj, func) { +if (klp_find_func (old_obj, func)) +return false; + } + } + } }[Severity: High]
Can passing an unvalidated function toklp_find_func()cause a NULL pointer dereference here?If a new livepatch module is loaded with an improperly initialized
klp_funcarray (e.g., accidentally missingold_namebut providingnew_func),klp_for_each_func_static()will still process it because structural validation inklp_init_patch()hasn't occurred yet at this point in the loading process.When this unvalidated func is passed as the second argument to
klp_find_func(old_obj, func), the roles insideklp_find_func()are reversed from its usual context. Theold_funcparameter represents the new patch's unvalidated function, while the local func iterator represents the already-installed patch.
Quoted 8 lines
Inside
klp_find_func(), the check evaluates:if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0)Since the installed patch's
func->old_nameis guaranteed to be non-NULL,strcmp()will be called withold_func->old_name. Ifold_func->old_nameis NULL, does this turn what would normally be a graceful-EINVALmodule rejection into a system crash?
Oops, I missed that. It seems we should better check both func->name and old_func->name in patch #1.
kernel/livepatch/core.c +9 -7
@@ -82,20 +82,22 @@ static bool klp_initialized(void)return !!klp_root_kobj; } +/* Check if @func is present in @obj */ static struct klp_func *klp_find_func (struct klp_object *obj, -struct klp_func *old_func) +struct klp_func *func) { -struct klp_func *func; +struct klp_func *obj_func; -klp_for_each_func (obj, func) { +klp_for_each_func (obj, obj_func) {/* * Besides identical old_sympos, also consider old_sympos * of 0 and 1 are identical. */ -if ((strcmp (old_func->old_name, func->old_name) ==0 ) && - ((old_func->old_sympos == func->old_sympos) || - (old_func->old_sympos ==0 && func->old_sympos ==1 ) || - (old_func->old_sympos ==1 && func->old_sympos ==0 ))) { +if ((obj_func->old_name && func->old_name && +strcmp (obj_func->old_name, func->old_name) ==0 ) && + ((obj_func->old_sympos == func->old_sympos) || + (obj_func->old_sympos ==0 && func->old_sympos ==1 ) || + (obj_func->old_sympos ==1 && func->old_sympos ==0 ))) {return func; } }
Signature · 2 lines
Regards Yafang
Petr Mladek
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Yafang ShaoQuoted 19 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Quoted 7 lines
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_set
The commit message is not bad. But the patch is breaking the backward compatibility. We should explain the motivation first.
I would write something like:
<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.
The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given replace_set number.
On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>
Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.
It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
3. Introduce a system wide flag, sysctl livepatch_replace_all which would allow to enable/disable the replace_all feature of either .replace_set == 0 or per-patch.replace_all flag.
It would allow the customer to preserve their custom livepatches when they know what they do. For example, when they use the livepatch to modify a 3rd party module or tune some functionality.
4. Just taint the kernel when a livepatch with .replace_set != 0 is installed. Then the OS provider could say that a tainted kernel is not longer officially supported.
I personally prefer the 4th solution because it is simple.
Best Regards,
Petr
PS: I still have to review the actual code changes. I'll do
it in a separate mail, ...
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 83 lines · Petr Mladek
Quoted 19 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Quoted 7 lines
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_setThe commit message is not bad. But the patch is breaking the backward compatibility. We should explain the motivation first.
I would write something like:
<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>
Quoted 6 lines
Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Thanks for refining the commit message. I will update it.
Quoted 38 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
3. Introduce a system wide flag, sysctl
livepatch_replace_allwhich would allow to enable/disable thereplace_allfeature of either .replace_set == 0 or per-patch.replace_all flag.
Quoted 8 lines
It would allow the customer to preserve their custom livepatches when they know what they do. For example, when they use the livepatch to modify a 3rd party module or tune some functionality.
4. Just taint the kernel when a livepatch with .replace_set != 0 is installed. Then the OS provider could say that a tainted kernel is not longer officially supported.
Since the kernel is already tainted with TAINT_LIVEPATCH upon loading a livepatch, are you recommending the addition of a distinct flag, such as TAINT_LIVEPATCH_REPLACE_SET?
Quoted 10 lines
I personally prefer the 4th solution because it is simple.
Best Regards,
PetrPS: I still have to review the actual code changes. I'll do
it in a separate mail, ...
Signature · 2 lines
Regards Yafang
Petr Mladek
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 71 lines · Yafang Shao
Quoted 70 lines · Petr Mladek
Quoted 19 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Quoted 7 lines
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_setNew idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
3. Introduce a system wide flag, sysctl
livepatch_replace_allwhich would allow to enable/disable thereplace_allfeature of either .replace_set == 0 or per-patch.replace_all flag.It would allow the customer to preserve their custom livepatches when they know what they do. For example, when they use the livepatch to modify a 3rd party module or tune some functionality.
Quoted 7 lines
Quoted 3 lines
4. Just taint the kernel when a livepatch with .replace_set != 0 is installed. Then the OS provider could say that a tainted kernel is not longer officially supported.
Since the kernel is already tainted with
TAINT_LIVEPATCHupon loading a livepatch, are you recommending the addition of a distinct flag, such asTAINT_LIVEPATCH_REPLACE_SET?
Yeah, I would call it TAINT_PARALLEL_LIVEPATCH orTAINT_MORE_LIVEPATCHES.
But maybe, it is not necessary. We have a tool which allows to get info about the running system, including the loaded modules and livepatches. It might be enough.
Let's see what others think about this. Note that Miroslav has vacation this week.
Best Regards,
Petr
Petr Mladek
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Petr MladekQuoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the replace_all functionality.
There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.
I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 8 lines
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
This is not ideal because it is asymetric. Why is "0" special?
Quoted 5 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.
Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.
I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct klp_patch {
[...]
unsigned int replace_set;
const unsigned int *supersedes; /* Zero terminated array of replace_set IDs */
[...]
}
So that the cumulative livepatch might optionally define another "replace_set"s which would be replaced.
This would work well when both cumulative livepatches and the hotfix are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module option to the cumulative livepatch, .e.g supersedes=id[,id]* We could add some support into the kernel for handling the module parameter a standard way.
It is not trivial. But it is also not horribly complex. It looks like a good compromise between the requirements and code complexity.
We really need input from others here.
Best Regards,
Petr
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 138 lines · Petr Mladek
Quoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the
replace_allfunctionality.There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "
replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 8 lines
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
This is not ideal because it is asymetric. Why is "0" special?
Quoted 5 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "
replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct
klp_patch{
[...]
unsigned intreplace_set;
const unsigned int *supersedes; /* Zero terminated array ofreplace_setIDs */
[...]
}So that the cumulative livepatch might optionally define another "replace_set"s which would be replaced.
Quoted 7 lines
This would work well when both cumulative livepatches and the hotfix are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module option to the cumulative livepatch, .e.g supersedes=id[,id]* We could add some support into the kernel for handling the module parameter a standard way.
I prefer this option because it allows us to dynamically set the supersedes at runtime, avoiding hardcoded values at build time. This flexibility is essential for handling complex production environments.
Quoted 6 lines
It is not trivial. But it is also not horribly complex. It looks like a good compromise between the requirements and code complexity.
We really need input from others here.
Happy to hear what others think as well.
Signature · 2 lines
Regards Yafang
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 128 lines · Yafang Shao
Quoted 126 lines · Petr Mladek
Quoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the
replace_allfunctionality.There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "
replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 8 lines
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
This is not ideal because it is asymetric. Why is "0" special?
Quoted 5 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "
replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
Quoted 8 lines
Quoted 8 lines
We could add:
struct
klp_patch{
[...]
unsigned intreplace_set;
const unsigned int *supersedes; /* Zero terminated array ofreplace_setIDs */
[...]
}
After further consideration, what about merging replace_set and supersedes into a single field? For example:
struct klp_patch {
[...]
unsigned int *replace_set;
[...]
};This replace_set field can be set at build time and also dynamically updated at load time. By default, it contains a single ID, 0. To replace a livepatch with ID 1, we can set it to 1 at load time. To replace livepatches with both ID 1 and ID 2, we can set it to [1, 2].
In other words, a livepatch with replace_set [1, 2] can replace livepatches with IDs 1, 2, or [1, 2]. A livepatch with replace_set [1, 2, 3] can replace livepatches with IDs 1, 2, 3, [1, 2], [1, 3], [2, 3], or [1, 2, 3].
I believe this approach is well-suited to complex production deployment environments.
[...]
Signature · 2 lines
Regards Yafang
Joe Lawrence
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Petr MladekQuoted 90 lines · Petr Mladek
Quoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the
replace_allfunctionality.There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "
replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 2 lines
I though about 4 approaches approaches:
Quoted 9 lines
Quoted 6 lines
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
This is not ideal because it is asymetric. Why is "0" special?
Hah, why is zero special? Because we said so and the asymmetry is the point. :) On my first pass through this patchset and reply chain, I'd say I lean toward approach (1) as it's dead simple and means not participating in replace_set values = no functional changes for the former atomic-replace user ...
Quoted 46 lines
Quoted 6 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "
replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct
klp_patch{
[...]
unsigned intreplace_set;
const unsigned int *supersedes; /* Zero terminated array ofreplace_setIDs */
[...]
}So that the cumulative livepatch might optionally define another "replace_set"s which would be replaced.
This would work well when both cumulative livepatches and the hotfix are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module option to the cumulative livepatch, .e.g supersedes=id[,id]* We could add some support into the kernel for handling the module parameter a standard way.
Quoted 6 lines
It is not trivial. But it is also not horribly complex. It looks like a good compromise between the requirements and code complexity.
We really need input from others here.
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?
The model becomes:
- replace_set: isolation sets (as Yafang has implemented)
- overlay (bool): "I'm a partial addition to my set, not a full replacement"
and then the vendor zero-day scenario looks like:
Mon: cumulative patch (set 0, overlay=false)
Tue: hotfix (set 0, overlay=true) stacks on top, overrides one function
Wed: new cumulative (set 0, overlay=false) replaces both
If overlay patches are cumulative, then it should support iterating on zero-day fixes like:
Mon: cumulative base patch
Tue: hotfix v1 disable vulnerable code
Wed: hotfix v2 vendor-specific attempt to solve
Thu: cumulative patch with final CVE fix
So I think either the supercedes or overlay feature handle vendor-only scenarios well.
The big difference overlay has from supercede is that it intentionally only plays within the vendor replace-set space. So if a (customer) feature replace-set was off touching function_foo() and a CVE landed there, the overlay feature would remain blocked from patching it. Supercede provides a big hammer here.
That said, blind eviction via supersede assumes the customer's replace-set patches are actually safe to bounce. The customer's patch may have allocated shadow variables, modified system state via callbacks, or changed data structure semantics, all designed to be unwound by the next customer version of that patch, not by an unrelated vendor patch. The vendor can't know what semantic landmines the customer's patch left behind, and the kernel can't validate that at load time.
So maybe it boils down to: is the supercedes big hammer desired and safe enough to deploy? Is overlay useful enough to be worth implementing?
--
Joe
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 99 lines · Joe Lawrence
Quoted 97 lines · Petr Mladek
Quoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the
replace_allfunctionality.There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "
replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 8 lines
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
Quoted 8 lines
Quoted 2 lines
This is not ideal because it is asymetric. Why is "0" special?
Hah, why is zero special? Because we said so and the asymmetry is the point. :) On my first pass through this patchset and reply chain, I'd say I lean toward approach (1) as it's dead simple and means not participating in
replace_setvalues = no functional changes for the former atomic-replace user ...
Making zero a special case might reintroduce the issues with cumulative and non-cumulative patches. See the detailed example below.
Quoted 60 lines
Quoted 47 lines
Quoted 7 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "
replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct
klp_patch{
[...]
unsigned intreplace_set;
const unsigned int *supersedes; /* Zero terminated array ofreplace_setIDs */
[...]
}So that the cumulative livepatch might optionally define another "replace_set"s which would be replaced.
This would work well when both cumulative livepatches and the hotfix are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module option to the cumulative livepatch, .e.g supersedes=id[,id]* We could add some support into the kernel for handling the module parameter a standard way.
Quoted 6 lines
It is not trivial. But it is also not horribly complex. It looks like a good compromise between the requirements and code complexity.
We really need input from others here.
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?The model becomes:
Quoted 7 lines
-
replace_set: isolation sets (as Yafang has implemented)
- overlay (bool): "I'm a partial addition to my set, not a full replacement"and then the vendor zero-day scenario looks like:
Mon: cumulative patch (set 0, overlay=false)
Tue: hotfix (set 0, overlay=true) stacks on top, overrides one function
At this point, if the user reboots the machine, the loading order of these livepatches becomes undetermined. If the hotfix is loaded first, the cumulative patch loaded next will replace it. As a result, the user must maintain the load order of these livepatches, which can be quite painful.
Quoted 30 lines
Wed: new cumulative (set 0, overlay=false) replaces both
If overlay patches are cumulative, then it should support iterating on zero-day fixes like:
Mon: cumulative base patch
Tue: hotfix v1 disable vulnerable code
Wed: hotfix v2 vendor-specific attempt to solve
Thu: cumulative patch with final CVE fixSo I think either the supercedes or overlay feature handle vendor-only scenarios well.
The big difference overlay has from supercede is that it intentionally only plays within the vendor replace-set space. So if a (customer) feature replace-set was off touching
function_foo()and a CVE landed there, the overlay feature would remain blocked from patching it. Supercede provides a big hammer here.That said, blind eviction via supersede assumes the customer's replace-set patches are actually safe to bounce. The customer's patch may have allocated shadow variables, modified system state via callbacks, or changed data structure semantics, all designed to be unwound by the next customer version of that patch, not by an unrelated vendor patch. The vendor can't know what semantic landmines the customer's patch left behind, and the kernel can't validate that at load time.
So maybe it boils down to: is the supersedes big hammer desired and safe enough to deploy? Is overlay useful enough to be worth implementing?
Signature · 2 lines
Regards Yafang
Joe Lawrence
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 177 lines · Yafang Shao
Quoted 99 lines · Joe Lawrence
Quoted 97 lines · Petr Mladek
Quoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the
replace_allfunctionality.There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "
replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 8 lines
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
Quoted 8 lines
Quoted 2 lines
This is not ideal because it is asymetric. Why is "0" special?
Hah, why is zero special? Because we said so and the asymmetry is the point. :) On my first pass through this patchset and reply chain, I'd say I lean toward approach (1) as it's dead simple and means not participating in
replace_setvalues = no functional changes for the former atomic-replace user ...Making zero a special case might reintroduce the issues with cumulative and non-cumulative patches. See the detailed example below.
Quoted 65 lines
Quoted 47 lines
Quoted 7 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "
replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct
klp_patch{
[...]
unsigned intreplace_set;
const unsigned int *supersedes; /* Zero terminated array ofreplace_setIDs */
[...]
}So that the cumulative livepatch might optionally define another "replace_set"s which would be replaced.
This would work well when both cumulative livepatches and the hotfix are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module option to the cumulative livepatch, .e.g supersedes=id[,id]* We could add some support into the kernel for handling the module parameter a standard way.
Quoted 6 lines
It is not trivial. But it is also not horribly complex. It looks like a good compromise between the requirements and code complexity.
We really need input from others here.
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?The model becomes:
-
replace_set: isolation sets (as Yafang has implemented)
- overlay (bool): "I'm a partial addition to my set, not a full replacement"and then the vendor zero-day scenario looks like:
Quoted 9 lines
Quoted 2 lines
Mon: cumulative patch (set 0, overlay=false)
Tue: hotfix (set 0, overlay=true) stacks on top, overrides one functionAt this point, if the user reboots the machine, the loading order of these livepatches becomes undetermined. If the hotfix is loaded first, the cumulative patch loaded next will replace it. As a result, the user must maintain the load order of these livepatches, which can be quite painful.
[ Edit: Feel free to jump to the bottom. Having been on PTO + holiday,
I needed to run through the full thought experiement below to come to the same conclusion as Petr and Yafang. Leaving it here in case it helps anyone else trace through the problem. ]
Ah right, this overlay idea drives us right back into stack_order headache.
Now to take the same scenario to the supersede feature. If I understand correctly, the idea is that cumulative vendor patches roll out at some interval (weekly, monthly, etc.) and they live in set=0. Emergency CVE firedrill ensues and to expedite the fix, the vendor skips the long cumulative build/QE/etc. with a targeted hotfix that lives in set=1. A while later, the vendor releases a full cumulative update, set=0 and supersedes=1 to replace the temporary hotfix(es):
Mon: cumulative base patch (set=0)
Tue: hotfix v1 disable vulnerable code (set=1)
Wed: hotfix v2 vendor-specific attempt to solve (set=1)
Thu: cumulative patch with final CVE fix (set=0, supersedes=1)
If Wednesday's hotfix v2 removes hotfix v1 from disk, then rebooting before Thursday's cumulative is safe regardless of load order, as set=0 and set=1 coexist independently. If stale hotfix versions remain on disk however, same-set replacement within set=1 means the last one loaded wins, which may silently downgrade the fix. With that packaging detail in place, this scenario looks good.
One additional note is that supersedes is only a mechanism to replace the hotfixes. Hotfixes still adhere to replace set rules, so if a 0-day lands in a function the current cumulative already patches, the hotfix can't be deployed as a separate set at all. The vendor is forced to rebuild the full cumulative.
Quoted 19 lines
Quoted 19 lines
Wed: new cumulative (set 0, overlay=false) replaces both
If overlay patches are cumulative, then it should support iterating on zero-day fixes like:
Mon: cumulative base patch
Tue: hotfix v1 disable vulnerable code
Wed: hotfix v2 vendor-specific attempt to solve
Thu: cumulative patch with final CVE fixSo I think either the supercedes or overlay feature handle vendor-only scenarios well.
The big difference overlay has from supercede is that it intentionally only plays within the vendor replace-set space. So if a (customer) feature replace-set was off touching
function_foo()and a CVE landed there, the overlay feature would remain blocked from patching it. Supercede provides a big hammer here.
Quoted 9 lines
Quoted 9 lines
That said, blind eviction via supersede assumes the customer's replace-set patches are actually safe to bounce. The customer's patch may have allocated shadow variables, modified system state via callbacks, or changed data structure semantics, all designed to be unwound by the next customer version of that patch, not by an unrelated vendor patch. The vendor can't know what semantic landmines the customer's patch left behind, and the kernel can't validate that at load time.
Now it gets complicated and I've got a fresh cup of tea to consider how supersede coexists with user livepatch replace sets.
Scenario 1: 0-day in foo(), nobody patches it yet:
Mon: cumulative base patch (set=0)
customer feature patch (set=2)
Tue: hotfix v1 disable vulnerable code (set=1) Wed: hotfix v2 vendor-specific attempt to solve (set=1)
Thu: cumulative patch with final CVE fix (set=0, supersedes=1)
Life is great, the customer feature livepatch sits out in set=2, unaffected by all the vendor cumulative (set=0) and hotfix (set=1) churn.
Scenario 2: 0-day in bar(), customer's set owns it:
Mon: cumulative base patch (set=0)
customer feature patch (set=2)
Tue: hotfix v1 patches bar() (set=1) < REJECTED, bar() owned by set=2The kernel rejects the vendor's hotfix because the customer set=2 owns bar() and it doesn't supersede it. <Ahah moment> if supersedes is provided as a vendor livepatch module parameter, the educated customer could then choose the hammer and let their vendor's livepatch replace their bar().
[ Edit: Joe is finally up to speed here. ]
Alright I think I'm onboard with the supersede feature and its optional module parameter.
With that, is it worth documenting a convention for replace_set allocation? Something as simple as "vendors use low-numbered sets, customers use higher ones" might help avoid collisions, with the understanding that the kernel makes no distinction between them.
--
Joe
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 281 lines · Joe Lawrence
Quoted 177 lines · Yafang Shao
Quoted 99 lines · Joe Lawrence
Quoted 97 lines · Petr Mladek
Quoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the
replace_allfunctionality.There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "
replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 8 lines
I though about 4 approaches approaches:
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
Quoted 8 lines
Quoted 2 lines
This is not ideal because it is asymetric. Why is "0" special?
Hah, why is zero special? Because we said so and the asymmetry is the point. :) On my first pass through this patchset and reply chain, I'd say I lean toward approach (1) as it's dead simple and means not participating in
replace_setvalues = no functional changes for the former atomic-replace user ...Making zero a special case might reintroduce the issues with cumulative and non-cumulative patches. See the detailed example below.
Quoted 65 lines
Quoted 47 lines
Quoted 7 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "
replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct
klp_patch{
[...]
unsigned intreplace_set;
const unsigned int *supersedes; /* Zero terminated array ofreplace_setIDs */
[...]
}So that the cumulative livepatch might optionally define another "replace_set"s which would be replaced.
This would work well when both cumulative livepatches and the hotfix are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module option to the cumulative livepatch, .e.g supersedes=id[,id]* We could add some support into the kernel for handling the module parameter a standard way.
Quoted 6 lines
It is not trivial. But it is also not horribly complex. It looks like a good compromise between the requirements and code complexity.
We really need input from others here.
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?The model becomes:
-
replace_set: isolation sets (as Yafang has implemented)
- overlay (bool): "I'm a partial addition to my set, not a full replacement"and then the vendor zero-day scenario looks like:
Quoted 9 lines
Quoted 2 lines
Mon: cumulative patch (set 0, overlay=false)
Tue: hotfix (set 0, overlay=true) stacks on top, overrides one functionAt this point, if the user reboots the machine, the loading order of these livepatches becomes undetermined. If the hotfix is loaded first, the cumulative patch loaded next will replace it. As a result, the user must maintain the load order of these livepatches, which can be quite painful.
[ Edit: Feel free to jump to the bottom. Having been on PTO + holiday,
I needed to run through the full thought experiement below to come to the same conclusion as Petr and Yafang. Leaving it here in case it helps anyone else trace through the problem. ]Ah right, this overlay idea drives us right back into
stack_orderheadache.Now to take the same scenario to the supersede feature. If I understand correctly, the idea is that cumulative vendor patches roll out at some interval (weekly, monthly, etc.) and they live in set=0. Emergency CVE firedrill ensues and to expedite the fix, the vendor skips the long cumulative build/QE/etc. with a targeted hotfix that lives in set=1. A while later, the vendor releases a full cumulative update, set=0 and supersedes=1 to replace the temporary hotfix(es):
Mon: cumulative base patch (set=0)
Tue: hotfix v1 disable vulnerable code (set=1)
Wed: hotfix v2 vendor-specific attempt to solve (set=1)
Thu: cumulative patch with final CVE fix (set=0, supersedes=1)If Wednesday's hotfix v2 removes hotfix v1 from disk, then rebooting before Thursday's cumulative is safe regardless of load order, as set=0 and set=1 coexist independently. If stale hotfix versions remain on disk however, same-set replacement within set=1 means the last one loaded wins, which may silently downgrade the fix. With that packaging detail in place, this scenario looks good.
One additional note is that supersedes is only a mechanism to replace the hotfixes. Hotfixes still adhere to replace set rules, so if a 0-day lands in a function the current cumulative already patches, the hotfix can't be deployed as a separate set at all. The vendor is forced to rebuild the full cumulative.
Quoted 19 lines
Quoted 19 lines
Wed: new cumulative (set 0, overlay=false) replaces both
If overlay patches are cumulative, then it should support iterating on zero-day fixes like:
Mon: cumulative base patch
Tue: hotfix v1 disable vulnerable code
Wed: hotfix v2 vendor-specific attempt to solve
Thu: cumulative patch with final CVE fixSo I think either the supercedes or overlay feature handle vendor-only scenarios well.
The big difference overlay has from supercede is that it intentionally only plays within the vendor replace-set space. So if a (customer) feature replace-set was off touching
function_foo()and a CVE landed there, the overlay feature would remain blocked from patching it. Supercede provides a big hammer here.Quoted 9 lines
Quoted 9 lines
That said, blind eviction via supersede assumes the customer's replace-set patches are actually safe to bounce. The customer's patch may have allocated shadow variables, modified system state via callbacks, or changed data structure semantics, all designed to be unwound by the next customer version of that patch, not by an unrelated vendor patch. The vendor can't know what semantic landmines the customer's patch left behind, and the kernel can't validate that at load time.
Now it gets complicated and I've got a fresh cup of tea to consider how supersede coexists with user livepatch replace sets.
Scenario 1: 0-day in
foo(), nobody patches it yet:Mon: cumulative base patch (set=0) customer feature patch (set=2) Tue: hotfix v1 disable vulnerable code (set=1)Wed: hotfix v2 vendor-specific attempt to solve (set=1)
Thu: cumulative patch with final CVE fix (set=0, supersedes=1)Life is great, the customer feature livepatch sits out in set=2, unaffected by all the vendor cumulative (set=0) and hotfix (set=1) churn.
Scenario 2: 0-day in
bar(), customer's set owns it:Mon: cumulative base patch (set=0) customer feature patch (set=2) Tue: hotfix v1 patches bar() (set=1) < REJECTED, bar() owned by set=2The kernel rejects the vendor's hotfix because the customer set=2 owns
bar()and it doesn't supersede it. <Ahah moment> if supersedes is provided as a vendor livepatch module parameter, the educated customer could then choose the hammer and let their vendor's livepatch replace theirbar().[ Edit: Joe is finally up to speed here. ]
Quoted 7 lines
Alright I think I'm onboard with the supersede feature and its optional module parameter.
With that, is it worth documenting a convention for
replace_setallocation? Something as simple as "vendors use low-numbered sets, customers use higher ones" might help avoid collisions, with the understanding that the kernel makes no distinction between them.
Since replace_sets can be configured dynamically as needed, I don't think we need to document it explicitly. Users can simply choose the right sets for their production environment—for example, by checking the currently used sets and adjusting accordingly.
Signature · 2 lines
Regards Yafang
Petr Mladek
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Joe LawrenceQuoted 157 lines · Joe Lawrence
Quoted 90 lines · Petr Mladek
Quoted 60 lines · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
I would write something like:<proposal>
The practice shows that the current semantic of the patch.replace flag is not ideal.The atomic replace is disabled by default. And the no-replace mode allows wild installation of many livepatches in parallel. The author and administrator are fully responsible for preventing problems caused by producing and installing incompatible livepatches.
The most safe atomic replace mode must be explicitly enabled by setting "patch.replace = true". It is all or nothing. The livepatch with enabled .replace will always replace all already installed livepatches. It makes it very safe but it might be too harsh.
Improve the situation by switching "bool .replace" flag to "u32 .replace_set" and and updating its semantic.
Any .replace_set value might be associated with a set of livepatched symbols, callbacks, shadow variable and state IDs.
A livepatch with a particular .replace_set number will atomically rreplace any already installed livepatch with the same .replace_set number. By definition, there can only ever be one active livepatch for a given
replace_setnumber.On the contrary, livepatches with a different .replace_set number must not modify the same function, or use the state with the same ID [*]. Any attempt to load an incompatible livepatch will be rejected.
Summary:
The most safe mode when any livepatch replaces any other livepatch will be the default. Note that all livepatches must keep .replace_set = 0.
It will be possible to install more livepatches in parallel by using different .replace_set numbers. The livepatches might be updated independently using the atomic replace feature as long as the new version does not break compatibility. The kernel will reject a livepatch from a different replace set when it would want to modify the same function or livepatch state from another replace set.
[*] The compatibility check of callbacks and shadow variables will
be improved later by reworking their semantic. There is a work in progress, see [0]
</proposal>Quoted 1 line
I have realized that I actually sent "v1-iter12" to the public mailing list as the official v1. So we could use:
Quoted 7 lines
New idea:
I have briefly discussed the new semantic with Miroslav when I met him in person. And he was a bit concerned. We as an OS distributor might want to be sure that our livepatches can be installed the most safe way. So, we still might want to preserve the "replace all" semantic to make sure that our livepatches will not break anything.
I thought more about it and we would need some solution to preserve the
replace_allfunctionality.There were recently reported few serious 0-day vulnerabilities. We discussed a possibility to ship a quick fix with a livepatch. Or that customers might want to fix it themself by a livepatch. Such a livepatch would need to be installed in parallel to the official livepatch fixing older bugs. But the next official cumulative livepatch would need to replace it.
The above scenario will not longer work with the current "
replace_set" handling. The hotfix would need to use another "replace_set" so that it can be installed in parallel. But the next cumulative livepatch won't be able to replace it because it would need to modify the same function.I consulted this with AI (claude-sonet-4.6) and it gave the following feedback/ideas ;-)
Quoted 2 lines
I though about 4 approaches approaches:
Quoted 9 lines
Quoted 6 lines
1. Make .replace_set=0 special so that it will always replace everything. Similar to the current .replace=true mode.
Customers will still be able to install custom livepatches later with .replace_set != 0. But the "0" livepatch will always wipe them out.
This is not ideal because it is asymetric. Why is "0" special?
Hah, why is zero special? Because we said so and the asymmetry is the point. :) On my first pass through this patchset and reply chain, I'd say I lean toward approach (1) as it's dead simple and means not participating in
replace_setvalues = no functional changes for the former atomic-replace user ...Quoted 50 lines
Quoted 6 lines
2. Use two flags in the livepatch, for example
a. Rename .replace to .replace_all. The livepatch with this
flag set will always wipe all other livepatches.Quoted 7 lines
b. Add .replace_set which will allow to install more livepatches
in parallel, replace the livepatches with the same .replace_set atomically, and check the compatibility. As described above.It is a bit more complicated. But it is more compatible with the current state. And it removes the special meaning of .replace_set == 0.
This looks more straightforward. But the fact that "
replace_all" replaces everything brings back the problem with the original "replace" flag. So, it makes this whole exercise more or less pointless.I had another idea with storing list of fixed bugs/CVEs in each livepatch. Independent fixes might be fixed by independent livepatches. Then a cumulative livepatch would replace only the livepatches which fixed the same bugs before.
And (claude-sonnet-4.6) came with an interesting simplification.
We could add:
struct
klp_patch{
[...]
unsigned intreplace_set;
const unsigned int *supersedes; /* Zero terminated array ofreplace_setIDs */
[...]
}So that the cumulative livepatch might optionally define another "replace_set"s which would be replaced.
This would work well when both cumulative livepatches and the hotfix are provided by the same vendor or group.
We could also allow to change it dynamically by adding an module option to the cumulative livepatch, .e.g supersedes=id[,id]* We could add some support into the kernel for handling the module parameter a standard way.
It is not trivial. But it is also not horribly complex. It looks like a good compromise between the requirements and code complexity.
Quoted 6 lines
Quoted 2 lines
We really need input from others here.
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?
I continue with the brainstorming ;-)
Quoted 10 lines
The model becomes:
-
replace_set: isolation sets (as Yafang has implemented)
- overlay (bool): "I'm a partial addition to my set, not a full replacement"and then the vendor zero-day scenario looks like:
Mon: cumulative patch (set 0, overlay=false)
Tue: hotfix (set 0, overlay=true) stacks on top, overrides one function
Wed: new cumulative (set 0, overlay=false) replaces both
First, I am not much happy with the "overlay" terminology. In the filesystem world an overlay allows to have the same file in more layers and usually only the highest one is visible.
But this whole exercise with "replace_set" was motivated by adding some safety when installing more livepatches in parallel. And the most obvious danger is when two livepatches modify the same function. So I wanted to prevent this.
It is also related to the commit 3dae09de406167 ("livepatch:
Add stack_order sysfs attribute") which helped to debug such problems.
Quoted 10 lines
If overlay patches are cumulative, then it should support iterating on zero-day fixes like:
Mon: cumulative base patch
Tue: hotfix v1 disable vulnerable code
Wed: hotfix v2 vendor-specific attempt to solve
Thu: cumulative patch with final CVE fixSo I think either the supercedes or overlay feature handle vendor-only scenarios well.
Second, this would kind of solve the OS vendor problems. But the customer might want the same flexibility.
Quoted 6 lines
The big difference overlay has from supercede is that it intentionally only plays within the vendor replace-set space. So if a (customer) feature replace-set was off touching
function_foo()and a CVE landed there, the overlay feature would remain blocked from patching it. Supercede provides a big hammer here.
Quoted 8 lines
That said, blind eviction via supersede assumes the customer's replace-set patches are actually safe to bounce. The customer's patch may have allocated shadow variables, modified system state via callbacks, or changed data structure semantics, all designed to be unwound by the next customer version of that patch, not by an unrelated vendor patch. The vendor can't know what semantic landmines the customer's patch left behind, and the kernel can't validate that at load time.
Good point. The dependecies and conflicts between shadow variables and callbacks should have been solved by the livepatch state. IMHO, we should never allow to replace livepatches with incompatible livepatch states.
Unfortunately, the states are not well connected with the shadow variables and callbacks at the moment. But there is a patchset improving this, see https://lore.kernel.org/r/[email protected]
Quoted 2 lines
So maybe it boils down to: is the supercedes big hammer desired and safe enough to deploy? Is overlay useful enough to be worth implementing?
I personally like the solution with a zero-terminated array of replace_sets:
struct patch {
[...]
unsigned int *replace_sets;
[...],
};, which would allow to build a cumulative livepatch which replaces known hotfixes out of box.
Note that the hotfix should not be allowed to modify a function or livepatch state which is modified by another livepatch. It would be dangerous. We should allow to solve this only by a cumulative livepatch.
IMHO, the OS vendor should not touch customer specific livepatches by default. The customer installed them for a reason. We should just refuse to install two conflicting livepatches. Where we could reliably compare only the livepatched functions. But it still is good because most livepatches only modify functions.
Plus, I would still allow to resolve the possible conflict by using the atomic replace. It could be done by a module-specific parameter. I would call it: override_replace_sets=X[,Y]... or so.
Finally, I assume that most users will keep using only the default replace_sets=0 [*]. They will never have to deal with another sets.
The non-default replace sets will be only for adventurous users who want to deal with the complexity and accept the risks.
[*] It we allow the zero-terminated array of replace_sets then
zero should not be the default. Or it could be but it would be a special set which could never be replaced by anything else than another zero replace set.
The zero replace set might be for users who do not want to deal with the complexity at all. For example, for an os-vendor who does not want to release separate hotfixes.
Best Regards,
Petr
Joe Lawrence
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 11 lines · Petr Mladek
Quoted 3 lines · Joe Lawrence
Quoted 2 lines · Petr Mladek
Quoted 1 line · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
[ ... snip ... ]
Quoted 3 lines
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?I continue with the brainstorming ;-)
Thanks for walking through it with me. Your reply crossed with my note to Yafang at nearly the same time.
Quoted 7 lines
[ ... snip ... ]
Quoted 2 lines
So maybe it boils down to: is the supercedes big hammer desired and safe enough to deploy?
I personally like the solution with a zero-terminated array of
replace_sets:
Quoted 9 lines
struct patch { [...] unsigned int *replace_sets; [...], };, which would allow to build a cumulative livepatch which replaces known hotfixes out of box.
Question on this at the bottom ...
Quoted 5 lines
Note that the hotfix should not be allowed to modify a function or livepatch state which is modified by another livepatch. It would be dangerous. We should allow to solve this only by a cumulative livepatch.
Agreed.
Quoted 11 lines
IMHO, the OS vendor should not touch customer specific livepatches by default. The customer installed them for a reason. We should just refuse to install two conflicting livepatches. Where we could reliably compare only the livepatched functions. But it still is good because most livepatches only modify functions.
Plus, I would still allow to resolve the possible conflict by using the atomic replace. It could be done by a module-specific parameter. I would call it: override_replace_sets=X[,Y]... or so.
Naming nitpick: "override_replace_sets" sounds like it may override the "replace_sets" value and not supplement it. But that's just an implementation detail to bikeshed later :D
Quoted 6 lines
Finally, I assume that most users will keep using only the default replace_sets=0 [*]. They will never have to deal with another sets.
The non-default replace sets will be only for adventurous users who want to deal with the complexity and accept the risks.
Quoted 9 lines
[*] It we allow the zero-terminated array of
replace_setsthen
zero should not be the default. Or it could be but it would be a special set which could never be replaced by anything else than another zero replace set.The zero replace set might be for users who do not want to deal with the complexity at all. For example, for an os-vendor who does not want to release separate hotfixes.
Hmm, I do like the default replace_sets=0 not dealing with the complication of the replace sets.
But first, back to the larger question I mentioned at the beginning.
Originally there was:
unsigned int replace_set; /* the set I belong to */
const unsigned int *supersedes; /* other sets I also replace */
and now it's just:
unsigned int *replace_sets; /* sets I belong to AND replace? */
Could you trace through a few cycles of cumulative + hotfix releases with this approach? For example:
Wed: klp-1a: cumulative (replace_sets={1})
Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a
Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set)
Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c *
Tue: klp-2b: hotfix (replace_sets={2}) <- coexists with klp-2a[*] After klp-2a loads with {1, 2}, is it permanently in both sets? Or
does it just evict set 2 and then only occupy set 1 going forward? The latter makes klp-2b's load straightforward.
I can read replace_sets two ways:
1. Positional: { set [, eviction_set ...] } where the first element is the patch's own set and the rest are evicted on load.
2. Flat: the patch belongs to every listed set equally. But then how could klp-2b load into set 2 without replacing the entire cumulative klp-2a that also occupies it?
Thanks,
--
Joe
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 103 lines · Joe Lawrence
Quoted 11 lines · Petr Mladek
Quoted 3 lines · Joe Lawrence
Quoted 2 lines · Petr Mladek
Quoted 1 line · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
[ ... snip ... ]
Quoted 3 lines
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?I continue with the brainstorming ;-)
Thanks for walking through it with me. Your reply crossed with my note to Yafang at nearly the same time.
Quoted 7 lines
[ ... snip ... ]
Quoted 2 lines
So maybe it boils down to: is the supercedes big hammer desired and safe enough to deploy?
I personally like the solution with a zero-terminated array of
replace_sets:Quoted 9 lines
struct patch { [...] unsigned int *replace_sets; [...], };, which would allow to build a cumulative livepatch which replaces known hotfixes out of box.
Question on this at the bottom ...
Quoted 5 lines
Note that the hotfix should not be allowed to modify a function or livepatch state which is modified by another livepatch. It would be dangerous. We should allow to solve this only by a cumulative livepatch.
Agreed.
Quoted 11 lines
IMHO, the OS vendor should not touch customer specific livepatches by default. The customer installed them for a reason. We should just refuse to install two conflicting livepatches. Where we could reliably compare only the livepatched functions. But it still is good because most livepatches only modify functions.
Plus, I would still allow to resolve the possible conflict by using the atomic replace. It could be done by a module-specific parameter. I would call it: override_replace_sets=X[,Y]... or so.
Naming nitpick: "
override_replace_sets" sounds like it may override the "replace_sets" value and not supplement it. But that's just an implementation detail to bikeshed later :DQuoted 6 lines
Finally, I assume that most users will keep using only the default replace_sets=0 [*]. They will never have to deal with another sets.
The non-default replace sets will be only for adventurous users who want to deal with the complexity and accept the risks.
Quoted 9 lines
[*] It we allow the zero-terminated array of
replace_setsthen
zero should not be the default. Or it could be but it would be a special set which could never be replaced by anything else than another zero replace set.The zero replace set might be for users who do not want to deal with the complexity at all. For example, for an os-vendor who does not want to release separate hotfixes.
Hmm, I do like the default replace_sets=0 not dealing with the complication of the replace sets.
But first, back to the larger question I mentioned at the beginning.
Originally there was:
unsigned int
replace_set; /* the set I belong to */
const unsigned int *supersedes; /* other sets I also replace */and now it's just:
unsigned int
*replace_sets; /* sets I belong to AND replace? */Could you trace through a few cycles of cumulative + hotfix releases with this approach? For example:
Wed: klp-1a: cumulative (replace_sets={1}) Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set) Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c * Tue: klp-2b: hotfix (replace_sets={2}) <- coexists with klp-2a[*] After klp-2a loads with {1, 2}, is it permanently in both sets? Or
does it just evict set 2 and then only occupy set 1 going forward? The latter makes klp-2b's load straightforward.
Quoted 8 lines
I can read
replace_setstwo ways:1. Positional: { set [,
eviction_set...] } where the first element is the patch's own set and the rest are evicted on load.2. Flat: the patch belongs to every listed set equally. But then how could klp-2b load into set 2 without replacing the entire cumulative klp-2a that also occupies it?
I support the flat mode approach. The hotfix should be assigned to a set that is not currently in use — for example, klp-2a should select a new set like set 3. The core design idea is to set replace_set dynamically. To determine which sets are already occupied, a user-space script can inspect /sys/kernel/livepatch/*/replace_set.
Signature · 2 lines
Regards Yafang
Petr Mladek
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Joe LawrenceQuoted 50 lines · Joe Lawrence
Quoted 11 lines · Petr Mladek
Quoted 3 lines · Joe Lawrence
Quoted 2 lines · Petr Mladek
Quoted 1 line · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
[ ... snip ... ]
Quoted 3 lines
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?I continue with the brainstorming ;-)
Thanks for walking through it with me. Your reply crossed with my note to Yafang at nearly the same time.
Quoted 7 lines
[ ... snip ... ]
Quoted 2 lines
So maybe it boils down to: is the supercedes big hammer desired and safe enough to deploy?
I personally like the solution with a zero-terminated array of
replace_sets:Quoted 9 lines
struct patch { [...] unsigned int *replace_sets; [...], };, which would allow to build a cumulative livepatch which replaces known hotfixes out of box.
Question on this at the bottom ...
Quoted 5 lines
Note that the hotfix should not be allowed to modify a function or livepatch state which is modified by another livepatch. It would be dangerous. We should allow to solve this only by a cumulative livepatch.
Agreed.
Quoted 7 lines
IMHO, the OS vendor should not touch customer specific livepatches by default. The customer installed them for a reason. We should just refuse to install two conflicting livepatches. Where we could reliably compare only the livepatched functions. But it still is good because most livepatches only modify functions.
Quoted 8 lines
Quoted 4 lines
Plus, I would still allow to resolve the possible conflict by using the atomic replace. It could be done by a module-specific parameter. I would call it: override_replace_sets=X[,Y]... or so.
Naming nitpick: "
override_replace_sets" sounds like it may override the "replace_sets" value and not supplement it. But that's just an implementation detail to bikeshed later :D
Good point! "supplement_replace_sets" or "add_replace_sets" would be better :D
But see below.
Quoted 43 lines
Quoted 6 lines
Finally, I assume that most users will keep using only the default replace_sets=0 [*]. They will never have to deal with another sets.
The non-default replace sets will be only for adventurous users who want to deal with the complexity and accept the risks.
Quoted 9 lines
[*] It we allow the zero-terminated array of
replace_setsthen
zero should not be the default. Or it could be but it would be a special set which could never be replaced by anything else than another zero replace set.The zero replace set might be for users who do not want to deal with the complexity at all. For example, for an os-vendor who does not want to release separate hotfixes.
Hmm, I do like the default replace_sets=0 not dealing with the complication of the replace sets.
But first, back to the larger question I mentioned at the beginning.
Originally there was:
unsigned int
replace_set; /* the set I belong to */
const unsigned int *supersedes; /* other sets I also replace */and now it's just:
unsigned int
*replace_sets; /* sets I belong to AND replace? */Could you trace through a few cycles of cumulative + hotfix releases with this approach? For example:
Wed: klp-1a: cumulative (replace_sets={1}) Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set) Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c * Tue: klp-2b: hotfix (replace_sets={2}) <- coexists with klp-2a[*] After klp-2a loads with {1, 2}, is it permanently in both sets? Or
does it just evict set 2 and then only occupy set 1 going forward? The latter makes klp-2b's load straightforward.
Quoted 8 lines
I can read
replace_setstwo ways:1. Positional: { set [,
eviction_set...] } where the first element is the patch's own set and the rest are evicted on load.2. Flat: the patch belongs to every listed set equally. But then how could klp-2b load into set 2 without replacing the entire cumulative klp-2a that also occupies it?
I understand it a 3rd way (similar to Yafang?) ;-)
3. Set: the patch replaces the given set of replace_sets. Where klp-2a is a cumulative livepatch for two
replace_sets: 1,2. And klp-2b hotfix would need to use a new replace_set, .e.g. 3.
I see "replace_set" as a set of modifications (functions, shadow variables, and callbacks) which is supposed to replace/update/downgrade the same "replace_set".
It would have the following consequences:
-----------------------------------------
First, any newer cumulative livepatch would need to replace all older hotfixes. Let's extend your example:
Wed: klp-1a: cumulative (replace_sets={1})
Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a
Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set)
Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c
Tue: klp-2b: hotfix (replace_sets={3}) <- coexists with klp-2a
Fri: klp-3a: cumulative (replace_sets={1,2,3}) <- replaces klp-2a AND wipes klp-2b
Fri: klp-4a: cumulative (replace_sets={1,2,3}) <- replaces klp-3a
Fri: klp-5a: cumulative (replace_sets={1,2,3}) <- replaces klp-4aSecond, it would limit downgrades, for example:
+ klp-3a, klp-4a, and klp-5a looks compatible from the replace_set POV. The replace_set should not limit replacing each other.
Well, the replacing still might be limited by the states.
Plus the pending patchset adds per-state "block_disable" flag which should handle situations where the change (by a callback) can't be reverted, see
https://lore.kernel.org/all/[email protected]/
Hmm, this brings a question how exactly replace_sets and states play together and if we need them both.
I did some brainstorming and came with the following definitions:
-----------------------------------------------------------------
+ Each patch.objs[i].funcs[j] defines a particular livepatched function.
+ Each patch.states[i] defines either a particular shadow variable
(same id + state.is_shadow=true) [1] and/or set of callbacks [2]
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/+ Each shadow variable "id" defines a particular data (type)
+ Each set of callback (pre/post/enable/disable) is connected either with a particular shadow variable (for its lifetime handling) or it can change the system state with a one-time operation.
Why do we need "states"?
------------------------
I see "states" as a definition of shadow variable ids and callbacks sets. We need to somehow tell the kernel that the livepatch is going to use them.
The numeric "id" allows to compare the compatibility of the definitions between livepatches "easily".
Note that we do not need states to compare livepatched functions. The kernel can compare them by the info in patch.objs[].funcs[].old_name.
Why do we need "replace_set" ?
------------------------------
I see "replace_set" as an union of fixes (livepatched functions, shadow variables, callbacks) which is supposed to be handled using atomic replace.
It defines which livepatches upgrade/downgrade or can be installed in parallel with other livepatches.
I see it like "package name" in the RPM package management system. The "rpm" tools allows to upgrade/downgrade packages with the same name. It can even upgrade/downgrade a package with another name when "provides" [*] are defined.
Note that the "replace_set" would allow even downgrade because new livepatch might:
+ stop modifying some functions,see klp_add_nops().
+ stop using some shadow variables and/or revert changes done by some callbacks, until it gets blocked by per-state "block_disable", see
https://lore.kernel.org/all/[email protected]/
[*] "provides" seems to be better name than "supplements".
Has "replace_set" a good name and semantic?
-------------------------------------------
I think that we really could find some analogy with the package management.
"replace_set" does not exist in the package management terminology. Also "replace_sets" is a set of replace sets which sounds a bit ugly. Also I sometimes wanted to say "replace a replace set" which overwhelming.
Well, we likely do not want to introduce livepatch names. They might get confused with module names.
We could not use module names because they must differ. Otherwise, kernel could not load both old and newer livepatch in parallel.
I would stay with numbers. They are kind of IDs. But we do want to name it patch.id because it might get confused with state.id.
We could call it "patch_id" but "patch.patch_id" is a but ugly.
I did some brainstorming and came up with:
"project_id"
"changeset_id"
"provides_id"
"track_id"
"fix_id"and claude-sonnet-4.6 also suggested to use:
"slot"
which has a similar meaning in the Gentoo package management, see https://devmanual.gentoo.org/general-concepts/slotting/
The "slots" name is interesting but they seems to be always mutually exclusive. I do not see any concept of merging slots in Gentoo.
My preferences:
Honestly, I feel a bit lost. I think that I need to sleep over it.
I kind of like:
* @slot: Livepatches with the same slot replace each other. Livepatches with different slots might be installed in parallel.
unsigned long slot;
And I would handle the merging of other slots separately by:
* @merge_slots: Replace livepatches with the given slots. unsigned long merge_slots[];
Plus, a module parameter add_merge_slots=x[,y]...
But I do not have strong opinion.
Best Regards,
Petr
Joe Lawrence
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 134 lines · Petr Mladek
Quoted 50 lines · Joe Lawrence
Quoted 11 lines · Petr Mladek
Quoted 3 lines · Joe Lawrence
Quoted 2 lines · Petr Mladek
Quoted 1 line · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
[ ... snip ... ]
Quoted 3 lines
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?I continue with the brainstorming ;-)
Thanks for walking through it with me. Your reply crossed with my note to Yafang at nearly the same time.
Quoted 7 lines
[ ... snip ... ]
Quoted 2 lines
So maybe it boils down to: is the supercedes big hammer desired and safe enough to deploy?
I personally like the solution with a zero-terminated array of
replace_sets:Quoted 9 lines
struct patch { [...] unsigned int *replace_sets; [...], };, which would allow to build a cumulative livepatch which replaces known hotfixes out of box.
Question on this at the bottom ...
Quoted 5 lines
Note that the hotfix should not be allowed to modify a function or livepatch state which is modified by another livepatch. It would be dangerous. We should allow to solve this only by a cumulative livepatch.
Agreed.
Quoted 7 lines
IMHO, the OS vendor should not touch customer specific livepatches by default. The customer installed them for a reason. We should just refuse to install two conflicting livepatches. Where we could reliably compare only the livepatched functions. But it still is good because most livepatches only modify functions.
Quoted 8 lines
Quoted 4 lines
Plus, I would still allow to resolve the possible conflict by using the atomic replace. It could be done by a module-specific parameter. I would call it: override_replace_sets=X[,Y]... or so.
Naming nitpick: "
override_replace_sets" sounds like it may override the "replace_sets" value and not supplement it. But that's just an implementation detail to bikeshed later :DGood point! "
supplement_replace_sets" or "add_replace_sets" would be better :DBut see below.
Quoted 43 lines
Quoted 6 lines
Finally, I assume that most users will keep using only the default replace_sets=0 [*]. They will never have to deal with another sets.
The non-default replace sets will be only for adventurous users who want to deal with the complexity and accept the risks.
Quoted 9 lines
[*] It we allow the zero-terminated array of
replace_setsthen
zero should not be the default. Or it could be but it would be a special set which could never be replaced by anything else than another zero replace set.The zero replace set might be for users who do not want to deal with the complexity at all. For example, for an os-vendor who does not want to release separate hotfixes.
Hmm, I do like the default replace_sets=0 not dealing with the complication of the replace sets.
But first, back to the larger question I mentioned at the beginning.
Originally there was:
unsigned int
replace_set; /* the set I belong to */
const unsigned int *supersedes; /* other sets I also replace */and now it's just:
unsigned int
*replace_sets; /* sets I belong to AND replace? */Could you trace through a few cycles of cumulative + hotfix releases with this approach? For example:
Wed: klp-1a: cumulative (replace_sets={1}) Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set) Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c * Tue: klp-2b: hotfix (replace_sets={2}) <- coexists with klp-2a[*] After klp-2a loads with {1, 2}, is it permanently in both sets? Or
does it just evict set 2 and then only occupy set 1 going forward? The latter makes klp-2b's load straightforward.Quoted 8 lines
I can read
replace_setstwo ways:1. Positional: { set [,
eviction_set...] } where the first element is the patch's own set and the rest are evicted on load.2. Flat: the patch belongs to every listed set equally. But then how could klp-2b load into set 2 without replacing the entire cumulative klp-2a that also occupies it?
I understand it a 3rd way (similar to Yafang?) ;-)
3. Set: the patch replaces the given set of
replace_sets. Where klp-2a is a cumulative livepatch for two
replace_sets: 1,2. And klp-2b hotfix would need to use a newreplace_set, .e.g. 3.I see "
replace_set" as a set of modifications (functions, shadow variables, and callbacks) which is supposed to replace/update/downgrade the same "replace_set".It would have the following consequences:
-----------------------------------------First, any newer cumulative livepatch would need to replace all older hotfixes. Let's extend your example:
Quoted 9 lines
Wed: klp-1a: cumulative (replace_sets={1})
Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a
Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set)
Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c
Tue: klp-2b: hotfix (replace_sets={3}) <- coexists with klp-2a
Fri: klp-3a: cumulative (replace_sets={1,2,3}) <- replaces klp-2a AND wipes klp-2b
Fri: klp-4a: cumulative (replace_sets={1,2,3}) <- replaces klp-3a
Fri: klp-5a: cumulative (replace_sets={1,2,3}) <- replaces klp-4aThis is making sense so far: hotfixes introduce new replace_set(s), subsequent cumulatives replace all sets that came before it.
Quick question for you or Yafang based on his thoughts on my other reply:
Quoted 5 lines
[Yafang] I support the flat mode approach. The hotfix should be assigned to a set that is not currently in use — for example, klp-2a should select a new set like set 3. The core design idea is to set
replace_setdynamically. To determine which sets are already occupied, a user-space script can inspect/sys/kernel/livepatch/*/replace_set.
How would Petr's 3rd way handle such dynamic replace_set enumeration? Using the extended example above, without considering user patches, a vendor could hardcode the replace_sets values at build time as shown.
However, if a user patch has already occupied say, replace_set 3, then klp-2b would need to skip over 3 and set replace_sets=4. But then when the next cumulative patch, klp-3a, loads, how does it know that it should replace_sets=1,2,4 and leave 3 alone?
Quoted 5 lines
Second, it would limit downgrades, for example:
+ klp-3a, klp-4a, and klp-5a looks compatible from the
replace_setPOV. Thereplace_setshould not limit replacing each other.
This should be somewhat minimized assuming they are upgraded as part of the same distro package, each new one replaces the previous one on disk. But there would be nothing preventing someone from loading klp-3a after klp-5a if they wanted to.
Quoted 29 lines
Well, the replacing still might be limited by the states.
Plus the pending patchset adds per-state "
block_disable" flag which should handle situations where the change (by a callback) can't be reverted, see
https://lore.kernel.org/all/[email protected]/Hmm, this brings a question how exactly
replace_setsand states play together and if we need them both.I did some brainstorming and came with the following definitions:
-----------------------------------------------------------------+ Each patch.objs[i].funcs[j] defines a particular livepatched function.
+ Each patch.states[i] defines either a particular shadow variable
(same id + state.is_shadow=true) [1] and/or set of callbacks [2] [1] https://lore.kernel.org/all/[email protected]/ [2] https://lore.kernel.org/all/[email protected]/+ Each shadow variable "id" defines a particular data (type)
+ Each set of callback (pre/post/enable/disable) is connected either with a particular shadow variable (for its lifetime handling) or it can change the system state with a one-time operation.
Quoted 7 lines
Why do we need "states"?
------------------------I see "states" as a definition of shadow variable ids and callbacks sets. We need to somehow tell the kernel that the livepatch is going to use them.
Aside: IIRC the shadow variable + callback sets were the concrete use case for states, but technically any special livepatch side effect could be considered its own state, right?
Quoted 14 lines
The numeric "id" allows to compare the compatibility of the definitions between livepatches "easily".
Note that we do not need states to compare livepatched functions. The kernel can compare them by the info in patch.objs[].funcs[].old_name.
Why do we need "
replace_set" ?
------------------------------I see "
replace_set" as an union of fixes (livepatched functions, shadow variables, callbacks) which is supposed to be handled using atomic replace.
Quoted 8 lines
It defines which livepatches upgrade/downgrade or can be installed in parallel with other livepatches.
I see it like "package name" in the RPM package management system. The "rpm" tools allows to upgrade/downgrade packages with the same name. It can even upgrade/downgrade a package with another name when "provides" [*] are defined.
<nod> When listing out the future culumative + hotfix examples, my brain went there (package mgmt), too.
Quoted 65 lines
Note that the "
replace_set" would allow even downgrade because new livepatch might:+ stop modifying some functions,see
klp_add_nops().+ stop using some shadow variables and/or revert changes done by some callbacks, until it gets blocked by per-state "
block_disable", see
https://lore.kernel.org/all/[email protected]/[*] "provides" seems to be better name than "supplements".
Has "
replace_set" a good name and semantic?
-------------------------------------------I think that we really could find some analogy with the package management.
"
replace_set" does not exist in the package management terminology. Also "replace_sets" is a set of replace sets which sounds a bit ugly. Also I sometimes wanted to say "replace a replace set" which overwhelming.Well, we likely do not want to introduce livepatch names. They might get confused with module names.
We could not use module names because they must differ. Otherwise, kernel could not load both old and newer livepatch in parallel.
I would stay with numbers. They are kind of IDs. But we do want to name it patch.id because it might get confused with state.id.
We could call it "
patch_id" but "patch.patch_id" is a but ugly.I did some brainstorming and came up with:
"project_id" "changeset_id" "provides_id" "track_id" "fix_id"and claude-sonnet-4.6 also suggested to use:
"slot"which has a similar meaning in the Gentoo package management, see https://devmanual.gentoo.org/general-concepts/slotting/
The "slots" name is interesting but they seems to be always mutually exclusive. I do not see any concept of merging slots in Gentoo.
My preferences:
Honestly, I feel a bit lost. I think that I need to sleep over it.
I kind of like:
* @slot: Livepatches with the same slot replace each other. Livepatches with different slots might be installed in parallel.
unsigned long slot;
Quoted 9 lines
And I would handle the merging of other slots separately by:
* @merge_slots: Replace livepatches with the given slots. unsigned long merge_slots[];
Plus, a module parameter add_merge_slots=x[,y]...
But I do not have strong opinion.
How about following the package management analogy almost exactly:
@provides: id < only one active livepatch per id
@obsoletes: { id [, id ...] } < replace given livepatch id(s)
@also_obsoletes: { id [, id ...] } < replace addt'l livepatch id(s)Claude offers alternative naming like: family, group, track, series and absorbs, evicts, replaces, retires.
--
Joe
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 157 lines · Joe Lawrence
Quoted 134 lines · Petr Mladek
Quoted 50 lines · Joe Lawrence
Quoted 11 lines · Petr Mladek
Quoted 3 lines · Joe Lawrence
Quoted 2 lines · Petr Mladek
Quoted 1 line · Petr Mladek
On Sun 2026-06-07 21:16:55, Yafang Shao wrote:
[ ... snip ... ]
Quoted 3 lines
I'm not against supercedes functionality, but continuing the
brainstorming: what about solution 1 (.replace_set=0 special) with a special zero-day overlay?I continue with the brainstorming ;-)
Thanks for walking through it with me. Your reply crossed with my note to Yafang at nearly the same time.
Quoted 7 lines
[ ... snip ... ]
Quoted 2 lines
So maybe it boils down to: is the supercedes big hammer desired and safe enough to deploy?
I personally like the solution with a zero-terminated array of
replace_sets:Quoted 9 lines
struct patch { [...] unsigned int *replace_sets; [...], };, which would allow to build a cumulative livepatch which replaces known hotfixes out of box.
Question on this at the bottom ...
Quoted 5 lines
Note that the hotfix should not be allowed to modify a function or livepatch state which is modified by another livepatch. It would be dangerous. We should allow to solve this only by a cumulative livepatch.
Agreed.
Quoted 7 lines
IMHO, the OS vendor should not touch customer specific livepatches by default. The customer installed them for a reason. We should just refuse to install two conflicting livepatches. Where we could reliably compare only the livepatched functions. But it still is good because most livepatches only modify functions.
Quoted 8 lines
Quoted 4 lines
Plus, I would still allow to resolve the possible conflict by using the atomic replace. It could be done by a module-specific parameter. I would call it: override_replace_sets=X[,Y]... or so.
Naming nitpick: "
override_replace_sets" sounds like it may override the "replace_sets" value and not supplement it. But that's just an implementation detail to bikeshed later :DGood point! "
supplement_replace_sets" or "add_replace_sets" would be better :DBut see below.
Quoted 43 lines
Quoted 6 lines
Finally, I assume that most users will keep using only the default replace_sets=0 [*]. They will never have to deal with another sets.
The non-default replace sets will be only for adventurous users who want to deal with the complexity and accept the risks.
Quoted 9 lines
[*] It we allow the zero-terminated array of
replace_setsthen
zero should not be the default. Or it could be but it would be a special set which could never be replaced by anything else than another zero replace set.The zero replace set might be for users who do not want to deal with the complexity at all. For example, for an os-vendor who does not want to release separate hotfixes.
Hmm, I do like the default replace_sets=0 not dealing with the complication of the replace sets.
But first, back to the larger question I mentioned at the beginning.
Originally there was:
unsigned int
replace_set; /* the set I belong to */
const unsigned int *supersedes; /* other sets I also replace */and now it's just:
unsigned int
*replace_sets; /* sets I belong to AND replace? */Could you trace through a few cycles of cumulative + hotfix releases with this approach? For example:
Wed: klp-1a: cumulative (replace_sets={1}) Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set) Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c * Tue: klp-2b: hotfix (replace_sets={2}) <- coexists with klp-2a[*] After klp-2a loads with {1, 2}, is it permanently in both sets? Or
does it just evict set 2 and then only occupy set 1 going forward? The latter makes klp-2b's load straightforward.Quoted 8 lines
I can read
replace_setstwo ways:1. Positional: { set [,
eviction_set...] } where the first element is the patch's own set and the rest are evicted on load.2. Flat: the patch belongs to every listed set equally. But then how could klp-2b load into set 2 without replacing the entire cumulative klp-2a that also occupies it?
I understand it a 3rd way (similar to Yafang?) ;-)
3. Set: the patch replaces the given set of
replace_sets. Where klp-2a is a cumulative livepatch for two
replace_sets: 1,2. And klp-2b hotfix would need to use a newreplace_set, .e.g. 3.I see "
replace_set" as a set of modifications (functions, shadow variables, and callbacks) which is supposed to replace/update/downgrade the same "replace_set".It would have the following consequences:
-----------------------------------------First, any newer cumulative livepatch would need to replace all older hotfixes. Let's extend your example:
Quoted 9 lines
Wed: klp-1a: cumulative (replace_sets={1}) Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set) Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c Tue: klp-2b: hotfix (replace_sets={3}) <- coexists with klp-2a Fri: klp-3a: cumulative (replace_sets={1,2,3}) <- replaces klp-2a AND wipes klp-2b Fri: klp-4a: cumulative (replace_sets={1,2,3}) <- replaces klp-3a Fri: klp-5a: cumulative (replace_sets={1,2,3}) <- replaces klp-4aThis is making sense so far: hotfixes introduce new
replace_set(s), subsequent cumulatives replace all sets that came before it.Quick question for you or Yafang based on his thoughts on my other reply:
Quoted 5 lines
[Yafang] I support the flat mode approach. The hotfix should be assigned to a set that is not currently in use — for example, klp-2a should select a new set like set 3. The core design idea is to set
replace_setdynamically. To determine which sets are already occupied, a user-space script can inspect/sys/kernel/livepatch/*/replace_set.
Quoted 8 lines
How would Petr's 3rd way handle such dynamic
replace_setenumeration? Using the extended example above, without considering user patches, a vendor could hardcode thereplace_setsvalues at build time as shown.However, if a user patch has already occupied say,
replace_set3, then klp-2b would need to skip over 3 and set replace_sets=4. But then when the next cumulative patch, klp-3a, loads, how does it know that it should replace_sets=1,2,4 and leave 3 alone?
Wed: klp-1a: cumulative (replace_sets={1})
Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a
Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b(same set)
Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a
AND wipes klp-1c
Mon: klp-user: cumulative (replace_sets={3}) <- coexists with klp-2a
Tue: klp-2b: hotfix (replace_sets={4}) <- choose an unused id
Wed: klp-3a: cumulative
When loading klp-3a, the user can inspect the currently active set IDs by checking /sys/kernel/livepatch/klp-2a/replace_set and /sys/kernel/livepatch/klp-2b/replace_set, then dynamically configure replace_sets to {1, 2, 4} accordingly.
However, I don't have a strong opinion on this. If you both prefer the positional mode, I'm happy to implement it that way.
Quoted 154 lines
Quoted 6 lines
Second, it would limit downgrades, for example:
+ klp-3a, klp-4a, and klp-5a looks compatible from the
replace_setPOV. Thereplace_setshould not limit replacing each other.This should be somewhat minimized assuming they are upgraded as part of the same distro package, each new one replaces the previous one on disk. But there would be nothing preventing someone from loading klp-3a after klp-5a if they wanted to.
Quoted 29 lines
Well, the replacing still might be limited by the states.
Plus the pending patchset adds per-state "
block_disable" flag which should handle situations where the change (by a callback) can't be reverted, see
https://lore.kernel.org/all/[email protected]/Hmm, this brings a question how exactly
replace_setsand states play together and if we need them both.I did some brainstorming and came with the following definitions:
-----------------------------------------------------------------+ Each patch.objs[i].funcs[j] defines a particular livepatched function.
+ Each patch.states[i] defines either a particular shadow variable
(same id + state.is_shadow=true) [1] and/or set of callbacks [2] [1] https://lore.kernel.org/all/[email protected]/ [2] https://lore.kernel.org/all/[email protected]/+ Each shadow variable "id" defines a particular data (type)
+ Each set of callback (pre/post/enable/disable) is connected either with a particular shadow variable (for its lifetime handling) or it can change the system state with a one-time operation.
Quoted 7 lines
Why do we need "states"?
------------------------I see "states" as a definition of shadow variable ids and callbacks sets. We need to somehow tell the kernel that the livepatch is going to use them.
Aside: IIRC the shadow variable + callback sets were the concrete use case for states, but technically any special livepatch side effect could be considered its own state, right?
Quoted 14 lines
The numeric "id" allows to compare the compatibility of the definitions between livepatches "easily".
Note that we do not need states to compare livepatched functions. The kernel can compare them by the info in patch.objs[].funcs[].old_name.
Why do we need "
replace_set" ?
------------------------------I see "
replace_set" as an union of fixes (livepatched functions, shadow variables, callbacks) which is supposed to be handled using atomic replace.Quoted 8 lines
It defines which livepatches upgrade/downgrade or can be installed in parallel with other livepatches.
I see it like "package name" in the RPM package management system. The "rpm" tools allows to upgrade/downgrade packages with the same name. It can even upgrade/downgrade a package with another name when "provides" [*] are defined.
<nod> When listing out the future culumative + hotfix examples, my brain went there (package mgmt), too.
Quoted 65 lines
Note that the "
replace_set" would allow even downgrade because new livepatch might:+ stop modifying some functions,see
klp_add_nops().+ stop using some shadow variables and/or revert changes done by some callbacks, until it gets blocked by per-state "
block_disable", see
https://lore.kernel.org/all/[email protected]/[*] "provides" seems to be better name than "supplements".
Has "
replace_set" a good name and semantic?
-------------------------------------------I think that we really could find some analogy with the package management.
"
replace_set" does not exist in the package management terminology. Also "replace_sets" is a set of replace sets which sounds a bit ugly. Also I sometimes wanted to say "replace a replace set" which overwhelming.Well, we likely do not want to introduce livepatch names. They might get confused with module names.
We could not use module names because they must differ. Otherwise, kernel could not load both old and newer livepatch in parallel.
I would stay with numbers. They are kind of IDs. But we do want to name it patch.id because it might get confused with state.id.
We could call it "
patch_id" but "patch.patch_id" is a but ugly.I did some brainstorming and came up with:
"project_id" "changeset_id" "provides_id" "track_id" "fix_id"and claude-sonnet-4.6 also suggested to use:
"slot"which has a similar meaning in the Gentoo package management, see https://devmanual.gentoo.org/general-concepts/slotting/
The "slots" name is interesting but they seems to be always mutually exclusive. I do not see any concept of merging slots in Gentoo.
My preferences:
Honestly, I feel a bit lost. I think that I need to sleep over it.
I kind of like:
* @slot: Livepatches with the same slot replace each other. Livepatches with different slots might be installed in parallel.
unsigned long slot;Quoted 9 lines
And I would handle the merging of other slots separately by:
* @merge_slots: Replace livepatches with the given slots. unsigned long merge_slots[];
Plus, a module parameter add_merge_slots=x[,y]...
But I do not have strong opinion.
Quoted 8 lines
How about following the package management analogy almost exactly:
@provides: id < only one active livepatch per id @obsoletes: { id [, id ...] } < replace given livepatch id(s) @also_obsoletes: { id [, id ...] } < replace addt'l livepatch id(s)Claude offers alternative naming like: family, group, track, series and absorbs, evicts, replaces, retires.
It seems @provides and @obsoletes are easier to understand, but I don't have a strong opinion either way.
Signature · 2 lines
Regards Yafang
Joe Lawrence
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 75 lines · Yafang Shao
Quoted 55 lines · Joe Lawrence
Quoted 32 lines · Petr Mladek
Quoted 5 lines · Joe Lawrence
Quoted 1 line · Petr Mladek
On Tue 2026-06-16 16:15:17, Joe Lawrence wrote:
[ ... snip ... ]
Quoted 8 lines
I can read
replace_setstwo ways:1. Positional: { set [,
eviction_set...] } where the first element is the patch's own set and the rest are evicted on load.2. Flat: the patch belongs to every listed set equally. But then how could klp-2b load into set 2 without replacing the entire cumulative klp-2a that also occupies it?
I understand it a 3rd way (similar to Yafang?) ;-)
3. Set: the patch replaces the given set of
replace_sets. Where klp-2a is a cumulative livepatch for two
replace_sets: 1,2. And klp-2b hotfix would need to use a newreplace_set, .e.g. 3.I see "
replace_set" as a set of modifications (functions, shadow variables, and callbacks) which is supposed to replace/update/downgrade the same "replace_set".It would have the following consequences:
-----------------------------------------First, any newer cumulative livepatch would need to replace all older hotfixes. Let's extend your example:
Quoted 9 lines
Wed: klp-1a: cumulative (replace_sets={1}) Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b (same set) Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a AND wipes klp-1c Tue: klp-2b: hotfix (replace_sets={3}) <- coexists with klp-2a Fri: klp-3a: cumulative (replace_sets={1,2,3}) <- replaces klp-2a AND wipes klp-2b Fri: klp-4a: cumulative (replace_sets={1,2,3}) <- replaces klp-3a Fri: klp-5a: cumulative (replace_sets={1,2,3}) <- replaces klp-4aThis is making sense so far: hotfixes introduce new
replace_set(s), subsequent cumulatives replace all sets that came before it.Quick question for you or Yafang based on his thoughts on my other reply:
Quoted 5 lines
[Yafang] I support the flat mode approach. The hotfix should be assigned to a set that is not currently in use — for example, klp-2a should select a new set like set 3. The core design idea is to set
replace_setdynamically. To determine which sets are already occupied, a user-space script can inspect/sys/kernel/livepatch/*/replace_set.Quoted 8 lines
How would Petr's 3rd way handle such dynamic
replace_setenumeration? Using the extended example above, without considering user patches, a vendor could hardcode thereplace_setsvalues at build time as shown.However, if a user patch has already occupied say,
replace_set3, then klp-2b would need to skip over 3 and set replace_sets=4. But then when the next cumulative patch, klp-3a, loads, how does it know that it should replace_sets=1,2,4 and leave 3 alone?Wed: klp-1a: cumulative (replace_sets={1}) Thu: klp-1b: hotfix (replace_sets={2}) <- coexists with klp-1a Fri: klp-1c: hotfix v2 (replace_sets={2}) <- replaces klp-1b(same set)
Mon: klp-2a: cumulative (replace_sets={1,2}) <- replaces klp-1a
AND wipes klp-1c
Mon: klp-user: cumulative (replace_sets={3}) <- coexists with klp-2a
Tue: klp-2b: hotfix (replace_sets={4}) <- choose an unused id
Wed: klp-3a: cumulative
Quoted 5 lines
When loading klp-3a, the user can inspect the currently active set IDs by checking
/sys/kernel/livepatch/klp-2a/replace_setand/sys/kernel/livepatch/klp-2b/replace_set, then dynamically configurereplace_setsto {1, 2, 4} accordingly.
Ok, so the kernel only provides set ID information and userspace gets to manage how it interacts (or not) with that.
A livepatch loading script could know to look for /sys/kernel/livepatch/distro-*/replace_set to figure out it's previous dynamically set IDs. Local livepatches the same. This would even allow for groups of sets (vendor, customer1, customer2, etc.) if someone wanted to complicate matters.
Quoted 3 lines
However, I don't have a strong opinion on this. If you both prefer the positional mode, I'm happy to implement it that way.
We'll see what the others think. To catch up with the thread, I'm trying to run through these thought experiments to see how they play out. :)
Signature · 1 line
Joe
Petr Mladek
maintainercode review: was: Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Yafang ShaoQuoted 30 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_set
Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 52
Quoted 7 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +1
-1@@ -47,13 +47,12 @@ Description: disabled when the feature is used. See Documentation/livepatch/livepatch.rst for more information. -What: /sys/kernel/livepatch/<patch>/replace +What: /sys/kernel/livepatch/<patch>/replace_set Date: Jun 2024 KernelVersion: 6.11.0
The Date and KernelVersion should be upsated as well. It is a new attribute...
Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition.
Quoted 13 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +1
-2Contact: [email protected] Description: - An attribute which indicates whether the patch supports - atomic-replace. + An attribute to show the replace_set of this livepatch. What: /sys/kernel/livepatch/<patch>/stack_order Date: Jan 2025Documentation/livepatch/cumulative-patches.rst +0
-0@@ -17,18 +17,20 @@ from all older livepatches and completely replace them in one transition.
We need to update also the introduction part above. I propose the following text:
<proposal>
Livepatches are used to fix kernel bugs. New fixes need to be added over time. The fixes might be independent, but they might also depend on each other. This brings a challenge of how to keep the livepatched system safe and consistent.
Part of the solution is the "Atomic Replace" feature, which allows the kernel to atomically replace an existing livepatch with another one. These newer livepatches are designed as "Cumulative Patches". They include all wanted changes from all older livepatches and completely replace them in one transition.
The second part of the solution is the newly introduced ``replace_set`` feature, which allows the installation of multiple livepatches in parallel. A livepatch will only replace other livepatches that share the same ``replace_set`` number. This might be used to fix independent problems separately, for example, the livepatches might be prepared by separate teams focusing on particular functionality or a subsystem.
It should be emphasized that the preferred and most secure way is to always use the default ``replace_set = 0``. In this mode, any livepatch replaces any other livepatch, preventing any unexpected interactions between incompatible livepatches.
</proposal>
Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition. · line 18
Quoted 2 lines
Documentation/livepatch/cumulative-patches.rst +0
-0Usage -----
I would split the "Usage" section into two new sections, see below.
Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition. · line 29
Quoted 13 lines
Documentation/livepatch/cumulative-patches.rst +5
-3-The atomic replace can be enabled by setting "replace" flag in struct klp_patch, -for example:: +The "replace_set" attribute in ``struct klp_patch`` acts as a **replace_set**, +defining the scope of the replacement. By default, the replace_set is 0. + +For example:: static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, - .replace = true, + .replace_set = 0, };
I would use the above text in a new section called "Replace Set":
<proposal>
Replace Set
-----------
The "replace_set" attribute in ``struct klp_patch`` acts as a **replace_set**, defining the scope of the replacement. By default, the replace_set is 0.
For example::
static struct klp_patch patch = {
.mod = THIS_MODULE,
.objs = objs,
.replace_set = 0,
};Any ``replace_set`` value might be associated with a set of livepatched symbols, callbacks, shadow variables, and state IDs. By definition, there can only ever be one active livepatch for a given ``replace_set`` number.
On the contrary, livepatches with a different ``replace_set`` number must not modify the same function, or use the state with the same ID. Any attempt to load an incompatible livepatch will be rejected by the kernel. </proposal>
And the rest would be in a new section called:
Atomic Replace
--------------
Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition. · line 33
Quoted 5 lines
Documentation/livepatch/cumulative-patches.rst +2
-2All processes are then migrated to use the code only from the new patch. -Once the transition is finished, all older patches are automatically -disabled. +Once the transition is finished, all older patches with the same replace +set are automatically disabled. Patches with different tags remain active.
There always could be only one livepatch with the given replace set. I would write something like:
<proposal>
A livepatch with a given ``replace_set`` number is replaced by another livepatch using the same number. All processes are migrated to use the code only from the new patch. Once the transition is finished, the older patch. Patches with different replace sets are not affected and remain active.
</proposal>
kernel/livepatch/core.c static int klp_add_nops(struct klp_patch *patch) · line 604
Quoted 10 lines
Documentation/livepatch/cumulative-patches.rst +0
-0Ftrace handlers are transparently removed from functions that are no longer modified by the new cumulative patch.kernel/livepatch/core.c +2
-0@@ -600,6 +600,8 @@ static int klp_add_nops(struct klp_patch *patch)klp_for_each_object (old_patch, old_obj) {int err; +if (patch->replace_set != old_patch->replace_set) +continue ;
This should be checked on the klp_for_each_patch(old_patch) level. The result is the same for each old_obj from the given old_patch...
kernel/livepatch/core.c void klp_unpatch_replaced_patches(struct klp_patch *new_patch) · line 1178
Quoted 7 lines
kernel/livepatch/core.c +0
-0err =klp_add_object_nops (patch, old_obj);if (err)return err;@@ -1174,6 +1176,8 @@ void klp_unpatch_replaced_patches(struct klp_patch *new_patch)if (old_patch == new_patch)return ;
Nit: Remove the empty line here.
kernel/livepatch/core.c void klp_unpatch_replaced_patches(struct klp_patch *new_patch) · line 1180
Quoted 2 lines
kernel/livepatch/core.c +2
-0+if (old_patch->replace_set != new_patch->replace_set) +continue ;
Nit: And put it here instead. To separate if/return/continue part from
the changes done for the eligible old_patch.
Quoted 68 lines
kernel/livepatch/core.c +0
-0old_patch->enabled = false;klp_unpatch_objects (old_patch); }kernel/livepatch/state.c +29
-10@@ -85,34 +85,65 @@ EXPORT_SYMBOL_GPL(klp_get_prev_state);/* Check if the patch is able to deal with the existing system state. */ static bool klp_is_state_compatible (struct klp_patch *patch, +struct klp_patch *old_patch,struct klp_state *old_state) {struct klp_state *state; state =klp_get_state (patch, old_state->id); +if (patch->replace_set == old_patch->replace_set) { +/* +* If the new livepatch shares a state set with an existing +* one, it must maintain compatibility with all states +* modified by the old patch. +*/ +if (!state) +return false; +return state->version >= old_state->version; -/* A cumulative livepatch must handle all already modified states. */ -if (!state) -return !patch->replace; + } -return state->version >= old_state->version; +/* +* Two livepatches with a different "replace_set" must _not_ use +* the same "state->id. +*/ +return !state; } -/* -* Check that the new livepatch will not break the existing system states. -* Cumulative patches must handle all already modified states. -* Non-cumulative patches can touch already modified states. -*/ +/* Check that the new livepatch will not break the existing system states. */ bool klp_is_patch_compatible (struct klp_patch *patch) { +struct klp_object *obj, *old_obj;struct klp_patch *old_patch;struct klp_state *old_state; +struct klp_func *func;klp_for_each_patch (old_patch) {klp_for_each_state (old_patch, old_state) { -if (!klp_is_state_compatible (patch, old_state)) +if (!klp_is_state_compatible (patch, old_patch, old_state))return false; } + +if (old_patch->replace_set == patch->replace_set) +continue ; + +/* +* Refuse loading a livepatch which would want to modify a +* function which is already livepatched with the livepatch +* with another "replace_set". +*/
kernel/livepatch/state.c EXPORT_SYMBOL_GPL(klp_get_prev_state); · line 144
Quoted 10 lines
kernel/livepatch/state.c +10
-0+klp_for_each_object_static (patch, obj) { +klp_for_each_object (old_patch, old_obj) { +if (!!obj->name != !!old_obj->name) +continue ; +if (obj->name &&strcmp (obj->name, old_obj->name)) +continue ; +klp_for_each_func_static (obj, func) { +if (klp_find_func (old_obj, func)) +return false; + }
The combination of for_each_() and for_each_*_static() variants look correct but it is a bit scarry.
I think about calling klp_init_patch_early() before klp_is_patch_compatible() so that we could use the non-static for_each_*() variants even for the new patch. It would make the life easier. But I do not have strong opinion about it.
kernel/livepatch/state.c EXPORT_SYMBOL_GPL(klp_get_prev_state); · line 145
Quoted 1 line
kernel/livepatch/state.c +1
-0+ }
Anyway, please, put the new check into a separate function, something like:
bool klp_has_function_conflict(struct klp_patch *patch,
struct klp_patch *old_patch);
kernel/livepatch/state.c EXPORT_SYMBOL_GPL(klp_get_prev_state); · line 149
Quoted 4 lines
kernel/livepatch/state.c +1
-0+ } }return true;
The rest looks good.
Best Regards,
Petr
Re: code review: was: Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 35 lines · Petr Mladek
Quoted 33 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_setDocumentation/ABI/testing/sysfs-kernel-livepatch +0
-0@@ -47,13 +47,12 @@ Description: disabled when the feature is used. See Documentation/livepatch/livepatch.rst for more information.
Quoted 7 lines
Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 52
Quoted 4 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +1
-1-What: /sys/kernel/livepatch/<patch>/replace +What: /sys/kernel/livepatch/<patch>/replace_set Date: Jun 2024 KernelVersion: 6.11.0The Date and KernelVersion should be upsated as well. It is a new attribute...
Sure
Quoted 36 lines
Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition.
Quoted 14 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +1
-2Contact: [email protected] Description: - An attribute which indicates whether the patch supports - atomic-replace. + An attribute to show the replace_set of this livepatch. What: /sys/kernel/livepatch/<patch>/stack_order Date: Jan 2025Documentation/livepatch/cumulative-patches.rst +0
-0@@ -17,18 +17,20 @@ from all older livepatches and completely replace them in one transition.We need to update also the introduction part above. I propose the following text:
<proposal>
Livepatches are used to fix kernel bugs. New fixes need to be added over time. The fixes might be independent, but they might also depend on each other. This brings a challenge of how to keep the livepatched system safe and consistent.Part of the solution is the "Atomic Replace" feature, which allows the kernel to atomically replace an existing livepatch with another one. These newer livepatches are designed as "Cumulative Patches". They include all wanted changes from all older livepatches and completely replace them in one transition.
The second part of the solution is the newly introduced ``replace_set`` feature, which allows the installation of multiple livepatches in parallel. A livepatch will only replace other livepatches that share the same ``replace_set`` number. This might be used to fix independent problems separately, for example, the livepatches might be prepared by separate teams focusing on particular functionality or a subsystem.
Quoted 5 lines
It should be emphasized that the preferred and most secure way is to always use the default ``replace_set = 0``. In this mode, any livepatch replaces any other livepatch, preventing any unexpected interactions between incompatible livepatches.
</proposal>
I will update it.
Quoted 60 lines
Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition. · line 18
Quoted 3 lines
Documentation/livepatch/cumulative-patches.rst +0
-0Usage -----I would split the "Usage" section into two new sections, see below.
Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition. · line 29
Quoted 13 lines
Documentation/livepatch/cumulative-patches.rst +5
-3-The atomic replace can be enabled by setting "replace" flag in struct klp_patch, -for example:: +The "replace_set" attribute in ``struct klp_patch`` acts as a **replace_set**, +defining the scope of the replacement. By default, the replace_set is 0. + +For example:: static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, - .replace = true, + .replace_set = 0, };I would use the above text in a new section called "Replace Set":
<proposal>
Replace Set
-----------The "
replace_set" attribute in ``struct klp_patch`` acts as a **replace_set**, defining the scope of the replacement. By default, thereplace_setis 0.For example::
static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, .replace_set = 0, };Any ``replace_set`` value might be associated with a set of livepatched symbols, callbacks, shadow variables, and state IDs. By definition, there can only ever be one active livepatch for a given ``replace_set`` number.
On the contrary, livepatches with a different ``replace_set`` number must not modify the same function, or use the state with the same ID. Any attempt to load an incompatible livepatch will be rejected by the kernel. </proposal>
And the rest would be in a new section called:
Atomic Replace
--------------Documentation/livepatch/cumulative-patches.rst from all older livepatches and completely replace them in one transition. · line 33
Quoted 5 lines
Documentation/livepatch/cumulative-patches.rst +2
-2All processes are then migrated to use the code only from the new patch. -Once the transition is finished, all older patches are automatically -disabled. +Once the transition is finished, all older patches with the same replace +set are automatically disabled. Patches with different tags remain active.There always could be only one livepatch with the given replace set. I would write something like:
Quoted 7 lines
<proposal>
A livepatch with a given ``replace_set`` number is replaced by another livepatch using the same number. All processes are migrated to use the code only from the new patch. Once the transition is finished, the older patch. Patches with different replace sets are not affected and remain active.
</proposal>
I will update it.
Quoted 9 lines
Quoted 9 lines
Documentation/livepatch/cumulative-patches.rst +0
-0Ftrace handlers are transparently removed from functions that are no longer modified by the new cumulative patch.kernel/livepatch/core.c +0
-0@@ -600,6 +600,8 @@ static int klp_add_nops(struct klp_patch *patch)klp_for_each_object (old_patch, old_obj) {int err;
Quoted 5 lines
kernel/livepatch/core.c static int klp_add_nops(struct klp_patch *patch) · line 604
Quoted 2 lines
kernel/livepatch/core.c +2
-0+if (patch->replace_set != old_patch->replace_set) +continue ;This should be checked on the
klp_for_each_patch(old_patch)level. The result is the same for eachold_objfrom the givenold_patch...
will update it.
Quoted 11 lines
kernel/livepatch/core.c void klp_unpatch_replaced_patches(struct klp_patch *new_patch) · line 1178
Quoted 8 lines
kernel/livepatch/core.c +0
-0err =klp_add_object_nops (patch, old_obj);if (err)return err;@@ -1174,6 +1176,8 @@ void klp_unpatch_replaced_patches(struct klp_patch *new_patch)if (old_patch == new_patch)return ;Nit: Remove the empty line here.
Quoted 5 lines
kernel/livepatch/core.c void klp_unpatch_replaced_patches(struct klp_patch *new_patch) · line 1180
Quoted 2 lines
kernel/livepatch/core.c +2
-0+if (old_patch->replace_set != new_patch->replace_set) +continue ;Nit: And put it here instead. To separate if/return/continue part from
the changes done for the eligibleold_patch.
Thanks for the code style improvements.
Quoted 83 lines
Quoted 69 lines
kernel/livepatch/core.c +0
-0old_patch->enabled = false;klp_unpatch_objects (old_patch); }kernel/livepatch/state.c +29
-10@@ -85,34 +85,65 @@ EXPORT_SYMBOL_GPL(klp_get_prev_state);/* Check if the patch is able to deal with the existing system state. */ static bool klp_is_state_compatible (struct klp_patch *patch, +struct klp_patch *old_patch,struct klp_state *old_state) {struct klp_state *state; state =klp_get_state (patch, old_state->id); +if (patch->replace_set == old_patch->replace_set) { +/* +* If the new livepatch shares a state set with an existing +* one, it must maintain compatibility with all states +* modified by the old patch. +*/ +if (!state) +return false; +return state->version >= old_state->version; -/* A cumulative livepatch must handle all already modified states. */ -if (!state) -return !patch->replace; + } -return state->version >= old_state->version; +/* +* Two livepatches with a different "replace_set" must _not_ use +* the same "state->id. +*/ +return !state; } -/* -* Check that the new livepatch will not break the existing system states. -* Cumulative patches must handle all already modified states. -* Non-cumulative patches can touch already modified states. -*/ +/* Check that the new livepatch will not break the existing system states. */ bool klp_is_patch_compatible (struct klp_patch *patch) { +struct klp_object *obj, *old_obj;struct klp_patch *old_patch;struct klp_state *old_state; +struct klp_func *func;klp_for_each_patch (old_patch) {klp_for_each_state (old_patch, old_state) { -if (!klp_is_state_compatible (patch, old_state)) +if (!klp_is_state_compatible (patch, old_patch, old_state))return false; } + +if (old_patch->replace_set == patch->replace_set) +continue ; + +/* +* Refuse loading a livepatch which would want to modify a +* function which is already livepatched with the livepatch +* with another "replace_set". +*/ kernel/livepatch/state.c EXPORT_SYMBOL_GPL(klp_get_prev_state); · line 144
Quoted 10 lines
kernel/livepatch/state.c +10
-0+klp_for_each_object_static (patch, obj) { +klp_for_each_object (old_patch, old_obj) { +if (!!obj->name != !!old_obj->name) +continue ; +if (obj->name &&strcmp (obj->name, old_obj->name)) +continue ; +klp_for_each_func_static (obj, func) { +if (klp_find_func (old_obj, func)) +return false; + }The combination of
for_each_()and for_each_*_static() variants look correct but it is a bit scarry.
Quoted 4 lines
I think about calling
klp_init_patch_early()beforeklp_is_patch_compatible()so that we could use the non-static for_each_*() variants even for the new patch. It would make the life easier. But I do not have strong opinion about it.
I will think about it.
Quoted 8 lines
kernel/livepatch/state.c EXPORT_SYMBOL_GPL(klp_get_prev_state); · line 145
Quoted 2 lines
kernel/livepatch/state.c +1
-0+ }Anyway, please, put the new check into a separate function, something like:
bool klp_has_function_conflict(struct
klp_patch*patch,struct klp_patch *old_patch);
I will update it.
Quoted 8 lines
kernel/livepatch/state.c EXPORT_SYMBOL_GPL(klp_get_prev_state); · line 149
Quoted 6 lines
kernel/livepatch/state.c +1
-0+ } }return true;The rest looks good.
Thanks a lot for the review!
Signature · 2 lines
Regards Yafang
Joe Lawrence
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Yafang ShaoQuoted 69 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_setSuggested-by Song Liu <[email protected]>Suggested-by Petr Mladek <[email protected]>Signed-off-by Yafang Shao <[email protected]>--- .../ABI/testing/sysfs-kernel-livepatch | 5 +- .../livepatch/cumulative-patches.rst | 23 ++++++--- Documentation/livepatch/livepatch.rst | 21 ++++---- include/linux/livepatch.h | 5 +- kernel/livepatch/core.c | 24 +++++---- kernel/livepatch/state.c | 51 +++++++++++++++---- kernel/livepatch/transition.c | 11 ++-- scripts/livepatch/init.c | 6 +-- scripts/livepatch/klp-build | 16 +++--- 9 files changed, 104 insertions(+), 58 deletions(-)[ ... snip ... ]
kernel/livepatch/core.c +4
-0@@ -600,6 +600,8 @@ static int klp_add_nops(struct klp_patch *patch)klp_for_each_object (old_patch, old_obj) {int err; +if (patch->replace_set != old_patch->replace_set) +continue ; err =klp_add_object_nops (patch, old_obj);if (err)return err;@@ -772,6 +774,8 @@ void klp_free_replaced_patches_async(struct klp_patch *new_patch)klp_for_each_patch_safe (old_patch, tmp_patch) {if (old_patch == new_patch)return ; +if (old_patch->replace_set != new_patch->replace_set) +continue ;klp_free_patch_async (old_patch); } }@@ -967,11 +971,9 @@ static int klp_init_patch(struct klp_patch *patch)if (ret)
kernel/livepatch/core.c static int klp_init_patch(struct klp_patch *patch) · line 976
Quoted 10 lines
kernel/livepatch/core.c +3
-5return ret; -if (patch->replace) { - ret =klp_add_nops (patch); -if (ret) -return ret; - } + ret =klp_add_nops (patch); +if (ret) +return ret;
The pre-existing comment above klp_add_nops() is now misleading:
They are added only when the atomic replace mode is used and only for functions which are currently livepatched but are no longer included in the new livepatch.
That function is now called unconditionally, and with this patchset, there is no more "replace mode" but "replace sets". How about something like:
For each older patch in the same replace_set, any function that is currently livepatched, but no longer included in the new livepatch gets a nop entry, ensuring a clean transition back to the original code during atomic replacement.
--
Joe
Miroslav Benes
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
In reply to Yafang ShaoHi,
Quoted 19 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Quoted 7 lines
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_set
I will add my feedback here because the thread where it would belong to is more about details now. I am sorry that I got to it later than I wanted to.
What I like about the current state (non-replace and replace_all patches) is that it is simple when it comes to the code and it is agnostic to different use cases as we know them. Yes, it can lead to really problematic scenarios on users' side but the kernel code is relatively simple and flexible to allow that. As a distributor we chose something that suits our needs and what we think suits our customers as well. However, it is a downstream choice and implementation.
Now we learnt that some users would welcome a specific use case of keeping parallel live patches applied on their system and they lack the kernel support for that. That is ok and we should do something about that. There are two things which I am concerned about though.
1. I think that we should not leave our existing users (which we do not know much about) behind and regress. I mean we should still allow the same level of flexibility. If not possible, it should be seriously thought through. I am talking about non-replace patches here.
2. Slightly connected. We should not optimize too much for specific scenarios. It seems perfectly fine to introduce a specific feature which helps someone but I am concerned about restricting different use cases at the same time. The latest discussion next door dives into very specific scenarios and my question is "Do we really care?". The user (either a distributor or anyone else) can choose what they want to implement in the end (policy) and how to maintain it (a distributor will typically refuse to support a system with a user applied live patches not provided by the distributor).
I think that latest proposals in the other thread go in the right direction if I understand them correctly but I also think that we should keep the above in mind (or disagree with me please).
It might be difficult to keep the code simple and maintainable in the end and it certainly would not have benefits as the original replace_set proposal where it would all be very simple in the end (only one live patch per function allowed which might lead to substantial code simplification all around the stack).
Regards,
Miroslav
Petr Mladek
maintainerRe: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 48 lines · Miroslav Benes
Hi,
Quoted 19 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Quoted 7 lines
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_setI will add my feedback here because the thread where it would belong to is more about details now. I am sorry that I got to it later than I wanted to.
What I like about the current state (non-replace and
replace_allpatches) is that it is simple when it comes to the code and it is agnostic to different use cases as we know them. Yes, it can lead to really problematic scenarios on users' side but the kernel code is relatively simple and flexible to allow that. As a distributor we chose something that suits our needs and what we think suits our customers as well. However, it is a downstream choice and implementation.Now we learnt that some users would welcome a specific use case of keeping parallel live patches applied on their system and they lack the kernel support for that. That is ok and we should do something about that. There are two things which I am concerned about though.
Quoted 4 lines
1. I think that we should not leave our existing users (which we do not know much about) behind and regress. I mean we should still allow the same level of flexibility. If not possible, it should be seriously thought through. I am talking about non-replace patches here.
Good point! We do not know about all existing users.
We have already changed the behavior in the past but it has been relatively long time ago. And it was related to introducing the "atomic replace":
+ commit 0b3d52790e1cfd6b ("livepatch: Remove signal sysfs attribute
[Jan 2019]
+ commit d67a53720966f2ef ("livepatch: Remove ordering (stacking)
of the livepatches") [Jan 2019]
+ commit e1452b607c48c642c ("livepatch: Add atomic replace")
[Jan 2019]
+ commit 958ef1e39d24d6cb8 ("livepatch: Simplify API by removing
registration step") [Jan 2019]IMHO, we hoped that people would start using the concept of "cumulative livepatches" and stop using the no-replace mode at all.
Obviously, some users keep using the no-replace mode. And it causes problems. I am pretty sure that it motivated the following changes:
+ commit 3dae09de4061671 ("livepatch: Add stack_order sysfs attribute") [Oct 2024. Wardenjohn <[email protected]>]
+ commit adb68ed26a3e922 ("livepatch: Add "replace" sysfs attribute") [Jun 2024, Yafang Shao <[email protected]>]
I am not sure if Wardenjohn and Yafang made the changes for the same user or they were independent.
Another question is whether there are other users who are managing the dependencies another way or were not able to contribute to the kernel.
My view:
I believe that there are only very few users who create livepatches. And they should have capable kernel developers. Because creating livepatches is not trivial, requires kernel development knowledge, and some infrastructure.
It is clear that some companies use the non-replace mode for some reason. But I believe that they have problems to manage them a safe way.
Quoted 10 lines
2. Slightly connected. We should not optimize too much for specific scenarios. It seems perfectly fine to introduce a specific feature which helps someone but I am concerned about restricting different use cases at the same time. The latest discussion next door dives into very specific scenarios and my question is "Do we really care?". The user (either a distributor or anyone else) can choose what they want to implement in the end (policy) and how to maintain it (a distributor will typically refuse to support a system with a user applied live patches not provided by the distributor).
Quoted 3 lines
I think that latest proposals in the other thread go in the right direction if I understand them correctly but I also think that we should keep the above in mind (or disagree with me please).
I personally see the proposed changes as another evolution/replacement of the too-wild and hard-to-manage no-replace mode.
IMHO, the gain is:
+ atomic replace even for livepatches installed in parallel
+ more safety by avoiding conflicts in livepatched functions and shadow variable IDs.
the drawback is:
+ loose of a complete freedom (jungle)
+ atomic replace must be used to replace already livepatched function
+ two or more livepatches need to be replaced using a single cumulative livepatch when a new change brings dependency between them
Quoted 5 lines
It might be difficult to keep the code simple and maintainable in the end and it certainly would not have benefits as the original
replace_setproposal where it would all be very simple in the end (only one live patch per function allowed which might lead to substantial code simplification all around the stack).
I agree that we do not want to maintain three modes. We should add the new approach only when it replaces to old unrestricted no-replace mode.
I personally believe that it is a good step forward and it should be acceptable.
Best Regards,
Petr
Re: [PATCH v3 3/7] livepatch: Support scoped atomic replace using replace_set
Quoted 76 lines · Petr Mladek
Quoted 48 lines · Miroslav Benes
Hi,
Quoted 19 lines · Yafang Shao
Convert the replace attribute from a boolean to a u32 to function as a "replace set." A newly loaded livepatch will now atomically replace any existing patch belonging to the same set. There can only ever be one active livepatch for a given
replace_setnumber.This change currently supports function replacement only. Livepatches that belong to different replace sets cannot modify the same function. If a new livepatch attempts to modify a function already modified by an older livepatch from a different
replace_set, the loading of the new livepatch will be refused.Similarly, for the KLP state, livepatches belonging to different replace sets cannot use the same state ID. The system will refuse to load a new livepatch if it uses a state ID already in use by an older livepatch from a different
replace_set.For the KLP shadow variable mechanism, developers must assign unique shadow IDs to livepatches that belong to different replace sets.
Quoted 7 lines
Support for
replace_setcompatibility with KLP state and shadow variables will be implemented after Petr's KLP state transfer work is completed [0].Other user-visible changes include:
- The non-replace model is now deprecated
-/sys/kernel/livepatch/livepatch_XXX/replaceattribute is replaced by/sys/kernel/livepatch/livepatch_XXX/replace_setI will add my feedback here because the thread where it would belong to is more about details now. I am sorry that I got to it later than I wanted to.
What I like about the current state (non-replace and
replace_allpatches) is that it is simple when it comes to the code and it is agnostic to different use cases as we know them. Yes, it can lead to really problematic scenarios on users' side but the kernel code is relatively simple and flexible to allow that. As a distributor we chose something that suits our needs and what we think suits our customers as well. However, it is a downstream choice and implementation.Now we learnt that some users would welcome a specific use case of keeping parallel live patches applied on their system and they lack the kernel support for that. That is ok and we should do something about that. There are two things which I am concerned about though.
Quoted 4 lines
1. I think that we should not leave our existing users (which we do not know much about) behind and regress. I mean we should still allow the same level of flexibility. If not possible, it should be seriously thought through. I am talking about non-replace patches here.
Good point! We do not know about all existing users.
We have already changed the behavior in the past but it has been relatively long time ago. And it was related to introducing the "atomic replace":
+ commit
0b3d52790e1cfd6b("livepatch: Remove signal sysfs attribute[Jan 2019] + commit d67a53720966f2ef ("livepatch: Remove ordering (stacking) of the livepatches") [Jan 2019] + commit e1452b607c48c642c ("livepatch: Add atomic replace") [Jan 2019] + commit 958ef1e39d24d6cb8 ("livepatch: Simplify API by removing registration step") [Jan 2019]IMHO, we hoped that people would start using the concept of "cumulative livepatches" and stop using the no-replace mode at all.
Obviously, some users keep using the no-replace mode. And it causes problems. I am pretty sure that it motivated the following changes:
Quoted 7 lines
+ commit
3dae09de4061671("livepatch: Addstack_ordersysfs attribute") [Oct 2024. Wardenjohn <[email protected]>]
+ commitadb68ed26a3e922("livepatch: Add "replace" sysfs attribute") [Jun 2024, Yafang Shao <[email protected]>]I am not sure if Wardenjohn and Yafang made the changes for the same user or they were independent.
We have migrated all non-replace livepatches to the cumulative livepatch model. I find the atomic-replace mode particularly beneficial, as it significantly simplifies kernel development. This motivates me to continue enhancing the atomic-replace mode to ensure it covers all use cases.
[...]
Signature · 2 lines
Regards Yafang
PATCH v3 4/7 livepatch: Deprecate stack_order
In reply to Yafang Shaostack_order is no longer needed for atomic-replace livepatches, as a single function can only be modified by a unique replace_set. To maintain backward compatibility, print a dummy value, as suggested by sashiko-bot.
--- .../ABI/removed/sysfs-kernel-livepatch | 9 +++ .../ABI/testing/sysfs-kernel-livepatch | 9 --- kernel/livepatch/core.c | 20 +----- .../testing/selftests/livepatch/test-sysfs.sh | 69 ------------------- 4 files changed, 12 insertions(+), 95 deletions(-) create mode 100644 Documentation/ABI/removed/sysfs-kernel-livepatch
Documentation/ABI/removed/sysfs-kernel-livepatch new file +9 -0
@@ -0,0 +1,9 @@ +What: /sys/kernel/livepatch/<patch>/stack_order +Date: Jan 2025 +KernelVersion: 6.14.0 +Description: + This attribute specifies the sequence in which live patch modules + are applied to the system. If multiple live patches modify the same + function, the implementation with the biggest 'stack_order' number + is used, unless a transition is currently in progress. +
Documentation/ABI/testing/sysfs-kernel-livepatch +0 -9
@@ -54,15 +54,6 @@ Contact: [email protected] Description: An attribute to show the replace_set of this livepatch. -What: /sys/kernel/livepatch/<patch>/stack_order -Date: Jan 2025 -KernelVersion: 6.14.0 -Description: - This attribute specifies the sequence in which live patch modules - are applied to the system. If multiple live patches modify the same - function, the implementation with the biggest 'stack_order' number - is used, unless a transition is currently in progress. - What: /sys/kernel/livepatch/<patch>/<object> Date: Nov 2014 KernelVersion: 3.19.0
kernel/livepatch/core.c +3 -17
@@ -330,7 +330,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,* /sys/kernel/livepatch/<patch>/transition * /sys/kernel/livepatch/<patch>/force * /sys/kernel/livepatch/<patch>/replace_set -* /sys/kernel/livepatch/<patch>/stack_order +* /sys/kernel/livepatch/<patch>/stack_order <deprecated> * /sys/kernel/livepatch/<patch>/<object> * /sys/kernel/livepatch/<patch>/<object>/patched * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -436,25 +436,11 @@ static ssize_t replace_set_show(struct kobject *kobj,return sysfs_emit (buf,"%u\n" , patch->replace_set); } +/* This interface is deprecated and will be removed in the next release */ static ssize_t stack_order_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) { -struct klp_patch *patch, *this_patch; -int stack_order =0 ; - - this_patch = container_of(kobj, struct klp_patch, kobj); - -mutex_lock (&klp_mutex); - -klp_for_each_patch (patch) { - stack_order++; -if (patch == this_patch) -break ; - } - -mutex_unlock (&klp_mutex); - -return sysfs_emit (buf,"%d\n" , stack_order); +return sysfs_emit (buf,"-1\n" ); }static struct kobj_attribute enabled_kobj_attr =__ATTR_RW (enabled);
tools/testing/selftests/livepatch/test-sysfs.sh +0 -69
79 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v3 4/7] livepatch: Deprecate stack_order
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [Medium] Returning -1 as the dummy value for the deprecated stack_order sysfs attribute risks breaking backward compatibility.
- [Low] Test coverage for the deprecated stack_order sysfs attribute was completely removed instead of being updated.
- [Low] The deprecated stack_order ABI documentation is placed in the wrong directory and contains an outdated description.
Pre-existing issues:
- [High] A NULL pointer dereference occurs in klp_find_func() when verifying patch compatibility with a malformed livepatch that omits .old_name. --
commit ea264255177cd1b15e55c6d6aa2b21dbb4abd6c2
Author: Yafang Shao <[email protected]>
livepatch: Deprecate stack_order
stack_order is no longer needed for atomic-replace livepatches, as a single function can only be modified by a unique replace_set. To maintain backward compatibility, print a dummy value, as suggested by sashiko-bot.
Quoted 6 lines
Documentation/ABI/removed/sysfs-kernel-livepatch new file +0
-0
Documentation/ABI/removed/sysfs-kernel-livepatch line 8
Quoted 8 lines
Documentation/ABI/removed/sysfs-kernel-livepatch new file +8
-0@@ -0,0 +1,9 @@ +What: /sys/kernel/livepatch/<patch>/stack_order +Date: Jan 2025 +KernelVersion: 6.14.0 +Description: + This attribute specifies the sequence in which live patch modules + are applied to the system. If multiple live patches modify the same + function, the implementation with the biggest 'stack_order' number + is used, unless a transition is currently in progress.
[Severity: Low]
Is Documentation/ABI/removed/ the right place for this file since the attribute is still present in the kernel?
According to Documentation/ABI/README, the removed/ directory is strictly for interfaces that have been completely deleted. Since the attribute still exists and returns a dummy value, should this be placed in obsolete/ instead?
Also, should the description be updated to explain that the attribute is now obsolete and just returns a dummy value, rather than claiming it specifies the sequence in which live patch modules are applied?
Quoted 4 lines
kernel/livepatch/core.c +0
-0
[ ... ]
Quoted 15 lines
kernel/livepatch/core.c +1
-7@@ -436,25 +436,11 @@ static ssize_t replace_set_show(struct kobject *kobj,return sysfs_emit (buf,"%u\n" , patch->replace_set); } +/* This interface is deprecated and will be removed in the next release */ static ssize_t stack_order_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) { -struct klp_patch *patch, *this_patch; -int stack_order =0 ; - - this_patch = container_of(kobj, struct klp_patch, kobj); - -mutex_lock (&klp_mutex); -
kernel/livepatch/core.c static ssize_t replace_set_show(struct kobject *kobj, · line 443
Quoted 10 lines
kernel/livepatch/core.c +1
-9-klp_for_each_patch (patch) { - stack_order++; -if (patch == this_patch) -break ; - } - -mutex_unlock (&klp_mutex); - -return sysfs_emit (buf,"%d\n" , stack_order); +return sysfs_emit (buf,"-1\n" );
[Severity: Medium]
Will returning -1 break userspace tools that expect a non-negative integer or parse this as unsigned?
The commit message mentions printing a dummy value to maintain backward compatibility. Since the previous implementation returned a strictly positive sequence (1, 2, ...), could we use a previously valid integer like 1 to ensure older scripts don't fail when encountering a negative sign?
[Severity: High]
This isn't a bug introduced by this patch, but an earlier commit in this series ("livepatch: Support scoped atomic replace using replace_set") appears to introduce a NULL pointer dereference when a malformed patch omits .old_name.
When klp_enable_patch() is called, it invokes klp_is_patch_compatible() before klp_init_patch() validates that func->old_name is non-NULL.
The klp_is_patch_compatible() function passes unvalidated functions to klp_find_func() as the old_func argument:
kernel/livepatch/state.c:klp_is_patch_compatible() {
...
if (klp_find_func(old_obj, func))
return false;
...
}Inside klp_find_func(), old_func->old_name is unconditionally dereferenced in the first argument to strcmp():
kernel/livepatch/core.h:klp_find_func() {
...
if ((func->old_name && strcmp(old_func->old_name, func->old_name) == 0) &&
...
}Could this trigger a kernel panic during patch load?
tools/testing/selftests/livepatch/test-sysfs.sh check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" · line 25
Quoted 10 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-2@@ -21,8 +21,6 @@ check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1" check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------" check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" -check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--" -check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1"
[Severity: Low]
Does removing these checks completely leave the deprecated attribute untested?
Since stack_order is intentionally kept to maintain backward compatibility, should the test suite still verify its presence, correct permissions, and the new dummy output? This would ensure future changes don't accidentally remove the sysfs node before the deprecation period ends.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Petr Mladek
maintainerRe: [PATCH v3 4/7] livepatch: Deprecate stack_order
In reply to Yafang ShaoQuoted 4 lines · Yafang Shao
stack_orderis no longer needed for atomic-replace livepatches, as a single function can only be modified by a uniquereplace_set. To maintain backward compatibility, print a dummy value, as suggested by sashiko-bot.
I would personally remove it completely. I believe that there are only few users around the world. And they will need to update the tooling/strategy for the new "replace_set" anyway.
Documentation/ABI/removed/sysfs-kernel-livepatch line 8
Quoted 11 lines
Documentation/ABI/removed/sysfs-kernel-livepatch new file +8
-0@@ -0,0 +1,9 @@ +What: /sys/kernel/livepatch/<patch>/stack_order +Date: Jan 2025 +KernelVersion: 6.14.0 +Description: + This attribute specifies the sequence in which live patch modules + are applied to the system. If multiple live patches modify the same + function, the implementation with the biggest 'stack_order' number + is used, unless a transition is currently in progress.
I was not aware of this ABI/removed part. We should put here also the livepatch/replace interface which was removed in the 3rd patch.
Quoted 12 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-2@@ -21,8 +21,6 @@ check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1" check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------" check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" -check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--" -check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1" check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--" check_sysfs_value "$MOD_LIVEPATCH" "transition" "0" check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--"
tools/testing/selftests/livepatch/test-sysfs.sh livepatch: '$MOD_LIVEPATCH': completing unpatching transition · line 139
Quoted 5 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-2@@ -135,71 +133,4 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition livepatch: '$MOD_LIVEPATCH': unpatching complete % rmmod $MOD_LIVEPATCH" -start_test "sysfs test stack_order value" -
This is not longer needed in linux-next. Marcos made the test optional, see
https://lore.kernel.org/all/[email protected]/
The changes are queued for 7.2 merge window which will likely start next week.
I suggest to wait with v4 until the change is merged. We should wait for opinion from others (Miroslav, Josh, Joe, Song) anyway. We need to be sure that the change of the semantic is acceptable in general.
tools/testing/selftests/livepatch/test-sysfs.sh livepatch: '$MOD_LIVEPATCH': completing unpatching transition · line 148
Quoted 9 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-9-load_lp $MOD_LIVEPATCH - -check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1" - -load_lp $MOD_LIVEPATCH2 - -check_sysfs_value "$MOD_LIVEPATCH2" "stack_order" "2" - -load_lp $MOD_LIVEPATCH3
Nit: It seems that MOD_LIVEPATCH2 and MOD_LIVEPATCH3 are not longer used
at least in this test-sysfs.sh file. Well, I guess that we will keep this test optional for older kernels.
tools/testing/selftests/livepatch/test-sysfs.sh livepatch: '$MOD_LIVEPATCH': completing unpatching transition · line 150
Quoted 2 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-2-check_sysfs_value "$MOD_LIVEPATCH3" "stack_order" "3" -
Best Regards,
Petr
Re: [PATCH v3 4/7] livepatch: Deprecate stack_order
Quoted 10 lines · Petr Mladek
Quoted 4 lines · Yafang Shao
stack_orderis no longer needed for atomic-replace livepatches, as a single function can only be modified by a uniquereplace_set. To maintain backward compatibility, print a dummy value, as suggested by sashiko-bot.I would personally remove it completely. I believe that there are only few users around the world. And they will need to update the tooling/strategy for the new "
replace_set" anyway.
I will remove it completely in the next version.
Quoted 15 lines
Documentation/ABI/removed/sysfs-kernel-livepatch line 8
Quoted 12 lines
Documentation/ABI/removed/sysfs-kernel-livepatch new file +8
-0@@ -0,0 +1,9 @@ +What: /sys/kernel/livepatch/<patch>/stack_order +Date: Jan 2025 +KernelVersion: 6.14.0 +Description: + This attribute specifies the sequence in which live patch modules + are applied to the system. If multiple live patches modify the same + function, the implementation with the biggest 'stack_order' number + is used, unless a transition is currently in progress.I was not aware of this ABI/removed part. We should put here also the livepatch/replace interface which was removed in the 3rd patch.
sure
Quoted 16 lines
Quoted 16 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-2@@ -21,8 +21,6 @@ check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1" check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------" check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" -check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--" -check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1" check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--" check_sysfs_value "$MOD_LIVEPATCH" "transition" "0" check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--"@@ -135,71 +133,4 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition livepatch: '$MOD_LIVEPATCH': unpatching complete % rmmod $MOD_LIVEPATCH"
Quoted 6 lines
tools/testing/selftests/livepatch/test-sysfs.sh livepatch: '$MOD_LIVEPATCH': completing unpatching transition · line 139
Quoted 2 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-2-start_test "sysfs test stack_order value" -This is not longer needed in linux-next. Marcos made the test optional, see
https://lore.kernel.org/all/[email protected]/
Thanks for sharing.
Quoted 8 lines
The changes are queued for 7.2 merge window which will likely start next week.
I suggest to wait with v4 until the change is merged. We should wait for opinion from others (Miroslav, Josh, Joe, Song) anyway. We need to be sure that the change of the semantic is acceptable in general.
Understood. I'll wait for further feedback.
Quoted 21 lines
tools/testing/selftests/livepatch/test-sysfs.sh livepatch: '$MOD_LIVEPATCH': completing unpatching transition · line 148
Quoted 11 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-9-load_lp $MOD_LIVEPATCH - -check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1" - -load_lp $MOD_LIVEPATCH2 - -check_sysfs_value "$MOD_LIVEPATCH2" "stack_order" "2" - -load_lp $MOD_LIVEPATCH3Nit: It seems that
MOD_LIVEPATCH2andMOD_LIVEPATCH3are not longer used
at least in thistest-sysfs.shfile. Well, I guess that we will keep this test optional for older kernels.tools/testing/selftests/livepatch/test-sysfs.sh livepatch: '$MOD_LIVEPATCH': completing unpatching transition · line 150
Quoted 2 lines
tools/testing/selftests/livepatch/test-sysfs.sh +0
-2-check_sysfs_value "$MOD_LIVEPATCH3" "stack_order" "3" -Best Regards,
Petr
Signature · 2 lines
Regards Yafang
Joe Lawrence
maintainerRe: [PATCH v3 4/7] livepatch: Deprecate stack_order
Quoted 8 lines · Yafang Shao
Quoted 7 lines · Petr Mladek
Quoted 4 lines · Yafang Shao
stack_orderis no longer needed for atomic-replace livepatches, as a single function can only be modified by a uniquereplace_set. To maintain backward compatibility, print a dummy value, as suggested by sashiko-bot.
Quoted 6 lines
Quoted 3 lines
I would personally remove it completely. I believe that there are only few users around the world. And they will need to update the tooling/strategy for the new "
replace_set" anyway.I will remove it completely in the next version.
The kpatch-utility uses it (thanks for adding [email protected] to CC), but as I understand this patchset should effectively eliminate the need for it (as per Wardenjohn's original use-case). So I'd be in favor of removing it from sysfs as Petr suggested.
--
Joe
PATCH v3 5/7 selftests/livepatch: Update tests for replace_set
In reply to Yafang ShaoThe changes are as follows:
- Replace "replace" with "replace_set"
- For atomic-replace test cases, we configure two different livepatches that share the same replace_set.
- For non-atomic-replace test cases, we configure multiple livepatches, each with a different replace_set.
- Remove the test case that an atomic replace livepatch disables multiple existing livepatches
The result are as follows,
$ ./test-callbacks.sh TEST: target module before livepatch ... ok TEST: module_coming notifier ... ok TEST: module_going notifier ... ok TEST: module_coming and module_going notifiers ... ok TEST: target module not present ... ok TEST: pre-patch callback -ENODEV ... ok TEST: module_coming + pre-patch callback -ENODEV ... ok TEST: multiple target modules ... ok TEST: busy target module ... ok TEST: multiple livepatches ... ok TEST: atomic replace ... ok
$ ./test-ftrace.sh TEST: livepatch interaction with ftrace_enabled sysctl ... ok TEST: trace livepatched function and check that the live patch remains in effect ... ok TEST: livepatch a traced function and check that the live patch remains in effect ... ok
$ ./test-kprobe.sh TEST: livepatch interaction with kprobed function with post_handler ... ok TEST: livepatch interaction with kprobed function without post_handler ... ok
$ ./test-livepatch.sh TEST: basic function patching ... ok TEST: multiple livepatches ... ok TEST: module function patching ... ok TEST: module function patching (livepatch first) ... ok
$ ./test-shadow-vars.sh TEST: basic shadow variable API ... ok
$ ./test-state.sh TEST: system state modification ... ok TEST: taking over system state modification ... ok TEST: compatible cumulative livepatches ... ok TEST: incompatible cumulative livepatches ... ok
$ ./test-syscall.sh TEST: patch getpid syscall while being heavily hammered ... ok
--- .../selftests/livepatch/test-callbacks.sh | 33 +++--- .../selftests/livepatch/test-livepatch.sh | 100 +----------------- .../testing/selftests/livepatch/test-sysfs.sh | 22 ++-- .../test_modules/test_klp_atomic_replace.c | 10 +- .../test_modules/test_klp_callbacks_demo.c | 6 ++ .../test_modules/test_klp_callbacks_demo2.c | 10 +- .../test_modules/test_klp_livepatch.c | 6 ++ .../livepatch/test_modules/test_klp_state.c | 2 +- .../livepatch/test_modules/test_klp_state2.c | 2 +- 9 files changed, 55 insertions(+), 136 deletions(-)
tools/testing/selftests/livepatch/test-callbacks.sh +16 -17
@@ -451,8 +451,8 @@ $MOD_TARGET_BUSY: busymod_work_func exit $MOD_TARGET_BUSY: ${MOD_TARGET_BUSY}_exit" -# Test loading multiple livepatches. This test-case is mainly for comparing -# with the next test-case. +# Test loading multiple livepatches sharing different replace_set. +# This test-case is mainly for comparing with the next test-case. # # - Load and unload two livepatches, pre and post (un)patch callbacks # execute as each patch progresses through its (un)patching
@@ -460,14 +460,14 @@ $MOD_TARGET_BUSY: ${MOD_TARGET_BUSY}_exit" start_test "multiple livepatches" -load_lp $MOD_LIVEPATCH -load_lp $MOD_LIVEPATCH2 +load_lp $MOD_LIVEPATCH replace_set=0 +load_lp $MOD_LIVEPATCH2 replace_set=1 disable_lp $MOD_LIVEPATCH2 disable_lp $MOD_LIVEPATCH unload_lp $MOD_LIVEPATCH2 unload_lp $MOD_LIVEPATCH -check_result "% insmod test_modules/$MOD_LIVEPATCH.ko +check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace_set=0 livepatch: enabling patch '$MOD_LIVEPATCH' livepatch: '$MOD_LIVEPATCH': initializing patching transition $MOD_LIVEPATCH: pre_patch_callback: vmlinux
@@ -475,7 +475,7 @@ livepatch: '$MOD_LIVEPATCH': starting patching transition livepatch: '$MOD_LIVEPATCH': completing patching transition $MOD_LIVEPATCH: post_patch_callback: vmlinux livepatch: '$MOD_LIVEPATCH': patching complete -% insmod test_modules/$MOD_LIVEPATCH2.ko +% insmod test_modules/$MOD_LIVEPATCH2.ko replace_set=1 livepatch: enabling patch '$MOD_LIVEPATCH2' livepatch: '$MOD_LIVEPATCH2': initializing patching transition $MOD_LIVEPATCH2: pre_patch_callback: vmlinux
@@ -501,14 +501,13 @@ livepatch: '$MOD_LIVEPATCH': unpatching complete % rmmod $MOD_LIVEPATCH" -# Load multiple livepatches, but the second as an 'atomic-replace' -# patch. When the latter loads, the original livepatch should be -# disabled and *none* of its pre/post-unpatch callbacks executed. On -# the other hand, when the atomic-replace livepatch is disabled, its -# pre/post-unpatch callbacks *should* be executed. +# Load multiple livepatches sharing the same replace_set. +# When the latter loads, the original livepatch should be disabled and +# *none* of its pre/post-unpatch callbacks executed. On the other hand, +# when the atomic-replace livepatch is disabled, its pre/post-unpatch +# callbacks *should* be executed. # -# - Load and unload two livepatches, the second of which has its -# .replace flag set true. +# - Load and unload two livepatches sharing the same replace_set # # - Pre and post patch callbacks are executed for both livepatches. #
@@ -517,13 +516,13 @@ livepatch: '$MOD_LIVEPATCH': unpatching complete start_test "atomic replace" -load_lp $MOD_LIVEPATCH -load_lp $MOD_LIVEPATCH2 replace=1 +load_lp $MOD_LIVEPATCH replace_set=0 +load_lp $MOD_LIVEPATCH2 replace_set=0 disable_lp $MOD_LIVEPATCH2 unload_lp $MOD_LIVEPATCH2 unload_lp $MOD_LIVEPATCH -check_result "% insmod test_modules/$MOD_LIVEPATCH.ko +check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace_set=0 livepatch: enabling patch '$MOD_LIVEPATCH' livepatch: '$MOD_LIVEPATCH': initializing patching transition $MOD_LIVEPATCH: pre_patch_callback: vmlinux
@@ -531,7 +530,7 @@ livepatch: '$MOD_LIVEPATCH': starting patching transition livepatch: '$MOD_LIVEPATCH': completing patching transition $MOD_LIVEPATCH: post_patch_callback: vmlinux livepatch: '$MOD_LIVEPATCH': patching complete -% insmod test_modules/$MOD_LIVEPATCH2.ko replace=1 +% insmod test_modules/$MOD_LIVEPATCH2.ko replace_set=0 livepatch: enabling patch '$MOD_LIVEPATCH2' livepatch: '$MOD_LIVEPATCH2': initializing patching transition $MOD_LIVEPATCH2: pre_patch_callback: vmlinux
tools/testing/selftests/livepatch/test-livepatch.sh +4 -96
134 lines not on this page · raw message
tools/testing/selftests/livepatch/test-sysfs.sh +11 -11
@@ -20,7 +20,7 @@ check_sysfs_rights "$MOD_LIVEPATCH" "" "drwxr-xr-x" check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1" check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------" -check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" +check_sysfs_rights "$MOD_LIVEPATCH" "replace_set" "-r--r--r--" check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--" check_sysfs_value "$MOD_LIVEPATCH" "transition" "0" check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--"
@@ -86,18 +86,18 @@ test_klp_callbacks_demo: post_unpatch_callback: vmlinux livepatch: 'test_klp_callbacks_demo': unpatching complete % rmmod test_klp_callbacks_demo" -start_test "sysfs test replace enabled" +start_test "sysfs test replace_set 0" MOD_LIVEPATCH=test_klp_atomic_replace -load_lp $MOD_LIVEPATCH replace=1 +load_lp $MOD_LIVEPATCH replace_set=0 -check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" -check_sysfs_value "$MOD_LIVEPATCH" "replace" "1" +check_sysfs_rights "$MOD_LIVEPATCH" "replace_set" "-r--r--r--" +check_sysfs_value "$MOD_LIVEPATCH" "replace_set" "0" disable_lp $MOD_LIVEPATCH unload_lp $MOD_LIVEPATCH -check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace=1 +check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace_set=0 livepatch: enabling patch '$MOD_LIVEPATCH' livepatch: '$MOD_LIVEPATCH': initializing patching transition livepatch: '$MOD_LIVEPATCH': starting patching transition
@@ -110,17 +110,17 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition livepatch: '$MOD_LIVEPATCH': unpatching complete % rmmod $MOD_LIVEPATCH" -start_test "sysfs test replace disabled" +start_test "sysfs test replace_set 1234" -load_lp $MOD_LIVEPATCH replace=0 +load_lp $MOD_LIVEPATCH replace_set=1234 -check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" -check_sysfs_value "$MOD_LIVEPATCH" "replace" "0" +check_sysfs_rights "$MOD_LIVEPATCH" "replace_set" "-r--r--r--" +check_sysfs_value "$MOD_LIVEPATCH" "replace_set" "1234" disable_lp $MOD_LIVEPATCH unload_lp $MOD_LIVEPATCH -check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace=0 +check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace_set=1234 livepatch: enabling patch '$MOD_LIVEPATCH' livepatch: '$MOD_LIVEPATCH': initializing patching transition livepatch: '$MOD_LIVEPATCH': starting patching transition
tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace.c +5 -5
@@ -7,9 +7,9 @@#include <linux/kernel.h> #include <linux/livepatch.h> -static int replace; -module_param (replace, int,0644 ); -MODULE_PARM_DESC (replace,"replace (default=0)" ); +static int replace_set; +module_param (replace_set, int,0644 ); +MODULE_PARM_DESC (replace_set,"replace_set (default=0)" );#include <linux/seq_file.h> static int livepatch_meminfo_proc_show (struct seq_file *m,void *v)
@@ -36,12 +36,12 @@ static struct klp_object objs[] = {static struct klp_patch patch = { .mod =THIS_MODULE , .objs = objs, -/* set .replace in the init function below for demo purposes */ +/* set .replace_set in the init function below for demo purposes */ };static int test_klp_atomic_replace_init (void ) { - patch.replace = replace; + patch.replace_set = replace_set;return klp_enable_patch (&patch); }
tools/testing/selftests/livepatch/test_modules/test_klp_callbacks_demo.c +6 -0
@@ -7,6 +7,10 @@#include <linux/kernel.h> #include <linux/livepatch.h> +static int replace_set; +module_param (replace_set, int,0644 ); +MODULE_PARM_DESC (replace_set,"replace_set (default=0)" ); +static int pre_patch_ret;module_param (pre_patch_ret, int,0644 );MODULE_PARM_DESC (pre_patch_ret,"pre_patch_ret (default=0)" );
@@ -102,10 +106,12 @@ static struct klp_object objs[] = {static struct klp_patch patch = { .mod =THIS_MODULE , .objs = objs, +/* set .replace_set in the init function below for demo purposes */ };static int test_klp_callbacks_demo_init (void ) { + patch.replace_set = replace_set;return klp_enable_patch (&patch); }
tools/testing/selftests/livepatch/test_modules/test_klp_callbacks_demo2.c +5 -5
@@ -7,9 +7,9 @@#include <linux/kernel.h> #include <linux/livepatch.h> -static int replace; -module_param (replace, int,0644 ); -MODULE_PARM_DESC (replace,"replace (default=0)" ); +static int replace_set; +module_param (replace_set, int,0644 ); +MODULE_PARM_DESC (replace_set,"replace_set (default=0)" );static const char *const module_state[] = { [MODULE_STATE_LIVE ] ="[MODULE_STATE_LIVE] Normal state" ,
@@ -72,12 +72,12 @@ static struct klp_object objs[] = {static struct klp_patch patch = { .mod =THIS_MODULE , .objs = objs, -/* set .replace in the init function below for demo purposes */ +/* set .replace_set in the init function below for demo purposes */ };static int test_klp_callbacks_demo2_init (void ) { - patch.replace = replace; + patch.replace_set = replace_set;return klp_enable_patch (&patch); }
tools/testing/selftests/livepatch/test_modules/test_klp_livepatch.c +6 -0
@@ -15,6 +15,10 @@ static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)return 0 ; } +static int replace_set; +module_param (replace_set, int,0644 ); +MODULE_PARM_DESC (replace_set,"replace_set (default=0)" ); +static struct klp_func funcs[] = { { .old_name ="cmdline_proc_show" ,
@@ -32,10 +36,12 @@ static struct klp_object objs[] = {static struct klp_patch patch = { .mod =THIS_MODULE , .objs = objs, +/* set .replace_set in the init function below for demo purposes */ };static int test_klp_livepatch_init (void ) { + patch.replace_set = replace_set;return klp_enable_patch (&patch); }
tools/testing/selftests/livepatch/test_modules/test_klp_state.c +1 -1
@@ -142,7 +142,7 @@ static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, .states = states, - .replace = true, + .replace_set = 0, };static int test_klp_callbacks_demo_init (void )
tools/testing/selftests/livepatch/test_modules/test_klp_state2.c +1 -1
@@ -171,7 +171,7 @@ static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, .states = states, - .replace = true, + .replace_set = 0, };static int test_klp_callbacks_demo_init (void )
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH v3 5/7] selftests/livepatch: Update tests for replace_set
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The `replace_set` module parameter is defined as `int` with `0644` permissions, but the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The replace_set module parameter is defined as int with 0644 permissions, but the replace_set field in struct klp_patch is an unsigned int and cannot be dynamically modified post-initialization. --
commit 4cfbab500868bad0b10a33bdcbb852806612d546
Author: Yafang Shao <[email protected]>
selftests/livepatch: Update tests for replace_set
This commit updates the livepatch selftests to replace the replace flag with replace_set. It adjusts test cases to configure multiple livepatches that share either the same or different replace_set values, and removes the test case where an atomic replace disables multiple existing livepatches.
[ ... ]
tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace.c line 11
Quoted 13 lines
tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace.c +2
-3@@ -7,9 +7,9 @@#include <linux/kernel.h> #include <linux/livepatch.h> -static int replace; -module_param (replace, int,0644 ); -MODULE_PARM_DESC (replace,"replace (default=0)" ); +static int replace_set; +module_param (replace_set, int,0644 );
[Severity: Low]
The replace_set field in struct klp_patch is an unsigned int, and it cannot be dynamically modified after initialization.
Should this module parameter be defined as uint with read-only permissions (0444) instead of int and 0644?
Using int and 0644 allows negative values which could cause improper implicit casts, and runtime modifications have no actual effect on the livepatch.
[ ... ]
tools/testing/selftests/livepatch/test_modules/test_klp_livepatch.c static int livepatch_cmdline_proc_show(struct seq_file *m, void *v) · line 19
Quoted 10 lines
tools/testing/selftests/livepatch/test_modules/test_klp_livepatch.c +2
-0@@ -15,6 +15,10 @@ static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)return 0 ; } +static int replace_set; +module_param (replace_set, int,0644 );
[Severity: Low]
Does this parameter also need to be updated to uint and 0444?
As noted above, the underlying struct klp_patch replace_set field is an unsigned int and is unaffected by modifications after initialization.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v3 6/7 selftests/livepatch: Add test for state ID conflict across replace_sets
In reply to Yafang ShaoLivepatches with different replace_sets must not share the same state ID. If a second livepatch attempts to reuse a state ID already registered by a livepatch with a different replace_set, the loading will fail.
Add a test case to verify this behavior. The test result is as follows:
$ ./test-state.sh TEST: system state modification ... ok TEST: taking over system state modification ... ok TEST: compatible cumulative livepatches ... ok TEST: incompatible cumulative livepatches ... ok TEST: livepatches state compatibility ... ok <<<< This case
--- .../testing/selftests/livepatch/test-state.sh | 34 ++++ .../selftests/livepatch/test_modules/Makefile | 1 + .../livepatch/test_modules/test_klp_state.c | 2 +- .../livepatch/test_modules/test_klp_state2.c | 2 +- .../livepatch/test_modules/test_klp_state4.c | 163 ++++++++++++++++++ 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_state4.c
tools/testing/selftests/livepatch/test-state.sh +34 -0
@@ -7,6 +7,7 @@ MOD_LIVEPATCH=test_klp_state MOD_LIVEPATCH2=test_klp_state2 MOD_LIVEPATCH3=test_klp_state3 +MOD_LIVEPATCH4=test_klp_state4 setup_config
@@ -173,4 +174,37 @@ $MOD_LIVEPATCH2: free_loglevel_state: freeing space for the stored console_logle livepatch: '$MOD_LIVEPATCH2': unpatching complete % rmmod $MOD_LIVEPATCH2" +# livepatches with different replace_set sharing the same state ID + +start_test "livepatches state compatibility " + +load_lp $MOD_LIVEPATCH +load_failing_mod $MOD_LIVEPATCH4 +disable_lp $MOD_LIVEPATCH +unload_lp $MOD_LIVEPATCH + +check_result "% insmod test_modules/$MOD_LIVEPATCH.ko +livepatch: enabling patch '$MOD_LIVEPATCH' +livepatch: '$MOD_LIVEPATCH': initializing patching transition +$MOD_LIVEPATCH: pre_patch_callback: vmlinux +$MOD_LIVEPATCH: allocate_loglevel_state: allocating space to store console_loglevel +livepatch: '$MOD_LIVEPATCH': starting patching transition +livepatch: '$MOD_LIVEPATCH': completing patching transition +$MOD_LIVEPATCH: post_patch_callback: vmlinux +$MOD_LIVEPATCH: fix_console_loglevel: fixing console_loglevel +livepatch: '$MOD_LIVEPATCH': patching complete +% insmod test_modules/$MOD_LIVEPATCH4.ko +livepatch: Livepatch patch ($MOD_LIVEPATCH4) is not compatible with the already installed livepatches. +insmod: ERROR: could not insert module test_modules/$MOD_LIVEPATCH4.ko: Invalid parameters +% echo 0 > $SYSFS_KLP_DIR/$MOD_LIVEPATCH/enabled +livepatch: '$MOD_LIVEPATCH': initializing unpatching transition +$MOD_LIVEPATCH: pre_unpatch_callback: vmlinux +$MOD_LIVEPATCH: restore_console_loglevel: restoring console_loglevel +livepatch: '$MOD_LIVEPATCH': starting unpatching transition +livepatch: '$MOD_LIVEPATCH': completing unpatching transition +$MOD_LIVEPATCH: post_unpatch_callback: vmlinux +$MOD_LIVEPATCH: free_loglevel_state: freeing space for the stored console_loglevel +livepatch: '$MOD_LIVEPATCH': unpatching complete +% rmmod $MOD_LIVEPATCH" + exit 0
tools/testing/selftests/livepatch/test_modules/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-m += test_klp_atomic_replace.o \ test_klp_state.o \ test_klp_state2.o \ test_klp_state3.o \ + test_klp_state4.o \ test_klp_syscall.o # Ensure that KDIR exists, otherwise skip the compilation
tools/testing/selftests/livepatch/test_modules/test_klp_state.c +1 -1
@@ -39,7 +39,7 @@ static int allocate_loglevel_state(void)if (!loglevel_state)return -EINVAL ; - loglevel_state->data =kzalloc (sizeof (console_loglevel),GFP_KERNEL ); + loglevel_state->data =kzalloc_obj (console_loglevel,GFP_KERNEL );if (!loglevel_state->data)return -ENOMEM ;
tools/testing/selftests/livepatch/test_modules/test_klp_state2.c +1 -1
@@ -46,7 +46,7 @@ static int allocate_loglevel_state(void)if (!loglevel_state)return -EINVAL ; - loglevel_state->data =kzalloc (sizeof (console_loglevel),GFP_KERNEL ); + loglevel_state->data =kzalloc_obj (console_loglevel,GFP_KERNEL );if (!loglevel_state->data)return -ENOMEM ;
tools/testing/selftests/livepatch/test_modules/test_klp_state4.c new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
2.52.0
Petr Mladek
maintainerRe: [PATCH v3 6/7] selftests/livepatch: Add test for state ID conflict across replace_sets
Hi,
I am sorry I am getting busy with some other tasks so I won't review the new selftests carefully. They might change in v4 anyway. Just one note, see below.
tools/testing/selftests/livepatch/test_modules/test_klp_state4.c
Quoted 27 lines · Yafang Shao
Livepatches with different
replace_setsmust not share the same state ID. If a second livepatch attempts to reuse a state ID already registered by a livepatch with a differentreplace_set, the loading will fail.Add a test case to verify this behavior. The test result is as follows:
$ ./test-state.sh TEST: system state modification ... ok TEST: taking over system state modification ... ok TEST: compatible cumulative livepatches ... ok TEST: incompatible cumulative livepatches ... ok TEST: livepatches state compatibility ... ok <<<< This caseSigned-off-by Yafang Shao <[email protected]>--- .../testing/selftests/livepatch/test-state.sh | 34 ++++ .../selftests/livepatch/test_modules/Makefile | 1 + .../livepatch/test_modules/test_klp_state.c | 2 +- .../livepatch/test_modules/test_klp_state2.c | 2 +- .../livepatch/test_modules/test_klp_state4.c | 163 ++++++++++++++++++ 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_state4.ctools/testing/selftests/livepatch/test_modules/test_klp_state4.c new file +0
-0@@ -0,0 +1,163 @@
^^^^^^^^^
tools/testing/selftests/livepatch/test_modules/test_klp_state4.c line 5
Quoted 5 lines
tools/testing/selftests/livepatch/test_modules/test_klp_state4.c new file +5
-0+// SPDX-License-Identifier: GPL-2.0 +/* +* This test is identical to test_klp_state4.c, except that replace_set is +* set to 4 instead of 0. +*/
This seems to be copy&paste of another test module. I suggest to solve this by defining a variable in using #include, for example, look for tools/testing/selftests/livepatch/test_modules/test_klp_speaker2.c at
https://lore.kernel.org/all/[email protected]/
Best Regards,
Petr
Re: [PATCH v3 6/7] selftests/livepatch: Add test for state ID conflict across replace_sets
Quoted 37 lines · Petr Mladek
Hi,
I am sorry I am getting busy with some other tasks so I won't review the new selftests carefully. They might change in v4 anyway. Just one note, see below.
tools/testing/selftests/livepatch/test_modules/test_klp_state4.c
Quoted 27 lines · Yafang Shao
Livepatches with different
replace_setsmust not share the same state ID. If a second livepatch attempts to reuse a state ID already registered by a livepatch with a differentreplace_set, the loading will fail.Add a test case to verify this behavior. The test result is as follows:
$ ./test-state.sh TEST: system state modification ... ok TEST: taking over system state modification ... ok TEST: compatible cumulative livepatches ... ok TEST: incompatible cumulative livepatches ... ok TEST: livepatches state compatibility ... ok <<<< This caseSigned-off-by Yafang Shao <[email protected]>--- .../testing/selftests/livepatch/test-state.sh | 34 ++++ .../selftests/livepatch/test_modules/Makefile | 1 + .../livepatch/test_modules/test_klp_state.c | 2 +- .../livepatch/test_modules/test_klp_state2.c | 2 +- .../livepatch/test_modules/test_klp_state4.c | 163 ++++++++++++++++++ 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_state4.ctools/testing/selftests/livepatch/test_modules/test_klp_state4.c new file +0
-0@@ -0,0 +1,163 @@^^^^^^^^^
Quoted 11 lines
tools/testing/selftests/livepatch/test_modules/test_klp_state4.c line 5
Quoted 5 lines
tools/testing/selftests/livepatch/test_modules/test_klp_state4.c new file +5
-0+// SPDX-License-Identifier: GPL-2.0 +/* +* This test is identical to test_klp_state4.c, except that replace_set is +* set to 4 instead of 0. +*/ This seems to be copy&paste of another test module. I suggest to solve this by defining a variable in using #include, for example, look for
tools/testing/selftests/livepatch/test_modules/test_klp_speaker2.cat
https://lore.kernel.org/all/[email protected]/
I will update it.
Thanks for your suggestion.
Signature · 2 lines
Regards Yafang
PATCH v3 7/7 selftests/livepatch: Add test for function conflict across replace_sets
In reply to Yafang ShaoLivepatches with different replace_sets must not modify the same function. If a second livepatch attempts to modify a function that has already been modified by a loaded livepatch with a different replace_set, the loading will fail. if the second livepatch shares the same replace_set, it will load successfully.
Add a test case to verify this behavior. The test result is as follows:
$ ./test-livepatch.sh TEST: basic function patching ... ok TEST: multiple livepatches ... ok TEST: module function patching ... ok TEST: module function patching (livepatch first) ... ok TEST: function conflict: different replace_sets ... ok <<<< TEST: function conflict: the same replace_set ... ok <<<<
--- .../selftests/livepatch/test-livepatch.sh | 59 +++++++++++++++++++ .../selftests/livepatch/test_modules/Makefile | 1 + .../test_modules/test_klp_atomic_replace2.c | 55 +++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace2.c
tools/testing/selftests/livepatch/test-livepatch.sh +59 -0
@@ -6,6 +6,7 @@ MOD_LIVEPATCH1=test_klp_livepatch MOD_REPLACE=test_klp_atomic_replace +MOD_REPLACE2=test_klp_atomic_replace2 MOD_TARGET=test_klp_mod_target MOD_TARGET_PATCH=test_klp_mod_patch
@@ -203,5 +204,63 @@ livepatch: '$MOD_TARGET_PATCH': unpatching complete % rmmod $MOD_TARGET $MOD_TARGET: test_klp_mod_target_exit" +# - load a livepatch that modifies function A +# - loading another livepatch with a different replace_set that modifies +# the same function will fail + +start_test "function conflict: different replace_sets" + +load_lp $MOD_REPLACE replace_set=0 +load_failing_mod $MOD_REPLACE2 replace_set=1 +disable_lp $MOD_REPLACE +unload_lp $MOD_REPLACE + +check_result "% insmod test_modules/$MOD_REPLACE.ko replace_set=0 +livepatch: enabling patch '$MOD_REPLACE' +livepatch: '$MOD_REPLACE': initializing patching transition +livepatch: '$MOD_REPLACE': starting patching transition +livepatch: '$MOD_REPLACE': completing patching transition +livepatch: '$MOD_REPLACE': patching complete +% insmod test_modules/$MOD_REPLACE2.ko replace_set=1 +livepatch: Livepatch patch ($MOD_REPLACE2) is not compatible with the already installed livepatches. +insmod: ERROR: could not insert module test_modules/$MOD_REPLACE2.ko: Invalid parameters +% echo 0 > /sys/kernel/livepatch/$MOD_REPLACE/enabled +livepatch: '$MOD_REPLACE': initializing unpatching transition +livepatch: '$MOD_REPLACE': starting unpatching transition +livepatch: '$MOD_REPLACE': completing unpatching transition +livepatch: '$MOD_REPLACE': unpatching complete +% rmmod $MOD_REPLACE" + +# - load a livepatch that modifies function A +# - loading another livepatch with the same replace_set that modifies +# the same function will succeed + +start_test "function conflict: the same replace_set" + +load_lp $MOD_REPLACE replace_set=0 +load_lp $MOD_REPLACE2 replace_set=0 +disable_lp $MOD_REPLACE2 +unload_lp $MOD_REPLACE2 +unload_lp $MOD_REPLACE + +check_result "% insmod test_modules/$MOD_REPLACE.ko replace_set=0 +livepatch: enabling patch '$MOD_REPLACE' +livepatch: '$MOD_REPLACE': initializing patching transition +livepatch: '$MOD_REPLACE': starting patching transition +livepatch: '$MOD_REPLACE': completing patching transition +livepatch: '$MOD_REPLACE': patching complete +% insmod test_modules/$MOD_REPLACE2.ko replace_set=0 +livepatch: enabling patch '$MOD_REPLACE2' +livepatch: '$MOD_REPLACE2': initializing patching transition +livepatch: '$MOD_REPLACE2': starting patching transition +livepatch: '$MOD_REPLACE2': completing patching transition +livepatch: '$MOD_REPLACE2': patching complete +% echo 0 > /sys/kernel/livepatch/$MOD_REPLACE2/enabled +livepatch: '$MOD_REPLACE2': initializing unpatching transition +livepatch: '$MOD_REPLACE2': starting unpatching transition +livepatch: '$MOD_REPLACE2': completing unpatching transition +livepatch: '$MOD_REPLACE2': unpatching complete +% rmmod $MOD_REPLACE2 +% rmmod $MOD_REPLACE" exit 0
tools/testing/selftests/livepatch/test_modules/Makefile +1 -0
@@ -2,6 +2,7 @@ TESTMODS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) KDIR ?= /lib/modules/$(shell uname -r)/build obj-m += test_klp_atomic_replace.o \ + test_klp_atomic_replace2.o \ test_klp_callbacks_busy.o \ test_klp_callbacks_demo.o \ test_klp_callbacks_demo2.o \
tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace2.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.52.0
Joe Lawrence
maintainerQuoted 89 lines · Yafang Shao
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 patch introduces '
replace_set' to provide finer-grained control over livepatch management. The core rules and behaviors of areplace_setare defined as follows:
- Livepatches sharing the samereplace_setcan mutually replace each other.
- Only one livepatch within a givenreplace_setcan be active at a time.
- Livepatches belonging to differentreplace_setscan coexist on the system.
- Livepatches in differentreplace_setsare prohibited from modifying the same function.
- Livepatches in differentreplace_setscannot use the same state ID.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_setmechanism 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
v2->v3:
- Address the feedback from Sachiko AI
- Fix the pre-existing NULL pointer dereference issue
- Moveklp_find_funcintocore.h
- Don't deprecatestack_ordercompletelyv2: https://lore.kernel.org/live-patching/[email protected]/
v1->v2:
- Incorporate feedback from Petr:
- Initializereplace_setto 0 by default
- Improve documentation
- Enforce that livepatches in differentreplace_setscannot use the samestate->id.- Enforce that livepatches in different
replace_setscannot modify the same function.
- Ensure consistent capitalization and naming usage ofKLP_REPLACE_SET.
- Incorporate feedback from Sachiko AI:
- Skip theklp_transitionpatch duringklp_force_transition().v1 (RFC): https://lore.kernel.org/live-patching/[email protected]/
Yafang Shao (7):
livepatch: Fix NULL pointer dereference inklp_find_func()
livepatch: Moveklp_find_func()intocore.h
livepatch: Support scoped atomic replace usingreplace_set
livepatch: Deprecatestack_orderselftests/livepatch: Update tests forreplace_setselftests/livepatch: Add test for state ID conflict across
replace_sets
selftests/livepatch: Add test for function conflict across
replace_sets.../ABI/removed/sysfs-kernel-livepatch | 9 + .../ABI/testing/sysfs-kernel-livepatch | 14 +- .../livepatch/cumulative-patches.rst | 23 ++- Documentation/livepatch/livepatch.rst | 21 ++- include/linux/livepatch.h | 5 +- kernel/livepatch/core.c | 65 ++----- kernel/livepatch/core.h | 21 +++ kernel/livepatch/state.c | 51 ++++-- kernel/livepatch/transition.c | 11 +- scripts/livepatch/init.c | 6 +- scripts/livepatch/klp-build | 16 +- .../selftests/livepatch/test-callbacks.sh | 33 ++-- .../selftests/livepatch/test-livepatch.sh | 159 +++++++---------- .../testing/selftests/livepatch/test-state.sh | 34 ++++ .../testing/selftests/livepatch/test-sysfs.sh | 91 ++-------- .../selftests/livepatch/test_modules/Makefile | 2 + .../test_modules/test_klp_atomic_replace.c | 10 +- .../test_modules/test_klp_atomic_replace2.c | 55 ++++++ .../test_modules/test_klp_callbacks_demo.c | 6 + .../test_modules/test_klp_callbacks_demo2.c | 10 +-
Quoted 12 lines
.../test_modules/test_klp_livepatch.c | 6 + .../livepatch/test_modules/test_klp_state.c | 4 +- .../livepatch/test_modules/test_klp_state2.c | 4 +- .../livepatch/test_modules/test_klp_state4.c | 163 ++++++++++++++++++ 24 files changed, 507 insertions(+), 312 deletions(-) create mode 100644 Documentation/ABI/removed/sysfs-kernel-livepatch create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace2.c create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_state4.cSignature · 1 line
2.52.0
Hi Yafang,
Thanks for implementing this. Supporting both replace and non-replace style patches has always been a headache for me when reading through the code, or worse, actual end user cases. A few minor nitpicks:
After applying the series, Documentation/livepatch/system-state.rst still references the old non-replace model. Section 2 states that "Non-cumulative livepatches are allowed to touch already modified system states," which is no longer true. The introductions in both system-state.rst and cumulative-patches.rst also frame atomic replace as opt-in. Petr's proposed documentation rewrites cover some of this, but system-state.rst section 2 needs updating as well.
See also my replies to specific patches/replies, mainly around the supercedes feature discussion.
--
Joe
Quoted 110 lines · Joe Lawrence
Quoted 98 lines · Yafang Shao
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 patch introduces '
replace_set' to provide finer-grained control over livepatch management. The core rules and behaviors of areplace_setare defined as follows:
- Livepatches sharing the samereplace_setcan mutually replace each other.
- Only one livepatch within a givenreplace_setcan be active at a time.
- Livepatches belonging to differentreplace_setscan coexist on the system.
- Livepatches in differentreplace_setsare prohibited from modifying the same function.
- Livepatches in differentreplace_setscannot use the same state ID.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_setmechanism 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
v2->v3:
- Address the feedback from Sachiko AI
- Fix the pre-existing NULL pointer dereference issue
- Moveklp_find_funcintocore.h
- Don't deprecatestack_ordercompletelyv2: https://lore.kernel.org/live-patching/[email protected]/
v1->v2:
- Incorporate feedback from Petr:
- Initializereplace_setto 0 by default
- Improve documentation
- Enforce that livepatches in differentreplace_setscannot use the samestate->id.- Enforce that livepatches in different
replace_setscannot modify the same function.
- Ensure consistent capitalization and naming usage ofKLP_REPLACE_SET.
- Incorporate feedback from Sachiko AI:
- Skip theklp_transitionpatch duringklp_force_transition().v1 (RFC): https://lore.kernel.org/live-patching/[email protected]/
Yafang Shao (7):
livepatch: Fix NULL pointer dereference inklp_find_func()
livepatch: Moveklp_find_func()intocore.h
livepatch: Support scoped atomic replace usingreplace_set
livepatch: Deprecatestack_orderselftests/livepatch: Update tests forreplace_setselftests/livepatch: Add test for state ID conflict across
replace_sets
selftests/livepatch: Add test for function conflict across
replace_sets.../ABI/removed/sysfs-kernel-livepatch | 9 + .../ABI/testing/sysfs-kernel-livepatch | 14 +- .../livepatch/cumulative-patches.rst | 23 ++- Documentation/livepatch/livepatch.rst | 21 ++- include/linux/livepatch.h | 5 +- kernel/livepatch/core.c | 65 ++----- kernel/livepatch/core.h | 21 +++ kernel/livepatch/state.c | 51 ++++-- kernel/livepatch/transition.c | 11 +- scripts/livepatch/init.c | 6 +- scripts/livepatch/klp-build | 16 +- .../selftests/livepatch/test-callbacks.sh | 33 ++-- .../selftests/livepatch/test-livepatch.sh | 159 +++++++---------- .../testing/selftests/livepatch/test-state.sh | 34 ++++ .../testing/selftests/livepatch/test-sysfs.sh | 91 ++-------- .../selftests/livepatch/test_modules/Makefile | 2 + .../test_modules/test_klp_atomic_replace.c | 10 +- .../test_modules/test_klp_atomic_replace2.c | 55 ++++++ .../test_modules/test_klp_callbacks_demo.c | 6 + .../test_modules/test_klp_callbacks_demo2.c | 10 +- .../test_modules/test_klp_livepatch.c | 6 + .../livepatch/test_modules/test_klp_state.c | 4 +- .../livepatch/test_modules/test_klp_state2.c | 4 +- .../livepatch/test_modules/test_klp_state4.c | 163 ++++++++++++++++++ 24 files changed, 507 insertions(+), 312 deletions(-) create mode 100644 Documentation/ABI/removed/sysfs-kernel-livepatch create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_atomic_replace2.c create mode 100644 tools/testing/selftests/livepatch/test_modules/test_klp_state4.cQuoted 3 lines
--
2.52.0Hi Yafang,
Thanks for implementing this. Supporting both replace and non-replace style patches has always been a headache for me when reading through the code, or worse, actual end user cases. A few minor nitpicks:
Quoted 7 lines
After applying the series,
Documentation/livepatch/system-state.rststill references the old non-replace model. Section 2 states that "Non-cumulative livepatches are allowed to touch already modified system states," which is no longer true. The introductions in bothsystem-state.rstandcumulative-patches.rstalso frame atomic replace as opt-in. Petr's proposed documentation rewrites cover some of this, butsystem-state.rstsection 2 needs updating as well.
Thanks for your suggestion. I will rewrite it to adapt to this new replace_set.
Quoted 3 lines
See also my replies to specific patches/replies, mainly around the supercedes feature discussion.
Thanks for your review!
Signature · 2 lines
Regards Yafang