Commit Graph

212 Commits

Author SHA1 Message Date
Seth Jennings
15da394a2f add man .gz files to gitignore
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-27 16:29:14 -05:00
Josh Poimboeuf
334fe44dee Merge pull request #84 from spartacus06/fixes
Refactoring and perf improvements for create-diff-object
2014-03-27 09:01:55 -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
75c2601a6c Merge pull request #88 from jpoimboe/implicit-make-clean
always rebuild core module
2014-03-26 23:32:02 -05:00
Josh Poimboeuf
d4ab5fab2e always rebuild core module
If the kernel updates, make won't detect that the core module needs
rebuilding.  So always rebuild it.
2014-03-26 21:28:37 -07:00
Josh Poimboeuf
e8fb594637 Merge pull request #85 from useidel/master
added man pages and updated SPEC file
2014-03-26 00:18:08 -05:00
Udo Seidel
148ef3b941 fixed typos 2014-03-25 17:12:50 +01:00
Udo Seidel
fd11e9f5d6 added man pages and updated SPEC file 2014-03-25 08:36:20 +01: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
7656fc6213 Merge pull request #83 from useidel/master
Reworked version of spec file following the discussion of PR 80
2014-03-24 13:57:53 -05:00
Udo Seidel
a95589a816 reworked version of spec file 2014-03-24 17:53:42 +01:00
Josh Poimboeuf
c7b5837d89 Merge pull request #82 from spartacus06/fixes
small fixes
2014-03-24 11:35:27 -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
Josh Poimboeuf
8dfa41ed78 Merge pull request #79 from spartacus06/ignore-init-funcs
ignore init functions during bundling
2014-03-21 15:19:54 -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
Seth Jennings
7fea36599b Merge pull request #78 from jpoimboe/readme-limitations
readme: add more detail to limitations section
2014-03-21 15:05:37 -05:00
Josh Poimboeuf
710a72e1ab readme: add more detail to limitations section 2014-03-21 14:57:52 -05:00
Seth Jennings
95b76492e4 Merge pull request #77 from ryanmiao/master
Add -c|--config option to kpatch-build
2014-03-21 11:08:24 -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
Josh Poimboeuf
5961e198cd Merge pull request #75 from spartacus06/symorder
order local FUNC syms before SECTION syms
2014-03-20 16:55:39 -05: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
Josh Poimboeuf
39a88d0703 Merge pull request #74 from spartacus06/uninstall
add uninstall target
2014-03-20 11:31:16 -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
Seth Jennings
bdd8554c96 Merge pull request #73 from jpoimboe/core-notrace
kmod/core: add "notrace" to ftrace handler
2014-03-20 09:10:15 -05:00
Seth Jennings
f9c8536a43 Merge pull request #72 from jpoimboe/no-patched-functions
add-patches-section: detect no patched functions
2014-03-20 09:09:29 -05:00
Josh Poimboeuf
2d7be5f48c kmod/core: add "notrace" to ftrace handler
The ftrace handler needs the notrace annotation so that ftrace won't
trace it and get into a recursive loop.
2014-03-19 19:16:12 -05:00
Josh Poimboeuf
add37f3f44 add-patches-section: detect no patched functions 2014-03-19 17:46:53 -05:00
Josh Poimboeuf
0688d1ed24 Merge pull request #71 from spartacus06/fixes
error on symbol ambiguity in link-vmlinux-syms
2014-03-19 16:45:32 -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
Seth Jennings
e941fd446e Merge pull request #69 from jpoimboe/core-cumulative-performance
kmod/core: improve performance for cumulative patching
2014-03-19 10:45:10 -05:00
Seth Jennings
8d019434a2 Merge pull request #70 from jpoimboe/readme-contributions
readme: small clarification about contributing
2014-03-19 10:43:36 -05:00
Josh Poimboeuf
8834d25564 readme: small clarification about contributing 2014-03-19 10:29:07 -05:00
Josh Poimboeuf
29227a0fbd kmod/core: improve performance for cumulative patching
When multiple patch modules patch the same function, there's no need to
patch all the intermediate functions.  Just hook them all into the
original function and use the ftrace handler to find the newest one.

Also use a mutex in the register/unregister functions to protect changes
to kpatch_num_registered, kpatch_func_hash and calls to the ftrace
functions by other register/unregister invocations.
2014-03-19 10:05:07 -05:00
Josh Poimboeuf
37a756af58 kmod/core: protect kpatch_[un]register with mutex
Use a mutex in the register/unregister functions to protect changes to
kpatch_num_registered, kpatch_func_hash and calls to the ftrace
functions by other register/unregister invocations.
2014-03-19 10:05:07 -05:00
Seth Jennings
ae6fce2cd9 Merge pull request #68 from jpoimboe/core-no-kzalloc
core/kmod: use kmalloc instead of kzalloc
2014-03-18 17:06:03 -05:00
Josh Poimboeuf
ff44a0af26 core/kmod: use kmalloc instead of kzalloc
There's no need to zero out the kpatch funcs array.  The addr fields are
initialized by the patch module, the mod field is intialized by the core
module, and the node struct doesn't need to be initialized because its
fields are overwritten by hash_add.
2014-03-18 16:57:51 -05:00
Seth Jennings
fd2c137acf Merge pull request #63 from jpoimboe/core-api-hash
kmod/core: new API and kpatch_funcs_hash
2014-03-18 16:50:56 -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
Josh Poimboeuf
b9f55460ed Merge pull request #55 from spartacus06/fixes
Fixes for symbol collisions in add-patches-section and cleanup
2014-03-18 13:14:58 -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
Seth Jennings
c09ed67945 Merge pull request #62 from jpoimboe/core-cleanup
kmod/core: long overdue cleanup
2014-03-14 20:39:09 -05:00