Skip to contentSkip to conversation

livepatch: add sysfs interface /sys/kernel/livepatch/state

PATCH In review Li Bin 2 participants 5 messages Jun 17, 2015 – Jun 18, 2015 Live patching

lore
Share & tools
lore

Li Bin

author
#0 lore raw

PATCH 1/1 livepatch: add sysfs interface /sys/kernel/livepatch/state

The added sysfs interface /sys/kernel/livepatch/state is read-only, it shows the patches that have been applied, incluing the stack index and the state of each patch.

$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			enabled
-----------------------------------------------
$ echo 0 > /sys/kernel/livepatch/klp_test3/enabled
$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			disabled
-----------------------------------------------
---
 Documentation/ABI/testing/sysfs-kernel-livepatch |    9 +++++
 kernel/livepatch/core.c                          |   41 +++++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletions(-)
Documentation/ABI/testing/sysfs-kernel-livepatch +9 -0
index 5bf42a8..01c64da 100644
@@ -8,6 +8,15 @@ Description:
 		The /sys/kernel/livepatch directory contains subdirectories for
 		each loaded live patch module.
 
+What:		/sys/kernel/livepatch/state
+Date:		Jun 2015
+KernelVersion:	4.1.0	
+Contact:	[email protected]
+Description:
+		The state file is read-only and shows the patches that have
+		been applied, including the patch stack index and state of
+		each patch. 
+
 What:		/sys/kernel/livepatch/<patch>
 Date:		Nov 2014
 KernelVersion:	3.19.0
kernel/livepatch/core.c +40 -1

64 lines not on this page · raw message

Signature · 1 line
1.7.7
maintainer
#1 lore raw
Quoted 21 lines · Li Bin

The added sysfs interface /sys/kernel/livepatch/state is read-only, it shows the patches that have been applied, incluing the stack index and the state of each patch.

$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			enabled
-----------------------------------------------
$ echo 0 > /sys/kernel/livepatch/klp_test3/enabled
$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			disabled
-----------------------------------------------
Quoted 2 lines

---

Hi,

I think we should comply with sysfs policy and keep 'one value per attribute' as mentioned in the Documentation/filesystems/sysfs.txt:

"
Attributes should be ASCII text files, preferably with only one value per file. It is noted that it may not be efficient to contain only one value per file, so it is socially acceptable to express an array of values of the same type.

Mixing types, expressing multiple lines of data, and doing fancy formatting of data is heavily frowned upon. Doing these things may get you publicly humiliated and your code rewritten without notice. "
The list of applied patches can be obtained just by 'ls /sys/kernel/livepatch' and their state is in enabled attribute in each respective patch (no, you cannot obtain the order in the stack).

Thanks,

Miroslav Benes
SUSE Labs

author
#2 lore raw
Quoted 37 lines · Miroslav Benes
Quoted 21 lines · Li Bin

The added sysfs interface /sys/kernel/livepatch/state is read-only, it shows the patches that have been applied, incluing the stack index and the state of each patch.

$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			enabled
-----------------------------------------------
$ echo 0 > /sys/kernel/livepatch/klp_test3/enabled
$ cat /sys/kernel/livepatch/state
Index	Patch				State
-----------------------------------------------
1	klp_test1			enabled
2	klp_test2			enabled
3	klp_test3			disabled
-----------------------------------------------
Quoted 2 lines

---

Hi,

I think we should comply with sysfs policy and keep 'one value per attribute' as mentioned in the Documentation/filesystems/sysfs.txt:

"
Attributes should be ASCII text files, preferably with only one value per file. It is noted that it may not be efficient to contain only one value per file, so it is socially acceptable to express an array of values of the same type.

Quoted 4 lines

Mixing types, expressing multiple lines of data, and doing fancy formatting of data is heavily frowned upon. Doing these things may get you publicly humiliated and your code rewritten without notice. "

Hi Miroslav Benes,
Thanks for your comments.

Quoted 3 lines

The list of applied patches can be obtained just by 'ls /sys/kernel/livepatch' and their state is in enabled attribute in each respective patch (no, you cannot obtain the order in the stack).

But why we cannot obtain it? I think We indeed need the stack order when we will disable one patch, at least, we can find out whether it is on the top of the stack if failed to disable one patch.

Thanks,
Li Bin

Quoted 8 lines

Thanks,

Miroslav Benes
SUSE Labs

.

maintainer
#3 lore raw
Quoted 10 lines · Li Bin
Quoted 5 lines · Miroslav Benes

On Wed, 17 Jun 2015, Li Bin wrote:

The list of applied patches can be obtained just by 'ls /sys/kernel/livepatch' and their state is in enabled attribute in each respective patch (no, you cannot obtain the order in the stack).

But why we cannot obtain it? I think We indeed need the stack order when we will disable one patch, at least, we can find out whether it is on the top of the stack if failed to disable one patch.

I meant with the current means. It is correct that we do not export information about stacking order anywhere.

What we do in kGraft is that there is something like refcount for each patch. When the patch is being applied the refcount of all the previous patches is increased. Only the patch with the refcount equal to 0 can be removed. This information is exported and gives one a clue about the order.

So if there is a need to have something like this there would certainly be a way (or ways to be precise) how to do it. The question is if we need it right now.

Regards,
Miroslav

author
#4 lore raw
Quoted 13 lines · Miroslav Benes
Quoted 10 lines · Li Bin
Quoted 5 lines · Miroslav Benes

On Wed, 17 Jun 2015, Li Bin wrote:

The list of applied patches can be obtained just by 'ls /sys/kernel/livepatch' and their state is in enabled attribute in each respective patch (no, you cannot obtain the order in the stack).

But why we cannot obtain it? I think We indeed need the stack order when we will disable one patch, at least, we can find out whether it is on the top of the stack if failed to disable one patch.

Quoted 9 lines

I meant with the current means. It is correct that we do not export information about stacking order anywhere.

What we do in kGraft is that there is something like refcount for each patch. When the patch is being applied the refcount of all the previous patches is increased. Only the patch with the refcount equal to 0 can be removed. This information is exported and gives one a clue about the order.

It sounds good, but the information is limited that cannot show the stack order, right? (The refcount of all the disabled patch is equal to 0, if being enable one disabled patch, the stack order is also needed.)

refcount Patch
-------------------
3 patch1(enabled)
2 patch2(enabled)
1 patch3(enabled)
0 patch4(enabled)
0 patch5(disabled)
0 patch6(disabled)

Unless the refcount is allowed to be less than 0, then when the patch is being disabled the refcount of all the patches is decreased, when the patch is being enabled the refcount of all patches is increased. Only the patch with the refcount equal to 0 can be disabled and only equal to -1 can be enabled, and only less or equal to 0 can be removed (that the livepatch does not support right now).

refcount Patch
-------------------
3 patch1(enabled)
2 patch2(enabled)
1 patch3(enabled)
0 patch4(enabled)
-1 patch5(disabled)
-2 patch6(disabled)

Thanks,
Li Bin

Quoted 9 lines

So if there is a need to have something like this there would certainly be a way (or ways to be precise) how to do it. The question is if we need it right now.

Regards,
Miroslav

.