Skip to content

Commit

Permalink
docs: livepatch: convert docs to ReST and rename to *.rst
Browse files Browse the repository at this point in the history
Convert livepatch documentation to ReST format. The changes
are mostly trivial, as the documents are already on a good
shape. Just a few markup changes are needed for Sphinx to
properly parse the docs.

The conversion is actually:
  - add blank lines and identation in order to identify paragraphs;
  - fix tables markups;
  - add some lists markups;
  - mark literal blocks;
  - The in-file TOC becomes a comment, in order to skip it from the
    output, as Sphinx already generates an index there.
  - adjust title markups.

At its new index.rst, let's add a :orphan: while this is not linked to
the main index.rst file, in order to avoid build warnings.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Reviewed-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
  • Loading branch information
Mauro Carvalho Chehab authored and Jonathan Corbet committed May 7, 2019
1 parent 894ee5f commit 89e33ea
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Documentation/ABI/testing/sysfs-kernel-livepatch
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Description:
use this feature without a clearance from a patch
distributor. Removal (rmmod) of patch modules is permanently
disabled when the feature is used. See
Documentation/livepatch/livepatch.txt for more information.
Documentation/livepatch/livepatch.rst for more information.

What: /sys/kernel/livepatch/<patch>/<object>
Date: Nov 2014
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ be patched, irrespective of the target klp_object's current state.

Callbacks can be registered for the following livepatch actions:

* Pre-patch - before a klp_object is patched
* Pre-patch
- before a klp_object is patched

* Post-patch - after a klp_object has been patched and is active
* Post-patch
- after a klp_object has been patched and is active
across all tasks

* Pre-unpatch - before a klp_object is unpatched (ie, patched code is
* Pre-unpatch
- before a klp_object is unpatched (ie, patched code is
active), used to clean up post-patch callback
resources

* Post-unpatch - after a klp_object has been patched, all code has
* Post-unpatch
- after a klp_object has been patched, all code has
been restored and no tasks are running patched code,
used to cleanup pre-patch callback resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Usage
-----

The atomic replace can be enabled by setting "replace" flag in struct klp_patch,
for example:
for example::

static struct klp_patch patch = {
.mod = THIS_MODULE,
Expand Down Expand Up @@ -49,19 +49,19 @@ Features

The atomic replace allows:

+ Atomically revert some functions in a previous patch while
- Atomically revert some functions in a previous patch while
upgrading other functions.

+ Remove eventual performance impact caused by core redirection
- Remove eventual performance impact caused by core redirection
for functions that are no longer patched.

+ Decrease user confusion about dependencies between livepatches.
- Decrease user confusion about dependencies between livepatches.


Limitations:
------------

+ Once the operation finishes, there is no straightforward way
- 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.
Expand All @@ -74,7 +74,7 @@ Limitations:
only when the transition was not forced.


+ Only the (un)patching callbacks from the _new_ cumulative livepatch are
- 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
Expand All @@ -93,7 +93,7 @@ Limitations:
enabled patches were called.


+ There is no special handling of shadow variables. Livepatch authors
- 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.
Expand Down
21 changes: 21 additions & 0 deletions Documentation/livepatch/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
:orphan:

===================
Kernel Livepatching
===================

.. toctree::
:maxdepth: 1

livepatch
callbacks
cumulative-patches
module-elf-format
shadow-vars

.. only:: subproject and html

Indices
=======

* :ref:`genindex`
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ Livepatch

This document outlines basic information about kernel livepatching.

Table of Contents:

1. Motivation
2. Kprobes, Ftrace, Livepatching
3. Consistency model
4. Livepatch module
4.1. New functions
4.2. Metadata
5. Livepatch life-cycle
5.1. Loading
5.2. Enabling
5.3. Replacing
5.4. Disabling
5.5. Removing
6. Sysfs
7. Limitations
.. Table of Contents:
1. Motivation
2. Kprobes, Ftrace, Livepatching
3. Consistency model
4. Livepatch module
4.1. New functions
4.2. Metadata
5. Livepatch life-cycle
5.1. Loading
5.2. Enabling
5.3. Replacing
5.4. Disabling
5.5. Removing
6. Sysfs
7. Limitations
1. Motivation
Expand All @@ -40,14 +40,14 @@ There are multiple mechanisms in the Linux kernel that are directly related
to redirection of code execution; namely: kernel probes, function tracing,
and livepatching:

+ The kernel probes are the most generic. The code can be redirected by
- The kernel probes are the most generic. The code can be redirected by
putting a breakpoint instruction instead of any instruction.

+ The function tracer calls the code from a predefined location that is
- The function tracer calls the code from a predefined location that is
close to the function entry point. This location is generated by the
compiler using the '-pg' gcc option.

+ Livepatching typically needs to redirect the code at the very beginning
- Livepatching typically needs to redirect the code at the very beginning
of the function entry before the function parameters or the stack
are in any way modified.

Expand Down Expand Up @@ -249,7 +249,7 @@ The patch contains only functions that are really modified. But they
might want to access functions or data from the original source file
that may only be locally accessible. This can be solved by a special
relocation section in the generated livepatch module, see
Documentation/livepatch/module-elf-format.txt for more details.
Documentation/livepatch/module-elf-format.rst for more details.


4.2. Metadata
Expand All @@ -258,7 +258,7 @@ Documentation/livepatch/module-elf-format.txt for more details.
The patch is described by several structures that split the information
into three levels:

+ struct klp_func is defined for each patched function. It describes
- struct klp_func is defined for each patched function. It describes
the relation between the original and the new implementation of a
particular function.

Expand All @@ -275,7 +275,7 @@ into three levels:
only for a particular object ( vmlinux or a kernel module ). Note that
kallsyms allows for searching symbols according to the object name.

+ struct klp_object defines an array of patched functions (struct
- struct klp_object defines an array of patched functions (struct
klp_func) in the same object. Where the object is either vmlinux
(NULL) or a module name.

Expand All @@ -285,7 +285,7 @@ into three levels:
only when they are available.


+ struct klp_patch defines an array of patched objects (struct
- struct klp_patch defines an array of patched objects (struct
klp_object).

This structure handles all patched functions consistently and eventually,
Expand Down Expand Up @@ -337,14 +337,16 @@ operation fails.
Second, livepatch enters into a transition state where tasks are converging
to the patched state. If an original function is patched for the first
time, a function specific struct klp_ops is created and an universal
ftrace handler is registered[*]. This stage is indicated by a value of '1'
ftrace handler is registered\ [#]_. This stage is indicated by a value of '1'
in /sys/kernel/livepatch/<name>/transition. For more information about
this process, see the "Consistency model" section.

Finally, once all tasks have been patched, the 'transition' value changes
to '0'.

[*] Note that functions might be patched multiple times. The ftrace handler
.. [#]
Note that functions might be patched multiple times. The ftrace handler
is registered only once for a given function. Further patches just add
an entry to the list (see field `func_stack`) of the struct klp_ops.
The right implementation is selected by the ftrace handler, see
Expand All @@ -368,7 +370,7 @@ the ftrace handler is unregistered and the struct klp_ops is
freed when the related function is not modified by the new patch
and func_stack list becomes empty.

See Documentation/livepatch/cumulative-patches.txt for more details.
See Documentation/livepatch/cumulative-patches.rst for more details.


5.4. Disabling
Expand Down Expand Up @@ -421,7 +423,7 @@ See Documentation/ABI/testing/sysfs-kernel-livepatch for more details.

The current Livepatch implementation has several limitations:

+ Only functions that can be traced could be patched.
- Only functions that can be traced could be patched.

Livepatch is based on the dynamic ftrace. In particular, functions
implementing ftrace or the livepatch ftrace handler could not be
Expand All @@ -431,7 +433,7 @@ The current Livepatch implementation has several limitations:



+ Livepatch works reliably only when the dynamic ftrace is located at
- Livepatch works reliably only when the dynamic ftrace is located at
the very beginning of the function.

The function need to be redirected before the stack or the function
Expand All @@ -445,15 +447,15 @@ The current Livepatch implementation has several limitations:
this is handled on the ftrace level.


+ Kretprobes using the ftrace framework conflict with the patched
- Kretprobes using the ftrace framework conflict with the patched
functions.

Both kretprobes and livepatches use a ftrace handler that modifies
the return address. The first user wins. Either the probe or the patch
is rejected when the handler is already in use by the other.


+ Kprobes in the original function are ignored when the code is
- Kprobes in the original function are ignored when the code is
redirected to the new implementation.

There is a work in progress to add warnings about this situation.
Loading

0 comments on commit 89e33ea

Please sign in to comment.