Commit Graph

300 Commits

Author SHA1 Message Date
Joe Lawrence
314504b777 test/integration/rhel-9.1: add kernel-5.14.0-162.6.1.el9_1 tests
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-24 15:34:26 -04:00
Joe Lawrence
71fbd169f0 test/unit: update for .eh_frame removal
Update the unit test submodule reference to include ppc64le files w/o
.eh_frame.  At the same time, give additional guidance on stripping
these sections going forward.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-09-23 14:14:40 -04:00
Joe Lawrence
14f24fe481 test/integration: add missing syscall-LOADED.test for rhel-9.0
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-06-17 14:50:52 -04:00
Joe Lawrence
8aa91803be test/integration: tweak paravirt call in module.patch
Calling __flush_tlb_local() may result in a kernel warning:

  STATIC_NOPV void native_flush_tlb_local(void)
  {
          /*
           * Preemption or interrupts must be disabled to protect the access
           * to the per CPU variable and to prevent being preempted between
           * read_cr3() and write_cr3().
           */
          WARN_ON_ONCE(preemptible());

so use another paravirt call like slow_down_io() instead.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-06-16 11:06:10 -04:00
Joe Lawrence
30f09bfaa2 test/integration: add upstream 5.18.0 patches
Add patches rebased on top of upstream 5.18.0.

Integration tests for these can be ran as this:

  $ make PATCH_DIR="linux-5.18.0" KPATCH_BUILD_OPTS="--non-replace --sourcedir /path/to/src/linux-5.18.0" integration-slow

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-06-16 11:06:07 -04:00
Josh Poimboeuf
a1171b112e create-diff-object: Create missing section symbol
Recent toolchains only create a section symbol if it's needed, i.e. if
there's a reference to it.  If there's a missing section symbol in
kpatch_create_intermediate_sections(), create one instead of erroring
out.

Fixes #1272.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-06-07 20:31:10 -07:00
Joe Lawrence
b6abf449d6 test/integration/lib.sh: combine Fedora, CentOS with RHEL dependencies
All three distributions work more or less the same, so just combine
their dependency installs.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence
e72b876f97 test/integration/lib.sh: fix kernel build dependencies
The yum-builddep utility doesn't always install all the kernel build
dependencies.  Using the --skip-unavailable flag (rhel8+) lets us skip
over packages that it can't find, but continue to install the ones it
can. (Unavailable packages are usually platform-specific or not strictly
necessary for kpatch-build's kernel build invocation.)

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence
6b0b482d16 test/integration/lib.sh: tweak epel URL for rhel-major
EPEL ships an epel-release-latest-X.noarch.rpm per rhel-X major release.
Install the package matching the system release.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence
6a0dcb0da8
Merge pull request #1263 from anatasluo/master
kpatch-build: add support for openEuler
2022-05-13 10:00:22 -04:00
Joe Lawrence
f6e0142b3c
Merge pull request #1265 from joe-lawrence/integration-tests-rhel-9.0
test/integration/rhel-9.0: add kernel-5.14.0-70.13.1.el9_0 tests
2022-05-10 18:32:00 -04:00
Joe Lawrence
4774d070d2 test/integration/rhel-9.0: remove obsolete tests
Clean out any integration tests that no longer exercise their original
use cases.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-06 14:42:11 -04:00
anatasluo
2784f5056b kpatch-build: add support for openEuler
As I noticed, commit eaaced191 has added
partial support for openEuler.

This patch enables usage in openEuler like:
kpatch-build xxxx.patch

I test it in openEuler 21.09, for people who
want to use kpatch in openEuler, two more steps
are needed.

1) add repo source
source rpm package of openEuler kernel are put in
two places. One is
https://repo.openeuler.org/openEuler-21.09/source/
Another one is
https://repo.openeuler.org/openEuler-21.09/update/source/
The latter one is not inclued in rpm repo lists by default.

2) compile kernel with CONFIG_LIVEPATCH_PER_TASK_CONSISTENCY enabled
openEuler has its own strategy when trying to apply patches.
We can use the klp_enable_patch function only when
CONFIG_LIVEPATCH_PER_TASK_CONSISTENCY is enabled.

Signed-off-by: anatasluo <luolongjuna@gmail.com>
2022-05-06 10:58:20 +08:00
Joe Lawrence
dc1d49a142 test/integration/rhel-9.0: add kernel-5.14.0-70.13.1.el9_0 tests
* gcc-constprop.patch
In v4.20, 33e26418193f ("y2038: make do_gettimeofday() and get_seconds()
inline"), do_gettimeofdat() no longer exists as a stand alone function
in kernel/time/timekeeping.c.

* gcc-static-local-var-4.patch
Unlike on rhel-8.4, _always_inline put_aio_ring_file() is causing too
many inlines and results in modified, but not ftrace-able,
__do_sys_io_submit() and __do_sys_io_setup().  Remove the annotation
from this function.

* module.patch
In v4.20, 9ceddd9da134 ("knfsd: Allow lockless lookups of the exports"),
the nfs_exports_op seq_operations converted to RCU protected lookups.
Calling yield() from a kpatched e_show() results in a kernel warning,
"Voluntary context switch within RCU read-side critical section!"
Substitute with single_task_running(), which does not context switch or
have any other side effects.

In v5.10, ec6347bb4339 ("x86, powerpc: Rename memcpy_mcsafe() to
copy_mc_to_{user, kernel}()") did away with the mcsafe_key.  Use
another exported static key like context_tracking_enabled.

In v5.13, a0e2bf7cb700 ("x86/paravirt: Switch time pvops functions to
use static_call()"), paravirt_sched_clock() was converted from a
paravirt call to a non-exported static call.  Update the x86 code to
instead call __flush_tlb_local() (which is still a paravirt call).

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-01 11:34:28 -04:00
Joe Lawrence
734a9d9ef5 test/integration/rhel-8.6: add kernel-4.18.0-372.9.1.el8 tests
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-04-29 16:14:30 -04:00
Josh Poimboeuf
b0444d2599
Merge pull request #1173 from jpoimboe/syscall-macros
Add syscall macros
2022-04-26 11:44:02 -05:00
Josh Poimboeuf
f835cff795 test/unit: bump
Oops, this somehow ended up with a reference to nonexistent commit.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-22 09:33:49 -07:00
Josh Poimboeuf
373993ec1c test/integration: Add tests for patching a syscall
Add ".kpatch" to the end of "uname -s".

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-20 08:35:12 -07:00
Josh Poimboeuf
641daaa489 test/unit: bump to master
Pull in unit tests for dyndbg & __LINE__ fixes.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-04-06 07:34:21 -07:00
Joe Lawrence
f67a008478 test/unit: update for cross-arch testing
Bump the submodule reference and modify the unit test Makefile to check
all supported architectures.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-02-02 17:36:24 -05:00
Joe Lawrence
6c4c8c0a2d create-diff-object: update for __already_done
Upstream v5.14+ kernel change a358f40600b3 ("once: implement
DO_ONCE_LITE for non-fast-path "do once" functionality") consolidated a
bunch of do-once macros into a common macro:

  #define DO_ONCE_LITE_IF(condition, func, ...)				\
  	({								\
  		static bool __section(".data.once") __already_done;	\
  		...

which replaced static local variable __warned with __already_done.

Update any __warned static local checks to also look for the new
__already_done variable as well.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-12-08 11:05:31 -05:00
Artem Savkov
6fa8e4fd43 test/integration/linux-5.10.11: fix patches to build on ppc64le
module-call-external.patch and new-function.patch fail to build on
ppc64le with "Found an unsupported sibling call". Add
fno-optimize-sibling-calls attributes to functions in question.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-11-19 10:12:12 +01:00
Keiya Nobuta
7612b4da68 kpatch-test: Change DYNDEBUG_CONTROL setting to use sudo
Depending on environment, "Permission denied" error may occur
when /sys/kernel/debug/dynamic_debug/control setting.

Signed-off-by: Keiya Nobuta <nobuta.keiya@fujitsu.com>
2021-11-02 15:22:03 +09:00
Joe Lawrence
ef0ce9715a create-diff-object: fix use after free in kpatch-check-relocations()
Building data-read-mostly.patch on rhel-9.0-beta for ppc64le leads to a
segmentation fault:

    Program received signal SIGSEGV, Segmentation fault.
    kpatch_check_relocations (kelf=0x10040490) at create-diff-object.c:2571
    2571                                    sdata = rela->sym->sec->data;
    (gdb) bt
    (gdb) p rela->sym->sec->data
    Cannot access memory at address 0x160000007e

Valgrind narrows the problem down to invalid reads through rela->sym in
kpatch-check-relocations().

The culprits are kpatch_create_intermediate_sections(), which marks
symbols referenced by rela sections that are now dynrelas to be
stripped, and kpatch_strip_unneeded_syms(), which removes and frees
them.

The problem with the symbol stripping is that multiple relas may
reference the same ELF symbol.  If any remaining relocation references a
shared symbol, we must keep it.

Replace the symbol->strip boolean with an enumeration:

  SYMBOL_DEFAULT - initial value, symbol usage unknown
  SYMBOL_USED    - symbol is definitely used by a rela
  SYMBOL_STRIP   - symbol was only referenced by dynrela(s)

Allow transitions from SYMBOL_DEFAULT to SYMBOL_* and SYMBOL_STRIP to
SYMBOL_USED, but _not_ SYMBOL_USED to SYMBOL_*.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-09-14 22:54:09 -04:00
Artem Savkov
8f7e7c21b5
Merge pull request #1204 from sm00th/files
Support for multiple source files
2021-08-24 09:05:27 +02:00
Joe Lawrence
1ca8e8fc1f
Merge pull request #1205 from joe-lawrence/atomic-replace-fixes
Makefile tweaks for handling non-replace kpatch building
2021-08-17 12:45:44 -04:00
Artem Savkov
941a96742d Include unit-tests for multifile case
Update unit-test submodule pointer to include a multi-file unit-test.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-08-17 09:38:30 +02:00
Artem Savkov
a132000868 test/integration/rhel-8.0: disable unneeded test
gcc-static-local-var-4.patch is disabled on this distribution, disable
the test as well as it will always fail during 'slow' integration test
runs.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-08-17 09:37:44 +02:00
Josh Poimboeuf
56471ffc7c kpatch-build: Support CONFIG_PRINTK_INDEX, part 2
For each printk() call site, CONFIG_PRINTK_INDEX makes a static local
struct named `_entry`, and then adds a pointer to it in the
`.printk_index` section.

When regenerating the `.printk_index` section for the patch module, we
only need to include those entries which are referenced by included
functions.  Luckily this is a common pattern already used by several
other "special" sections.  Add `.printk_index` to the special section
handling logic.

Fixes: #1206

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-08-11 08:47:04 -07:00
Josh Poimboeuf
6cf50a6fca create-diff-object: Support CONFIG_PRINTK_INDEX, part 1
CONFIG_PRINTK_INDEX creates a static local struct variable named
`_entry` for every call site to printk().  The initializer for that
struct assigns the `__LINE__` macro to one of its fields.

Similarly to the WARN macro's usage [1] of `__LINE__`, it causes
problems because it results in the line number getting directly embedded
in the struct.  If a line is added or removed higher up in the source
file, the `_entry` struct changes accordingly due to a change in the
printk() call site line number.

`_entry` is similar to other "special" static locals, in that we don't
need to correlate the patched version with the original version.  We can
instead just ignore any changes to it.

Any substantial (non-line-number) change to the `_entry` struct would be
a second-order (dependent) effect of a first-order code change, which
would be detected using other means.  In that case the patched version
of `_entry` will be included, due to being referenced by the changed
function.

Fixes: #1206

[1] See kpatch_line_macro_change_only()

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-08-11 08:46:32 -07:00
Joe Lawrence
a19c4ed296 testing: pass KPATCH_BUILD_OPTS to kpatch-test
Update the test/integration/Makefile to pass a KPATCH_BUILD_OPTS
variable to kpatch-test.  This allows the user better control over the
kpatch build process, for example, building non-atomic replace .ko files
on kernels that do support atomic-replace:

  % make integration KPATCH_BUILD_OPTS="--non-replace"

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-08-09 17:58:02 -04:00
Artem Savkov
ae574f6975 Bump unittest objs submodule
Update unittest objects submodule to point to a version that contains
objectfiles to test #1193.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-07-13 17:42:36 +02:00
Song Liu
4b68be868f kpatch-test: disable replace flag when the kernel doesn't support it
For redhat kernel < 4.18.0-193.el8 or non-redhat kernel version < 5.1,
add -R to $KPATCHBUILD_OPTS.

Signed-off-by: Song Liu <song@kernel.org>
2021-05-25 15:22:27 -07:00
Joe Lawrence
c819391c26
Merge pull request #1174 from joe-lawrence/rhel-8.4-support
Additional rhel 8.4 support
2021-04-20 14:19:57 -04:00
Joe Lawrence
fed5786932 integration: add rhel-8.4
Rebased to kernel-4.18.0-304.el8.

Note: since RHEL-8.4 dropped klp.arch support, we can now re-enable
those tests that reference static keys defined in vmlinux.

Also, adjust for adjust for ppc64le inlining:

Building gcc-static-local-var-4.patch on ppc64le results in test
failure, as the kpatch .ko now contains a 'free_ioctx' symbol (the test
expects to NOT see one).

From the build log:

  aio.o: changed function: free_ioctx
  aio.o: new function: put_aio_ring_file      << now un-inlined?
  aio.o: changed function: aio_free_ring
  aio.o: changed function: ioctx_alloc
  aio.o: changed function: aio_prep_rw
  aio.o: changed function: aio_read_events
  aio.o: new function: kpatch_aio_foo         << expected new function

and a source code change to free_ioctx():

  % diff -upr \
       <(objdump -D -j .text.free_ioctx ~/.kpatch/tmp/orig/fs/aio.o) \
       <(objdump -D -j .text.free_ioctx ~/.kpatch/tmp/patched/fs/aio.o)

  --- /dev/fd/63  2020-10-26 14:28:18.086236019 -0400
  +++ /dev/fd/62  2020-10-26 14:28:18.086236019 -0400
  @@ -1,5 +1,5 @@

  -/root/.kpatch/tmp/orig/fs/aio.o:     file format elf64-powerpcle
  +/root/.kpatch/tmp/patched/fs/aio.o:     file format elf64-powerpcle

   Disassembly of section .text.free_ioctx:
  @@ -53,7 +53,7 @@ Disassembly of section .text.free_ioctx:
     b0:  00 00 82 3c     addis   r4,r2,0
     b4:  00 00 84 e8     ld      r4,0(r4)
     b8:  78 fb e6 7f     mr      r6,r31
  -  bc:  e0 00 63 38     addi    r3,r3,224
  +  bc:  38 00 63 38     addi    r3,r3,56
     c0:  01 00 00 48     bl      c0 <free_ioctx+0xb8>
     c4:  00 00 00 60     nop
     c8:  70 ff ff 4b     b       38 <free_ioctx+0x30>

Marking put_aio_ring_file() as __always_inline keeps the r3 / 224
offset value, leaving free_ioctx() unchanged.  Since it's no longer
included in the resulting .ko, gcc-static-local-var-4.test will pass
once again.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-04-20 11:40:59 -04:00
Josh Poimboeuf
7be75549ba kpatch-build: add support for static calls
Add the new .static_call_sites special section.

Fixes #1165.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-03-24 10:37:44 -05:00
Artem Savkov
d84c734245 Bump unittest objfile submodule
Update unittest submodule pointer to include unittests for this case.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-03-05 09:20:40 +01:00
Artem Savkov
d81447fb26 Include clang unit tests
Bump submodule pointer to include clang unit-tests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-19 12:41:12 +01:00
Artem Savkov
b75bcba6e2 test/integration: fix ppc64le dependencies for fedora
gcc-plugin-devel needs to be installed on ppc64le fedora.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-17 12:59:54 +01:00
Artem Savkov
0baefa561b test/integration: add upstream 5.10.11 patches
Add patches rebased on top of upstream 5.10.11 tarball. Integration
tests for these can be ran as this:

make PATCH_DIR="linux-5.10.11" KPATCHBUILD_OPTS="-s /path/to/src/linux-5.10.11" integration-slow

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-17 12:59:54 +01:00
Yannick Cote
27766f00d8
test/integration: add rhel-8.3 rebased patches
Signed-off-by: Yannick Cote <ycote@redhat.com>
2020-12-10 12:39:15 -05:00
Joe Lawrence
eccf6bf566 test/integration: add rhel-7.9
Rebased against kernel-3.10.0-1160.el7.

data-read-mostly.patch.disabled remains disabled as we hit several build
errors like:

  "Found a jump label at __netif_receive_skb_core()+0x50, using key
  netstamp_needed.  Jump labels aren't supported with this kernel.  Use
  static_key_enabled() instead."

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-09-04 13:57:02 -04:00
Julien Thierry
11df5340c9 test/integration: Add integration tests for symvers disagreement
Add a RHEL reproducer that causes a kpatch-build to fail when the final
module references a symbol with a different CRC than the original
kernel.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-08-17 12:38:32 +01:00
Joe Lawrence
de1d0c6e08 kpatch-test: don't clear dmesg during test
The kpatch-test script clears the kernel log buffer to distinguish
between old and new dmesg entries.  Wiping out the old buffer may
surprise some users, but isn't too hard to avoid:

  - save the last dmesg line
  - run the tests
  - filter out old dmesg lines until after finding the saved entry
    - if no saved entry is found, the buffer most likely overflowed
      - inform the user to increase the log size

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-07-30 14:59:32 -04:00
Joe Lawrence
d76110ed24 kpatch-test: clear dmesg just before tests commence
Defer clearing the kernel buffer until we're ready to start the tests,
otherwise we increase the likelihood of catching stray errors while
we're building the modules and preparing the tests.

Fixes #1133 ("kpatch-test should ignore older kernel log messages")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-07-30 14:58:31 -04:00
Artem Savkov
104d835342 test/integration: centos-8 support
Add centos-8 as a symlink to latest rhel-8.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-07-22 11:16:09 +02:00
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
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
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