Commit Graph

2183 Commits

Author SHA1 Message Date
Joe Lawrence
354e204540 patch-author-guide: mention issue #1124 __LINE__ shift
Issue #1124 ("Jump label issues are triggered from an unrelated
function") was caused by a minor __LINE__ change in a pr_warn statement.
Reference it here in the author guide for future reference.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-07-21 16:22:17 -04:00
Joe Lawrence
37ce430773
Merge pull request #1127 from kamalesh-babulal/make-unsupported-arch
kpatch-build/Makefile: Fail build on unsupported architectures
2020-07-21 16:17:25 -04:00
Joe Lawrence
6531a7e075 kpatch-build: avoid modpost .output.o.cmd complaints
The modpost step complains about one of our generated files, output.o
and that it can't find a corresponding .cmd file for it (full path names
stripped):

	WARNING: could not find .output.o.cmd for output.o

This was turned into an error in v5.8:

	.output.o.cmd: No such file or directory

Avoid this by creating an empty .cmd file so that modpost acknowledges
that the file exists, but doesn't parse anything out of it.

Fixes #1125
Reported-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> (for v5.8+)
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-07-21 09:52:48 -04:00
Yannick Cote
da58c9aa19
Merge pull request #1122 from euspectre/kpatch-test-custom-tools
kpatch-test: make it easier to use custom kpatch and kpatch-build commands
2020-07-20 18:38:47 -04:00
Kamalesh Babulal
ea647e50ae kpatch-build/Makefile: Fail build on unsupported architectures
Fail the kpatch build, while attempted to build on unsupported
architecture. The build will eventually fail but with the error that
doesn't hint the user clearly about the support status of kpatch, on the
architecture.  This patch forces the build error with the message about
the unsupported status, avoiding confusion to the user.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-07-20 18:37:00 +05:30
Evgenii Shatokhin
78f2c063ae kpatch-test: make it easier to use custom kpatch and kpatch-build commands
The commands used to build the livepatches and to load or unload them
are currently hard-coded in kpatch-test.

This patch adds 2 options to kpatch-test to make it easier to use custom
kpatch and kpatch-build commands:

*  --system-kpatch-tools - if set, 'sudo kpatch' will be used to
load/unload the patches; 'kpatch-build' - to build them.

To use custom tools here, the user can adjust $PATH.

If the option is not set, kpatch-test will assume it is in kpatch source
tree, same as before this commit, and will use the tools from there.

* --kpatch-build-opts="..." - additional options to pass to
kpatch-build.

Example:

  ./kpatch-test \
    --system-kpatch-tools \
    --kpatch-build-opts="-s ./linux-src -c ./config -v ./vmlinux" \
    -d my_kpatch_tests/test/integration/v01

In this case, kpatch and kpatch-build installed in the system will be used,
and kpatch-build will look for the kernel source tree, configuration
file and vmlinux binary in the current directory.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
2020-07-16 20:36:23 +03:00
Joe Lawrence
01b8d34c4b
Merge pull request #1121 from sm00th/skip_cleanup_log
Keep build.log on --skip-cleanup
2020-07-01 08:53:48 -04:00
Artem Savkov
17ec03ef95 Keep build.log on --skip-cleanup
Before kpatch-build would only keep build.log with --debug option
specified, but it also makes sense to keep it if --skip-cleanup is
specified.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-07-01 10:03:51 +02:00
Yannick Cote
62cd3efc57
Merge pull request #1118 from sm00th/ddbg-fix
Don't enable dynamic debug during integration tests on older rhels
2020-06-30 18:46:52 -04:00
Josh Poimboeuf
3c5f6db366
Merge pull request #1119 from jpoimboe/latest-unit-tests
test/unit: Update to latest tests
2020-06-30 17:06:49 -05:00
Josh Poimboeuf
4d75b26fe5 test/unit: Update to latest tests
Update master to use the latest tests for #1091 and #1102.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-06-30 17:03:48 -05:00
Artem Savkov
3fc97d75c3 Don't enable dynamic debug during integration tests on older rhels
RHELs older than 7.7 are missing 5279631271b3 "module: fix ddebug_remove_module()"
which leads to a crash if dynamic debug is used with livepatching.
Disable recent dynamic debug addition on those distros.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-06-30 11:48:28 +02:00
Yannick Cote
a6e8fd84cc
Merge pull request #1115 from kamalesh-babulal/tristate-lookup-fix
lookup: Add __UNIQUE_ID_ to maybe_discarded_sym list
2020-06-26 12:09:10 -04:00
Artem Savkov
32e2f502f5
Merge pull request #1116 from kamalesh-babulal/jump-labels-log-improv
create-diff-object: improve jump label warnings
2020-06-26 10:41:31 +02:00
Joe Lawrence
e0221f489e
Merge pull request #1117 from jpoimboe/rela-equal
Ignore changes to .altinstr_aux
2020-06-25 10:34:41 -04:00
Josh Poimboeuf
ed849a9b3e create-diff-object: Ignore changes to .altinstr_aux
On x86, .altinstr_aux is used to store temporary code which allows
static_cpu_has() to work before apply_alternatives() has run.  This code
is completely inert for modules, because apply_alternatives() runs
during module init, before the module is fully formed.  Any changed
references to it (i.e. changed addend) can be ignored.  As long as
they're both references to .altinstr_aux, they can be considered equal,
even if the addends differ.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-06-23 22:27:52 -05:00
Josh Poimboeuf
abd2ff81c7 create-diff-object: change rela_equal() to return bool
Change rela_equal's return value to bool to make its return semantics
more clear.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-06-23 22:20:33 -05:00
Kamalesh Babulal
514acc32e9 create-diff-object: improve jump label warnings
Improve logging of Jump label warnings with a new line between warnings.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-06-23 20:02:35 +05:30
Kamalesh Babulal
b381a0cc0b lookup: Add __UNIQUE_ID_ to maybe_discarded_sym list
Linux kernel tristate config options allows selected feature, either to
be built-in to the kernel or to be built as a kernel module. When built
as a kernel module, it's expected that the module, will be built with
module information such as author, license, description and others.

For each of the modinfo, a corresponding __UNIQUE_ID_ symbol is
generated.  Their lookup succeeds in the case of module but fails when
selected to built-in to the kernel, the reason being that the kernel
discards these __UNIQUE_ID_ symbols during linking. Add __UNIQUE_ID_
symbols to maybe_discarded_sym list, to avoid failure in case of
table->object is vmlinux.

i.e.:
 # cat .config|grep IOSCHED_BFQ (can be compiled as module too)
 CONFIG_IOSCHED_BFQ=y

 # readelf -sW ./block/bfq-iosched.o|grep UNIQUE
   219: 0000000000000000    54 OBJECT  LOCAL  DEFAULT  267 __UNIQUE_ID_description223
   220: 0000000000000036    16 OBJECT  LOCAL  DEFAULT  267 __UNIQUE_ID_license222
   221: 0000000000000046    19 OBJECT  LOCAL  DEFAULT  267 __UNIQUE_ID_file221
   222: 0000000000000059    25 OBJECT  LOCAL  DEFAULT  267 __UNIQUE_ID_author220
   223: 0000000000000072    22 OBJECT  LOCAL  DEFAULT  267 __UNIQUE_ID_alias219

the line below before the kpatch error, is a debug printf to find the failing lookup symbol:
Failed lookup for __UNIQUE_ID_description223
/root/kpatch/kpatch-build/create-diff-object: ERROR: bfq-iosched.o: find_local_syms: 180: couldn't find matching bfq-iosched.c local symbols in ./vmlinux symbol table

with the patch, it successfully builds with both y/m config options:
...
bfq-iosched.o: changed function: bfq_idle_slice_timer
Patched objects: vmlinux
Building patch module:
livepatch-0001-block-bfq-fix-use-after-free-in-b.ko
SUCCESS

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-06-18 12:40:57 +05:30
Joe Lawrence
ae64019237
Merge pull request #1112 from kamalesh-babulal/more-gcc10-fixes
gcc-plugin: ppc64le - GCC 10 fixes
2020-06-17 09:02:11 -04:00
Kamalesh Babulal
67aa131137 gcc-plugin: GCC 10 - update local/non local insn names
Kernel livepatching modules build on GCC 10, with patched functions
referring to local function would fail to load with the error:
 module_64: livepatch_ext4_cond_resched: Expected nop after call, got 7fe5fb78 at ext4_setup_system_zone+0x460/0xc90 [livepatch_ext4_cond_resched]

for more details on the error, refer to discussion at:
 https://lkml.kernel.org/r/1508217523-18885-1-git-send-email-kamalesh@linux.vnet.ibm.com

the reason was that the gcc-plugin would skip the pass on error, failing
to convert the local calls into global, i.e on ppc64le every global call
is followed by a nop instruction, that gets replaced by the kernel to
restore
the TOC/r2 value of the callee, while parsing the relocations and would
skip the TOC restoration for local functions, where the TOC remains the
same across sibling functions.

GCC 10 commit 07c48b61a082("[RS6000] Put call cookie back in AIX/ELFv2
call patterns") merged a couple of call codes definition, breaking the
plugin.  Change the plugin codes to match the GCC 10 codes.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-06-12 13:27:06 +05:30
Kamalesh Babulal
92c42039bf gcc-plugin: abort building klp module on error
Abort building the klp module, if the code for local and non-local calls
are not found instead of skipping the pass and building module, which
might result in un-loadable module with the kernel error:

module_64: livepatch_ext4_cond_resched: Expected nop after call, got 7fe5fb78 at ext4_setup_system_zone+0x460/0xc90 [livepatch_ext4_cond_resched]

gcc would not allow me to use "can't" in the error message and throw
build error:

gcc-plugins/ppc64le-plugin.c:49:17: error: contraction ‘can't’ in format; use ‘cannot’ instead [-Werror=format-diag]

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-06-12 13:26:50 +05:30
Yannick Cote
6caf77a114
Merge pull request #1111 from kamalesh-babulal/gcc-10-fix
gcc-plugin: Fix build failure with GCC 10
2020-06-11 09:11:25 -04:00
Kamalesh Babulal
fde1a75b7f gcc-plugin: Fix build failure with GCC 10
Building on Fedora 32 with GCC 10.1.1, triggers build failures:

In file included from gcc-plugins/ppc64le-plugin.c:1:
gcc-plugins/gcc-common.h:37:10: fatal error: params.h: No such file or directory
   37 | #include "params.h"
      |          ^~~~~~~~~~
compilation terminated.

In file included from gcc-plugins/ppc64le-plugin.c:1:
gcc-plugins/gcc-common.h:841:13: error: redefinition of ‘static bool is_a_helper<T>::test(U*) [with U = const gimple; T = const ggoto*]’
  841 | inline bool is_a_helper<const ggoto *>::test(const_gimple gs)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gcc-plugins/gcc-common.h:124,
                 from gcc-plugins/ppc64le-plugin.c:1:
/usr/lib/gcc/ppc64le-redhat-linux/10/plugin/include/gimple.h:1037:1:
note: ‘static bool is_a_helper<T>::test(U*) [with U = const gimple; T = const ggoto*]’ previously declared here
 1037 | is_a_helper <const ggoto *>::test (const gimple *gs)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gcc-plugins/ppc64le-plugin.c:1:
gcc-plugins/gcc-common.h:848:13: error: redefinition of ‘static bool is_a_helper<T>::test(U*) [with U = const gimple; T = const greturn*]’
  848 | inline bool is_a_helper<const greturn *>::test(const_gimple gs)
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gcc-plugins/gcc-common.h:124,
                 from gcc-plugins/ppc64le-plugin.c:1:
/usr/lib/gcc/ppc64le-redhat-linux/10/plugin/include/gimple.h:1489:1:
note: ‘static bool is_a_helper<T>::test(U*) [with U = const gimple; T = const greturn*]’ previously declared here
 1489 | is_a_helper <const greturn *>::test (const gimple *gs)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

as per kernel commit c7527373fe28 ("gcc-common.h: Update for GCC 10")
 "params.h header file has been dropped from GCC 10 and is_a_helper()
  macro is now defined in gimple.h"

this patch fix them by guarding the both param.h header file and
is_a_helper() with #ifdef checking for gcc version < 10000.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2020-06-09 20:34:27 +05:30
julien-thierry
181c512867
Merge pull request #1110 from julien-thierry/shellcheck-fixes
Shellcheck fixes
2020-06-08 12:32:35 +01:00
Julien Thierry
60bdd3435b Makefile: Add test and utility scripts to files to check
Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
22e2c1a95c test: Ignore remaining quoting warnings
Fixing the remaining warnings suggesting to quote the output subshell
invocation would hinder readability. Also the results of dirname and
"type -p" used in the subshell should return spaceless strings in kpatch
usecases.

Ignore the warnings for now.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
e906db9b81 test: Fix shellcheck quoting issues
It wouldn't be bash without pondering over what to quote or not to
quote.

Shellcheck reports a bunch of quoting issues in our scripts. Fix what
can be fixed.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
f876aed900 test/difftree.sh: Silence warning about looping over find output
Shellcheck emits the following warning:
SC2044: For loops over find output are fragile. Use find -exec or a while read loop.

Disable it for now.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
ac2d6e3759 test/difftree.sh: Remove useless command invocations
Shellchecks warns about two useless commands:
SC2005: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.

Simplify that line with those suggestions.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
4dd55cd407 test: Avoid issues with names starting with dashes
Shellcheck emmits the following warning:
SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options.

Which seems like a fair recommendation.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
22d1046412 test/difftree.sh: Remove unused variable
Shellcheck reports VMVLINUX is unused. Also it seems to has a typo
in the name.

Lets remove it.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
857f892407 kpatch-test: Fix type error
Shellcheck reports the following error:
SC2145: Argument mixes string and array.

Lets pretend that types are a thing in bash and use the list of
arguments as a single string instead of the array of arguments.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
555a578fe9 kpatch-test: Remove unused variable
As reported by shellcheck, RMMOD seems no longer used. Get rid of it.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
1839980d1d test/integration: Silence warning about which
Shellcheck complains with the following warning:
SC2230: which is non-standard.

It is probably fair to assume that which is available for now, so just
ignore the warning.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Julien Thierry
9a66fa7df4 test/integration: Silence unspecified input warning
Shellcheck complains with the following warning:
SC1091: Not following: /etc/os-release was not specified as input (see shellcheck -x)

Which is already silenced in lib.sh.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 20:30:28 +01:00
Yannick Cote
ae6819f142
Merge pull request #1109 from julien-thierry/rhel8-deps
Rhel8 deps
2020-06-04 13:11:35 -04:00
Julien Thierry
ea8c6169e8 README: Recommend using available script to install dependencies
A bash script is available to automatically install necessary
dependencies for building/using kpatch on some distributions.

Update the README sections for those distributions to use that script.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-04 17:44:47 +01:00
Julien Thierry
443cdedb29 test/integration: Explicitly add some missing dependencies for RHEL-8
On RHEL-8, yum builddep misses some necessary dependencies to build the
kernel.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-02 19:40:40 +01:00
Julien Thierry
4df66fa15f test/integration: Handle python version for RHEL-8 platforms
On RHEL-8, version agnostic python-devel package does not exist.

On previous RHEL releases, python-devel is for python2.

On RHEL-8, the platform-python (which provides the needed utilities)
is python3.

Assuming this will be the same for future RHEL releases, specify the
python major as part of the kpatch dependencies.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-06-02 19:40:36 +01:00
Yannick Cote
91952cbf86
Merge pull request #1108 from sm00th/verbose_stall
integration test: more debug info on stalled transition
2020-05-27 06:18:09 -04:00
Artem Savkov
5edd45bbcf Integration tests: enable dynamic debug in klp_try_switch_task()
Enable dynamic debug prints in klp_try_switch_task() function before
going through with load tests and switch back to a previous state
afterwards.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-05-20 14:54:41 +02:00
Artem Savkov
c3f9f4be2d kpatch: show stalled processes on failed transition
Call show_stalled_processes() before unloading the patch on stalled
transition.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-05-20 13:48:57 +02:00
Artem Savkov
7edcd7b36c kpatch: show stalled process's stack as well as pid
Add process stack information to output of show_stalled_process()

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-05-20 13:46:16 +02:00
Yannick Cote
dd24313e9b
Merge pull request #1106 from joe-lawrence/integration-tests-rhel-8.2
test/integration: add RHEL-8.2 integration tests
2020-05-18 09:22:31 -04:00
Joe Lawrence
5331463768
Merge pull request #1102 from joe-lawrence/jp-ppc-mcount
create-diff-object: Add ppc64le mcount support
2020-05-18 09:20:40 -04:00
Joe Lawrence
5a7a6cff9f
Merge pull request #1107 from joe-lawrence/integration-tests-rhel-8.1
testing/rhel-8.1: disable shadow-newpid-LOADED integration test
2020-05-18 09:19:16 -04:00
Joe Lawrence
1a4fd65282 testing/rhel-8.1: disable shadow-newpid-LOADED integration test
For consistency, disable the shadow-newpid-LOADED integration test
script since its corresponding patch already is already disabled.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-05-18 08:42:46 -04:00
Josh Poimboeuf
b958ed601c create-diff-object: Add ppc64le mcount support
Add the __mcount_loc section on ppc64le.  It has pointers to all the
mcount calls.  This will enable the ftrace hook to be used for patched
functions.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> (rebased)
2020-05-18 08:35:33 -04:00
Joe Lawrence
3aa8fd9a4f test/integration: add RHEL-8.2 integration tests
Patches rebased against RHEL-8.2 GA kernel-4.18.0-193.el8.

Tests disabled for errors when building against updated
4.18.0-193.3.1.el8_2.x86_64 z-stream kernel:

  * data-read-mostly.patch:
  dev.o: Found a jump label at __netif_receive_skb_core()+0x32, using key netstamp_needed_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  dev.o: Found a jump label at __netif_receive_skb_core()+0x95, using key generic_xdp_needed_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  dev.o: Found a jump label at __netif_receive_skb_core()+0xd0, using key ingress_needed_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  dev.o: Found a jump label at __netif_receive_skb_core()+0x412, using key nf_hooks_needed.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  /root/github-kpatch/kpatch-build/create-diff-object: ERROR: dev.o: kpatch_regenerate_special_section: 2344: Found 4 jump label(s) in the patched code. Jump labels aren't currently supported. Use static_key_enabled() instead.

  * gcc-static-local-var-4.patch (ppc64le only):
  aio.o: Found a jump label at aio_free_ring()+0x7c, using key devmap_managed_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  /root/github-kpatch/kpatch-build/create-diff-object: ERROR: aio.o: kpatch_regenerate_special_section: 2344: Found 1 jump label(s) in the patched code. Jump labels aren't currently supported. Use static_key_enabled() instead.

  * shadow-newpid.patch:
  fork.o: WARNING: unable to correlate static local variable ctr.70325 used by _do_fork, assuming variable is new
  fork.o: changed function: _do_fork
  exit.o: Found a jump label at do_exit()+0x6d3, using key devmap_managed_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  /root/github-kpatch/kpatch-build/create-diff-object: ERROR: exit.o: kpatch_regenerate_special_section: 2344: Found 1 jump label(s) in the patched code. Jump labels aren't currently supported. Use static_key_enabled() instead.

  * special-static.patch:
  fork.o: Found a jump label at copy_process.part.34()+0x1fc, using key memcg_kmem_enabled_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  fork.o: Found a jump label at copy_process.part.34()+0x21b, using key memory_cgrp_subsys_enabled_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  fork.o: Found a jump label at copy_process.part.34()+0x72a, using key memory_cgrp_subsys_enabled_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead.
  fork.o: Found a jump label at copy_process.part.34()+0x773, using key memcg_kmem_enabled_key.  Jump labels aren't supported with this kernel.  Use static_key_enabled() instead
  ./root/github-kpatch/kpatch-build/create-diff-object: ERROR: fork.o: kpatch_regenerate_special_section: 2344: Found 4 jump label(s) in the patched code. Jump labels aren't currently supported. Use static_key_enabled() instead.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-05-17 11:07:08 -04:00