Skip to contentSkip to conversation

livepatch: Add "stack_order" sysfs attribute

PATCH Superseded Wardenjohn 4 participants 11 messages Sep 29, 2024 – Oct 6, 2024 1 message not in the archive Live patching

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Wardenjohn

author
#0 lore raw

v3 cover livepatch: Add "stack_order" sysfs attribute

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.

V2 -> V3:
1. Squash 2 patches into 1. Update description of stack_order in ABI Document. (Suggested by Miroslav)
2. Update subject and commit log. (Suggested by Miroslav)
3. Update code format for some line of the patch. (Suggested by Miroslav)

Regards.
Wardenjohn.

author
#1 lore raw

PATCH v3 1/1 livepatch: Add "stack_order" sysfs attribute

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

---
 .../ABI/testing/sysfs-kernel-livepatch        |  8 ++++++
 kernel/livepatch/core.c                       | 25 +++++++++++++++++++
 2 files changed, 33 insertions(+)
Documentation/ABI/testing/sysfs-kernel-livepatch +8 -0
index a5df9b4910dc..2a60b49aa9a5 100644
@@ -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:        [email protected]
+Description:
+		This attribute holds the stack order of a livepatch module applied
+		to the running system.
+
 What:		/sys/kernel/livepatch/<patch>/<object>
 Date:		Nov 2014
 KernelVersion:	3.19.0
kernel/livepatch/core.c +25 -0
index ecbc9b6aba3a..30ab3668c59e 100644
@@ -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);
+
+	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);
Signature · 1 line
2.18.2
maintainer
#2 lore raw
Quoted 26 lines · 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

---
 .../ABI/testing/sysfs-kernel-livepatch        |  8 ++++++
 kernel/livepatch/core.c                       | 25 +++++++++++++++++++
 2 files changed, 33 insertions(+)
Documentation/ABI/testing/sysfs-kernel-livepatch +0 -0
index a5df9b4910dc..2a60b49aa9a5 100644

Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 52

Quoted 6 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +3 -0
@@ -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

These will probably need to be updated (can probably be done by Petr when applying).

Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 56

Quoted 4 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +4 -0
+Contact:        [email protected]
+Description:
+		This attribute holds the stack order of a livepatch module applied
+		to the running system.

It's probably a good idea to clarify what "stack order" means. Also, try to keep the text under 80 columns for consistency.

How about:

This attribute indicates the order the patch was applied compared to other patches. For example, a stack_order value of '2' indicates the patch was applied after the patch with stack order '1' and before any other currently applied patches.

Signature · 1 line
Josh
#3 lore raw

Hi, Josh!

Quoted 10 lines · Josh Poimboeuf
Quoted 9 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +0 -0
index a5df9b4910dc..2a60b49aa9a5 100644
@@ -47,6 +47,14 @@ 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 3 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +3 -0
+What:           /sys/kernel/livepatch/<patch>/stack_order
+Date:           Sep 2024
+KernelVersion:  6.12.0

These will probably need to be updated (can probably be done by Petr when applying).

True, kernel version may need Petr to decide.

Quoted 8 lines

Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 56

Quoted 4 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +4 -0
+Contact:        [email protected]
+Description:
+ This attribute holds the stack order of a livepatch module applied
+ to the running system.

It's probably a good idea to clarify what "stack order" means. Also, try to keep the text under 80 columns for consistency.

Quoted 7 lines

How about:

This attribute indicates the order the patch was applied compared to other patches. For example, a stack_order value of '2' indicates the patch was applied after the patch with stack order '1' and before any other currently applied patches.

Or how about:

This attribute indicates the order of the livepatch module applied to the system. The stack_order value N means that this module is the Nth applied to the system. If there are serval patches changing the same function, the function version of the biggest stack_order is enabling in the system.

Regards.
Wardenjohn.

maintainer
#4 lore raw
Quoted 12 lines · zhang warden

Hi, Josh!

Quoted 10 lines · Josh Poimboeuf
Quoted 9 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +0 -0
index a5df9b4910dc..2a60b49aa9a5 100644
@@ -47,6 +47,14 @@ Description:

disabled when the feature is used. See Documentation/livepatch/livepatch.rst for more information.

Quoted 8 lines
Quoted 7 lines

Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 52

Quoted 3 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +3 -0
+What:           /sys/kernel/livepatch/<patch>/stack_order
+Date:           Sep 2024
+KernelVersion:  6.12.0

These will probably need to be updated (can probably be done by Petr when applying).

True, kernel version may need Petr to decide.

It would be for 6.13 if the changes are accepted in time before the next merge window.

Also please rebase the patch on top of current Linus' master or v6.11. There are conflicts with the commit adb68ed26a3e922 ("livepatch: Add "replace" sysfs attribute").

Quoted 16 lines
Quoted 8 lines

Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 56

Quoted 4 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +4 -0
+Contact:        [email protected]
+Description:
+ This attribute holds the stack order of a livepatch module applied
+ to the running system.

It's probably a good idea to clarify what "stack order" means. Also, try to keep the text under 80 columns for consistency.

Quoted 7 lines

How about:

This attribute indicates the order the patch was applied compared to other patches. For example, a stack_order value of '2' indicates the patch was applied after the patch with stack order '1' and before any other currently applied patches.

Quoted 7 lines

Or how about:

This attribute indicates the order of the livepatch module applied to the system. The stack_order value N means that this module is the Nth applied to the system. If there are serval patches changing the same function, the function version of the biggest stack_order is enabling in the system.

The 2nd sentence looks superfluous. The 3rd sentence explains the important effect.

Well, the part "is enabling in the system" is a bit cryptic. I would write something like:

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 highest stack order is used, unless a transition is currently in progress.

Best Regards,
Petr

#5 lore raw

Hi, Petr.

Quoted 4 lines

Also please rebase the patch on top of current Linus' master or v6.11. There are conflicts with the commit adb68ed26a3e922 ("livepatch: Add "replace" sysfs attribute").

OK, will fix it.

Quoted 27 lines
Quoted 16 lines
Quoted 8 lines

Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 56

Quoted 4 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +4 -0
+Contact:        [email protected]
+Description:
+ This attribute holds the stack order of a livepatch module applied
+ to the running system.

It's probably a good idea to clarify what "stack order" means. Also, try to keep the text under 80 columns for consistency.

Quoted 7 lines

How about:

This attribute indicates the order the patch was applied compared to other patches. For example, a stack_order value of '2' indicates the patch was applied after the patch with stack order '1' and before any other currently applied patches.

Quoted 7 lines

Or how about:

This attribute indicates the order of the livepatch module applied to the system. The stack_order value N means that this module is the Nth applied to the system. If there are serval patches changing the same function, the function version of the biggest stack_order is enabling in the system.

The 2nd sentence looks superfluous. The 3rd sentence explains the important effect.

Quoted 7 lines

Well, the part "is enabling in the system" is a bit cryptic. I would write something like:

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 highest stack order is used, unless a transition is currently in progress.

This description looks good to me. What's the suggestion of other maintainers ?

Regards.
Wardenjohn.

maintainer
#6 lore raw
Quoted 7 lines · zhang warden
Quoted 4 lines

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 highest stack order is used, unless a transition is currently in progress.

This description looks good to me. What's the suggestion of other maintainers ?

I like it, though "highest stack order" is still a bit arbitrary, since the highest stack order is actually the lowest number.

Signature · 1 line
Josh
#7 lore raw
Quoted 10 lines · Josh Poimboeuf
Quoted 5 lines · zhang warden
Quoted 4 lines

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 highest stack order is used, unless a transition is currently in progress.

Quoted 8 lines
Quoted 2 lines

This description looks good to me. What's the suggestion of other maintainers ?

I like it, though "highest stack order" is still a bit arbitrary, since the highest stack order is actually the lowest number.

Signature · 1 line
Josh

How about:

This attribute specifies the sequence in which live patch module 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.

Regards.
Wardenjohn.

maintainer
#8 lore raw
In reply to Wardenjohn

Hello,

Quoted 4 lines · Wardenjohn

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.

Quoted 8 lines

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'.

could you also include the selftests as discussed before, please?

Miroslav

A message that is not in the archive (sent off-list or not yet received): CADDyLDU4Hsp-FCjocEyfEmY6-JOKeH+YjsBfUr+xbO=opOEhgw@mail.gmail.com

maintainer
#10 lore raw
Quoted 5 lines · zhang warden

Hi,Miroslav.

Quoted 1 line

could you also include the selftests as discussed before, please?

Should I submit the selftests in one patch?

I would put it into a separate patch from the patch adding the "stack_order" attribute.

You might split the selftests into more patches if many selftests are added.

Best Regards,
Petr

#11 lore raw
In reply to Miroslav Benes

Hi, Miroslav.

Quoted 7 lines · Miroslav Benes

Hello,

could you also include the selftests as discussed before, please?

Miroslav

Should I include selftests in one patch?

Regards.
Wardenjohn.