Commit Graph

1376 Commits

Author SHA1 Message Date
Josh Poimboeuf
2991e6259a create-diff-object: Fix PPC64_LOCAL_ENTRY_OFFSET usage
GCC 7.2.1 complains about the usage of the PPC64_LOCAL_ENTRY_OFFSET
macro:

  create-diff-object.c: In function ‘is_gcc6_localentry_bundled_sym’:
  create-diff-object.c:119:83: error: ‘<<’ in boolean context, did you mean ‘<’ ? [-Werror=int-in-bool-context]
            (((1 << (((other) & STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
  create-diff-object.c:140:10: note: in expansion of macro ‘PPC64_LOCAL_ENTRY_OFFSET’
    return (PPC64_LOCAL_ENTRY_OFFSET(sym->sym.st_other) &&
          ^~~~~~~~~~~~~~~~~~~~~~~~

Fix it by explicitly treating the macro as an integer instead of a bool.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-03-16 17:20:27 -05:00
Joe Lawrence
3adfc41217
Merge pull request #794 from sm00th/dirtytree-fix
Fix resulting module vermagic when source dir is a git tree
2018-03-14 09:58:24 -04:00
Artem Savkov
5782a977a8 Fix resulting module vermagic when source dir is a git tree
Sometimes git doesn't see that the patches have been reverted, if that
happens during ./scripts/setlocalversion call the resulting patch module
is built with a wrong vermagic because the tree is still considered
dirty.

Fix by moving git update-index call into remove_patches function so that
it is called every time the patches are reverted, not only on cleanup.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-03-13 16:23:03 +01:00
Joe Lawrence
07c7200cc9
Merge pull request #790 from euspectre/retry-disable
If kpatch fails to disable a patch, retry a few times
2018-02-28 10:30:50 -05:00
Evgenii Shatokhin
23f4e7554d If kpatch fails to disable a patch, retry a few times
This is similar to how loading of the patches works now. Needed mostly
for the "old" kpatch, i.e. for the kernels that do not support livepatch.

If the patched functions are currently used, loading of the patch fails
with "Device or resource busy" error. kpatch script then retries the
operation several times.

In some cases, it could be convenient to do the same thing when
unloading or simply disabling the patches. One of the use cases is when
it is needed to replace a loaded cumulative patch with its previous
version, esp. if the patches have patch/unpatch hooks. It is often more
reliable to disable the loaded patches first and then load the new
patch. Disable operation may fail due to activeness safety check - so
let us retry it a few times.

v2:
As suggested in PR #790, disable_patch() no longer returns a value but
rather calls die() at the point of error.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2018-02-28 14:44:00 +03:00
Joe Lawrence
2d0fd42c64
Merge pull request #788 from euspectre/no-hint-in-error-msgs
kpatch-build: 'hint' is not needed in kpatch_create_*_sections()
2018-02-22 10:03:32 -05:00
Evgenii Shatokhin
f8669fa8e8 kpatch-build: 'hint' is not needed in kpatch_create_*_sections()
Found in the scope of https://github.com/dynup/kpatch/pull/755 but not
related to the main problem discussed there.

kpatch_create_patches_sections() and kpatch_create_intermediate_sections()
used 'hint' in error messages.

However, the string 'hint' refers to is owned by 'kelf_base' and is
freed before kpatch_create_*_sections() are called. As a result, if
these functions try to output errors and print 'hint',
create-diff-object will crash.

As suggested in the mentioned PR, 'hint' is actually no longer needed at
that stage, so I have removed it from kpatch_create_*_sections().
2018-02-22 15:06:20 +03:00
Joe Lawrence
6d0d8d0b04
Merge pull request #786 from euspectre/makefile-krel-fix
kmod/core: fix definition of KERNELRELEASE
2018-02-20 15:08:01 -05:00
Joe Lawrence
17ea5939e1
Merge pull request #787 from euspectre/help-no-initrd
Do not mention initrd in the help messages and in the man page
2018-02-20 15:06:41 -05:00
Evgenii Shatokhin
cc09c5efd3 Do not mention initrd in the help messages and in the man page
Kpatch no longer uses initrd to make sure the patch modules are loaded
at boot. The users could either install the provided systemd service
for that or come up with some other solution.

The messages mentioning initrd could confuse the users.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2018-02-20 17:27:25 +03:00
Evgenii Shatokhin
03c41d05e3 kmod/core: fix definition of KERNELRELEASE
A cosmetic fix.

If KPATCH_BUILD ending with 'build/' is passed to 'make', KERNELRELEASE
will become 'build' and the error message will look like:

"<...> doesn't exist. Try installing the kernel-devel-build RPM or
linux-headers-build DEB."

Let us fix that.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2018-02-19 13:13:03 +03:00
Joe Lawrence
84f2405dd3
Merge pull request #784 from euspectre/kpatch-retry-cosmetic
kpatch: a couple small enhancements in retry logic
2018-02-08 11:49:46 -05:00
Evgenii Shatokhin
58cc8fc626 kpatch: make it easier to tune the number of attempts to load the patch
... and the interval between the retries.

If activeness safety check fails and the patch fails to load, kpatch waits
for 2 seconds and then retries loading of that patch.

It may be needed to change the number of retries and the interval
between them in some cases, e.g. during stress testing of patches, etc.

Make it a bit easier by keeping these values in the variables close to
the beginning of the script.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2018-02-08 15:08:25 +03:00
Evgenii Shatokhin
2ac771fbe2 kpatch: set LC_ALL=C explicitly when loading the patch module
kpatch checks the messages output by insmod to decide if loading failed
with -EBUSY (i.e. activeness safety check failed). It looks for
"Device or resource busy" message, but one cannot guarantee it is not
output in some other language.

Let us use LC_ALL=C to be sure.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2018-02-08 15:08:19 +03:00
Joe Lawrence
4ef38429ab
Merge pull request #782 from bmcculley/patch-1
dnf to yum
2018-01-11 11:19:11 -05:00
bmcculley
c3a1d5c762
fixing RHEL and oracle typos as well. 2018-01-10 20:08:06 -05:00
bmcculley
00cdbee63c
dnf to yum
switch dnf to yum command under centos 7 section.
2018-01-10 20:04:14 -05:00
Josh Poimboeuf
866b6a26ea
Merge pull request #777 from aliceinwire/version_update
version update
2017-12-29 07:55:34 -06:00
Alice Ferrazzi
db6efbb8c7 version update 2017-12-27 22:13:14 +09:00
Joe Lawrence
00958de8e9
Merge pull request #775 from aliceinwire/manpage
updated man page
2017-12-21 16:40:21 -05:00
Alice Ferrazzi
70aaf2b063 updated man page 2017-12-22 02:20:20 +09:00
Josh Poimboeuf
258ac3f39a
Merge pull request #757 from jpoimboe/TODO-ppc-fix
Some ppc64le cleanups and fixes
2017-12-20 23:02:48 -06:00
Joe Lawrence
f4c0f3209e
Merge pull request #772 from aliceinwire/Readme_add_Gentoo
Add Gentoo to README
2017-12-05 09:29:00 -05:00
Alice Ferrazzi
4c5049f7e0 Add Gentoo to README 2017-12-03 23:39:28 +09:00
Joe Lawrence
6d1425e132
Merge pull request #760 from juergh/improve-logging
Improve logging
2017-11-17 15:32:31 -05:00
Joe Lawrence
270d783947
Merge pull request #759 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 #753 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 #754.

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 #756 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 #750 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