mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
@ 2024-10-24  4:43 Wardenjohn
  2024-10-24  4:43 ` [PATCH V2] selftests: livepatch: add test cases of stack_order sysfs interface Wardenjohn
  2024-10-24  8:15 ` [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute Petr Mladek
  0 siblings, 2 replies; 10+ messages in thread
From: Wardenjohn @ 2024-10-24  4:43 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel, Wardenjohn

Add "stack_order" sysfs attribute which holds the order in which a live
patch module was loaded into the system. A user can then determine an
active live patched version of a function.

cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1

means that livepatch_1 is the first live patch applied

cat /sys/kernel/livepatch/livepatch_module/stack_order -> N

means that livepatch_module is the Nth live patch applied

Suggested-by: Petr Mladek <pmladek@suse.com>
Suggested-by: Miroslav Benes <mbenes@suse.cz>
Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
---
 .../ABI/testing/sysfs-kernel-livepatch        |  9 +++++++
 kernel/livepatch/core.c                       | 24 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch
index 3735d868013d..73e40d02345e 100644
--- a/Documentation/ABI/testing/sysfs-kernel-livepatch
+++ b/Documentation/ABI/testing/sysfs-kernel-livepatch
@@ -55,6 +55,15 @@ Description:
 		An attribute which indicates whether the patch supports
 		atomic-replace.
 
+What:		/sys/kernel/livepatch/<patch>/stack_order
+Date:		Oct 2024
+KernelVersion:	6.13.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
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 3c21c31796db..0cd39954d5a1 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -347,6 +347,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
+ * /sys/kernel/livepatch/<patch>/stack_order
  * /sys/kernel/livepatch/<patch>/<object>
  * /sys/kernel/livepatch/<patch>/<object>/patched
  * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -452,15 +453,38 @@ static ssize_t replace_show(struct kobject *kobj,
 	return sysfs_emit(buf, "%d\n", patch->replace);
 }
 
+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);
+}
+
 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 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,
+	&stack_order_kobj_attr.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(klp_patch);
-- 
2.18.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH V2] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-24  4:43 [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute Wardenjohn
@ 2024-10-24  4:43 ` Wardenjohn
  2024-10-24  8:20   ` Petr Mladek
  2024-10-24  8:15 ` [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute Petr Mladek
  1 sibling, 1 reply; 10+ messages in thread
From: Wardenjohn @ 2024-10-24  4:43 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel, Wardenjohn

Add selftest test cases to sysfs attribute 'stack_order'.

Suggested-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
---
 .../testing/selftests/livepatch/test-sysfs.sh | 71 +++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/tools/testing/selftests/livepatch/test-sysfs.sh b/tools/testing/selftests/livepatch/test-sysfs.sh
index 05a14f5a7bfb..718027cc3aba 100755
--- a/tools/testing/selftests/livepatch/test-sysfs.sh
+++ b/tools/testing/selftests/livepatch/test-sysfs.sh
@@ -5,6 +5,8 @@
 . $(dirname $0)/functions.sh
 
 MOD_LIVEPATCH=test_klp_livepatch
+MOD_LIVEPATCH2=test_klp_callbacks_demo
+MOD_LIVEPATCH3=test_klp_syscall
 
 setup_config
 
@@ -21,6 +23,8 @@ check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------"
 check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--"
 check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--"
 check_sysfs_value  "$MOD_LIVEPATCH" "transition" "0"
+check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--"
+check_sysfs_value  "$MOD_LIVEPATCH" "stack_order" "1"
 check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--"
 check_sysfs_value  "$MOD_LIVEPATCH" "vmlinux/patched" "1"
 
@@ -131,4 +135,71 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition
 livepatch: '$MOD_LIVEPATCH': unpatching complete
 % rmmod $MOD_LIVEPATCH"
 
+start_test "sysfs test stack_order value"
+
+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
+
+check_sysfs_value  "$MOD_LIVEPATCH3" "stack_order" "3"
+
+disable_lp $MOD_LIVEPATCH2
+unload_lp $MOD_LIVEPATCH2
+
+check_sysfs_value  "$MOD_LIVEPATCH" "stack_order" "1"
+check_sysfs_value  "$MOD_LIVEPATCH3" "stack_order" "2"
+
+disable_lp $MOD_LIVEPATCH3
+unload_lp $MOD_LIVEPATCH3
+
+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
+livepatch: '$MOD_LIVEPATCH': starting patching transition
+livepatch: '$MOD_LIVEPATCH': completing patching transition
+livepatch: '$MOD_LIVEPATCH': patching complete
+% insmod test_modules/$MOD_LIVEPATCH2.ko
+livepatch: enabling patch '$MOD_LIVEPATCH2'
+livepatch: '$MOD_LIVEPATCH2': initializing patching transition
+$MOD_LIVEPATCH2: pre_patch_callback: vmlinux
+livepatch: '$MOD_LIVEPATCH2': starting patching transition
+livepatch: '$MOD_LIVEPATCH2': completing patching transition
+$MOD_LIVEPATCH2: post_patch_callback: vmlinux
+livepatch: '$MOD_LIVEPATCH2': patching complete
+% insmod test_modules/$MOD_LIVEPATCH3.ko
+livepatch: enabling patch '$MOD_LIVEPATCH3'
+livepatch: '$MOD_LIVEPATCH3': initializing patching transition
+livepatch: '$MOD_LIVEPATCH3': starting patching transition
+livepatch: '$MOD_LIVEPATCH3': completing patching transition
+livepatch: '$MOD_LIVEPATCH3': patching complete
+% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH2/enabled
+livepatch: '$MOD_LIVEPATCH2': initializing unpatching transition
+$MOD_LIVEPATCH2: pre_unpatch_callback: vmlinux
+livepatch: '$MOD_LIVEPATCH2': starting unpatching transition
+livepatch: '$MOD_LIVEPATCH2': completing unpatching transition
+$MOD_LIVEPATCH2: post_unpatch_callback: vmlinux
+livepatch: '$MOD_LIVEPATCH2': unpatching complete
+% rmmod $MOD_LIVEPATCH2
+% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH3/enabled
+livepatch: '$MOD_LIVEPATCH3': initializing unpatching transition
+livepatch: '$MOD_LIVEPATCH3': starting unpatching transition
+livepatch: '$MOD_LIVEPATCH3': completing unpatching transition
+livepatch: '$MOD_LIVEPATCH3': unpatching complete
+% rmmod $MOD_LIVEPATCH3
+% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
+livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
+livepatch: '$MOD_LIVEPATCH': starting unpatching transition
+livepatch: '$MOD_LIVEPATCH': completing unpatching transition
+livepatch: '$MOD_LIVEPATCH': unpatching complete
+% rmmod $MOD_LIVEPATCH"
+
 exit 0
-- 
2.43.5


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
  2024-10-24  4:43 [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute Wardenjohn
  2024-10-24  4:43 ` [PATCH V2] selftests: livepatch: add test cases of stack_order sysfs interface Wardenjohn
@ 2024-10-24  8:15 ` Petr Mladek
  1 sibling, 0 replies; 10+ messages in thread
From: Petr Mladek @ 2024-10-24  8:15 UTC (permalink / raw)
  To: Wardenjohn
  Cc: jpoimboe, mbenes, jikos, joe.lawrence, live-patching, linux-kernel

On Thu 2024-10-24 12:43:16, Wardenjohn wrote:
> Add "stack_order" sysfs attribute which holds the order in which a live
> patch module was loaded into the system. A user can then determine an
> active live patched version of a function.
> 
> cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
> 
> means that livepatch_1 is the first live patch applied
> 
> cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
> 
> means that livepatch_module is the Nth live patch applied
> 
> Suggested-by: Petr Mladek <pmladek@suse.com>
> Suggested-by: Miroslav Benes <mbenes@suse.cz>
> Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>

This patch is the same as the one at
https://lore.kernel.org/r/20241008014856.3729-2-zhangwarden@gmail.com

So that we could add the already existing approvals:

Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-24  4:43 ` [PATCH V2] selftests: livepatch: add test cases of stack_order sysfs interface Wardenjohn
@ 2024-10-24  8:20   ` Petr Mladek
  2024-10-24  8:23     ` zhang warden
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Mladek @ 2024-10-24  8:20 UTC (permalink / raw)
  To: Wardenjohn
  Cc: jpoimboe, mbenes, jikos, joe.lawrence, live-patching, linux-kernel

On Thu 2024-10-24 12:43:17, Wardenjohn wrote:
> Add selftest test cases to sysfs attribute 'stack_order'.
> 
> Suggested-by: Petr Mladek <pmladek@suse.com>
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
> ---
>  .../testing/selftests/livepatch/test-sysfs.sh | 71 +++++++++++++++++++
>  1 file changed, 71 insertions(+)
> 
> diff --git a/tools/testing/selftests/livepatch/test-sysfs.sh b/tools/testing/selftests/livepatch/test-sysfs.sh
> index 05a14f5a7bfb..718027cc3aba 100755
> --- a/tools/testing/selftests/livepatch/test-sysfs.sh
> +++ b/tools/testing/selftests/livepatch/test-sysfs.sh
> @@ -5,6 +5,8 @@
>  . $(dirname $0)/functions.sh
>  
>  MOD_LIVEPATCH=test_klp_livepatch
> +MOD_LIVEPATCH2=test_klp_callbacks_demo
> +MOD_LIVEPATCH3=test_klp_syscall
>  
>  setup_config
>  
> @@ -21,6 +23,8 @@ check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------"
>  check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--"

Sigh, you moved it from some reason. My proposed diff added
"stack_order" here between "replace" and "transition" to follow
the alphabetical order.

>  check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--"
>  check_sysfs_value  "$MOD_LIVEPATCH" "transition" "0"
> +check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--"
> +check_sysfs_value  "$MOD_LIVEPATCH" "stack_order" "1"
>  check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--"
>  check_sysfs_value  "$MOD_LIVEPATCH" "vmlinux/patched" "1"

After fixing the alphabetical order:

Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>

I could fix the ordering when pushing the patch.

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V2] selftests: livepatch: add test cases of stack_order sysfs interface
  2024-10-24  8:20   ` Petr Mladek
@ 2024-10-24  8:23     ` zhang warden
  0 siblings, 0 replies; 10+ messages in thread
From: zhang warden @ 2024-10-24  8:23 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Josh Poimboeuf, Miroslav Benes, Jiri Kosina, Joe Lawrence,
	live-patching, linux-kernel



> On Oct 24, 2024, at 16:20, Petr Mladek <pmladek@suse.com> wrote:
> 
> On Thu 2024-10-24 12:43:17, Wardenjohn wrote:
>> Add selftest test cases to sysfs attribute 'stack_order'.
>> 
>> Suggested-by: Petr Mladek <pmladek@suse.com>
>> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
>> ---
>> .../testing/selftests/livepatch/test-sysfs.sh | 71 +++++++++++++++++++
>> 1 file changed, 71 insertions(+)
>> 
>> diff --git a/tools/testing/selftests/livepatch/test-sysfs.sh b/tools/testing/selftests/livepatch/test-sysfs.sh
>> index 05a14f5a7bfb..718027cc3aba 100755
>> --- a/tools/testing/selftests/livepatch/test-sysfs.sh
>> +++ b/tools/testing/selftests/livepatch/test-sysfs.sh
>> @@ -5,6 +5,8 @@
>> . $(dirname $0)/functions.sh
>> 
>> MOD_LIVEPATCH=test_klp_livepatch
>> +MOD_LIVEPATCH2=test_klp_callbacks_demo
>> +MOD_LIVEPATCH3=test_klp_syscall
>> 
>> setup_config
>> 
>> @@ -21,6 +23,8 @@ check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------"
>> check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--"
> 
> Sigh, you moved it from some reason. My proposed diff added
> "stack_order" here between "replace" and "transition" to follow
> the alphabetical order.
> 
>> check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--"
>> check_sysfs_value  "$MOD_LIVEPATCH" "transition" "0"
>> +check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--"
>> +check_sysfs_value  "$MOD_LIVEPATCH" "stack_order" "1"
>> check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--"
>> check_sysfs_value  "$MOD_LIVEPATCH" "vmlinux/patched" "1"
> 
> After fixing the alphabetical order:
> 
> Reviewed-by: Petr Mladek <pmladek@suse.com>
> Tested-by: Petr Mladek <pmladek@suse.com>
> 
> I could fix the ordering when pushing the patch.
> 
> Best Regards,
> Petr

OK, I use this order just according to the order added to this 
test case. Didn't consider the alphabetical order.

If necessary, I can resent a V3 patch.

Best Regards.
Wardenjohn.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
  2024-10-08  1:48 ` [PATCH V5 1/1] livepatch: Add stack_order " Wardenjohn
                     ` (2 preceding siblings ...)
  2024-10-11 11:20   ` Miroslav Benes
@ 2024-12-09 12:28   ` Petr Mladek
  3 siblings, 0 replies; 10+ messages in thread
From: Petr Mladek @ 2024-12-09 12:28 UTC (permalink / raw)
  To: Wardenjohn
  Cc: jpoimboe, mbenes, jikos, joe.lawrence, live-patching, linux-kernel

On Tue 2024-10-08 09:48:56, Wardenjohn wrote:
> Add "stack_order" sysfs attribute which holds the order in which a live
> patch module was loaded into the system. A user can then determine an
> active live patched version of a function.
> 
> cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
> 
> means that livepatch_1 is the first live patch applied
> 
> cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
> 
> means that livepatch_module is the Nth live patch applied
> 
> Suggested-by: Petr Mladek <pmladek@suse.com>
> Suggested-by: Miroslav Benes <mbenes@suse.cz>
> Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>

JFYI, the patch has been comitted into livepatching.git,
branch for-6.14/stack-order.

Note that I have updated the version in the ABI
documentation to 6.14.

Best Regards,
Petr

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
  2024-10-08  1:48 ` [PATCH V5 1/1] livepatch: Add stack_order " Wardenjohn
  2024-10-08 17:17   ` Josh Poimboeuf
  2024-10-11  8:55   ` Petr Mladek
@ 2024-10-11 11:20   ` Miroslav Benes
  2024-12-09 12:28   ` Petr Mladek
  3 siblings, 0 replies; 10+ messages in thread
From: Miroslav Benes @ 2024-10-11 11:20 UTC (permalink / raw)
  To: Wardenjohn
  Cc: jpoimboe, jikos, pmladek, joe.lawrence, live-patching, linux-kernel

On Tue, 8 Oct 2024, Wardenjohn wrote:

> Add "stack_order" sysfs attribute which holds the order in which a live
> patch module was loaded into the system. A user can then determine an
> active live patched version of a function.
> 
> cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
> 
> means that livepatch_1 is the first live patch applied
> 
> cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
> 
> means that livepatch_module is the Nth live patch applied
> 
> Suggested-by: Petr Mladek <pmladek@suse.com>
> Suggested-by: Miroslav Benes <mbenes@suse.cz>
> Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>

Reviewed-by: Miroslav Benes <mbenes@suse.cz>

M

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
  2024-10-08  1:48 ` [PATCH V5 1/1] livepatch: Add stack_order " Wardenjohn
  2024-10-08 17:17   ` Josh Poimboeuf
@ 2024-10-11  8:55   ` Petr Mladek
  2024-10-11 11:20   ` Miroslav Benes
  2024-12-09 12:28   ` Petr Mladek
  3 siblings, 0 replies; 10+ messages in thread
From: Petr Mladek @ 2024-10-11  8:55 UTC (permalink / raw)
  To: Wardenjohn
  Cc: jpoimboe, mbenes, jikos, joe.lawrence, live-patching, linux-kernel

On Tue 2024-10-08 09:48:56, Wardenjohn wrote:
> Add "stack_order" sysfs attribute which holds the order in which a live
> patch module was loaded into the system. A user can then determine an
> active live patched version of a function.
> 
> cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
> 
> means that livepatch_1 is the first live patch applied
> 
> cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
> 
> means that livepatch_module is the Nth live patch applied
> 
> Suggested-by: Petr Mladek <pmladek@suse.com>
> Suggested-by: Miroslav Benes <mbenes@suse.cz>
> Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>

Looks and works fine:

Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

PS: I'll wait for the selftest before pushing this change.
    It would be nice to send both patches together in a single
    thread.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
  2024-10-08  1:48 ` [PATCH V5 1/1] livepatch: Add stack_order " Wardenjohn
@ 2024-10-08 17:17   ` Josh Poimboeuf
  2024-10-11  8:55   ` Petr Mladek
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Josh Poimboeuf @ 2024-10-08 17:17 UTC (permalink / raw)
  To: Wardenjohn
  Cc: mbenes, jikos, pmladek, joe.lawrence, live-patching, linux-kernel

On Tue, Oct 08, 2024 at 09:48:56AM +0800, Wardenjohn wrote:
> Add "stack_order" sysfs attribute which holds the order in which a live
> patch module was loaded into the system. A user can then determine an
> active live patched version of a function.
> 
> cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
> 
> means that livepatch_1 is the first live patch applied
> 
> cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
> 
> means that livepatch_module is the Nth live patch applied
> 
> Suggested-by: Petr Mladek <pmladek@suse.com>
> Suggested-by: Miroslav Benes <mbenes@suse.cz>
> Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>

Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>

-- 
Josh

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
  2024-10-08  1:48 [PATCH V5 0/1] livepatch: Add "stack_order" " Wardenjohn
@ 2024-10-08  1:48 ` Wardenjohn
  2024-10-08 17:17   ` Josh Poimboeuf
                     ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Wardenjohn @ 2024-10-08  1:48 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel, Wardenjohn

Add "stack_order" sysfs attribute which holds the order in which a live
patch module was loaded into the system. A user can then determine an
active live patched version of a function.

cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1

means that livepatch_1 is the first live patch applied

cat /sys/kernel/livepatch/livepatch_module/stack_order -> N

means that livepatch_module is the Nth live patch applied

Suggested-by: Petr Mladek <pmladek@suse.com>
Suggested-by: Miroslav Benes <mbenes@suse.cz>
Suggested-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
---
 .../ABI/testing/sysfs-kernel-livepatch        |  9 +++++++
 kernel/livepatch/core.c                       | 24 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch
index 3735d868013d..73e40d02345e 100644
--- a/Documentation/ABI/testing/sysfs-kernel-livepatch
+++ b/Documentation/ABI/testing/sysfs-kernel-livepatch
@@ -55,6 +55,15 @@ Description:
 		An attribute which indicates whether the patch supports
 		atomic-replace.
 
+What:		/sys/kernel/livepatch/<patch>/stack_order
+Date:		Oct 2024
+KernelVersion:	6.13.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
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 3c21c31796db..0cd39954d5a1 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -347,6 +347,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
+ * /sys/kernel/livepatch/<patch>/stack_order
  * /sys/kernel/livepatch/<patch>/<object>
  * /sys/kernel/livepatch/<patch>/<object>/patched
  * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -452,15 +453,38 @@ static ssize_t replace_show(struct kobject *kobj,
 	return sysfs_emit(buf, "%d\n", patch->replace);
 }
 
+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);
+}
+
 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 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,
+	&stack_order_kobj_attr.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(klp_patch);
-- 
2.18.2


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-12-09 12:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-24  4:43 [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute Wardenjohn
2024-10-24  4:43 ` [PATCH V2] selftests: livepatch: add test cases of stack_order sysfs interface Wardenjohn
2024-10-24  8:20   ` Petr Mladek
2024-10-24  8:23     ` zhang warden
2024-10-24  8:15 ` [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute Petr Mladek
  -- strict thread matches above, loose matches on Subject: below --
2024-10-08  1:48 [PATCH V5 0/1] livepatch: Add "stack_order" " Wardenjohn
2024-10-08  1:48 ` [PATCH V5 1/1] livepatch: Add stack_order " Wardenjohn
2024-10-08 17:17   ` Josh Poimboeuf
2024-10-11  8:55   ` Petr Mladek
2024-10-11 11:20   ` Miroslav Benes
2024-12-09 12:28   ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome