Skip to content

Commit 7c3f326

Browse files
author
Denis Aleksandrov
committed
livepatch: Add stack_order sysfs attribute
JIRA: https://issues.redhat.com/browse/RHEL-85303 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> Reviewed-by: Petr Mladek <pmladek@suse.com> Tested-by: Petr Mladek <pmladek@suse.com> Reviewed-by: Miroslav Benes <mbenes@suse.cz> Link: https://lore.kernel.org/r/20241008014856.3729-2-zhangwarden@gmail.com [pmladek@suse.com: Updated kernel version and date in the ABI documentation.] Signed-off-by: Petr Mladek <pmladek@suse.com> (cherry picked from commit 3dae09d) Signed-off-by: Denis Aleksandrov <daleksan@redhat.com>
1 parent 6138952 commit 7c3f326

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Documentation/ABI/testing/sysfs-kernel-livepatch

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ Description:
5555
An attribute which indicates whether the patch supports
5656
atomic-replace.
5757

58+
What: /sys/kernel/livepatch/<patch>/stack_order
59+
Date: Jan 2025
60+
KernelVersion: 6.14.0
61+
Description:
62+
This attribute specifies the sequence in which live patch modules
63+
are applied to the system. If multiple live patches modify the same
64+
function, the implementation with the biggest 'stack_order' number
65+
is used, unless a transition is currently in progress.
66+
5867
What: /sys/kernel/livepatch/<patch>/<object>
5968
Date: Nov 2014
6069
KernelVersion: 3.19.0

kernel/livepatch/core.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,
358358
* /sys/kernel/livepatch/<patch>/transition
359359
* /sys/kernel/livepatch/<patch>/force
360360
* /sys/kernel/livepatch/<patch>/replace
361+
* /sys/kernel/livepatch/<patch>/stack_order
361362
* /sys/kernel/livepatch/<patch>/<object>
362363
* /sys/kernel/livepatch/<patch>/<object>/patched
363364
* /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -463,15 +464,38 @@ static ssize_t replace_show(struct kobject *kobj,
463464
return sysfs_emit(buf, "%d\n", patch->replace);
464465
}
465466

467+
static ssize_t stack_order_show(struct kobject *kobj,
468+
struct kobj_attribute *attr, char *buf)
469+
{
470+
struct klp_patch *patch, *this_patch;
471+
int stack_order = 0;
472+
473+
this_patch = container_of(kobj, struct klp_patch, kobj);
474+
475+
mutex_lock(&klp_mutex);
476+
477+
klp_for_each_patch(patch) {
478+
stack_order++;
479+
if (patch == this_patch)
480+
break;
481+
}
482+
483+
mutex_unlock(&klp_mutex);
484+
485+
return sysfs_emit(buf, "%d\n", stack_order);
486+
}
487+
466488
static struct kobj_attribute enabled_kobj_attr = __ATTR_RW(enabled);
467489
static struct kobj_attribute transition_kobj_attr = __ATTR_RO(transition);
468490
static struct kobj_attribute force_kobj_attr = __ATTR_WO(force);
469491
static struct kobj_attribute replace_kobj_attr = __ATTR_RO(replace);
492+
static struct kobj_attribute stack_order_kobj_attr = __ATTR_RO(stack_order);
470493
static struct attribute *klp_patch_attrs[] = {
471494
&enabled_kobj_attr.attr,
472495
&transition_kobj_attr.attr,
473496
&force_kobj_attr.attr,
474497
&replace_kobj_attr.attr,
498+
&stack_order_kobj_attr.attr,
475499
NULL
476500
};
477501
ATTRIBUTE_GROUPS(klp_patch);

0 commit comments

Comments
 (0)