Commit Graph

24 Commits

Author SHA1 Message Date
Josh Poimboeuf
991b25b067 kmod/core: require fentry
Only compile the core module if the compiler supports -mfentry.
2014-04-15 14:40:03 -05:00
Josh Poimboeuf
e6cad4f0b1 kmod/core: use pr_err instead of printk 2014-04-15 14:21:19 -05:00
Josh Poimboeuf
56645d346d kmod/core: taint kernel with TAINT_USER
For now, taint with TAINT_USER when loading a patch module so that the
user can always detect when a kpatch module has been previously loaded.
Eventually we will want a dedicated TAINT_KPATCH flag in the kernel.
2014-04-15 13:34:01 -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
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
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
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
Josh Poimboeuf
3fb9fd48ff kmod/core: move kpatch_remove_patch
Just move kpatch_remove_patch to a more logical location next to
kpatch_apply_patch.  No functional changes.
2014-03-14 20:23:12 -05:00
Josh Poimboeuf
5f243c9db1 kmod/core: remove obsolete kpatch_rela struct 2014-03-14 20:23:12 -05:00
Josh Poimboeuf
b81e2d607b kmod/core: print module load/unload messages
Print the loading/unloading messages after they have successfully
completed.  Using the KERN_NOTICE log level which corresponds to a
"normal but significant condition."
2014-03-14 20:23:12 -05:00
Josh Poimboeuf
e7dde72ed9 kmod/core: remove unused old_func_name field
Not needed, we can always add it again later if needed (for sanity
checks, maybe)
2014-03-14 20:23:12 -05:00
Josh Poimboeuf
15e1b83cfe kmod/core: handle kmalloc errors and fix leak 2014-03-14 20:23:12 -05:00
Josh Poimboeuf
aea0932655 kmod/core: remove sync_core comment
No need to call sync_core() since we aren't directly modifying any code.
2014-03-14 20:23:12 -05:00
Josh Poimboeuf
aa5346d13b kmod/core: remove comments about preemption
Preemption shouldn't cause a problem with determining activeness safety.
Even if a thread is preempted, it'll be on the backtrace.

We may need to disable preemption when reading the kpatch_funcs array,
but I'm removing that comment for now because the kpatch_funcs array
will soon be replaced by a much better data structure, and we'll deal
with proper synchronization then.
2014-03-14 20:23:12 -05:00
Josh Poimboeuf
57f45c89e6 kmod/core: remove ftrace hacks
These hacks were from a previous implementation and are no longer
needed.
2014-03-14 20:23:12 -05:00
Josh Poimboeuf
99dd4b53fb kmod/core: update module comments 2014-03-14 20:23:12 -05:00
Josh Poimboeuf
344050d8d3 kmod/core: remove assembler code
Long ago, the kpatch_trampoline required being written in assembler, but
that's no longer needed now that it integrates nicely with ftrace.

Move it to a C function and rename it kpatch_ftrace_handler.
2014-03-14 20:23:12 -05:00
Seth Jennings
2419410a52 fix KPATCH_BUILD path
use the build symlink in /lib/modules for a more portable
path to the build env for the kernel.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-03-05 11:31:15 -06:00
Josh Poimboeuf
330a08dd0d add GPLv2 headers to source files 2014-03-04 21:34:19 -06:00
Josh Poimboeuf
8085d0402b build and install core module with make
Build and install the kpatch core module with make and make install,
rather than building it every time with kpatch build.

The only downside to this approach is that the user has to make and make
install kpatch every time they get a new kernel.  But this is only
temporary, until the kpatch module is delivered in an RPM.
2014-02-18 07:44:33 -06:00
Josh Poimboeuf
62de820aab proper makefile support
- setup the makefiles to support "make" and "make install", which builds
  the kpatch-build tools and installs everything in /usr/local.
- update kpatch-build to support new paths
- add "kpatch build" wrapper around kpatch-build
2014-02-13 16:02:10 -06:00
Josh Poimboeuf
72b1ee7916 use consistent naming for core and patch modules 2014-02-13 11:00:12 -06:00
Josh Poimboeuf
4f27b9ae31 functional reorganization
Organize the files functionally:
- kmod/core: core kmod source
- kmod/patch: patch kmod source
- kpatch: kpatch script
- kpatch-build: kpatch build script and supporting tools
- contrib: distro-related files
2014-02-13 11:00:06 -06:00