Commit Graph

53 Commits

Author SHA1 Message Date
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
Julien Thierry
c1caee1468 create-diff-object: Ignore kpatch_ignored functions/sections missing ftrace hook
Some theoretically unchanged functions can have undesired changes if the
compiler decides to perform inlining in a different way (e.g. because of
newly added references). In such a case, it can be useful to discard
changes to functions that don't actually need modification.

Sadly, this currently doesn't work for functions missing the ftrace hook
(e.g. notrace code) as presence of the hook is checked before
identifying elements to ignore.

Look for functions/sections to ignore earlier.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-04-23 08:22:50 +01:00
Josh Poimboeuf
61ef8238d1 test/unit: Use non-failing jump label tests
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2020-04-14 17:41:17 -05:00
Julien Thierry
2265ce6fc2 test/unit: Add unit test for static local moving sections
Signed-off-by: Julien Thierry <jthierry@redhat.com>
2020-03-30 14:14:17 +01:00
Julien Thierry
68530e4c2b kpatch-build: Make local static twining stricter
The current code to find the twin of a local static variable allows two
variables of the same name to be wrongly matched with the other's twin.

While there isn't a magic formula to avoid this, make stricter
requirements for twining static local from the original object with
a symbol from the patched object. This reduces the risk of erroneous
matches.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-11-22 09:53:16 +00:00
Julien Thierry
54553c0622 test/unit: Update unit test submodule
Include test for mangled symbol modification.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
2019-11-01 07:37:54 +00:00
Josh Poimboeuf
935f199875 create-diff-object: simplify mangled function correlation
The RHEL powerpc kernel is compiled with -O3, which triggers some
"interesting" new optimizations.  One of them, which seems to be
relatively common, is the replacing of a function with two separate
"constprop" functions.

Previously we only ever saw a single constprop clone, so we just renamed
the patched version of the function to match the original version.  Now
that we can have two such clones, that no longer makes sense.

Instead of renaming functions, just improve the correlation logic such
that they can be correlated despite having slightly different symbol
names.  The first clone in the original object is correlated with the
first clone in the patched object; the second clone is correlated with
the second clone; and so on.

This assumes that the order of the symbols and sections doesn't change,
which seems to be a reasonable assumption based on past experience with
the compiler.  Otherwise it will just unnecessarily mark the cloned
constprop functions as changed, which is annoying but harmless, and
noticeable by a human anyway.

Fixes #935.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-10-03 09:38:29 -05:00
Josh Poimboeuf
2975775768 create-diff-object: allow dynamic debug static keys
While static keys (jump labels) are currently broken in livepatch, a
broken dynamic debug static key is harmless since it just disables
dynamically enabled debug printks in the patched code.

Fixes: #1021

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-08-15 16:01:55 -05:00
Josh Poimboeuf
c6259d898c
Merge pull request #1006 from sm00th/unit_fail
tests/unit: fix inconsistent FAIL test failures
2019-07-24 09:58:14 -05:00
Josh Poimboeuf
cef3360936 test/unit: Add unit test for ppc64le bundle replace_sections_syms()
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-23 18:11:54 -05:00
Josh Poimboeuf
9101ca99ef test/unit: update ppc64le tests for jump labels and sibling calls 2019-07-23 11:11:29 -05:00
Artem Savkov
8c6a031cdb tests/unit: fix inconsistent FAIL test failures
Use make's .DELETE_ON_ERROR special target to make sure we don't have
any .OUTPUT.o leftovers for failed tests.

Fixes: #999

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-07-23 10:57:43 +02:00
Josh Poimboeuf
64f07c6c72 test/unit: Fix symtab generation for ppc64le
The ppc64le unit tests are failing because the lookup code is getting
confused by the "[<localentry>: 8]" string in the readelf symbol table
output.

Remove the string so the lookup code can parse it correctly.
kpatch-build already uses the same sed, so they should match.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-22 14:48:25 -05:00
Josh Poimboeuf
ef98dd7544 test/unit: Bump unit tests to latest
Needed to make the unit tests pass again after adding jump label error
detection.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-17 09:03:17 -05:00
Josh Poimboeuf
b7edef7360 test/unit: Fix env override for Make 3.x
Make 3.8 doesn't support the "file" function, which is used by the unit
test Makefile to output the contents of a custom env file, if one
exists.  Use shell instead.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-16 21:58:41 -05:00
Josh Poimboeuf
9940c1d5a1 test/unit: add test object file for #990
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-16 16:16:24 -05:00
Josh Poimboeuf
20b7ab02c4 test/unit: Don't automatically rebase submodule
"make unit" automatically rebases the submodule, which causes a lot of
surprises.  Instead, just print a warning if it's out of date.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-15 18:49:00 -05:00
Josh Poimboeuf
3b936efa10 test/unit: add test object files for #975
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-15 18:11:48 -05:00
chenzefeng
d91b416b00 test: use readelf instead of eu-readelf
readelf is more standard, using readelf insteaded

test/difftree.sh: the symbol name may be with "FILE", which may be
get a incorrect count, here add "awk".

test/unit/Makefile.include: use "readelf -s --wide" instead of
"eu-readelf -s".

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
2019-05-30 17:45:44 +08:00
Joe Lawrence
7dff9b5f6a unit-tests: include oot-issue-928 objects
Add object files that verify kpatch issue #928.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-02-22 10:50:55 -05:00
Joe Lawrence
ccd0615407 test/unit: relax stripped object requirement
Some unit tests may need debug symbols to reproduce problems (see
issue #928 for example), so skip the unit-test Makefile.include
check_stripped call for objects that include "NOSTRIP" in their
filename.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2019-02-22 10:49:54 -05:00
Josh Poimboeuf
09ee03f3df Revert "create-diff-object: add jump label support"
This reverts commit 87c64519fc.

The jump label support doesn't work with upstream livepatch.  Joe
Lawrence found the following ordering issue:

load_module

  apply_relocations

    /* Livepatch relocation sections are applied by livepatch */
    if (info->sechdrs[i].sh_flags & SHF_RELA_LIVEPATCH)
            continue;

  post_relocation
    module_finalize
      jump_label_apply_nops        << crash

  ...

  do_init_module
    do_one_initcall(mod->init)
      __init patch_init [kpatch-patch]
        klp_register_patch
          klp_init_patch
            klp_init_object
              klp_init_object_loaded
                klp_write_object_relocations

So jump_label_apply_nops() is called *before*
klp_write_object_relocations() has had a chance to write the klp
relocations (.klp.rela.kvm_intel.__jump_table, for example).

We need to resolve this upstream first.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-02-19 16:10:54 -06:00
Joe Lawrence
a16c003d88
Merge pull request #937 from jpoimboe/jump-tables
Add jump label support
2019-02-11 13:47:36 -05:00
Josh Poimboeuf
87c64519fc create-diff-object: add jump label support
Add support for jump labels, also known as static jumps, static keys,
static branches, and jump tables.  Luckily,
kpatch_process_special_sections() is already generic enough to make this
an easy fix.

Fixes: #931

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-02-08 13:45:38 -06:00
Artem Savkov
e94bba2b94 test/unit: add support for .env files
Add support for optional <test-name>.env files that contain additional
environment variables. This can also be used to override per-arch env
vars we have because last value assigned will be used.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2019-02-08 15:16:17 +01:00
Artem Savkov
b746182847 Unit test submodule update
Bump unit-test-objs submodule head pointer to include latest test:

f82c458 x86_64: added a test for a function that uses _THIS_IP_
4a097d9 ppc64le: Test const var requiring .data.rel relocation

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-09-12 09:50:29 +02:00
Artem Savkov
41f025d392 Include mrecord-mcount unit tests
Update objs-repo pointer to include new unit tests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-07-26 16:51:28 +02:00
Artem Savkov
7cb5baccde Include gcc8 unit-tests
Update submodule pointer to include new gcc8 unit tests.

This update also includes unit-test for https://github.com/dynup/kpatch/pull/892

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-07-13 09:39:26 +02:00
Artem Savkov
b10e0b7d82 unittests: skip clean if objdir is not present
Don't try to call unittest clean if objfile dir is non-existant (e.g.
when objfile submodule wasn't cloned). Another solution would be to make
clean target dependant on objdir but that would mean downloading a lot
of unneeded data for users who don't run unit-tests.

Fixes: #872

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-06-04 13:14:28 +02:00
Josh Poimboeuf
a7c413d4e9
Merge pull request #856 from sm00th/unlikely-cold
create-diff-object: ignore .cold.* suffixes in is_bundleable()
2018-05-31 09:25:28 -05:00
Artem Savkov
6c58f09cc7 test/unit: update objects to include cold testcase
Update unit test objects subrepo to include x86_64 gcc-constprop-cold
testcase.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-31 15:29:06 +02:00
Joe Lawrence
ace1e2cbf6
Merge pull request #849 from sm00th/cdo-symtab
create-diff-object symtab
2018-05-30 14:15:43 -04:00
Josh Poimboeuf
5736f18d83 test/unit: run submodule command from base git directory
This fixes the following error with an older version of git
(1.8.3.1):

  make -C test/unit
  make[1]: Entering directory `/root/kpatch/test/unit'
  git submodule update --init --rebase
  You need to run this command from the toplevel of the working tree.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-05-30 10:54:24 -05:00
Artem Savkov
3aa5abb807 kpatch-build: use symbol table instead of kobject
create-diff-object doesn't really need the full kernel object file as
input. All it requires is a symbol table. Switch to using "eu-readelf -s"'s
output instead of object files. This will enable us to cover more cases
in unit tests.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-18 09:24:40 +02:00
Artem Savkov
5f610fdda2 ppc64le: add WARN detection
ppc64le lacked kpatch_line_macro_change_only() implementation. Add one
based on x86_64 version and available unit tests.

Fixes: #843

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-05-04 16:32:48 +02:00
Artem Savkov
e0acd5f835 unittests: object submodule update
Update submodule to 6774fbc "ppc64le: initial object files"
Remove CDO_ENV since it is moved to per-arch makefiles.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-27 20:10:43 +02:00
Artem Savkov
ffc4122efb Add kpatch-unit-objs submodule
Add a submodule containing object files for unittests.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-26 18:49:29 +02:00
Artem Savkov
89a8ac740c Disable git-lfs
While convenient git-lfs has too many restrictions for kpatch's needs.
Remove links to the objectfiles and related configs.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-26 15:08:24 +02:00
Joe Lawrence
70959ce6ec
Merge pull request #838 from jpoimboe/test-cleanups
Test cleanups
2018-04-23 17:31:35 -04:00
Josh Poimboeuf
3feb694c91 test/unit: further silence non-verbose mode
Just show a summary of each test command in non-verbose mode.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-20 08:16:26 -05:00
Josh Poimboeuf
4c1184dcf7 test/unit: add a library for common functions
I placed the library in the top-level test directory, as the same
assertions could also be used by the integration tests once we rework
them a bit.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-20 08:16:20 -05:00
Josh Poimboeuf
d6dfa4a992 test/unit: test the number of patched functions
As an extra sanity check, ensure the number of patched functions never
changes.

Also added a test for convert-global-local to ensure the global symbol
is converted to a local.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf
5629d91bfe test/unit: add WARN test
Add a WARN detection test, based on the integration test of the same
name.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:09 -05:00
Josh Poimboeuf
635754fc46 test/unit: add meminfo-string test
Copy the meminfo-string test from the integration tests.  It's a good
stress test for dynrelas.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
ff5bcc2fdc test/unit: broaden the 'clean' target
Broaden the impact of the 'clean' target so that output objects will
still get cleaned when when old tests get removed or renamed.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
af9f9f491c test: remove obsolete tests
After doing some research, I've discovered that most of these tests no
longer test what they were originally intended to test.

An exception here is the 'macro-hooks' test, which is probably better
suited as an integration test, so I removed its unit test and kept its
integration test.

Really, most of these tests weren't all that useful to begin with, so
it's not a big loss.  The one exception is 'gcc-static-local-var-2',
which was originally meant to test multiple static local variables with
the same name in the name function.  That's a good thing, so I'll try to
come up with another test for that which works with Linux 4.16.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
805b1f5d3f test/unit: fix 'new-fuction' test name typo
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 17:19:08 -05:00
Josh Poimboeuf
87939db272 create-diff-object: skip dynrelas for function pointers to new functions
With #755, we started using dynrelas for function pointers.  However,
this behavior only makes sense for function pointers to existing
functions.  For function pointers to *new* functions, just use a normal
rela.

The 'function-ptr-new' unit test is from the following patch:

  https://github.com/dynup/kpatch/files/1927198/new-static-callback.patch.txt

Fixes #834.

Fixes: 495e619750 ("kpatch-build, x86: do not use the patched functions as callbacks directly")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-19 07:56:12 -05:00
Josh Poimboeuf
69ba464462 unit: don't suppress stderr in non-fail tests
Don't suppress stderr in the non-fail unit tests so that
create-diff-object error messages will be printed.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2018-04-18 08:03:25 -05:00
Artem Savkov
a0edfc1ded unittests: check that obj files are fetched
Check that tested .o is not an lfs meta-file before testing.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 18:11:50 +02:00