livepatch: introduce klp_func called interface
Subsystems (2)
PATCH 1/1 livepatch: introduce klp_func called interface
Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.
This commit introduce a read only interface of livepatch sysfs interface. If a livepatch function is called, this sysfs interface "called" of the patched function will set to be 1.
/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called
This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called. Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.
--- include/linux/livepatch.h | 2 ++ kernel/livepatch/core.c | 18 ++++++++++++++++++ kernel/livepatch/patch.c | 2 ++ 3 files changed, 22 insertions(+)
include/linux/livepatch.h +2 -0
@@ -37,6 +37,7 @@* @nop: temporary patch to use the original code again; dyn. allocated * @patched: the func has been added to the klp_ops list * @transition: the func is currently being applied or reverted +* @called: the func is called * * The patched and transition variables define the func's patching state. When * patching, a func is always in one of the following states:
@@ -75,6 +76,7 @@ struct klp_func {bool nop;bool patched;bool transition; +bool called; };struct klp_object ;
kernel/livepatch/core.c +18 -0
@@ -470,6 +470,22 @@ static struct attribute *klp_object_attrs[] = { };ATTRIBUTE_GROUPS (klp_object); +static ssize_t called_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct klp_func *func; + + func = container_of(kobj, struct klp_func, kobj); +return sysfs_emit (buf,"%d\n" , func->called); +} + +static struct kobj_attribute called_kobj_attr =__ATTR_RO (called); +static struct attribute *klp_func_attrs[] = { + &called_kobj_attr.attr, +NULL , +}; +ATTRIBUTE_GROUPS (klp_func); +static void klp_free_object_dynamic (struct klp_object *obj) {kfree (obj->name);
@@ -631,6 +647,7 @@ static void klp_kobj_release_func(struct kobject *kobj)static const struct kobj_type klp_ktype_func = { .release = klp_kobj_release_func, .sysfs_ops = &kobj_sysfs_ops, + .default_groups = klp_func_groups, };static void __klp_free_funcs (struct klp_object *obj,bool nops_only)
@@ -903,6 +920,7 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)static void klp_init_func_early (struct klp_object *obj,struct klp_func *func) { + func->called =0 ;kobject_init (&func->kobj, &klp_ktype_func);list_add_tail (&func->node, &obj->func_list); }
kernel/livepatch/patch.c +2 -0
@@ -118,6 +118,8 @@ static void notrace klp_ftrace_handler(unsigned long ip,if (func->nop) goto unlock; +if (!func->called) + func->called = true;ftrace_regs_set_instruction_pointer (fregs, (unsigned long )func->new_func); unlock:
Signature · 1 line
2.37.3
…
Quoted 1 line
This commit introduce a read only interface of livepatch
Please improve the changelog with an imperative wording.
…
Quoted 2 lines
find out which function is successfully called. Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.
* I suggest to take preferred line lengths better into account also for such a change description.
* Please provide the tag “Signed-off-by”.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.9#n398
Regards,
Markus
OK, I will optimize my patch’s changelog in my next patch.
Quoted 4 lines · Markus Elfring
I suggest to take preferred line lengths better into account also for such a change description.
Quoted 9 lines · Wardenjohn
Livepatch module usually used to modify kernel functions. If the patched function have bug, it may cause serious result such as kernel crash.
This commit introduce a read only interface of livepatch sysfs interface. If a livepatch function is called, this sysfs interface "called" of the patched function will set to be 1.
Quoted 8 lines
/sys/kernel/livepatch/<patch>/<object>/<function,sympos>/called
This value "called" is quite necessary for kernel stability assurance for livepatching module of a running system. Testing process is important before a livepatch module apply to a production system. With this interface, testing process can easily find out which function is successfully called. Any testing process can make sure they have successfully cover all the patched function that changed with the help of this interface.
---
Always run your patches through checkpatch.
So this patch is so that testers can see if a function has been called? Can you not get the same information from gcov or ftrace?
There are style issues with the patch, but it's not so important until the design is agreed on.
regards,
dan carpenter
Quoted 14 lines · Dan Carpenter
Always run your patches through checkpatch.
So this patch is so that testers can see if a function has been called? Can you not get the same information from gcov or ftrace?
There are style issues with the patch, but it's not so important until the design is agreed on.
regards,
dan carpenter
Hi, Dan.
This patch have format issues as Markus said. A newer version of this patch is sent which is checked by ./scripts/checkpatch.pl
Thanks for your suggestions.
Regards,
Wardenjohn