livepatch: Add "stack_order" sysfs attribute
v5 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)
V3 -> V4:
1. Rebase the patch of to branch linux-master.
2. Update the description of ABI Document Description. (Suggested by Petr & Josh)
V4 -> V5:
1. Fix the typos from 'module' to 'modules' (found by Josh)
Regards.
Wardenjohn.
PATCH v5 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 | 9 +++++++ kernel/livepatch/core.c | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+)
Documentation/ABI/testing/sysfs-kernel-livepatch +9 -0
@@ -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
kernel/livepatch/core.c +24 -0
@@ -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);
Signature · 1 line
2.18.2
Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
Quoted 8 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-> 1means that
livepatch_1is the first live patch applied
Quoted 8 lines
cat
/sys/kernel/livepatch/livepatch_module/stack_order-> Nmeans that
livepatch_moduleis the Nth live patch appliedSuggested-by Petr Mladek <[email protected]>Suggested-by Miroslav Benes <[email protected]>Suggested-by Josh Poimboeuf <[email protected]>Signed-off-by Wardenjohn <[email protected]>
Signature · 1 line
Josh
Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
In reply to WardenjohnQuoted 8 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-> 1means that
livepatch_1is the first live patch applied
Quoted 8 lines
cat
/sys/kernel/livepatch/livepatch_module/stack_order-> Nmeans that
livepatch_moduleis the Nth live patch appliedSuggested-by Petr Mladek <[email protected]>Suggested-by Miroslav Benes <[email protected]>Suggested-by Josh Poimboeuf <[email protected]>Signed-off-by Wardenjohn <[email protected]>
Looks and works fine:
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.
Re: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
In reply to WardenjohnQuoted 8 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-> 1means that
livepatch_1is the first live patch applied
Quoted 8 lines
cat
/sys/kernel/livepatch/livepatch_module/stack_order-> Nmeans that
livepatch_moduleis the Nth live patch appliedSuggested-by Petr Mladek <[email protected]>Suggested-by Miroslav Benes <[email protected]>Suggested-by Josh Poimboeuf <[email protected]>Signed-off-by Wardenjohn <[email protected]>
M
Petr Mladek
maintainerRe: [PATCH V5 1/1] livepatch: Add stack_order sysfs attribute
In reply to WardenjohnQuoted 8 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-> 1means that
livepatch_1is the first live patch applied
Quoted 8 lines
cat
/sys/kernel/livepatch/livepatch_module/stack_order-> Nmeans that
livepatch_moduleis the Nth live patch appliedSuggested-by Petr Mladek <[email protected]>Suggested-by Miroslav Benes <[email protected]>Suggested-by Josh Poimboeuf <[email protected]>Signed-off-by Wardenjohn <[email protected]>
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