Commit Graph

78 Commits

Author SHA1 Message Date
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
Seth Jennings
57a6b12d9d remove rela twin field, never used
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-24 14:43:40 -05:00
Seth Jennings
1813d54d58 bundle with inclusive logic rather than exclusive
I've created a test designed to exercise the ability
of create-diff-object to parse, compare, and return
"no changed functions" for the entire kernel source
tree one file at a time by passing the same file as
both the original and patched file.

Through this process, I realized that excluding every
special case from being bundled it not feasible.  There
are many sections in the kernel that don't honor
-ffunction|data-sections, not just __ksymtab_strings and
.init.text.

Plus, excluding situations is not the best way.  We are
really only looking for sections that _were_ the result
of -f[function|data]-sections for bundling.

To that end, this commit looks to bundle only symbol/section
pairs that should be bundled ensuringthe .text/.data suffix
and the FUNC/OBJECT symbol name match.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-24 14:14:46 -05:00
Seth Jennings
eb915722cd do not proceed with output generation if no changed funcs
If there are no changed functions, print notice and exit.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-24 11:27:29 -05:00
Seth Jennings
8c487ad6a8 print "changed function" notice for all changed functions
A local changed function will not appear with a "changed function"
notice if it is a dependency of another changed function and that
function occurs before it in the symbol table.

Rearrange some logic to print the notice regardless of whether or not
the function symbols has already been selected for inclusion.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-24 10:38:32 -05:00
Seth Jennings
a15c6eca61 ignore init functions during bundling
When linking function bundles (.text/.rela/section sym/func sym)
ignore __init functions as they do not honor -ffunction-sections
and violate the one-to-one func/section assumption of the
function bundling.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-21 15:11:59 -05:00
Jincheng Miao
f5eac0d6d9 Add -c|--config option to kpatch-build
In some circumstances, the kernel is built outside from the source tree,
thus we should specify the .config file of build path.

This patch changes the basic option parsing by using getopt, and add more
information in usage().

Signed-off-by: Jincheng Miao <jincheng.miao@gmail.com>
2014-03-21 14:43:10 +08:00
Seth Jennings
fdf83f21c3 refactor copying symbols to output
Create a new function kpatch_copy_symbols() that copies symbols from
one kelf to another if the "select" function to return true for the
symbol.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-20 16:03:43 -05:00
Seth Jennings
e51fd3d28b order local FUNC syms before SECTION syms
ld drops FUNC syms that appear after the last SECTION
sym in the symbol table.

Make sure we order the FUNC syms before the SECTION syms.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-20 14:04:02 -05:00
Seth Jennings
5932f0d083 add uninstall target
Make it easy to clean up an install

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-20 11:29:25 -05:00
Josh Poimboeuf
add37f3f44 add-patches-section: detect no patched functions 2014-03-19 17:46:53 -05:00
Seth Jennings
2be6178d6a error on symbol ambiguity in link-vmlinux-syms
Like in add-patches-section, we should continue to
search the vmlinux symbol table to see if there
is a duplicate global symbol.  This normally would
not be possible, however, because create-diff-object
modifies unchanged local functions to be global
as a hack so they can be linked, there is a chance
that these symbols could collide with an existing
global symbol.  We should detect this case and error
out.

Hopefully we can figure out a way to avoid this
situation altogether.  But for now, this is a
protection against improper linking.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-19 16:26:43 -05:00
Josh Poimboeuf
bfad3b1880 kmod/core: update API and use hash table
My apologies for the size of this commit.  I combined these two features
(updating API and using a hash table) into a single commit because their
implementations are tightly coupled and I didn't want to have to add
support for the old kpatch_funcs array with the new API just for the
sake of splitting up the commit :-)

- Update the core module API to get a more clear separation between core
  module and patch module.  This is cleaner and will help our case for
  getting the core module merged upstream into the kernel.
- Convert the old kpatch_funcs array into a hash table.  This is so much
  nicer performance-wise and everything-else-wise than that ugly old
  array.
- Do the incremental patching in stop machine.  This ensures that the
  funcs hash is up to date and we don't miss anything.
- Disable preemption in the ftrace handler when accessing the func hash.
  That way we don't get conflicts with the stop_machine handler updating
  the hash.
2014-03-18 13:34:15 -05:00
Seth Jennings
ca55dcc5ad add TODO to de-dup code
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-18 11:44:17 -05:00
Seth Jennings
e3d2a68db3 remove obsolete comments
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-18 11:44:08 -05:00
Seth Jennings
3ac06ee128 remove dead code
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-18 11:38:55 -05:00
Seth Jennings
75ceca4f33 add file hint to add-patches-section
Currently, add-patches-section just blindly looks in vmlinux
for a function symbol matching the name of the patched function
in the input object file.  However, for local symbols, they may
appear multiple times in the vmlinux symbol table since the symbol
name may be reused locally in different files.

This commit add support for "file hinting".  It tracks what
file the symbol is in and searches for local symbols within
that file in vmlinux first.  If it doesn't find one, it then
searches globally like it always has.

Fixes issue #53

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-18 11:38:55 -05:00
Josh Poimboeuf
c164649d4e kmod/core: rename some variables
For the sake of consistency and readability, rename some variables.
Also change func->old_addr_end to func->old_size.
2014-03-14 20:23:12 -05:00
Seth Jennings
5e5f3a76f9 Merge pull request #61 from jpoimboe/patch-compile-fail-log
kpatch-build: add patch compile failure output to log
2014-03-14 17:14:33 -05:00
Josh Poimboeuf
2aef7d7c41 kpatch-build: add patch compile failure output to log
If the patch doesn't compile, make sure the LOGFILE has the error
output.
2014-03-14 11:12:40 -05:00
Josh Poimboeuf
d4363e0c9b kpatch-build: fix SCRIPTDIR for bash -x
More adventures in bash-land.  Running "bash -x kpatch-build foo.patch"
causes SCRIPTDIR to not get set properly.  This fixes that.
2014-03-14 11:09:29 -05:00
Seth Jennings
c83141be90 Merge pull request #56 from jpoimboe/patch-error-handling
Improve source patch error handling
2014-03-13 17:13:35 -05:00
Seth Jennings
26397afeaf Merge pull request #57 from jpoimboe/no-changed-objects
properly detect no changed objects
2014-03-13 17:06:33 -05:00
Seth Jennings
eb87ccf5fb Merge pull request #58 from jpoimboe/changed-function-output
make the changed function output more readable
2014-03-13 17:04:34 -05:00
Josh Poimboeuf
840a1b3e44 compile tools with -g for debug symbols 2014-03-13 12:28:35 -05:00
Josh Poimboeuf
72af45502f make the changed function output more readable
This makes it much easier to spot which functions have changed,
especially when there are more than one of them.
2014-03-13 12:22:01 -05:00
Josh Poimboeuf
c4ea0ea4ef properly detect no changed objects
The current solution doesn't work because "$?" will always be 0, even if
there were no "CC" lines in the build log.  Instead, just make sure the
changed_objs file isn't empty.
2014-03-13 12:20:13 -05:00
Josh Poimboeuf
72b5f3b4fb try source patch before compiling kernel
Add a patch testing step before compiling the kernel, so that users
don't have to wait for the kernel to compile before seeing if the patch
applies cleanly.

Also allow the printing of the patch command's stdout/stderr to make it
clear what files are being patched and whether there's any fuzz.
2014-03-13 12:08:25 -05:00
Josh Poimboeuf
a611185dce better patch file cleanup
If the patch file fails to apply, it "corrupts" the cache by leaving the
old applied-patch file around.  Fix that by always cleaning up after
ourselves.
2014-03-13 11:53:44 -05:00
Josh Poimboeuf
5ab497a2b3 kpatch-build --sourcedir option
Allow the user to supply a custom kernel source directory.  This copies
the directory to ~/.kpatch/src instead of using it in place.  Otherwise
the "make mrproper" (which is needed for compiling objects in a separate
tree) would modify the original source tree and remove its .config file.

There's currently no caching support for this option.  If needed, we
could implement that pretty easily by calculating an md5sum of the
original source directory.
2014-03-11 10:43:48 -05:00
Josh Poimboeuf
2d728c4f0d make kpatch-build a first class script
kpatch-build is outgrowing the kpatch script and probably is a better
fit as its own utility instead of being wrapped by kpatch.  Install
kpatch-build into /usr/local/bin, remove the kpatch wrapper around it,
and update the README accordingly.
2014-03-11 10:43:48 -05:00
Seth Jennings
e8fb5b1c9f fixup comment
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-10 15:11:23 -05:00
Seth Jennings
8b9de30581 add error for sym value != 0
For a local object or function symbol, we expect that
the section offset, sym.st_value, be 0 because we used
-ffunction-sections and -fdata-section during compile.

If value != 0, it undermines assumptions we make and
should return an error.  Exceptions should be handled
on a case by case basis, like __ksymtab_strings.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-10 15:11:23 -05:00
Seth Jennings
582f2b27e0 add comment for __ksymtab_strings case
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-10 14:49:56 -05:00
Josh Poimboeuf
942fbdf37a kpatch-build: show changed functions
Pipe create-diff-object output to both stdout and the log file, so the
user can see which functions have changed.
2014-03-10 11:18:18 -05:00
Seth Jennings
8eafea114a add inventory file creation to create-object-diff
In preparation for adding an automated test framework,
add an ability to create-object-diff that will create
a human readable list of included sections and symbols
with type and bind information so that the test framework
can compare against a known-good reference list with the
expected set of sections and symbols.

The file is created when the -i/--inventory option is
used.  The inventory filename is the user supplied output
file name suffixed by .inventory

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-07 17:02:45 -06:00
Seth Jennings
6550dd74f6 replace DEBUG compiler define with -d/--debug runtime option
I'm tired of setting CFLAGS and people shouldn't have to
recompile to get debug output.  This lays the foundations
proper option handling and logging levels.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-07 16:06:32 -06:00
Seth Jennings
159214a4fc fixup printf formats with -DDEBUG
Fix -Wformat warnings for printf formats with -DDEBUG

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-07 12:07:56 -06:00
Seth Jennings
e33695be27 remove dead code
refactoring.  A couple of comment touchups too.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-05 11:26:02 -06:00
Josh Poimboeuf
693426b5ef enable gcc warnings and fix all warnings 2014-03-05 09:46:10 -06:00
Josh Poimboeuf
81cc4a3542 Merge pull request #37 from spartacus06/fixes
refactor and fix multiple issues
2014-03-05 09:42:22 -06:00
Josh Poimboeuf
330a08dd0d add GPLv2 headers to source files 2014-03-04 21:34:19 -06:00
Seth Jennings
f6efd53541 refactor and fix multiple issues
- Fixup debug messages
- Remove dead code
- No more DEPENDENCY state
- Reachability test is now the "Inclusion tree" for determining
  which syms/sections will be included in the output
- 'reachable' field is now and 'include' and is the sole
  consideration in including sections/symbols (no more complex
  conditional checks)
- Order LOCAL before GLOBAL in the symbol table.  Apparently, after
  a FILE sym, all LOCAL symbols should precede GLOBAL syms or readelf
  shows <corrupt>
- Handle __ksymtab_strings section and __ksymtab_* syms

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-04 15:56:41 -06:00
Seth Jennings
d62798fde8 put localversions file in SRCDIR, not OBJDIR
The kernel Makefile look for localversion in the source tree,
not the object tree.  The absense from the source tree results
in a patch module that will not load because the kernel versions
don't match.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-02 19:47:23 -06:00
Josh Poimboeuf
5352d8b01a build objects in separate directory to fix caching
Setting KCFLAGS="-ffunction-sections -fdata-sections" causes make to
invalidate all the kernel objects, resulting in all the objects getting
rebuilt on the next pass, thus no build caching.

To fix that, build the objects in a separate directory (obj) for normal
builds, and another separate directory (obj2) for the builds with added
cflags.
2014-02-20 14:52:21 -06:00
Seth Jennings
084cbeaa80 iterate the iterator
It works better this way.  Trust me.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-02-18 16:17:21 -06:00