add sysfs entry "patched" for each klp_object
Subsystems (2)
Song Liu
maintainerv3 cover add sysfs entry "patched" for each klp_object
I was debugging an issue that a livepatch appears to be attached, but actually not. It turns out that there is a mismatch in module name (abc-xyz vs. abc_xyz), klp_find_object_module failed to find the module. Add a sysfs entry for each klp_object, so that it is easier to debug such issues.
Changes v2 => v3:
1. Improve selftest. (Petr Mladek and Joe Lawrence)
Changes v1 => v2:
1. Add selftest. (Petr Mladek)
2. Update documentation. (Petr Mladek)
3. Use sysfs_emit. (Petr Mladek)
Song Liu (2):
livepatch: add sysfs entry "patched" for each klp_object selftests/livepatch: add sysfs test
.../ABI/testing/sysfs-kernel-livepatch | 8 ++ kernel/livepatch/core.c | 18 ++++ tools/testing/selftests/livepatch/Makefile | 3 +- .../testing/selftests/livepatch/functions.sh | 34 ++++++++ .../testing/selftests/livepatch/test-sysfs.sh | 86 +++++++++++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/livepatch/test-sysfs.sh
--
2.30.2
Song Liu
maintainerPATCH v3 1/2 livepatch: add sysfs entry "patched" for each klp_object
Add per klp_object sysfs entry "patched". It makes it easier to debug typos in the module name.
---
I was debugging an issue that a livepatch appears to be attached, but actually not. It turns out that there is a mismatch in module name (abc-xyz vs. abc_xyz), klp_find_object_module failed to find the module.
--- .../ABI/testing/sysfs-kernel-livepatch | 8 ++++++++ kernel/livepatch/core.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+)
Documentation/ABI/testing/sysfs-kernel-livepatch +8 -0
@@ -55,6 +55,14 @@ Description: The object directory contains subdirectories for each function that is patched within the object. +What: /sys/kernel/livepatch/<patch>/<object>/patched +Date: August 2022 +KernelVersion: 6.0.0 +Contact: [email protected] +Description: + An attribute which indicates whether the object is currently + patched. + What: /sys/kernel/livepatch/<patch>/<object>/<function,sympos> Date: Nov 2014 KernelVersion: 3.19.0
kernel/livepatch/core.c +18 -0
@@ -325,6 +325,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>/<object> +* /sys/kernel/livepatch/<patch>/<object>/patched * /sys/kernel/livepatch/<patch>/<object>/<function,sympos> */ static int __klp_disable_patch (struct klp_patch *patch);
@@ -431,6 +432,22 @@ static struct attribute *klp_patch_attrs[] = { };ATTRIBUTE_GROUPS (klp_patch); +static ssize_t patched_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct klp_object *obj; + + obj = container_of(kobj, struct klp_object, kobj); +return sysfs_emit (buf,"%d\n" , obj->patched); +} + +static struct kobj_attribute patched_kobj_attr =__ATTR_RO (patched); +static struct attribute *klp_object_attrs[] = { + &patched_kobj_attr.attr, +NULL , +}; +ATTRIBUTE_GROUPS (klp_object); +static void klp_free_object_dynamic (struct klp_object *obj) {kfree (obj->name);
@@ -576,6 +593,7 @@ static void klp_kobj_release_object(struct kobject *kobj)static struct kobj_type klp_ktype_object = { .release = klp_kobj_release_object, .sysfs_ops = &kobj_sysfs_ops, + .default_groups = klp_object_groups, };static void klp_kobj_release_func (struct kobject *kobj)
Signature · 1 line
2.30.2
Petr Mladek
maintainerRe: [PATCH v3 1/2] livepatch: add sysfs entry "patched" for each klp_object
Quoted 5 lines · Song Liu
Add per
klp_objectsysfs entry "patched". It makes it easier to debug typos in the module name.Reviewed-by Joe Lawrence <[email protected]>Signed-off-by Song Liu <[email protected]>
Just a note. Signed-off-by of the author is always the first entry. It is followed by Acked-by, Reviewed-by, Tested-by, ... in the order in which they arrived.
I have fixed the ordering when pushing the patch.
Documentation/ABI/testing/sysfs-kernel-livepatch Description: · line 60
Quoted 9 lines
Documentation/ABI/testing/sysfs-kernel-livepatch +3
-0@@ -55,6 +55,14 @@ Description: The object directory contains subdirectories for each function that is patched within the object. +What: /sys/kernel/livepatch/<patch>/<object>/patched +Date: August 2022 +KernelVersion: 6.0.0
Also I have updated the version to 6.1.0. It should be the version produced by the upcoming merge window.
Best Regards,
Petr
Song Liu
maintainerPATCH v3 2/2 selftests/livepatch: add sysfs test
In reply to Song LiuAdd a test for livepatch sysfs entries.
--- tools/testing/selftests/livepatch/Makefile | 3 +- .../testing/selftests/livepatch/functions.sh | 34 ++++++++ .../testing/selftests/livepatch/test-sysfs.sh | 86 +++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/livepatch/test-sysfs.sh
tools/testing/selftests/livepatch/Makefile +2 -1
@@ -6,7 +6,8 @@ TEST_PROGS := \ test-callbacks.sh \ test-shadow-vars.sh \ test-state.sh \ - test-ftrace.sh + test-ftrace.sh \ + test-sysfs.sh TEST_FILES := settings
tools/testing/selftests/livepatch/functions.sh +34 -0
@@ -6,6 +6,7 @@ MAX_RETRIES=600 RETRY_INTERVAL=".1" # seconds +KLP_SYSFS_DIR="/sys/kernel/livepatch" # Kselftest framework requirement - SKIP code is 4 ksft_skip=4
@@ -308,3 +309,36 @@ function check_result { cleanup_dmesg_file } + +# check_sysfs_rights(modname, rel_path, expected_rights) - check sysfs +# path permissions +# modname - livepatch module creating the sysfs interface +# rel_path - relative path of the sysfs interface +# expected_rights - expected access rights +function check_sysfs_rights() { + local mod="$1"; shift + local rel_path="$1"; shift + local expected_rights="$1"; shift + + local path="$KLP_SYSFS_DIR/$mod/$rel_path" + local rights=$(/bin/stat --format '%A' "$path") + if test "$rights" != "$expected_rights" ; then + die "Unexpected access rights of $path: $expected_rights vs. $rights" + fi +} + +# check_sysfs_value(modname, rel_path, expected_value) - check sysfs value +# modname - livepatch module creating the sysfs interface +# rel_path - relative path of the sysfs interface +# expected_value - expected value read from the file +function check_sysfs_value() { + local mod="$1"; shift + local rel_path="$1"; shift + local expected_value="$1"; shift + + local path="$KLP_SYSFS_DIR/$mod/$rel_path" + local value=`cat $path` + if test "$value" != "$expected_value" ; then + die "Unexpected value in $path: $expected_value vs. $value" + fi +}
tools/testing/selftests/livepatch/test-sysfs.sh new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
2.30.2
Quoted 9 lines · Song Liu
I was debugging an issue that a livepatch appears to be attached, but actually not. It turns out that there is a mismatch in module name (abc-xyz vs.
abc_xyz),klp_find_object_modulefailed to find the module. Add a sysfs entry for eachklp_object, so that it is easier to debug such issues.Changes v2 => v3:
1. Improve selftest. (Petr Mladek and Joe Lawrence)
Quoted 8 lines
Changes v1 => v2:
1. Add selftest. (Petr Mladek)
2. Update documentation. (Petr Mladek)
3. Usesysfs_emit. (Petr Mladek)Song Liu (2):
livepatch: add sysfs entry "patched" for eachklp_objectselftests/livepatch: add sysfs test
For both patches:
And I have pushed the patchset into livepatching.git, for-6.1/sysfs-patched-object.
Best Regards,
Petr