1
0
mirror of https://github.com/dynup/kpatch synced 2025-03-30 07:06:23 +00:00
Commit Graph

1401 Commits

Author SHA1 Message Date
Joe Lawrence
270d783947
Merge pull request from juergh/master-next
kpatch-build cleanups
2017-11-17 11:02:41 -05:00
Juerg Haefliger
757bc71d2b kpatch-build: Add additional debug modes
By specifying -d, --debug multiple times, the following additional
debug modes can be enabled:
  -d -d:       Writes everything that is written to the logfile also to
               stdout.
  -d -d -d:    Same as '-d -d' plus sets 'xtrace' in kpatch-build.
  -d -d -d -d: Same as '-d -d -d' plus sets 'xtrace' in kpatch-gcc.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-17 15:04:11 +01:00
Josh Poimboeuf
c1db043fae
Merge pull request from joe-lawrence/consistency_model
kpatch script - livepatch fixups
2017-11-15 17:34:22 -06:00
Joe Lawrence
52c12cbad6 kpatch: wait for livepatch transitions, poke stragglers
When loading a livepatch, wait for the patching transition to complete
within a reasonable timeframe, then poke any stalled tasks with a
signal.  If the transition is still taking too long, reverse the patch
and unload the livepatch.

When re-enabling a livepatch, do the same wait and signaling.  If the
expected time expires, disable the livepatch.

When unloading a livepatch, perform the wait/signaling, but only emit an
error message if the transition exceeds the time limit.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-11-15 10:44:42 -05:00
Joe Lawrence
3582e10e42 kpatch: signal stalled processes
Add a "signal" command line option that iterates over all processes that
may be holding up the current livepatch transition.  Send such processes
a SIGSTOP / SIGCONT combination to try and expedite the transition.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-11-15 10:44:42 -05:00
Joe Lawrence
fb0bc53eb7 kpatch: show transitioning patches and stalled tasks
In 'kpatch list' output, show the current patch state: enabled,
disabled, and livepatch mid-transition states enabling... and
disabling...

Also provide a list of any tasks that are stalling a livepatch
transition.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-11-15 10:44:42 -05:00
Joe Lawrence
a2fbce1587 kpatch: don't complain about missing livepatch .kpatch.checksum
The verify_module_checksum() function reads a kpatch-specific ELF
section to compare on-disk and in-memory kernel modules.  The function
only reports a miscompare if the .kpatch.checksum section actually
exists.  Livepatches don't have such section, so throw away any "Section
'.kpatch.checksum' was not dumped because it does not exist!" warnings
from readelf.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-11-15 10:44:42 -05:00
Juerg Haefliger
b2c00b1215 kpatch-build: Add a flexible logger function
Add a logger funcition that can be used to log to both stdout and the
logfile or only to the logfile. This is needed for subsequent patches
where we introduce an alternate debug mode.

Since we're piping to a logger now, we need to set 'pipefail' otherwise
the return status of such a pipeline is always 0 (the exit status of the
logger) and we won't catch any errors.

From the bash manpage:
  The return status of a pipeline is the exit status of the last command,
  unless the pipefail option is enabled

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-15 09:42:41 +01:00
Josh Poimboeuf
63a94b8323 gcc-plugin: create a ppc64le GCC plugin which inserts nops after local calls
This is in response to an upstream discussion for the following patch:

  https://lkml.kernel.org/r/1508217523-18885-1-git-send-email-kamalesh@linux.vnet.ibm.com

This should hopefully make it a lot easier for the ppc64le kernel module
code to support klp relocations.

The gcc-common.h and gcc-generate-rtl-pass.h header files are copied
from the upstream Linux source tree.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-11-10 09:17:00 -06:00
Juerg Haefliger
b5f77d0608 kpatch-build: Stop reading vmlinux after the first match
When searching for 'Linux version ...' in vmlinux, stop after the first
match so that we don't keep reading a potentially huge file.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-10 08:51:41 +01:00
Juerg Haefliger
7770c18f93 kpatch-build: Fix the logfile checks for 'undefined'
The current checks never fail, because the first grep in the pipeline
doesn't write anything to stdout.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-10 08:51:41 +01:00
Juerg Haefliger
1950c193ec kpatch-build: Add -a, --archversion commandline option
This can be used for building a kpatch module for a non-running
kernel. Note that the correct kernel and debug packages still need
to be installed.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-10 08:50:22 +01:00
Josh Poimboeuf
57321ad7e6 create-diff-object: don't convert relocation destinations to symbols
When creating .kpatch.relocations, there's no reason to convert the
relocation destinations to symbols.  In fact, it's actively harmful
because it makes it harder for create-klp-module to deal with the GCC 6+
8-byte localentry gap.

This also fixes a regression which was introduced in 5888f316e6, which
broke ppc64le relocations.

Fixes .

Fixes: 5888f316e6 ("create-klp-module: support unbundled symbols")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-11-09 19:16:14 -06:00
Josh Poimboeuf
c6c153431f create-klp-module: get rid of redundant kpatch_relocation.offset field
kpatch_relocation's 'dest' addend and 'offset' fields are redundant.  In
fact, the 'offset' field isn't always accurate because it doesn't have a
relocation, so its value doesn't adjust when multiple .o files are
combined.  Just use the 'dest' addend instead.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-11-09 19:16:14 -06:00
Josh Poimboeuf
f0518ef58a create-diff-object: fix ppc64le kpatch_replace_sections_syms() bundling assumption
kpatch_replace_sections_syms() assumes that all bundled symbols start at
section offset zero.  With ppc64le and GCC 6+, that assumption is no
longer accurate.  When replacing a rela symbol section with its
corresponding symbol, adjust the addend as necessary.

Also, with this fix in place, the workaround in
create_klp_relasecs_and_syms() can be removed.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-11-09 19:16:14 -06:00
Josh Poimboeuf
bc2d5aa815 create-diff-object: allow correlated symbols to have different st_values
On ppc64le, adding a printk to total_mapping_size() caused it to change
from non-localentry to localentry, presumably because it was no longer a
leaf function.  With GCC 6, a localentry function is offset by 8 in the
section, so different st_values are ok.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-11-09 19:16:14 -06:00
Josh Poimboeuf
e598d9628f create-diff-object: simplify is_gcc6_localentry_bundled_sym()
The STT_FUNC and SHN_UNDEF checks aren't needed because they're already
implied by the localentry check.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-11-09 19:16:14 -06:00
Josh Poimboeuf
1eac193bfc create-diff-object: is_localentry_sym -> is_gcc6_localentry_bundled_sym
is_localentry_sym() isn't quite the right name, because it also checks
for the 8-byte gap introduced by GCC 6, and also checks that the
function is otherwise at the beginning of the section.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-11-09 19:16:14 -06:00
Juerg Haefliger
862327db3e kpatch-build: Fix indentation
Replace stray spaces with tabs, except in the usage output where tabs
don't make much sense.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-09 15:03:19 +01:00
Juerg Haefliger
15cdcc8b5f kpatch-build: Add -n, --name to the usage
Fixes: 8dc25d79d1 ('kpatch-build: let user specify kpatch module name')
Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-09 15:03:19 +01:00
Juerg Haefliger
c33adf0ff2 kpatch-build: Remove unnecessary 'make prepare'
This was introduced in commit 5352d8b01a ('build objects in separate
directory to fix caching') but is no longer necessary.

Fixes: 2e99d6b7a4 ('kpatch-build: build the kernel in ~/.kpatch/src again')
Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-09 15:03:06 +01:00
Josh Poimboeuf
d6bcffe954
Merge pull request from juergh/fix-clean-rule
kpatch-build: Fix clean rule (remove insn/*.o)
2017-11-07 11:36:09 -06:00
Juerg Haefliger
b6ba60f740 kpatch-build: Fix clean rule (remove insn/*.o)
Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
2017-11-07 13:18:42 +01:00
Joe Lawrence
64ba06606f Merge pull request from jpoimboe/rhel75
Fix livepatch version checks for RHEL
2017-10-18 14:11:13 -04:00
Josh Poimboeuf
2e85ec5672 kpatch-build: add support for CONFIG_LIVEPATCH on RHEL
Fix the version checks for when we enable CONFIG_LIVEPATCH on RHEL.  It
will be based on the latest upstream code.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-10-18 06:33:27 -05:00
Josh Poimboeuf
d44a4b9df5 livepatch-patch-hook: clean up version checks
Clean up the kernel version checks a little bit.  Use 'HAVE_*' naming
everywhere for consistency.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-10-18 06:32:53 -05:00
Joe Lawrence
ae074693e0 Merge pull request from jpoimboe/special-struct-padding
create-diff-object: handle missing padding at end of special section
2017-10-17 20:55:07 -04:00
Josh Poimboeuf
c2dc3836e8 create-diff-object: handle missing padding at end of special section
The paravirt_patch_site struct has 12 bytes of data and 4 bytes of
padding, for a total of 16 bytes.  However, when laying out the structs
in the .parainstructions section, the vmlinux script only aligns before
each struct's data, not after.  So the last entry doesn't have the
4-byte padding, which breaks kpatch_regenerate_special_section()'s
assumption of a 16-byte struct, resulting in a memcpy past the end of
the section.

Fixes .

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-10-17 11:09:01 -05:00
Josh Poimboeuf
7d99acf6ad Merge pull request from rudis/master
Shell quoting improvements and additional cleanup
2017-10-16 09:39:49 -05:00
Joe Lawrence
064f32ca4f Merge pull request from jpoimboe/backwards-compatibility
kpatch: add ABI backwards compatibility
2017-10-13 13:28:59 -04:00
Josh Poimboeuf
9eed5d4bac kpatch: add ABI backwards compatibility
When running a kernel for a long period of time without rebooting, it's
possible that newer versions of the kpatch script may get installed.  So
new versions of the kpatch script need to support old versions of
kpatch.ko.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-10-13 10:30:23 -05:00
Simon Ruderich
70aa26a0c0 kpatch-build: always use spaces around pipes 2017-10-13 11:59:59 +02:00
Simon Ruderich
8173d35a15 kpatch-build: use grep -F to match plain strings
The pattern contains dots which are treated as any character but in this
case should only match a dot.
2017-10-13 11:57:07 +02:00
Simon Ruderich
c2a7f2449a kpatch-build: ignore false positives detected by shellcheck 2017-10-13 11:47:56 +02:00
Simon Ruderich
223c65015c kpatch-build: further shell code cleanup
Replace find * with find ./* to prevent treating files with dashes as
options. The leading ./ is later used in comparisons and thus must be
removed before that.

Found by shellcheck.
2017-10-13 11:45:06 +02:00
Simon Ruderich
73cf473a21 kpatch/kpatch: silence shellcheck warning
Hiding the return value isn't an issue here, but lets keep shellcheck
happy.
2017-10-13 08:53:06 +02:00
Simon Ruderich
554e8839e3 Makefile: add check target to run shellcheck 2017-10-13 08:52:16 +02:00
Simon Ruderich
14706bcd4d Makefile: add missing .PHONY targets 2017-10-13 08:51:23 +02:00
Josh Poimboeuf
3081c8874c Merge pull request from rudis/doc
Documentation updates
2017-10-12 23:46:09 -05:00
Simon Ruderich
a51f9de534 README.md: use https:// for YouTube links 2017-10-12 17:32:12 +02:00
Simon Ruderich
b58c84fed0 README.md: add instructions for Debian 9 (Stretch) 2017-10-12 17:27:04 +02:00
Simon Ruderich
3507e30781 README.md: add release names to Debian versions
Also remove inconsistent minor version.
2017-10-12 17:27:04 +02:00
Simon Ruderich
c8fbe85d7f README.md: fix minor typo 2017-10-12 17:27:04 +02:00
Simon Ruderich
0b8a53163d kpatch-build: make gcc version check distribution independent
gcc --version varies too much for sane comparisons with vmlinux's
.comment section. Therefore compile a test file and compare its .comment
section.

Also fix gcc 4.8 check which used a lexicographically comparison which
will break for gcc versions >= 10. Instead check for the required
compiler options.

Closes .
2017-10-12 17:17:56 +02:00
Simon Ruderich
c06d17f020 doc: patch-author-guide: fix minor typo 2017-10-12 09:15:18 +02:00
Simon Ruderich
fa6a6dd821 kpatch-build: further shell code cleanup
- Replace grep | wc -l with grep -c.
- Use find -print0 and xargs -0 to handle non-alphanumeric filenames
  (shouldn't be an issue for us but it's good practice).
- Replace expr with $(( )).

Found by shellcheck.
2017-10-11 09:36:05 +02:00
Simon Ruderich
f796dc6014 kpatch-build: cleanup quoting of $UBUNTU_ABI
The double quotes are confusing as they don't quote $UBUNTU_ABI and thus
have no real effect. As $UBUNTU_ABI is a number simply remove them and
put $UBUNTU_ABI into the surrounding quotes.

Found by shellcheck.
2017-10-10 12:19:29 +02:00
Simon Ruderich
60e5125cb0 kpatch, kpatch-build: further shell code cleanup
- Replace echo $(cmd) with just cmd.
- Replace $@ inside quotes with $*.
- Always die if cd fails.
- Ensure rm -rf "$TEMPDIR"/* never expands to rm -rf /*.

Found by shellcheck.
2017-10-07 10:12:40 +02:00
Simon Ruderich
08fa04bb0d kpatch, kpatch-build, kpatch-gcc: quote all variables
Without proper quoting kpatch fails if the argument contains spaces, the
other scripts might be affected as well.

Not all new quotes are strictly necessary but they were added for
consistency with the existing code and to prevent copy & paste errors in
the future.

There's one conversion which is not straight-forward:

-       grepname=$grepname\\\.o
+       grepname="$grepname\.o"

There are different quoting rules with and without the double quotes.
2017-10-07 10:12:40 +02:00
Josh Poimboeuf
9017bfd32d Merge pull request from joe-lawrence/valgrind_create_klp_module
kpatch-build: create-klp-module: set default arguments.no_klp_arch
2017-10-06 10:02:15 -05:00