forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
…/git/livepatching/livepatching Pull livepatching updates from Jiri Kosina: - support for something we call 'atomic replace', and allows for much better handling of cumulative patches (which is something very useful for distros), from Jason Baron with help of Petr Mladek and Joe Lawrence - improvement of handling of tasks blocking finalization, from Miroslav Benes - update of MAINTAINERS file to reflect move towards group maintainership * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching: (22 commits) livepatch/selftests: use "$@" to preserve argument list livepatch: Module coming and going callbacks can proceed with all listed patches livepatch: Proper error handling in the shadow variables selftest livepatch: return -ENOMEM on ptr_id() allocation failure livepatch: Introduce klp_for_each_patch macro livepatch: core: Return EOPNOTSUPP instead of ENOSYS selftests/livepatch: add DYNAMIC_DEBUG config dependency livepatch: samples: non static warnings fix livepatch: update MAINTAINERS livepatch: Remove signal sysfs attribute livepatch: Send a fake signal periodically selftests/livepatch: introduce tests livepatch: Remove ordering (stacking) of the livepatches livepatch: Atomic replace and cumulative patches documentation livepatch: Remove Nop structures when unused livepatch: Add atomic replace livepatch: Use lists to manage patches, objects and functions livepatch: Simplify API by removing registration step livepatch: Don't block the removal of patches loaded after a forced transition livepatch: Consolidate klp_free functions ...
- Loading branch information
Showing
35 changed files
with
2,649 additions
and
1,071 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,18 +33,6 @@ Description: | |
An attribute which indicates whether the patch is currently in | ||
transition. | ||
|
||
What: /sys/kernel/livepatch/<patch>/signal | ||
Date: Nov 2017 | ||
KernelVersion: 4.15.0 | ||
Contact: [email protected] | ||
Description: | ||
A writable attribute that allows administrator to affect the | ||
course of an existing transition. Writing 1 sends a fake | ||
signal to all remaining blocking tasks. The fake signal | ||
means that no proper signal is delivered (there is no data in | ||
signal pending structures). Tasks are interrupted or woken up, | ||
and forced to change their patched state. | ||
|
||
What: /sys/kernel/livepatch/<patch>/force | ||
Date: Nov 2017 | ||
KernelVersion: 4.15.0 | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
=================================== | ||
Atomic Replace & Cumulative Patches | ||
=================================== | ||
|
||
There might be dependencies between livepatches. If multiple patches need | ||
to do different changes to the same function(s) then we need to define | ||
an order in which the patches will be installed. And function implementations | ||
from any newer livepatch must be done on top of the older ones. | ||
|
||
This might become a maintenance nightmare. Especially when more patches | ||
modified the same function in different ways. | ||
|
||
An elegant solution comes with the feature called "Atomic Replace". It allows | ||
creation of so called "Cumulative Patches". They include all wanted changes | ||
from all older livepatches and completely replace them in one transition. | ||
|
||
Usage | ||
----- | ||
|
||
The atomic replace can be enabled by setting "replace" flag in struct klp_patch, | ||
for example: | ||
|
||
static struct klp_patch patch = { | ||
.mod = THIS_MODULE, | ||
.objs = objs, | ||
.replace = true, | ||
}; | ||
|
||
All processes are then migrated to use the code only from the new patch. | ||
Once the transition is finished, all older patches are automatically | ||
disabled. | ||
|
||
Ftrace handlers are transparently removed from functions that are no | ||
longer modified by the new cumulative patch. | ||
|
||
As a result, the livepatch authors might maintain sources only for one | ||
cumulative patch. It helps to keep the patch consistent while adding or | ||
removing various fixes or features. | ||
|
||
Users could keep only the last patch installed on the system after | ||
the transition to has finished. It helps to clearly see what code is | ||
actually in use. Also the livepatch might then be seen as a "normal" | ||
module that modifies the kernel behavior. The only difference is that | ||
it can be updated at runtime without breaking its functionality. | ||
|
||
|
||
Features | ||
-------- | ||
|
||
The atomic replace allows: | ||
|
||
+ Atomically revert some functions in a previous patch while | ||
upgrading other functions. | ||
|
||
+ Remove eventual performance impact caused by core redirection | ||
for functions that are no longer patched. | ||
|
||
+ Decrease user confusion about dependencies between livepatches. | ||
|
||
|
||
Limitations: | ||
------------ | ||
|
||
+ Once the operation finishes, there is no straightforward way | ||
to reverse it and restore the replaced patches atomically. | ||
|
||
A good practice is to set .replace flag in any released livepatch. | ||
Then re-adding an older livepatch is equivalent to downgrading | ||
to that patch. This is safe as long as the livepatches do _not_ do | ||
extra modifications in (un)patching callbacks or in the module_init() | ||
or module_exit() functions, see below. | ||
|
||
Also note that the replaced patch can be removed and loaded again | ||
only when the transition was not forced. | ||
|
||
|
||
+ Only the (un)patching callbacks from the _new_ cumulative livepatch are | ||
executed. Any callbacks from the replaced patches are ignored. | ||
|
||
In other words, the cumulative patch is responsible for doing any actions | ||
that are necessary to properly replace any older patch. | ||
|
||
As a result, it might be dangerous to replace newer cumulative patches by | ||
older ones. The old livepatches might not provide the necessary callbacks. | ||
|
||
This might be seen as a limitation in some scenarios. But it makes life | ||
easier in many others. Only the new cumulative livepatch knows what | ||
fixes/features are added/removed and what special actions are necessary | ||
for a smooth transition. | ||
|
||
In any case, it would be a nightmare to think about the order of | ||
the various callbacks and their interactions if the callbacks from all | ||
enabled patches were called. | ||
|
||
|
||
+ There is no special handling of shadow variables. Livepatch authors | ||
must create their own rules how to pass them from one cumulative | ||
patch to the other. Especially that they should not blindly remove | ||
them in module_exit() functions. | ||
|
||
A good practice might be to remove shadow variables in the post-unpatch | ||
callback. It is called only when the livepatch is properly disabled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8967,10 +8967,10 @@ F: drivers/platform/x86/hp_accel.c | |
|
||
LIVE PATCHING | ||
M: Josh Poimboeuf <[email protected]> | ||
M: Jessica Yu <[email protected]> | ||
M: Jiri Kosina <[email protected]> | ||
M: Miroslav Benes <[email protected]> | ||
R: Petr Mladek <[email protected]> | ||
M: Petr Mladek <[email protected]> | ||
R: Joe Lawrence <[email protected]> | ||
S: Maintained | ||
F: kernel/livepatch/ | ||
F: include/linux/livepatch.h | ||
|
@@ -8979,8 +8979,9 @@ F: arch/x86/kernel/livepatch.c | |
F: Documentation/livepatch/ | ||
F: Documentation/ABI/testing/sysfs-kernel-livepatch | ||
F: samples/livepatch/ | ||
F: tools/testing/selftests/livepatch/ | ||
L: [email protected] | ||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/jikos/livepatching.git | ||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git | ||
|
||
LLC (802.2) | ||
L: [email protected] | ||
|
Oops, something went wrong.