Commit Graph

2019 Commits

Author SHA1 Message Date
julien-thierry
1051eea257
Merge pull request #1152 from julien-thierry/update-signal-behaviour
kpatch: Inform user when signal subcommand is unnecessary
2021-01-18 08:58:37 +00:00
Julien Thierry
b470e5091d kpatch: Inform user when signal subcommand is unnecessary
From Linux-5.1 onward, the sysfs interface to send signals to
processes stalling livepatch transitions is replace by a peridical
signal sent by the kernel.

On such systems, the kpatch signal subcommand does nothing. Just
let the user know they don't need to worry about it.

Fixes: #1151
Signed-off-by: Julien Thierry <jthierry@redhat.com>
2021-01-14 17:55:29 +01:00
Artem Savkov
0ba3f5aaab
Merge pull request #1149 from sm00th/always-y
kmod/patch: add kpatch.lds as a dependency for $(KPATCH_NAME).o
2021-01-04 20:50:53 +01:00
Yannick Cote
16950a70ba
Merge pull request #1085 from yhcote/integration-rhel-8.3
test/integration: add rhel-8.3 rebased patches
2021-01-04 14:21:41 -05:00
Artem Savkov
04021bbfd5 kmod/patch: add kpatch.lds as a dependency for $(KPATCH_NAME).o
Starting with v5.10 kbuild no longer builds built-in targets for
external modules (including extra-y). Further it wasn't guaranteed that
extra-y targets were going to be built before linking.
Do a proper thing and add kpatch.lds as a dependency for $(KPATCH_NAME).o.

Upstream discussion for reference: https://lore.kernel.org/linux-kbuild/20201103054425.59251-1-chao.wang@ucloud.cn/

Fixes: #1148

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-12-17 12:43:07 +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
158efe3191
Merge pull request #1147 from joe-lawrence/unload-retry-module-refcnt
kpatch: wait for module ref counts on unload
2020-11-19 11:47:48 -05:00
Joe Lawrence
cdee6bd650 kpatch: wait for module ref counts on unload
There exists a very small timing window in which "kpatch unload" gets to
its "rmmod" step before the kpatch-patch module's reference count has
cleared and the "rmmod" fails.

This is only a transient problem, but we can adopt code from upstream
livepatch kselftests which wait for the module refcounts to settle
before moving onto "rmmod".

A small wrinkle is that this is not supported by the older kpatch.ko
core.  The price for circumventing the activeness safety check via
KPATCH_FORCE_UNSAFE is that it must leave the kpatch patch modules in
place (see e1890e627a ("prevent rmmod of forced modules")).

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-11-18 08:56:45 -05:00
Joe Lawrence
33153f728b
Merge pull request #1146 from wcwxyz/fix-__section-change
kmod: convert __section to __kpatch_section
2020-11-05 11:28:37 -05:00
Joe Lawrence
ec5474ee8c
Merge pull request #1145 from wcwxyz/linux-5.9-fixes
Linux 5.9 fixes
2020-11-05 11:27:57 -05:00
WANG Chao
b8d4611edb kmod: convert __section to __kpatch_section
Convert __section to __kpatch_section to fix compile errors since
Linux 5.10, commit 33def8498fdd ("treewide: Convert macro and uses of
__section(foo) to __section("foo")").

Signed-off-by: WANG Chao <chao.wang@ucloud.cn>
2020-11-04 14:15:12 +08:00
WANG Chao
aea2cb96d6 create-diff-object: fix __dyndbg section inclusion
__verbose has renamed to __dyndbg since Linux 5.9, commit e5ebffe18e5a
("dyndbg: rename __verbose section to __dyndbg")

Signed-off-by: WANG Chao <chao.wang@ucloud.cn>
2020-10-27 15:25:36 +08:00
Joe Lawrence
141f57f016
Merge pull request #1144 from joe-lawrence/obj-output-perms
kpatch-elf: pass new ELF output file mode to kpatch_write_output_elf()
2020-09-28 09:10:04 -04:00
Joe Lawrence
ef420050e3 kpatch-elf: pass new ELF output file mode to kpatch_write_output_elf()
Currently all the callers of kpatch_write_output_elf() are creating
.o object files or .ko kernel modules.  Neither of these filetypes are
executable on their own, so enhance kpatch_write_output_elf() to accept
file creation mode and update its callers to pass 0664 to match
the expected permissions.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-09-25 09:30:13 -04:00
Joe Lawrence
f5c165a722
Merge pull request #1138 from joe-lawrence/bump-v0.9.2
Bump to v0.9.2
2020-09-15 12:49:30 -04:00
Joe Lawrence
60523a9976 Bump to v0.9.2
Interesting changes since v0.9.1:

- Integration test support for rhel-{7.8,7.9,8.1,8.2}, centos-8
- Better support for gcc child functions
- Batch jump label errors to report all instances
- Dynrela code cleanup
- Remove .klp.arch and add support for jump labels in v5.8+ kernels
- Mark ignored sections earlier to support functions missing ftrace hook
- Minor README.md improvements
- Add ppc64le mcount support to patched functions
- Show additional stalled process information in kpatch script
- Increased shellcheck coverage and fixes
- ppc64le plugin fixes for gcc v10
- Ignore __UNIQUE_ID_ symbol from tristate config objects
- Don't clear dmesg during integration tests
- Detect and report MODVERSIONS symbol version CRC changes

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-09-15 11:09:05 -04:00
Joe Lawrence
4f8f37268d
Merge pull request #1143 from joe-lawrence/create-diff-object-uninit
create-diff-object: cleanup maybe-uninitialized compiler complaints
2020-09-10 11:16:03 -04:00
Artem Savkov
78325e4651 travis: build with different optimization levels
Try building with -O2 and -O3.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2020-09-10 10:56:57 +02:00
Joe Lawrence
25f12681fa create-diff-object: cleanup maybe-uninitialized compiler complaints
User disaster123 reports the following build errors:

  create-diff-object.c: In function 'kpatch_process_special_sections':
  create-diff-object.c:2215:41: error: 'key' may be used uninitialized in this function [-Werror=maybe-uninitialized]
         code->sym->name, code->addend, key->sym->name);
                                           ^~
  create-diff-object.c:2138:22: note: 'key' was declared here
    struct rela *code, *key, *rela;
                        ^~~
  In file included from kpatch-elf.h:26,
                   from create-diff-object.c:53:
  log.h:20:3: error: 'code' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     printf(format, ##__VA_ARGS__); \
     ^~~~~~
  create-diff-object.c:2138:15: note: 'code' was declared here
    struct rela *code, *key, *rela;
                 ^~~~
  cc1: all warnings being treated as errors

These are reproducible when building with 9.3.1 and 8.3.1 when building
with optimization level > 2 ( CFLAGS=-O2 make ).  Fix them by
initializing the reported variables to NULL and verifying that they are
infact non-NULL after processing the __jump_table.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2020-09-09 14:28:44 -04:00
Joe Lawrence
8cc7ebf488
Merge pull request #1137 from joe-lawrence/integration-tests-rhel-7.9
test/integration: add rhel-7.9
2020-09-08 09:19:21 -04: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
Joe Lawrence
e0f0f984c2
Merge pull request #1134 from zhenjiangma/master
deal with the deadlock may occur in stop_machine context.
2020-08-26 10:39:03 -04:00
Joe Lawrence
cd2c3ede75
Merge pull request #1114 from julien-thierry/fix-symvers
Fix symvers
2020-08-24 09:31:15 -04:00
Joe Lawrence
f91bd455f2 patch-author-guide: add MODVERSIONS blurb to author guide
Explain MODVERSIONS in enough detail for a kpatch author:

  - What is it
  - How does a kpatch interact with it
  - How does kpatch-build report problems
  - How to fix / avoid CRC mismatches

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-08-17 12:38:32 +01: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
Julien Thierry
08056febfd kpatch-build: Check Final module symbols for loadability
If the final module has a reference in its symbol table to a kernel
symbol and the symbol version differs from the kernel symbol version,
the module will be unloadable.

Have kpatch-build emit a clear error and die in such a case instead
of providing an unusable module.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-08-17 12:38:32 +01:00
Julien Thierry
e9600c5513 kpatch-build: Check exported symbol version changes
The CRCs of exported symbols Module.symvers can differ between the
original build and the patched build.

In such a case, it is probably wise to rework the patch to avoid such
modifications.

Warn when a symbol changes version in the exported symbol list.

Fixes issue #1084

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-08-17 12:38:32 +01:00
Julien Thierry
b4c2753684 kpatch-build: Create module symbol version file once
When patching an OOT module, the symbol version file is obtained by
combining the file from the module build and the Module.symvers file
provided with kernel headers. This is done for each modified .o in the
OOT build.

Create the final Module.symvers file once for the whole OOT module.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-08-12 10:47:35 +01:00
zhenjiang.mzj
b311112702 deal with the deadlock may occur in stop_machine context.
we remove the pre_patch_callback/post_unpatch_callback from the
stop_machine context. If a schedule/sleep happend in callbacks while the
process to be scheuded later will send IPI, because all interrupts
are disabled, the machine will trap into a  deadlock in such situation.
So we remove the pre_patch_callback and post_unpatch_callback from
the stop_machine to avoid such situation. On the other hand, to avoid
the race between the patched code and post-patch/pre-unpatch callbacks when
run in parallel, we didn't remove  the post_patch_callback and
pre_unpatch_callback from stop_machine.
2020-08-10 14:53:04 +08:00
Joe Lawrence
6c0592d401
Merge pull request #1135 from joe-lawrence/integration-old-dmesg
kpatch-test dmesg fixes
2020-08-04 12:41:00 -04: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
3f885dedf5
Merge pull request #1132 from sm00th/co8
test/integration: centos-8 support
2020-07-23 15:51:09 +02:00
Yannick Cote
16140668db
Merge pull request #1129 from joe-lawrence/author-guide-LINE-shift
patch-author-guide: mention issue #1124 __LINE__ shift
2020-07-23 08:44:55 -04:00
Yannick Cote
677e5c29c4
Merge pull request #1128 from joe-lawrence/modpost-cmd-file
kpatch-build: avoid modpost .output.o.cmd complaints
2020-07-23 08:44:16 -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
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