Commit Graph

369 Commits

Author SHA1 Message Date
Seth Jennings
66cab1d4a2 Merge pull request #170 from jpoimboe/module-special-chars
kpatch-build: replace special characters in module name
2014-05-05 11:10:47 -05:00
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
2adb1d6837 Merge pull request #168 from jpoimboe/readme-patch-example
readme: give a more concrete patch example
2014-05-05 09:01:52 -05:00
Seth Jennings
6ecc8ce254 Merge pull request #169 from jpoimboe/unregister-fix
kmod/core: fixes in the unregister path
2014-05-05 09:01:41 -05:00
Josh Poimboeuf
6ee8803978 kmod/core: kpatch_unregister return error if !kpmod->enabled
It's probably cleaner to just return -EINVAL if the kpmod isn't enabled,
instead of warning and continuing, which would be dangerous.

I think the reason I had it WARN before is because this condition
shouldn't be possible given the source for the patch module.  But the
core module can't necessarily assume that it's our trustworthy patch
module code on the other side.
2014-05-02 23:02:29 -05:00
Josh Poimboeuf
4bde6c3bbf kmod/core: fix kpatch_num_registered decrement
Oops, kpatch_unregister doesn't decrement kpatch_num_registered whenever
it's > 1.
2014-05-02 22:55:32 -05:00
Josh Poimboeuf
9f69d1fe61 readme: give a more concrete patch example
I think a more concrete example makes it a little easier to grok.
2014-05-02 22:53:04 -05:00
Seth Jennings
8bce2712c7 Merge pull request #166 from jpoimboe/ftrace-check
kmod/core: check for needed kernel config options
2014-05-02 16:30:14 -05:00
Josh Poimboeuf
de40ff3e54 kmod/core: check for needed kernel config options
Yes, this is ugly.  There's a much cleaner way to do this for an in-tree
module, but this is the only way I know how to do it here.
2014-05-02 16:11:55 -05:00
Seth Jennings
bf45d8dc5e Merge pull request #160 from jpoimboe/kpatch-load-replace
support for "kpatch replace"
2014-05-02 15:49:54 -05:00
Josh Poimboeuf
65810a47d0 kpatch replace
Allow the user to atomically replace all existing modules with a new
"kpatch replace" command.  This provides a safe way to do atomic
upgrades for cumulative patch module updates.
2014-05-02 15:35:00 -05:00
Josh Poimboeuf
354b399be5 kpatch: reformat usage message
In prepraration for "kpatch load --replace", reformat the usage message
to give more room for the command descriptions.  Also move the
formatting logic to its own function.
2014-05-02 15:15:25 -05:00
Josh Poimboeuf
b7f32f8ade gitignore *.o.d
When the core module compilation fails, a kmod/core/.core.o.d file
appears.
2014-05-02 15:15:25 -05:00
Seth Jennings
59cbfe63b8 Merge pull request #164 from useidel/master
correct build requirements for Fedora 20; yum-utils was missing
2014-05-02 09:41:32 -05:00
Udo Seidel
6ea2a2ffcb correct build requirements for Fedora 20; yum-utils was missing 2014-05-02 12:18:36 +02:00
Seth Jennings
1717e17290 Merge pull request #162 from jpoimboe/lkml
a few style fixes
2014-05-01 16:14:01 -05:00
Josh Poimboeuf
411fd570f2 kmod/core: update a few comments
- update the file description comment to be a little more accurate and
  concise
- s/trampoline/ftrace handler/
2014-05-01 12:36:28 -05:00
Josh Poimboeuf
b5de5a8b25 kmod/core: checkpatch and sparse fixes
- checkpatch doesn't like the FSF address since it's subject to change
- checkpatch doesn't like strings split by line
- whitespace fix
- sparse suggested to change some variables and functions to static
2014-05-01 12:31:33 -05:00
Josh Poimboeuf
d76ba0b9a7 readme: taint clarifications 2014-05-01 12:15:58 -05:00
Josh Poimboeuf
c85467db04 readme: kpatch is an infrastructure, not a tool 2014-05-01 12:15:30 -05:00
Seth Jennings
c3f5766a69 Merge pull request #159 from jpoimboe/nmi-redesign
kmod/core: NMI synchronization improvements
2014-04-30 14:37:12 -05:00
Josh Poimboeuf
ac324f40f8 Merge pull request #161 from spartacus06/revert-jump-table
Revert "create-diff-object: support for __jump_table"
2014-04-30 14:31:09 -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
968845f1bd kmod/core: make WARN messages more informative 2014-04-30 13:42:22 -05:00
Josh Poimboeuf
ac22230761 kmod/core: make func->op an enum 2014-04-30 13:26:29 -05:00
Seth Jennings
2f9f2e1ee2 Merge pull request #158 from jpoimboe/cdo-jump-table
create-diff-object: support for __jump_table
2014-04-30 11:00:58 -05:00
Josh Poimboeuf
2f34cf9a89 kmod/core: NMI synchronization improvements
This is an attempt to both simplify and improve the correctness of the
NMI synchronization code.

There's a race in kpatch_ftrace_handler() between the kpatch_get_func()
and kpatch_finish_status() calls which could result in func being NULL.
The retry was supposed to fix this.  However, this race would still be a
problem in the repatching case (if the function had already been
previously patched), in which case func would not be NULL, but could
instead point to the previously patched version of the function.  In
this case it wouldn't retry and it would be possible for the previous
version of the function to run.

The fix is to use a memory barrier between accesses of the func hash and
the status variable, and then just call kpatch_get_func() *after*
accessing the status variable.  For OP_PATCH, if status is SUCCESS, then
func is guaranteed to point to the new function.  If status is FAILURE,
func might point to the new function, in which case we can use
get_prev_func to get the previous version of the function.

I also made some pretty big changes to try to simplify the design so
that there are less moving parts and so that it's hopefully easier to
understand.  I moved the OP field into the kpatch_func struct.  This
allows us to merge the two global state variables (status + op) into a
single global state variable (state), which helps make the code quite a
bit simpler.  I turned it into a proper state machine and documented the
meaning of each state in the comments.

Moving the OP field to the kpatch_func struct also paves the way for an
upcoming pull request which will allow patch modules to be atomically
replaced ("kpatch load --replace <module>").
2014-04-29 23:36:53 -05:00
Josh Poimboeuf
87d852afa2 kmod/core: fail more gracefully in kpatch_unregister
In kpatch_unregister(), if kpatch_remove_patch succeeds but one of the
subsequent ftrace unregistering calls fails, it returns an error and
fails to module_put() the patch module, even though the patch has been
removed.  This causes the patch module to get stuck in a weird place
where its patch has been unregistered but the patch module can't ever be
removed.

These errors aren't serious and wouldn't cause any real problems if they
did somehow fail, so instead just WARN if they fail.
2014-04-29 23:36:53 -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
Josh Poimboeuf
065619ec68 Merge pull request #155 from spartacus06/ubuntu-doc
update docs for Ubuntu support
2014-04-29 13:40:42 -05:00
Seth Jennings
86ee4d188f update docs for Ubuntu support
Signed-off-by: Seth Jennings <sjenning@redhat.com>
2014-04-29 13:33:02 -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
5e6a4ff042 Merge pull request #152 from jpoimboe/revert-init-fix
Revert "fail on changed init section"
2014-04-29 11:24:41 -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
Seth Jennings
96ea05ebea Merge pull request #148 from jpoimboe/kpatch-build-patch-dry-run
kpatch-build: test patch with --dry-run
2014-04-28 21:19:58 -05:00
Seth Jennings
1555a033d0 Merge pull request #149 from jpoimboe/readme
readme: add irc channel info
2014-04-28 21:17:36 -05:00
Josh Poimboeuf
d854e7f695 readme: add irc channel info
Fixes #142.
2014-04-28 21:13:50 -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
9d476546ed Merge pull request #147 from jpoimboe/integration-tests
create integration test framework
2014-04-28 13:34:25 -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
e19b0ad978 test: make load/unload errors fatal
No need to accumulate errors if the load or unload fails.  Leaving the
testprog failure non-fatal so that the test will then call unload to
clean up after itself.
2014-04-28 13:32:00 -05:00
Josh Poimboeuf
0858e8b054 add include linux/module.h to kpatch.h
Needed for the module and kobject structs.
2014-04-28 13:24:04 -05:00
Josh Poimboeuf
0d2ab160fe create integration test framework
This is a basic integration test framework for kpatch, which tests
building, loading, and unloading patches, as well as any other related
custom tests.

The kpatch-test script looks for test input files in the
tests/integration directory.  It expects certain file naming
conventions:

- foo.patch - patch that should build successfully

- bar-FAIL.patch - patch that should fail to build

- foo-LOADED.test - executable which tests whether the foo.patch module
  is loaded.  It will be used to test that loading/unloading the patch
  module works as expected.

Any other *.test files will be executed after all the patch modules have
been built from the *.patch files.  They can be used for more custom
tests above and beyond the simple loading and unloading tests.

I just have one test here, but many more to come eventually.  I'm
constantly doing manual testing of patches and am planning on automating
them with this framework.
2014-04-26 16:23:05 -05:00
Josh Poimboeuf
0bbddf629a Merge pull request #145 from spartacus06/parainstructions-support
add .parainstructions support
2014-04-25 23:27:19 -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
Josh Poimboeuf
8ed5aa06ea Merge pull request #144 from spartacus06/smp-locks
fix smp_lock support
2014-04-25 14:16:06 -05:00