Commit Graph

2243 Commits

Author SHA1 Message Date
Artem Savkov
6321c9ab5e
Merge pull request #1162 from sm00th/cold-noid
support for .cold functions with no id suffix
2021-03-09 10:26:33 +01: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
1b5a17f934 create-build-diff: support for .cold functions with no id suffix
create-build-diff expects .cold functions to be suffixed by an id, which
is not always the case. Drop the trailing '.' when searching for cold
functions.

Fixes: #1160

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-03-04 15:55:58 +01:00
Artem Savkov
09a42787d5
Merge pull request #1161 from sm00th/btf8.2
kpatch-build: check existance of Makefile.modfinal
2021-03-04 12:29:12 +01:00
Artem Savkov
fc4a56f6b2 kpatch-build: check existance of Makefile.modfinal
It turns out there is a stretch of time in kernel's history when
CONFIG_DEBUG_INFO_BTF was already added, but Makefile.modfinal wasn't
split off yet. To address those we need to either check the file's
existance or, as @liu-song-6 suggested initially, check config for
CONFIG_DEBUG_INFO_BTF_MODULES=y.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-03-03 09:13:30 +01:00
Artem Savkov
4dd3572ac5
Merge pull request #1159 from liu-song-6/workaround_modules_btf
kpatch-build: workaround pahole and CONFIG_DEBUG_INFO_BTF_MODULES
2021-03-03 08:16:05 +01:00
Song Liu
4cc2f06279 kpatch-build: workaround pahole and CONFIG_DEBUG_INFO_BTF_MODULES
With CONFIG_DEBUG_INFO_BTF_MODULES, the kernel build process adds BTF to
each in-tree modules. However, this process is broken with kpatch, with
error message like:

  Failed to parse base BTF 'vmlinux': -4001

Unblock build with CONFIG_DEBUG_INFO_BTF_MODULES with similar workaround
as the one for CONFIG_DEBUG_INFO_BTF.

Signed-off-by: Song Liu <songliubraving@fb.com>
2021-03-02 12:42:39 -08:00
Artem Savkov
73e3984ec4
Merge pull request #1158 from sm00th/dircleanup
kpatch: cleanup install directory
2021-03-01 17:07:37 +01:00
Artem Savkov
47c1bd435a kpatch: cleanup install directory
On module installation kpatch utility creates a directory with kernel
version as a name in /var/lib/kpatch which is never removed. To address
this check if any files are left in this directory after each
'uninstall' call and if not - remove it.

Signed-off-by: Artem Savkov <artem.savkov@gmail.com>
2021-02-25 15:34:03 +01:00
Artem Savkov
1f4e3d752a
Merge pull request #1156 from sm00th/clang
clang support
2021-02-24 15:17:33 +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
6c83b642a4 create-diff-object: make digit tail optional in kpatch_mengled_strcmp
Make kpatch_mangled_strcmp treat two strings as the same in case when
one has a digit tail and the other one doesn't.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-19 12:41:12 +01:00
Artem Savkov
b6e1d071ff create-diff-object: consider '.L' symbols not static local
Make kpatch_is_normal_static_local() treat all symbols prefixed by '.L'
as not static locals.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-19 12:41:12 +01:00
Artem Savkov
fddc6242c6 create-diff-object: support both gcc and clang style of static variables
gcc-generated static variables always have a numbered suffix, while
clang-generated static variables are always prepended with a function
name. Change is_special_static() so that it detects both cases.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-19 12:41:09 +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
Artem Savkov
38c2d7315d create-diff-object: clang __UNIQUE_ID symbol support
clang does not always use __UNIQUE_ID as prefix and can generate symbols
with names like this:
	trace_nfsd_exp_get_by_name.__UNIQUE_ID___addressable___SCK__tp_func_nfsd_exp_get_by_name645

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-17 12:59:54 +01:00
Artem Savkov
488f30c31b create-diff-object: .L.str* symbols support
Clang adds .L.str* symbols to .rodata.str sections which are used for
__FILE__ references. These are discarded during linking so add them to
maybe_discarded_sym().

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-17 12:59:54 +01:00
Artem Savkov
41de9e763a kpatch-build: clang support
Add support for clang-built kernels. This is completely automatic, we
check if the kernel was built with clang by looking for
CONFIG_CC_IS_CLANG in config.

This has almost no effect on non-clang built kernels with one exception:
we now do compliler checks _after_ we download kernel sources which is a
waste of resources in case when compilers don't match.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2021-02-17 12:59:51 +01:00
Joe Lawrence
2af31916ce
Merge pull request #1155 from joe-lawrence/CONFIG_DEBUG_INFO_BTF
kpatch-build: workaround pahole and CONFIG_DEBUG_INFO_BTF
2021-02-03 21:37:19 -05:00
Joe Lawrence
f951c1a92e kpatch-build: apply 'cp -f ... || die' pattern
Be robust and use "cp -f".  Finish with "|| die" to be dead serious
about it.

Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2021-02-02 17:07:24 -05:00
Joe Lawrence
e25450f5a8 kpatch-build: workaround pahole and CONFIG_DEBUG_INFO_BTF
kpatch-build requires gcc flags -f[function|data]-sections when building
original and patched targets.  These flags result in an ELF binary with
many sections, potentially requiring special extended ELF header
processing to parse correctly.

CONFIG_DEBUG_INFO_BTF invokes pahole as part of the kernel build and
unfortunately pahole cannot iterate through more than 65535 section
headers.  As result, the pahole program segfaults and fails the build
like so:

  ...
    BTF     .btf.vmlinux.bin.o
  scripts/link-vmlinux.sh: line 127: 718345 Segmentation fault      (core dumped) LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1}
  objcopy: --change-section-vma .BTF=0x0000000000000000 never used
  objcopy: --change-section-lma .BTF=0x0000000000000000 never used
  objcopy: error: the input file '.btf.vmlinux.bin' is empty
  Failed to generate BTF for vmlinux
  Try to disable CONFIG_DEBUG_INFO_BTF
  make: *** [Makefile:1050: vmlinux] Error 1

Workaround this limitation by disabling CONFIG_DEBUG_INFO_BTF code in
scripts/vmlinux-link.sh during kpatch-build.  This leaves
CONFIG_DEBUG_INFO_BTF contingent kernel code in place, but skips the
problematic pahole .BTF typeinfo generation step (for which kpatch
doesn't care about anyway).

Link: https://lore.kernel.org/dwarves/20210119231718.GA3173@redhat.com/T/
Link: https://lore.kernel.org/dwarves/20210121202203.9346-1-jolsa@kernel.org/T/
Link: https://lore.kernel.org/dwarves/20210122163920.59177-1-jolsa@kernel.org/T/
Link: https://lore.kernel.org/dwarves/b1469725-d462-9a6d-3329-f77c9eb6b43f@redhat.com/T/

Fixes: #1153
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Suggested-by: Josh Poimboeuf <jpoimboe@redhat.com>
2021-02-02 17:06:53 -05:00
Joe Lawrence
933fb21314
Merge pull request #1154 from kamalesh-babulal/powerpc-vdso
kpatch-gcc: powerpc - skip vdso files
2021-01-25 08:11:23 -05:00
Kamalesh Babulal
387914b683 kpatch-gcc: powerpc - skip vdso files
Starting v5.11-rc, kpatch-build fails on powerpc with the error:

ERROR: invalid ancestor arch/powerpc/kernel/vdso64/vdso64.so.dbg for arch/powerpc/kernel/vdso64/vgettimeofday.o

the upstream commit ab037dd87a2f(powerpc/vdso: Switch VDSO to generic
implementation) introduced this breakage, lets skip vdso files. They are
not compatible with kpatch.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2021-01-20 12:32:03 +05:30
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