Commit Graph

123 Commits

Author SHA1 Message Date
Josh Poimboeuf
5e4ac36253 kpatch-build: replace special characters in module name
Having a '.' in the kmod name confuses lsmod, which prints "Size" and
"Used by" values of -2.  Prevent any special characters other than '_'
and '-', so that our patch module names will be consistent with typical
kmod names.
2014-05-05 11:07:35 -05:00
Seth Jennings
16221237dd Revert "create-diff-object: support for __jump_table"
This reverts commit 5852ddb6a2.

The __jump_table section is more complex than the initial analysis
determined.  The __jump_table has three relocs per entry that must
be pulled in together and one of the relocs is to symbols contained
in the __tracepoints section whose rela section references the
__tracepoint_strings section.  So it's more complex and should just
fail rather than appear that it is being handled properly.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-30 14:23:03 -05:00
Josh Poimboeuf
5852ddb6a2 create-diff-object: support for __jump_table
Almost a line-for-line copy/paste of the smp locks function.  The only
differences are the section name, and an offset increment of 8 instead
of 4.

Fixes #157.
2014-04-29 16:21:03 -05:00
Seth Jennings
ad87448c9f Merge pull request #151 from jpoimboe/cdo-error-order
create-diff-object: better reachability error message
2014-04-29 12:26:28 -05:00
Josh Poimboeuf
a397818257 create-diff-object: better reachability error message
If a patch changes a single function which is in a special section that
we don't support, create-diff-object reports "no changed functions were
found".  Give a clearer error message in that case, by checking
reachability errors before unchanged errors and by printing all
reachability errors errors instead of the first one it encounters.

Fixes #150.
2014-04-29 12:24:01 -05:00
Josh Poimboeuf
cde0f8d062 Merge pull request #153 from spartacus06/ubuntu-support
Ubuntu support for kpatch-build
2014-04-29 11:31:38 -05:00
Seth Jennings
6236c3a196 Ubuntu support for kpatch-build
At this point the module does build (i.e. kpatch-build is correct);
however, the addresses in the generated vmlinux don't match that
of the running kernel so the modules fail to load with an ftrace
registration error. So that is something to be investigated.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-29 11:14:36 -05:00
Josh Poimboeuf
d07fe1d8b1 Revert "fail on changed init section"
This reverts commit 7b15e23149.

It seems that there was no bug to start with, so apparently the commit
didn't fix anything.

Fixes #103.
2014-04-29 11:08:12 -05:00
Josh Poimboeuf
897b17d9de kpatch-build: test patch with --dry-run
During the test whether the patch applies, if it partially applies, the
patch utility returns an error but leaves the source tree in a partially
patched state.  Use --dry-run instead.
2014-04-28 20:41:51 -05:00
Seth Jennings
89c42870ae Merge pull request #139 from jpoimboe/disable-before-unload
safe kpatch unload
2014-04-28 13:33:53 -05:00
Josh Poimboeuf
b7a2862f90 safe kpatch unload
Currently the patch module calls kpatch_unregister in the patch module
exit path.  If the activeness safety check fails in kpatch_unregister,
it's too late for the patch module to stop exiting, so all it can do is
panic.

Prevent this scenario by requiring the user to disable the patch module
via sysfs before allowing the module to be unloaded.  The sysfs write
will fail if the activeness safety check fails.  An rmmod will fail if
the patch is still enabled.

Also add support for this new unloading model in "kpatch unload".
2014-04-25 23:05:26 -05:00
Seth Jennings
6ea92f1fc5 add .parainstructions support
Following in the same solution, regenerate [.rela].parainstructions
sections if table entries contain relocations that reference changed
functions (if any).

Fixes #135

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-25 16:00:22 -05:00
Seth Jennings
e444b2cbb8 fix smp_lock support
The initial commit had a bug where the offset field of the
.rela.smp_locks entries was not updated to reflect the correct
offset in the truncated .smp_locks section.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-25 14:07:51 -05:00
Seth Jennings
30757f027f add smp_locks support
This commit uses the same approach as the bug table support,
mangling the .smp_locks and .rela.smp_locks sections so that
they only contain entries for changed functions (if any).

Fixes #107

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-25 10:46:24 -05:00
Josh Poimboeuf
f3f39c0587 fix activeness safety check when unpatching
When unpatching, the activeness safety logic should check for the new
function on the stack, not the old one.

Fixes #64.
2014-04-23 14:37:35 -05:00
Seth Jennings
47d4109f7e fixup review comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-22 11:01:01 -05:00
Seth Jennings
ab07805166 add info to expected rela sym error
While debugging the code for the bug table logic, I found it useful to
know which rela section and entry the error occurred on.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00
Seth Jennings
7cfcce1ed6 add bug table support
This commit adds a new function to properly handle the bug table.
It works by going through .rela__bug_table, after the changed
function symbols have already been marked, and rewrites the section
including only the relocations pertaining to bug entries for
changed functions.

The __bug_table section itself is not modified resulting in
"blank" bug entries: ones whose IP and filename pointers will
not be relocated and, therefore, will be zero.  While a waste
of space, it simplifies the code not to remove these blank
entries. They do no harm.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00
Seth Jennings
3753f06de4 use d_size instead of sh_size
The section header size is calculated at output time by libelf
and we use it as a read-only value from read files.

With the next patch we are changing the size of the .rela__bug_table
section.  Lets use d_size instead since it is the value that tells
libelf how to calculate sh_size at output time.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00
Seth Jennings
09262d4d67 support .bss.* bundling
Allow bundling of .bss.* sections that are the result of -fdata-sections
so that rela sections referencing data in bss sections by section symbol
can be replaced with the object symbol so it can be linked to the existing
data object in the kernel.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-21 17:40:38 -05:00
Seth Jennings
39200f2d9a Merge pull request #132 from jpoimboe/debug-keep-logfile
kpatch-build: don't delete logfile in debug mode
2014-04-21 16:27:53 -05:00
Josh Poimboeuf
cfd1ce3b34 kpatch-build: don't delete logfile in debug mode 2014-04-21 16:26:23 -05:00
Seth Jennings
4fb8d76eb3 Merge pull request #130 from jpoimboe/cdo-log-obj-name
create-diff-object logging improvements
2014-04-17 14:41:59 -05:00
Josh Poimboeuf
9b038039dd create-diff-object: removed unused function
kpatch_find_changed_functions isn't called by anybody, so remove it.
2014-04-15 19:17:40 -05:00
Josh Poimboeuf
0684c2f772 kpatch-build: put kpatch-build in the tmp dir name 2014-04-15 16:57:56 -05:00
Josh Poimboeuf
37a66ee57c create-diff-object: show object name in log messages
For log_normal and DIFF_FATAL messages, prefix them with the object name
to give more context, which is useful for patches which change multiple
objects.  Also, no need to add the function and line number to
DIFF_FATAL messages, as the error strings already give enough
information.

Example messages:

  meminfo.o: changed function: meminfo_proc_show
  cmdline.o: no changed functions were found
2014-04-15 16:49:59 -05:00
Josh Poimboeuf
e00d1394c4 Revert "kpatch-build: prevent die if only part of objects have no change"
This reverts commit ab29b1ff59.

Reverting this commit because it causes kpatch-build to ignore any
errors reported by create-diff-object, treating all errors as meaning
that no changes occurred, which is a dangerous assumption to make.
2014-04-14 12:34:44 -05:00
Seth Jennings
e1099dbbc1 Merge pull request #115 from madper/master
kpatch-build: prevent die if only part of objects have no change
2014-04-10 22:40:18 -05:00
Madper Xie
ab29b1ff59 kpatch-build: prevent die if only part of objects have no change
Consider following patch: https://lkml.org/lkml/diff/2014/1/7/637/1
Kpatch-build will generate two objects for it. however mlock.o has no
changed function and will cause kpatch-build die.
Signed-off-by: Madper Xie <cxie@redhat.com>
2014-04-11 11:24:05 +08:00
Seth Jennings
7b15e23149 fail on changed init section
fixes issue #103

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-08 12:45:55 -05:00
Seth Jennings
6626db1ad8 add debug message when section has changed
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-08 12:40:23 -05:00
Josh Poimboeuf
9bbea5c604 kpatch-build: small refactor
Split up the USERSRCDIR and SRCDIR code paths for better readability.
2014-04-01 11:07:08 -05:00
Josh Poimboeuf
0cb8025eff kpatch-build: add option to build from source RPM 2014-04-01 11:03:36 -05:00
Seth Jennings
68c925d9b2 Merge pull request #100 from jpoimboe/kpatch-build-noargs
kpatch-build: getopts arg parsing cleanup
2014-04-01 10:40:22 -05:00
Josh Poimboeuf
5a999ef68c kpatch-build: create applied-patch only after verifying patch
Create the applied-patch file only after the patch has been verified.

Otherwise if you accidentally supply a patch which had already been
applied to the source, the cleanup trap won't reverse apply it when
exiting the script.
2014-04-01 07:51:21 -05:00
Josh Poimboeuf
7fe5c3fef4 kpatch-build: don't ask to reverse apply patch
If the patch had already been mistakenly applied to the source tree,
don't ask the user if it should be reverse applied.  Instead, just exit
with an error.
2014-04-01 07:49:51 -05:00
Josh Poimboeuf
0f464b8500 kpatch-build: add "no patch file specified" error 2014-04-01 07:16:12 -05:00
Josh Poimboeuf
ece4124a45 kpatch-build: getopts arg parsing cleanup
Cleanup the kpatch-build argument parsing a little bit:
- gracefully handle no args
- allow white space in filenames
- use 'eval set -- $options' to allow use of $1 and $2 variables
2014-03-31 16:02:50 -05:00
Josh Poimboeuf
7523fd3460 Merge pull request #95 from spartacus06/debug-option
add debug option to kpatch-build
2014-03-27 19:33:51 -07:00
Seth Jennings
b65a8fddb4 Merge pull request #91 from jpoimboe/changed-objs
skip scripts/mod files when detecting changed objs
2014-03-27 21:33:13 -05:00
Josh Poimboeuf
fcd8d96b08 Merge pull request #93 from spartacus06/fixes
check for changed sections that are not included
2014-03-27 19:30:25 -07:00
Josh Poimboeuf
e904701b9d use "grep -e" instead of multiple grep invocations 2014-03-27 19:14:41 -07:00
Seth Jennings
2b4afa4695 add debug option to kpatch-build
When debugging kpatch-build failures it can be
beneficial to have the scratch files in /tmp that
kpatch-build was operating on.  These are
removed by default, as they can quickly fill /tmp.
However, for debugging reasons, the option should
exist to keep them around.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-27 18:49:44 -05:00
Josh Poimboeuf
3b489e7d29 support CONFIG_MODVERSIONS=y
When CONFIG_MODVERSIONS is enabled, loading of the patch module fails
with "no symbol version for kpatch_register".  When building the patch
module, we need to point it to the core module's Module.symvers file.

This also works when CONFIG_MODVERSIONS is disabled, since
Module.symvers is created regardless.
2014-03-27 16:36:43 -07:00
Seth Jennings
ead06280df check for changed sections that are not included
There are many cases where a section may have
changed due to soure-level change but the inclusion
logic has not selected it for output.  Some of these
cases are real no-go situations like changing data
structures.  Some are just situations that
create-diff-object isn't smart enough to figure out
(yet).

Either way, it should be considered fatal when a
changed section hasn't been selected for output.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-27 17:38:02 -05:00
Josh Poimboeuf
c21550ef63 skip scripts/mod files when detecting changed objs
In some environments, some files in scripts/mod (devicetable-offsets.s
and file2alias.o) are always getting rebuilt, and thus get incorrectly
added to the changed_objs file, resulting in the following error:

 strip:/root/.kpatch/3.10.0-115.el7.x86_64/obj2/scripts/mod/devicetable-offsets.s: File format not recognized
2014-03-27 14:53:11 -07:00
Seth Jennings
026362fab6 fix conditional in find_section_by_index()
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-27 10:24:28 -05:00
Seth Jennings
634b9cee78 improve find_[symbol|section]_by_index
The indexes are in order when being read from the
table.  Just index directly into the table; a benefit
of using an array for this structure instead of a linked
list.

Removes another hot path during the rela table initialization.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-24 17:56:21 -05:00
Seth Jennings
24894d263c change for_each_symbol to start at 1 (avoid ugh)
remove "ughs" by changing macro to start at symbol
index 1.  new for_each_symbol_zero will start at zero
for rare cases that need it.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-24 17:19:16 -05:00
Seth Jennings
6567762937 refactor rela section scanning
Upon realizing that there is no point in correlating rela entries,
I also realized that tracking the status of rela entries is also
not needed.

Additionally, the rela section correlation path (really misnamed
as it is the rela section _comparison path) is VERY hot.  Particularly
on files like fs/ext4/ext4.o (which create-diff-object currently can't
successfully parse entirely):

Samples: 40K of event 'cycles', Event count (approx.): 36516578362
49.49%  create-diff-obj  create-diff-object  [.] rela_equal
31.85%  create-diff-obj  create-diff-object  [.] kpatch_correlate_relas
16.22%  create-diff-obj  create-diff-object  [.] find_symbol_by_index

The refactor does a few things:
- replaces nested for loops with single for loop when comparing rela entries
- removes status field for rela entires
- compares rela and nonrela sections in the same path
- removes unnecessary setting of status fields as the inclusion tree
  will include them even if the section status isn't set to CHANGED. This is
  even better as unchanged sections won't appear as CHANGED just because
  their partner .text or .rela section is CHANGED.

This drastically reduced runtime for larger objects and cooled the rela
comparison path:

87.64%  create-diff-obj  create-diff-object  [.] find_symbol_by_index
6.98%  create-diff-obj  libc-2.18.so        [.] __GI___strcmp_ssse3
1.33%  create-diff-obj  create-diff-object  [.] find_section_by_index
1.16%  create-diff-obj  create-diff-object  [.] kpatch_correlate_symbols
0.61%  create-diff-obj  create-diff-object  [.] kpatch_create_rela_table
0.52%  create-diff-obj  create-diff-object  [.] kpatch_correlate_sections

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-24 16:29:40 -05:00