Re: [PATCH v3] livepatch: add (un)patch callbacks

From: Josh Poimboeuf
Date: Wed Aug 16 2017 - 16:29:33 EST


On Wed, Aug 16, 2017 at 03:17:04PM -0400, Joe Lawrence wrote:
> Provide livepatch modules a klp_object (un)patching notification
> mechanism. Pre and post-(un)patch callbacks allow livepatch modules to
> setup or synchronize changes that would be difficult to support in only
> patched-or-unpatched code contexts.
>
> Callbacks can be registered for target module or vmlinux klp_objects,
> but each implementation is klp_object specific.
>
> - Pre-(un)patch callbacks run before any (un)patching action takes
> place.
>
> - Post-(un)patch callbacks run once an object has been (un)patched and
> the klp_patch fully transitioned to its target state.
>
> Example use cases include modification of global data and registration
> of newly available services/handlers.
>
> See Documentation/livepatch/callback.txt for details.
>
> Signed-off-by: Joe Lawrence <joe.lawrence@xxxxxxxxxx>
> ---
> Documentation/livepatch/callbacks.txt | 87 ++++++++++++
> include/linux/livepatch.h | 81 ++++++++++++
> kernel/livepatch/core.c | 37 ++++--
> kernel/livepatch/patch.c | 5 +-
> kernel/livepatch/transition.c | 21 ++-
> samples/livepatch/Makefile | 2 +
> samples/livepatch/livepatch-callbacks-demo.c | 190 +++++++++++++++++++++++++++
> samples/livepatch/livepatch-callbacks-mod.c | 53 ++++++++
> 8 files changed, 462 insertions(+), 14 deletions(-)
> create mode 100644 Documentation/livepatch/callbacks.txt
> create mode 100644 samples/livepatch/livepatch-callbacks-demo.c
> create mode 100644 samples/livepatch/livepatch-callbacks-mod.c
>
> diff --git a/Documentation/livepatch/callbacks.txt b/Documentation/livepatch/callbacks.txt
> new file mode 100644
> index 000000000000..e18f2678f3bb
> --- /dev/null
> +++ b/Documentation/livepatch/callbacks.txt
> @@ -0,0 +1,87 @@
> +(Un)patching Callbacks
> +======================
> +
> +Livepatch (un)patch-callbacks provide a mechanism for livepatch modules
> +to execute callback functions when a kernel object is (un)patched. They
> +can be considered a "power feature" that extends livepatching abilities
> +to include:
> +
> + - Safe updates to global data
> +
> + - "Patches" to init and probe functions
> +
> + - Patching otherwise unpatchable code (i.e. assembly)
> +
> +In most cases, (un)patch hooks will need to be used in conjunction with

s/hooks/callbacks/

(though I wouldn't be opposed to changing them back to "hooks" anyway as
it's one fewer syllable :-) but no strong opinion either way on that)

--
Josh