livepatch: Add a new sysfs interface replace
PATCH 1/1 livepatch: Add a new sysfs interface replace
When building a livepatch, a user can set it to be either an atomic-replace livepatch or a non-atomic-replace livepatch. However, it is not easy to identify whether a livepatch is atomic-replace or not until it actually replaces some old livepatches. This can lead to mistakes in a mixed atomic-replace and non-atomic-replace environment, especially when transitioning all livepatches from non-atomic-replace to atomic-replace in a large fleet of servers.
To address this issue, a new sysfs interface called 'replace' is introduced in this patch. The result after this change is as follows:
$ cat /sys/kernel/livepatch/livepatch-non_replace/replace 0
$ cat /sys/kernel/livepatch/livepatch-replace/replace 1
--- Documentation/ABI/testing/sysfs-kernel-livepatch | 8 ++++++++ kernel/livepatch/core.c | 12 ++++++++++++ 2 files changed, 20 insertions(+)
Documentation/ABI/testing/sysfs-kernel-livepatch +8 -0
@@ -47,6 +47,14 @@ Description: disabled when the feature is used. See Documentation/livepatch/livepatch.rst for more information. +What: /sys/kernel/livepatch/<patch>/replace +Date: Jun 2024 +KernelVersion: 6.11.0 +Contact: [email protected] +Description: + An attribute which indicates whether the patch supports + atomic-replace. + What: /sys/kernel/livepatch/<patch>/<object> Date: Nov 2014 KernelVersion: 3.19.0
kernel/livepatch/core.c +12 -0
@@ -346,6 +346,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,* /sys/kernel/livepatch/<patch>/enabled * /sys/kernel/livepatch/<patch>/transition * /sys/kernel/livepatch/<patch>/force +* /sys/kernel/livepatch/<patch>/replace * /sys/kernel/livepatch/<patch>/<object> * /sys/kernel/livepatch/<patch>/<object>/patched * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
@@ -443,13 +444,24 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,return count; } +static ssize_t replace_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct klp_patch *patch; + + patch = container_of(kobj, struct klp_patch, kobj); +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , patch->replace); +} +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 attribute *klp_patch_attrs[] = { &enabled_kobj_attr.attr, &transition_kobj_attr.attr, &force_kobj_attr.attr, + &replace_kobj_attr.attr,NULL };ATTRIBUTE_GROUPS (klp_patch);
Signature · 1 line
2.39.1
Miroslav Benes
maintainerHi,
I think the subject should be something like
"livepatch: Add "replace" sysfs attribute"
or use a different way to stress "replace" is the name.
Quoted 2 lines · Yafang Shao
When building a livepatch, a user can set it to be either an atomic-replace livepatch or a non-atomic-replace livepatch.
I am not a native speaker but I would drop '-' everywhere in this context.
Quoted 3 lines
However, it is not easy to
identify whether a livepatch is atomic-replace or not until it actually replaces some old livepatches.
Ok.
Quoted 4 lines
This can lead to mistakes in a mixed
atomic-replace and non-atomic-replace environment, especially when transitioning all livepatches from non-atomic-replace to atomic-replace in a large fleet of servers.
Out of curiosity, could you describe your setup in more detail here? It is interesting to mix different type of livepatches so I would like to learn more.
Quoted 47 lines
To address this issue, a new sysfs interface called 'replace' is introduced in this patch. The result after this change is as follows:
$ cat /sys/kernel/livepatch/livepatch-non_replace/replace 0$ cat /sys/kernel/livepatch/livepatch-replace/replace 1Signed-off-by Yafang Shao <[email protected]>--- Documentation/ABI/testing/sysfs-kernel-livepatch | 8 ++++++++ kernel/livepatch/core.c | 12 ++++++++++++ 2 files changed, 20 insertions(+)Documentation/ABI/testing/sysfs-kernel-livepatch +8
-0@@ -47,6 +47,14 @@ Description: disabled when the feature is used. See Documentation/livepatch/livepatch.rst for more information. +What: /sys/kernel/livepatch/<patch>/replace +Date: Jun 2024 +KernelVersion: 6.11.0 +Contact: [email protected] +Description: + An attribute which indicates whether the patch supports + atomic-replace. + What: /sys/kernel/livepatch/<patch>/<object> Date: Nov 2014 KernelVersion: 3.19.0kernel/livepatch/core.c +1
-0@@ -346,6 +346,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,* /sys/kernel/livepatch/<patch>/enabled * /sys/kernel/livepatch/<patch>/transition * /sys/kernel/livepatch/<patch>/force +* /sys/kernel/livepatch/<patch>/replace * /sys/kernel/livepatch/<patch>/<object> * /sys/kernel/livepatch/<patch>/<object>/patched * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
kernel/livepatch/core.c static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, · line 453
Quoted 10 lines
kernel/livepatch/core.c +7
-0@@ -443,13 +444,24 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,return count; } +static ssize_t replace_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct klp_patch *patch; + + patch = container_of(kobj, struct klp_patch, kobj); +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , patch->replace);
It might be better to use sysfs_emit() here. See patched_show() in the same file. There are still snprintf() occurrences and it might be a separate cleanup patch if you are interested.
Regards,
Miroslav
Quoted 97 lines · Miroslav Benes
Hi,
I think the subject should be something like
"livepatch: Add "replace" sysfs attribute"
or use a different way to stress "replace" is the name.
Quoted 3 lines · Yafang Shao
When building a livepatch, a user can set it to be either an atomic-replace
livepatch or a non-atomic-replace livepatch.I am not a native speaker but I would drop '-' everywhere in this context.
Quoted 4 lines
However, it is not easy to
identify whether a livepatch is atomic-replace or not until it actually
replaces some old livepatches.Ok.
Quoted 5 lines
This can lead to mistakes in a mixed
atomic-replace and non-atomic-replace environment, especially when transitioning all livepatches from non-atomic-replace to atomic- replace in
a large fleet of servers.Out of curiosity, could you describe your setup in more detail here? It is
interesting to mix different type of livepatches so I would like to learn
more.Quoted 61 lines
To address this issue, a new sysfs interface called 'replace' is introduced
in this patch. The result after this change is as follows:$ cat /sys/kernel/livepatch/livepatch-non_replace/replace 0$ cat /sys/kernel/livepatch/livepatch-replace/replace 1Signed-off-by Yafang Shao <[email protected]>---
Documentation/ABI/testing/sysfs-kernel-livepatch | 8 ++++++++ kernel/livepatch/core.c | 12 ++++++++++++2 files changed, 20 insertions(+)Documentation/ABI/testing/sysfs-kernel-livepatch +0
-0@@ -47,6 +47,14 @@ Description:disabled when the feature is used. See
Documentation/livepatch/livepatch.rstfor more information.Documentation/ABI/testing/sysfs-kernel-livepatch +6
-0+What: /sys/kernel/livepatch/<patch>/replace +Date: Jun 2024 +KernelVersion: 6.11.0 +Contact: [email protected] +Description: + An attribute which indicates whether the patchsupports
Documentation/ABI/testing/sysfs-kernel-livepatch +2
-0+ atomic-replace. +What: /sys/kernel/livepatch/<patch>/<object>
Date: Nov 2014
KernelVersion: 3.19.0kernel/livepatch/core.c +1
-0@@ -346,6 +346,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs, * /sys/kernel/livepatch/<patch>/enabled * /sys/kernel/livepatch/<patch>/transition * /sys/kernel/livepatch/<patch>/force + * /sys/kernel/livepatch/<patch>/replace * /sys/kernel/livepatch/<patch>/<object> * /sys/kernel/livepatch/<patch>/<object>/patched* /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
kernel/livepatch/core.c +0
-0@@ -443,13 +444,24 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, return count; }kernel/livepatch/core.c +2
-0+static ssize_t replace_show (struct kobject *kobj, + struct kobj_attribute *attr, char*buf)
kernel/livepatch/core.c +2
-0+{ +struct klp_patch *patch;
Quoted 8 lines
kernel/livepatch/core.c static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, · line 453
Quoted 3 lines
kernel/livepatch/core.c +3
-0+ + patch = container_of(kobj, struct klp_patch, kobj); +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , patch->replace);It might be better to use
sysfs_emit()here. Seepatched_show()in the
same file. There are stillsnprintf()occurrences and it might be a separate cleanup patch if you are interested.
Hi Yafang, thanks for the patch!
Besides Miroslav's comments, I think that a new kselftest exercising this attribute would be good, since we have tests for other attributes as well.
Thanks,
Marcos
Quoted 4 lines
Regards,
Miroslav
Quoted 108 lines · Marcos Paulo de Souza
Quoted 92 lines · Miroslav Benes
Hi,
I think the subject should be something like
"livepatch: Add "replace" sysfs attribute"
or use a different way to stress "replace" is the name.
Quoted 3 lines · Yafang Shao
When building a livepatch, a user can set it to be either an atomic-replace
livepatch or a non-atomic-replace livepatch.I am not a native speaker but I would drop '-' everywhere in this context.
Quoted 4 lines
However, it is not easy to
identify whether a livepatch is atomic-replace or not until it actually
replaces some old livepatches.Ok.
Quoted 5 lines
This can lead to mistakes in a mixed
atomic-replace and non-atomic-replace environment, especially when transitioning all livepatches from non-atomic-replace to atomic- replace in
a large fleet of servers.Out of curiosity, could you describe your setup in more detail here? It is
interesting to mix different type of livepatches so I would like to learn
more.Quoted 56 lines
To address this issue, a new sysfs interface called 'replace' is introduced
in this patch. The result after this change is as follows:$ cat /sys/kernel/livepatch/livepatch-non_replace/replace 0$ cat /sys/kernel/livepatch/livepatch-replace/replace 1Signed-off-by Yafang Shao <[email protected]>--- Documentation/ABI/testing/sysfs-kernel-livepatch | 8 ++++++++ kernel/livepatch/core.c | 12 ++++++++++++ 2 files changed, 20 insertions(+)Documentation/ABI/testing/sysfs-kernel-livepatch +0
-0@@ -47,6 +47,14 @@ Description: disabled when the feature is used. See Documentation/livepatch/livepatch.rst for moreinformation.
Documentation/ABI/testing/sysfs-kernel-livepatch +6
-0+What: /sys/kernel/livepatch/<patch>/replace +Date: Jun 2024 +KernelVersion: 6.11.0 +Contact: [email protected] +Description: + An attribute which indicates whether the patchsupports
Documentation/ABI/testing/sysfs-kernel-livepatch +2
-0+ atomic-replace. + What: /sys/kernel/livepatch/<patch>/<object> Date: Nov 2014 KernelVersion: 3.19.0kernel/livepatch/core.c +1
-0@@ -346,6 +346,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs, * /sys/kernel/livepatch/<patch>/enabled * /sys/kernel/livepatch/<patch>/transition * /sys/kernel/livepatch/<patch>/force + * /sys/kernel/livepatch/<patch>/replace * /sys/kernel/livepatch/<patch>/<object> * /sys/kernel/livepatch/<patch>/<object>/patched* /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
kernel/livepatch/core.c +0
-0@@ -443,13 +444,24 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, return count; }Quoted 13 lines
kernel/livepatch/core.c static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, · line 453
Quoted 8 lines
kernel/livepatch/core.c +7
-0+static ssize_t replace_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct klp_patch *patch; + + patch = container_of(kobj, struct klp_patch, kobj); +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , patch->replace);It might be better to use
sysfs_emit()here. Seepatched_show()in the
same file. There are stillsnprintf()occurrences and it might be a separate cleanup patch if you are interested.
Quoted 5 lines
Hi Yafang, thanks for the patch!
Besides Miroslav's comments, I think that a new kselftest exercising this attribute would be good, since we have tests for other attributes as well.
I will add it. Thanks for your suggestion.
Signature · 2 lines
Regards Yafang
Quoted 6 lines · Miroslav Benes
Hi,
I think the subject should be something like
"livepatch: Add "replace" sysfs attribute"
agreed.
Quoted 9 lines
or use a different way to stress "replace" is the name.
Quoted 2 lines · Yafang Shao
When building a livepatch, a user can set it to be either an atomic-replace livepatch or a non-atomic-replace livepatch.
I am not a native speaker but I would drop '-' everywhere in this context.
agreed. I'm not a native speaker either :)
Quoted 7 lines
Quoted 4 lines
However, it is not easy to
identify whether a livepatch is atomic-replace or not until it actually replaces some old livepatches.Ok.
Quoted 8 lines
Quoted 4 lines
This can lead to mistakes in a mixed
atomic-replace and non-atomic-replace environment, especially when transitioning all livepatches from non-atomic-replace to atomic-replace in a large fleet of servers.Out of curiosity, could you describe your setup in more detail here? It is interesting to mix different type of livepatches so I would like to learn more.
It seems I didn't describe it clearly. We are transitioning non atomic replace livepatches to atomic replace livepatches, which will take some time to complete in a large fleet of servers. In other words, some servers are still running non atomic replace livepatches while others are running atomic replace livepatches. As a result, the sysadmins have complained that they can't find a way to identify whether a livepatch is an atomic replace or not. It will be beneficial to show it directly.
Quoted 51 lines
Quoted 51 lines
To address this issue, a new sysfs interface called 'replace' is introduced in this patch. The result after this change is as follows:
$ cat /sys/kernel/livepatch/livepatch-non_replace/replace 0$ cat /sys/kernel/livepatch/livepatch-replace/replace 1Signed-off-by Yafang Shao <[email protected]>--- Documentation/ABI/testing/sysfs-kernel-livepatch | 8 ++++++++ kernel/livepatch/core.c | 12 ++++++++++++ 2 files changed, 20 insertions(+)Documentation/ABI/testing/sysfs-kernel-livepatch +8
-0@@ -47,6 +47,14 @@ Description: disabled when the feature is used. See Documentation/livepatch/livepatch.rst for more information. +What: /sys/kernel/livepatch/<patch>/replace +Date: Jun 2024 +KernelVersion: 6.11.0 +Contact: [email protected] +Description: + An attribute which indicates whether the patch supports + atomic-replace. + What: /sys/kernel/livepatch/<patch>/<object> Date: Nov 2014 KernelVersion: 3.19.0kernel/livepatch/core.c +1
-0@@ -346,6 +346,7 @@ int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,* /sys/kernel/livepatch/<patch>/enabled * /sys/kernel/livepatch/<patch>/transition * /sys/kernel/livepatch/<patch>/force +* /sys/kernel/livepatch/<patch>/replace * /sys/kernel/livepatch/<patch>/<object> * /sys/kernel/livepatch/<patch>/<object>/patched * /sys/kernel/livepatch/<patch>/<object>/<function,sympos> @@ -443,13 +444,24 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,return count; }
Quoted 11 lines
kernel/livepatch/core.c static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr, · line 453
Quoted 7 lines
kernel/livepatch/core.c +7
-0+static ssize_t replace_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +struct klp_patch *patch; + + patch = container_of(kobj, struct klp_patch, kobj); +return snprintf (buf,PAGE_SIZE -1 ,"%d\n" , patch->replace);It might be better to use
sysfs_emit()here. Seepatched_show()in the same file. There are stillsnprintf()occurrences and it might be a separate cleanup patch if you are interested.
I will do it. Thanks for your suggestion.
Signature · 2 lines
Regards Yafang