Live Patching
 help / color / mirror / Atom feed
* [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch
@ 2024-09-25  6:40 Wardenjohn
  2024-09-25  6:40 ` [PATCH] " Wardenjohn
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Wardenjohn @ 2024-09-25  6:40 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel

As previous discussion, maintainers think that patch-level sysfs interface is the
only acceptable way to maintain the information of the order that klp_patch is 
applied to the system.

However, the previous patch introduce klp_ops into klp_func is a optimization 
methods of the patch introducing 'using' feature to klp_func.

But now, we don't support 'using' feature to klp_func and make 'klp_ops' patch
not necessary.

Therefore, this new version is only introduce the sysfs feature of klp_patch 
'stack_order'.

V1 -> V2:
1. According to the suggestion from Petr, to make the meaning more clear, rename
'order' to 'stack_order'.
2. According to the suggestion from Petr and Miroslav, this patch now move the 
calculating process to stack_order_show function. Adding klp_mutex lock protection.

Regards.
Wardenjohn.

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

* [PATCH] livepatch: introduce 'stack_order' sysfs interface to klp_patch
  2024-09-25  6:40 [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Wardenjohn
@ 2024-09-25  6:40 ` Wardenjohn
  2024-09-27 14:11   ` Miroslav Benes
  2024-09-25  6:40 ` [PATCH] Documentation: Add description to stack_order interface Wardenjohn
  2024-09-25 13:08 ` [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Marcos Paulo de Souza
  2 siblings, 1 reply; 9+ messages in thread
From: Wardenjohn @ 2024-09-25  6:40 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel, Wardenjohn

This feature can provide livepatch patch order information.
With the order of sysfs interface of one klp_patch, we can
use patch order to find out which function of the patch is
now activate.

After the discussion, we decided that patch-level sysfs
interface is the only accaptable way to introduce this
information.

This feature is like:
cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
means this livepatch_1 module is the 1st klp patch applied.

cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
means this lviepatch_module is the Nth klp patch applied
to the system.

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>

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index ecbc9b6aba3a..914b7cabf8fe 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -346,6 +346,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>/stack_order
  * /sys/kernel/livepatch/<patch>/<object>
  * /sys/kernel/livepatch/<patch>/<object>/patched
  * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -443,13 +444,37 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
 	return count;
 }
 
+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);
+
+	/* make sure the calculate of patch order correct */
+	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 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,
+	&stack_order_kobj_attr.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(klp_patch);
-- 
2.18.2


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

* [PATCH] Documentation: Add description to stack_order interface
  2024-09-25  6:40 [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Wardenjohn
  2024-09-25  6:40 ` [PATCH] " Wardenjohn
@ 2024-09-25  6:40 ` Wardenjohn
  2024-09-27 13:49   ` Miroslav Benes
  2024-09-25 13:08 ` [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Marcos Paulo de Souza
  2 siblings, 1 reply; 9+ messages in thread
From: Wardenjohn @ 2024-09-25  6:40 UTC (permalink / raw)
  To: jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel, Wardenjohn

Update description of klp_patch stack_order sysfs interface to
livepatch ABI documentation.

Signed-off-by: Wardenjohn <zhangwarden@gmail.com>

diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch
index a5df9b4910dc..9cad725a69c7 100644
--- a/Documentation/ABI/testing/sysfs-kernel-livepatch
+++ b/Documentation/ABI/testing/sysfs-kernel-livepatch
@@ -47,6 +47,14 @@ Description:
 		disabled when the feature is used. See
 		Documentation/livepatch/livepatch.rst for more information.
 
+What:           /sys/kernel/livepatch/<patch>/stack_order
+Date:           Sep 2024
+KernelVersion:  6.12.0
+Contact:        live-patching@vger.kernel.org
+Description:
+		This attribute record the stack order of this livepatch module
+		applied to the running system.
+
 What:		/sys/kernel/livepatch/<patch>/<object>
 Date:		Nov 2014
 KernelVersion:	3.19.0
-- 
2.18.2


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

* Re: [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch
  2024-09-25  6:40 [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Wardenjohn
  2024-09-25  6:40 ` [PATCH] " Wardenjohn
  2024-09-25  6:40 ` [PATCH] Documentation: Add description to stack_order interface Wardenjohn
@ 2024-09-25 13:08 ` Marcos Paulo de Souza
  2024-09-26 11:23   ` zhang warden
  2 siblings, 1 reply; 9+ messages in thread
From: Marcos Paulo de Souza @ 2024-09-25 13:08 UTC (permalink / raw)
  To: Wardenjohn, jpoimboe, mbenes, jikos, pmladek, joe.lawrence
  Cc: live-patching, linux-kernel

On Wed, 2024-09-25 at 14:40 +0800, Wardenjohn wrote:
> As previous discussion, maintainers think that patch-level sysfs
> interface is the
> only acceptable way to maintain the information of the order that
> klp_patch is 
> applied to the system.
> 
> However, the previous patch introduce klp_ops into klp_func is a
> optimization 
> methods of the patch introducing 'using' feature to klp_func.
> 
> But now, we don't support 'using' feature to klp_func and make
> 'klp_ops' patch
> not necessary.
> 
> Therefore, this new version is only introduce the sysfs feature of
> klp_patch 
> 'stack_order'.

The approach seems ok to me, but I would like to see selftests for this
new attribute. We have been trying to add more and more selftests for
existing known behavior, so IMO adding a new attribute should contain a
new test to exercise the correct behavior.

Other than that, for the series:

 Acked-by: Marcos Paulo de Souza <mpdesouza@suse.com>

> 
> V1 -> V2:
> 1. According to the suggestion from Petr, to make the meaning more
> clear, rename
> 'order' to 'stack_order'.
> 2. According to the suggestion from Petr and Miroslav, this patch now
> move the 
> calculating process to stack_order_show function. Adding klp_mutex
> lock protection.
> 
> Regards.
> Wardenjohn.
> 


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

* Re: [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch
  2024-09-25 13:08 ` [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Marcos Paulo de Souza
@ 2024-09-26 11:23   ` zhang warden
  0 siblings, 0 replies; 9+ messages in thread
From: zhang warden @ 2024-09-26 11:23 UTC (permalink / raw)
  To: Marcos Paulo de Souza
  Cc: Josh Poimboeuf, Miroslav Benes, Jiri Kosina, Petr Mladek,
	Joe Lawrence, live-patching, linux-kernel


> On Sep 25, 2024, at 21:08, Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
> 
> On Wed, 2024-09-25 at 14:40 +0800, Wardenjohn wrote:
>> As previous discussion, maintainers think that patch-level sysfs
>> interface is the
>> only acceptable way to maintain the information of the order that
>> klp_patch is 
>> applied to the system.
>> 
>> However, the previous patch introduce klp_ops into klp_func is a
>> optimization 
>> methods of the patch introducing 'using' feature to klp_func.
>> 
>> But now, we don't support 'using' feature to klp_func and make
>> 'klp_ops' patch
>> not necessary.
>> 
>> Therefore, this new version is only introduce the sysfs feature of
>> klp_patch 
>> 'stack_order'.
> 
> The approach seems ok to me, but I would like to see selftests for this
> new attribute. We have been trying to add more and more selftests for
> existing known behavior, so IMO adding a new attribute should contain a
> new test to exercise the correct behavior.
> 
> Other than that, for the series:
> 
> Acked-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> 

Hi, Macros!

Thanks a lot.

I will add selftest case for it as soon as possible.

Regards.
Wardenjohn.

(This email is resent because it seemed not sent to LKML...)

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

* Re: [PATCH] Documentation: Add description to stack_order interface
  2024-09-25  6:40 ` [PATCH] Documentation: Add description to stack_order interface Wardenjohn
@ 2024-09-27 13:49   ` Miroslav Benes
  0 siblings, 0 replies; 9+ messages in thread
From: Miroslav Benes @ 2024-09-27 13:49 UTC (permalink / raw)
  To: Wardenjohn
  Cc: jpoimboe, jikos, pmladek, joe.lawrence, live-patching,
	linux-kernel

On Wed, 25 Sep 2024, Wardenjohn wrote:

> Update description of klp_patch stack_order sysfs interface to
> livepatch ABI documentation.
> 
> Signed-off-by: Wardenjohn <zhangwarden@gmail.com>
> 
> diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch
> index a5df9b4910dc..9cad725a69c7 100644
> --- a/Documentation/ABI/testing/sysfs-kernel-livepatch
> +++ b/Documentation/ABI/testing/sysfs-kernel-livepatch
> @@ -47,6 +47,14 @@ Description:
>  		disabled when the feature is used. See
>  		Documentation/livepatch/livepatch.rst for more information.
>  
> +What:           /sys/kernel/livepatch/<patch>/stack_order
> +Date:           Sep 2024
> +KernelVersion:  6.12.0
> +Contact:        live-patching@vger.kernel.org
> +Description:
> +		This attribute record the stack order of this livepatch module
> +		applied to the running system.

"The attribute holds the stack order of a live patch module applied to the 
running system." ?

Please also squash the patch into the previous one. It belongs there.

Thank you,
Miroslav

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

* Re: [PATCH] livepatch: introduce 'stack_order' sysfs interface to klp_patch
  2024-09-25  6:40 ` [PATCH] " Wardenjohn
@ 2024-09-27 14:11   ` Miroslav Benes
  2024-09-29  1:51     ` zhang warden
  2024-09-29 14:47     ` zhang warden
  0 siblings, 2 replies; 9+ messages in thread
From: Miroslav Benes @ 2024-09-27 14:11 UTC (permalink / raw)
  To: Wardenjohn
  Cc: jpoimboe, jikos, pmladek, joe.lawrence, live-patching,
	linux-kernel

Hi,

I would change the subject to something like

"livepatch: Add "stack_order" sysfs attribute"

to keep it somehow consistent with what we have there so far.

On Wed, 25 Sep 2024, Wardenjohn wrote:

> This feature can provide livepatch patch order information.
> With the order of sysfs interface of one klp_patch, we can
> use patch order to find out which function of the patch is
> now activate.
> 
> After the discussion, we decided that patch-level sysfs
> interface is the only accaptable way to introduce this
> information.
> 
> This feature is like:
> cat /sys/kernel/livepatch/livepatch_1/stack_order -> 1
> means this livepatch_1 module is the 1st klp patch applied.
> 
> cat /sys/kernel/livepatch/livepatch_module/stack_order -> N
> means this lviepatch_module is the Nth klp patch applied
> to the system.

Perhaps something like

"
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>
 
How do you prepare your patches?

"---" delimiter is missing here.

> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index ecbc9b6aba3a..914b7cabf8fe 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -346,6 +346,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>/stack_order
>   * /sys/kernel/livepatch/<patch>/<object>
>   * /sys/kernel/livepatch/<patch>/<object>/patched
>   * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
> @@ -443,13 +444,37 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
>  	return count;
>  }
>  
> +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);
> +
> +	/* make sure the calculate of patch order correct */

The comment is not necessary.

> +	mutex_lock(&klp_mutex);
> +
> +	klp_for_each_patch(patch) {
> +		stack_order++;
> +		if (patch == this_patch)
> +			break;
> +	}
> +
> +	mutex_unlock(&klp_mutex);

Please add an empty line before return here.

>+       return sysfs_emit(buf, "%d\n", stack_order);
>+}

Miroslav

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

* Re: [PATCH] livepatch: introduce 'stack_order' sysfs interface to klp_patch
  2024-09-27 14:11   ` Miroslav Benes
@ 2024-09-29  1:51     ` zhang warden
  2024-09-29 14:47     ` zhang warden
  1 sibling, 0 replies; 9+ messages in thread
From: zhang warden @ 2024-09-29  1:51 UTC (permalink / raw)
  To: Miroslav Benes
  Cc: Josh Poimboeuf, Jiri Kosina, Petr Mladek, Joe Lawrence,
	live-patching, linux-kernel

Hi, Miroslav!
> 
> Perhaps something like
> 
> "
> 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>
> 
> How do you prepare your patches?
> 
> "---" delimiter is missing here.

I will commit my changes with 'git commit -m' option.
Then, I use 'git format-patch' to generate my patches.
After my patches is ready, I would use 'git send-email' to 
send my directory containing my patches and cover letter.

Is there any step I missed?

> 
>> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
>> index ecbc9b6aba3a..914b7cabf8fe 100644
>> --- a/kernel/livepatch/core.c
>> +++ b/kernel/livepatch/core.c
>> @@ -346,6 +346,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>/stack_order
>>  * /sys/kernel/livepatch/<patch>/<object>
>>  * /sys/kernel/livepatch/<patch>/<object>/patched
>>  * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
>> @@ -443,13 +444,37 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
>> return count;
>> }
>> 
>> +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);
>> +
>> + /* make sure the calculate of patch order correct */
> 
> The comment is not necessary.
> 
>> + mutex_lock(&klp_mutex);
>> +
>> + klp_for_each_patch(patch) {
>> + stack_order++;
>> + if (patch == this_patch)
>> + break;
>> + }
>> +
>> + mutex_unlock(&klp_mutex);
> 
> Please add an empty line before return here.
> 
>> +       return sysfs_emit(buf, "%d\n", stack_order);
>> +}
> 
> Miroslav

And the rest of the suggestions will be fix in the next version.

Regards.
Wardenjohn.


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

* Re: [PATCH] livepatch: introduce 'stack_order' sysfs interface to klp_patch
  2024-09-27 14:11   ` Miroslav Benes
  2024-09-29  1:51     ` zhang warden
@ 2024-09-29 14:47     ` zhang warden
  1 sibling, 0 replies; 9+ messages in thread
From: zhang warden @ 2024-09-29 14:47 UTC (permalink / raw)
  To: Miroslav Benes
  Cc: Josh Poimboeuf, Jiri Kosina, Petr Mladek, Joe Lawrence,
	live-patching, linux-kernel


Hi, Miroslav!
> On Sep 27, 2024, at 22:11, Miroslav Benes <mbenes@suse.cz> wrote:
> 
> 
> How do you prepare your patches?
> 
> "---" delimiter is missing here.

I seem to found out what cause this problem.

I seemed to use 'git format-patch' with '-p' option which
will make my patch have no diff state.

Sorry for this. A newer version was sent again.
Please review the V3 patch.

Thank you!
Wardenjohn.

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

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

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-25  6:40 [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Wardenjohn
2024-09-25  6:40 ` [PATCH] " Wardenjohn
2024-09-27 14:11   ` Miroslav Benes
2024-09-29  1:51     ` zhang warden
2024-09-29 14:47     ` zhang warden
2024-09-25  6:40 ` [PATCH] Documentation: Add description to stack_order interface Wardenjohn
2024-09-27 13:49   ` Miroslav Benes
2024-09-25 13:08 ` [PATCH 0/2] livepatch: introduce 'stack_order' sysfs interface to klp_patch Marcos Paulo de Souza
2024-09-26 11:23   ` zhang warden

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