Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

livepatch: Add "replace" sysfs attribute

There are situations when it might make sense to combine livepatches
with and without the atomic replace on the same system. For example,
the livepatch without the atomic replace might provide a hotfix
or extra tuning.

Managing livepatches on such systems might be challenging. And the
information which of the installed livepatches do not use the atomic
replace would be useful.

Add new sysfs interface 'replace'. It works as follows:

$ cat /sys/kernel/livepatch/livepatch-non_replace/replace
0

$ cat /sys/kernel/livepatch/livepatch-replace/replace
1

[ commit log improved by Petr ]

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Link: https://lore.kernel.org/r/20240625151123.2750-2-laoar.shao@gmail.com
Signed-off-by: Petr Mladek <pmladek@suse.com>

authored by

Yafang Shao and committed by
Petr Mladek
adb68ed2 8c06da67

+20
+8
Documentation/ABI/testing/sysfs-kernel-livepatch
··· 47 47 disabled when the feature is used. See 48 48 Documentation/livepatch/livepatch.rst for more information. 49 49 50 + What: /sys/kernel/livepatch/<patch>/replace 51 + Date: Jun 2024 52 + KernelVersion: 6.11.0 53 + Contact: live-patching@vger.kernel.org 54 + Description: 55 + An attribute which indicates whether the patch supports 56 + atomic-replace. 57 + 50 58 What: /sys/kernel/livepatch/<patch>/<object> 51 59 Date: Nov 2014 52 60 KernelVersion: 3.19.0
+12
kernel/livepatch/core.c
··· 346 346 * /sys/kernel/livepatch/<patch>/enabled 347 347 * /sys/kernel/livepatch/<patch>/transition 348 348 * /sys/kernel/livepatch/<patch>/force 349 + * /sys/kernel/livepatch/<patch>/replace 349 350 * /sys/kernel/livepatch/<patch>/<object> 350 351 * /sys/kernel/livepatch/<patch>/<object>/patched 351 352 * /sys/kernel/livepatch/<patch>/<object>/<function,sympos> ··· 444 443 return count; 445 444 } 446 445 446 + static ssize_t replace_show(struct kobject *kobj, 447 + struct kobj_attribute *attr, char *buf) 448 + { 449 + struct klp_patch *patch; 450 + 451 + patch = container_of(kobj, struct klp_patch, kobj); 452 + return sysfs_emit(buf, "%d\n", patch->replace); 453 + } 454 + 447 455 static struct kobj_attribute enabled_kobj_attr = __ATTR_RW(enabled); 448 456 static struct kobj_attribute transition_kobj_attr = __ATTR_RO(transition); 449 457 static struct kobj_attribute force_kobj_attr = __ATTR_WO(force); 458 + static struct kobj_attribute replace_kobj_attr = __ATTR_RO(replace); 450 459 static struct attribute *klp_patch_attrs[] = { 451 460 &enabled_kobj_attr.attr, 452 461 &transition_kobj_attr.attr, 453 462 &force_kobj_attr.attr, 463 + &replace_kobj_attr.attr, 454 464 NULL 455 465 }; 456 466 ATTRIBUTE_GROUPS(klp_patch);