Commit Graph

2262 Commits

Author SHA1 Message Date
Josh Poimboeuf
901445a54f create-diff-object: fix __UNIQUE_ID() variable correlation
kpatch_mangled_strcmp() only ignores the digits after the period, but in
the case of __UNIQUE_ID(), the symbol names have random digits before
the period due to the use of `__COUNTER__`.  Make sure such symbols are
properly correlated.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-21 19:46:18 -08:00
Joe Lawrence
bc145e95e5
Merge pull request #1311 from joe-lawrence/add-proc-version-example
examples: add /proc/version kpatch sample
2022-11-08 08:36:37 -05:00
Joe Lawrence
2feeb0f462 examples: add /proc/version kpatch sample
Create a simple kpatch test that should apply across a wide range of
kernels.  The version_proc_show() is a good candidate as it's easy to
verify and hasn't been touched upstream since 2008.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-11-07 11:02:00 -05:00
Joe Lawrence
a2333df7da
Merge pull request #1309 from joe-lawrence/integration-tests-kernel-4.18.0-425.3.1.el8
test/integration/rhel-8.7: add kernel-4.18.0-425.3.1.el8 tests
2022-11-07 08:01:39 -05:00
Joe Lawrence
51b4a7ce07
Merge pull request #1308 from joe-lawrence/integration-tests-kernel-5.14.0-162.6.1.el9_1
test/integration/rhel-9.1: add kernel-5.14.0-162.6.1.el9_1 tests
2022-11-07 08:01:25 -05:00
Joe Lawrence
a6958eca1c test/integration/rhel-8.7: add kernel-4.18.0-425.3.1.el8 tests
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-24 15:44:16 -04:00
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
Josh Poimboeuf
f1fbf97345
Merge pull request #1289 from jpoimboe/find_kobj
kpatch-build: support Linux 5.19 .cmd file format
2022-10-14 11:18:47 -05:00
Josh Poimboeuf
1d7e8a74bb kpatch-build: support Linux 5.19 .cmd file format
Rewrite kobj_find() to deal with Linux 5.19, where the .cmd files use
object file paths relative to the .cmd file rather than relative to the
root of the kernel tree.

While at it, add several performance enhancements to prevent all
currently known deep finds.

This is all quite fiddly.  But it works.

Fixes #1277.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Josh Poimboeuf
7861240f48 kpatch-build: Add find_kobj() short-circuit for OOT modules
When patching an OOT module, the parent object is always the OOT module.
Hard-code that to prevent the need for any further special casing in
find_kobj() (e.g., commit 9143e88f16 ("kpatch-build: fix
find_parent_obj")).

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Josh Poimboeuf
1ead10d2b2 kpatch-cc: Add more file ignores
These files aren't in the kernel proper, and can be ignored.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Joe Lawrence
6507700d02
Merge pull request #1305 from joe-lawrence/llvm-from-swine
Collection of small llvm fixes
2022-10-04 10:06:23 -04:00
Joe Lawrence
114878a002
Merge pull request #1306 from joe-lawrence/gcc-12-ppc64le-plugin
gcc-plugin: update headers for gcc-12
2022-10-04 10:05:56 -04:00
Joe Lawrence
13182e50b0 gcc-plugin: update headers for gcc-12
Fix build error seen on gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1):

  g++ -MMD -MP -I../kmod/patch -Iinsn -Wall -Wsign-compare -Wno-sign-conversion -g -Werror -shared -I/usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include -Igcc-plugins -fPIC -fno-rtti -O2 -Wall gcc-plugins/ppc64le-plugin.c -o gcc-plugins/ppc64le-plugin.so
  In file included from /usr/include/features.h:490,
                   from /usr/include/bits/libc-header-start.h:33,
                   from /usr/include/stdio.h:27,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/system.h:46,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/gcc-plugin.h:28,
                   from gcc-plugins/gcc-common.h:6,
                   from gcc-plugins/ppc64le-plugin.c:1:
  /usr/include/bits/error-ldbl.h:23:1: error: type of ‘error’ is unknown
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  /usr/include/bits/error-ldbl.h:23:1: error: ‘int error’ redeclared as different kind of entity
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  In file included from gcc-plugins/ppc64le-plugin.c:2:
  /usr/include/error.h:31:13: note: previous declaration ‘void error(int, int, const char*, ...)’
     31 | extern void error (int __status, int __errnum, const char *__format, ...)
        |             ^~~~~
  make[1]: *** [Makefile:39: gcc-plugins/ppc64le-plugin.so] Error 1

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-09-27 16:41:48 -04:00
Pete Swain
85781b7ea7 create-diff-object: ignore .llvm.* sections
Clang FDO adds a new, ignorable ELF section, .llvm.call-graph-profile

Generalize to ignore all .llvm.*

Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [subject line]
2022-09-27 15:56:06 -04:00
Pete Swain
3704057244 create-diff-object: ignore clang's .llvm_addrsig sections
Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [subject line]
2022-09-27 15:56:06 -04:00
Pete Swain
5f6c5965f1 kpatch-build: for clang, use .strtab if no .shstrtab
While gcc puts strings in .strtab and .shstrtab sections,
llvm toolchain just uses .strtab.

Adapt kpatch to handle both styles.

Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [small changes]
2022-09-27 15:56:06 -04:00
Joe Lawrence
4a59a546da
Merge pull request #1299 from yhcote/bump-0.9.7
Bump to version v0.9.7
2022-09-26 11:48:50 -04:00
Joe Lawrence
7ec1ed6330
Merge pull request #1303 from anatasluo/temp
kpatch-build: strengthen conditions for changed sections
2022-09-23 17:05:19 -04:00
Joe Lawrence
e9742249c1
Merge pull request #1304 from joe-lawrence/unit-test-eh_frame
test/unit: update for .eh_frame removal
2022-09-23 17:04:33 -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
Longjun Luo
d46fea98ef kpatch-build: strengthen conditions for changed sections
If two sections want to be the same, they need to satisfy
two conditions:

1) the result of memcmp is zero, which means they
have the same content.

2) they have the same relocation entries.

In one specific situation, two sections have the same content.
But one section has relocation entries while the other one has
no relocation entries. For example, in X86, consider the
following code:

original code
```
__noreturn noinline int kpatch_func(void)
{
	while(1) {};
}
```

patched code
```
__noreturn notrace noinline int kpatch_func(void)
{
	asm(".byte 0xe8, 0x00, 0x00, 0x00, 0x00");
	while(1){};
}
```

Since the original code has a fentry call, these two functions have
the same compile result. But obviously, they are different functions.
Currently, kpatch would not find their differences since the patched
code has no relocation entries.

For the situation that one section has relocation entries while the
other one doesn't have, it should be set to be changed directly.

Cooperated-by: Zongwu Li <lizongwu@huawei.com>
Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
2022-09-23 23:52:53 +08:00
Josh Poimboeuf
80fc15ac36
Merge pull request #1301 from anatasluo/master
kpatch-build: rela section could disappear after patched
2022-09-23 10:15:55 -05:00
Joe Lawrence
1f6a7dbbc0
Merge pull request #1298 from SuperSandro2000/patch-1
Add syntax highlighting to code blocks
2022-09-22 11:38:06 -04:00
Longjun Luo
9fac261ed0 kpatch-build: rela section could disappear after patched
After patched, rela information for some sections could
disappear. For example, a function like the following:

"
notrace noinline static int version_proc_show(struct seq_file *m,
    void *v)
{
    return 0;
}
"

Apart from common rela entries, trace and return thunk mechanism
will generate rela information. Use `notrace` to remove the
effect of trace. Make CONFIG_RETHUNK=n can remove the effect of
return thunk.

Discovered-by: Zongwu Li <lizongwu@huawei.com>
Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
2022-09-21 10:10:41 +08:00
Joe Lawrence
adf08fe441
Merge pull request #1297 from joe-lawrence/faq-new-arches
README: Add arch porting question
2022-09-20 12:04:51 -04:00
Yannick Cote
e1a3abca86 Bump to version v0.9.7
Updates of interest:

v0.9.7:
- S390x kpatch support
- Add support for openEuler + documentation (kpatch-build)
- Use err.h instead of error.h for musl support (kpatch-build)
- Add support for .return_sites section (kpatch-build x86)
- Create missing section symbol (kpatch-build)
- Fix symtab parsing lookup (kpatch-build)
- Many fixes and improvements in create-diff-object (kpatch-build)
- Unload already disabled modules (kpatch util)
- Add integration tests for: rhel-{8.6,9.0},5.18.0 (test)
- Add tests for patching a syscall (test)
- Combine and improve Fedora, CentOS with RHEL kpatch-build dependencies (test)
- Major revamp of README.md and documentation
- Add syscall patching macros (kmod)

Signed-off-by: Yannick Cote <ycote@redhat.com>
2022-09-14 09:36:00 -04:00
Sandro
c23661cfeb
Add syntax highlighting to code blocks 2022-09-14 11:51:16 +02:00
Joe Lawrence
feb5e2b176 README: Add arch porting question
Adding a new architecture pops up time to time, since the answer remains
the same each time, provide the common question/answer in the FAQ.

Answered-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-09-01 15:47:43 -04:00
Joe Lawrence
b10d0e2212
Merge pull request #1287 from androw/musl
kpatch-build: use err.h instead of error.h for musl support
2022-08-11 08:53:32 -04:00
Joe Lawrence
ec474ec0a3
Merge pull request #1288 from jpoimboe/oot-modname-fix
kpatch-build: fix KBUILD_MODNAME for OOT modules
2022-08-11 08:53:12 -04:00
Josh Poimboeuf
fe45029b4d kpatch-build: fix KBUILD_MODNAME for OOT modules
For consistency with what the kernel does (and what we already do for
in-tree modules), if the file has any dashes ('-'), replace them with
underscores in the objname (aka KBUILD_MODNAME).

Fixes #1286.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-08-05 09:29:39 -07:00
Nicolas Lorin
8cc0fedefb kpatch-build: use err.h instead of error.h for musl support 2022-08-05 08:52:03 +02:00
Joe Lawrence
67e4e2048a
Merge pull request #1283 from jerdfelt/jerdfelt/prefix-strip
kpatch-cc: fix stripping of source tree prefix
2022-08-02 09:23:48 -04:00
Johannes Erdfelt
07433e98c0 kpatch-cc: fix stripping of source tree prefix
To support building out-of-tree kernel modules, the source tree prefix
is attempted to be stripped from change object file paths to make them
relative. However, if the path is already relative, the change can
strip a substring instead, resulting in build errors.

Ensure just the prefix is stripped instead of any substring.

Fixes: #1282
Fixes: 51a8fad34f ("Add support for building out-of-tree modules")
2022-07-27 10:29:36 -07:00
Joe Lawrence
6992acf9c2
Merge pull request #1281 from dobsonj/issue1280
create-diff-object: add support for .return_sites section (x86)
2022-07-21 10:30:59 -04:00
Joe Lawrence
dbde872cee
Merge pull request #1279 from joe-lawrence/syscalls
macros: tweak syscall patching macros
2022-07-21 10:30:40 -04:00
Jonathan Dobson
33368a88cd create-diff-object: add support for .return_sites section (x86) 2022-07-16 15:46:54 -06:00
Joe Lawrence
e921c557f9 macros: tweak syscall patching macros
Kernel version specific __KPATCH_SYSCALL_DEFINEx macros were added to
kpatch-syscall.h for x86, but only single versions for other arches.
This works out for s390x, but not ppc64le for which kpatch-build support
goes back to kernel versions that require slightly different macros.

Reorder the __KPATCH_SYSCALL_DEFINEx macros to define the arch-specific
ones first (arch/.../include/asm/syscall_wrapper.h) and then fall back
to using generic ones (include/linux/syscalls.h versions).

Fixes: #1278
Fixes: 9c0b678621b9 ("macros: add syscall patching macros")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-07-13 22:30:28 -04:00
Joe Lawrence
dc7e5cb03d
Merge pull request #1203 from sumanthkorikkar/s390x-kpatch-support
S390x kpatch support
2022-06-29 09:55:53 -04:00
Joe Lawrence
d1423a3d65
Merge pull request #1275 from joe-lawrence/integration-updates-jun-2022
Integration updates
2022-06-29 09:45:34 -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
7fdbb2561c
Merge pull request #1273 from jpoimboe/create-secsym
create-diff-object: Create missing section symbol
2022-06-07 20:32:17 -07: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
e425e653aa
Merge pull request #1271 from joe-lawrence/integration-kpatch_rhel_dependencies
kpatch build dependency cleanup
2022-05-25 09:35:12 -04:00
Sumanth Korikkar
48d997f2a3 README: Update s390 as supported and backporting info
* Add s390 as supported.
* Add backporting information for the distros.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2022-05-25 06:20:04 +02:00
Joe Lawrence
02306e62ae Makefile: add make help
We've got a lot of top level Makefile targets, help out the user.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00
Joe Lawrence
b6b650a006 Makefile: add dependencies target
Installing the dependencies should be a one-step operation for the user.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-05-23 08:47:18 -04:00