aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-14 13:15:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-14 13:15:34 -0400
commit9497d7380b9c450830190c75aa43b25c278bb1f9 (patch)
tree019fe8a45676f873bf03746a671cc04bcc4512b0
parentd0bbe0dd353af9521e9d8bc5236308c677b6f62a (diff)
parent09675bd395458543e70d19544f8046038a2fd053 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/livepatching
Pull livepatching updates from Jiri Kosina: "These are mostly smaller things that got accumulated during the development cycle. The unified solution is still being worked on and is not mature enough for 4.1 yet. - s390 livepatching support, from Jiri Slaby (has Ack from s390 maintainers) - error handling simplification, from Josh Poimboeuf - two minor code cleanups from Josh Poimboeuf and Miroslav Benes" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/livepatching: livepatch: add support on s390 livepatch: remove unnecessary call to klp_find_object_module() livepatch: simplify disable error path livepatch: remove extern specifier from header files
-rw-r--r--arch/s390/Kconfig3
-rw-r--r--arch/s390/include/asm/livepatch.h43
-rw-r--r--arch/x86/include/asm/livepatch.h4
-rw-r--r--include/linux/livepatch.h8
-rw-r--r--kernel/livepatch/core.c69
5 files changed, 69 insertions, 58 deletions
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 373cd5badf1c..b2d7ec1669b4 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -133,6 +133,7 @@ config S390
133 select HAVE_KPROBES 133 select HAVE_KPROBES
134 select HAVE_KRETPROBES 134 select HAVE_KRETPROBES
135 select HAVE_KVM if 64BIT 135 select HAVE_KVM if 64BIT
136 select HAVE_LIVEPATCH
136 select HAVE_MEMBLOCK 137 select HAVE_MEMBLOCK
137 select HAVE_MEMBLOCK_NODE_MAP 138 select HAVE_MEMBLOCK_NODE_MAP
138 select HAVE_MEMBLOCK_PHYS_MAP 139 select HAVE_MEMBLOCK_PHYS_MAP
@@ -159,6 +160,8 @@ source "init/Kconfig"
159 160
160source "kernel/Kconfig.freezer" 161source "kernel/Kconfig.freezer"
161 162
163source "kernel/livepatch/Kconfig"
164
162menu "Processor type and features" 165menu "Processor type and features"
163 166
164config HAVE_MARCH_Z900_FEATURES 167config HAVE_MARCH_Z900_FEATURES
diff --git a/arch/s390/include/asm/livepatch.h b/arch/s390/include/asm/livepatch.h
new file mode 100644
index 000000000000..7aa799134a11
--- /dev/null
+++ b/arch/s390/include/asm/livepatch.h
@@ -0,0 +1,43 @@
1/*
2 * livepatch.h - s390-specific Kernel Live Patching Core
3 *
4 * Copyright (c) 2013-2015 SUSE
5 * Authors: Jiri Kosina
6 * Vojtech Pavlik
7 * Jiri Slaby
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 */
16
17#ifndef ASM_LIVEPATCH_H
18#define ASM_LIVEPATCH_H
19
20#include <linux/module.h>
21
22#ifdef CONFIG_LIVEPATCH
23static inline int klp_check_compiler_support(void)
24{
25 return 0;
26}
27
28static inline int klp_write_module_reloc(struct module *mod, unsigned long
29 type, unsigned long loc, unsigned long value)
30{
31 /* not supported yet */
32 return -ENOSYS;
33}
34
35static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
36{
37 regs->psw.addr = ip;
38}
39#else
40#error Live patching support is disabled; check CONFIG_LIVEPATCH
41#endif
42
43#endif
diff --git a/arch/x86/include/asm/livepatch.h b/arch/x86/include/asm/livepatch.h
index a455a53d789a..2d29197bd2fb 100644
--- a/arch/x86/include/asm/livepatch.h
+++ b/arch/x86/include/asm/livepatch.h
@@ -32,8 +32,8 @@ static inline int klp_check_compiler_support(void)
32#endif 32#endif
33 return 0; 33 return 0;
34} 34}
35extern int klp_write_module_reloc(struct module *mod, unsigned long type, 35int klp_write_module_reloc(struct module *mod, unsigned long type,
36 unsigned long loc, unsigned long value); 36 unsigned long loc, unsigned long value);
37 37
38static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip) 38static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
39{ 39{
diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 95023fd8b00d..ee6dbb39a809 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -123,10 +123,10 @@ struct klp_patch {
123 enum klp_state state; 123 enum klp_state state;
124}; 124};
125 125
126extern int klp_register_patch(struct klp_patch *); 126int klp_register_patch(struct klp_patch *);
127extern int klp_unregister_patch(struct klp_patch *); 127int klp_unregister_patch(struct klp_patch *);
128extern int klp_enable_patch(struct klp_patch *); 128int klp_enable_patch(struct klp_patch *);
129extern int klp_disable_patch(struct klp_patch *); 129int klp_disable_patch(struct klp_patch *);
130 130
131#endif /* CONFIG_LIVEPATCH */ 131#endif /* CONFIG_LIVEPATCH */
132 132
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 3f9f1d6b4c2e..284e2691e380 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -335,32 +335,20 @@ unlock:
335 rcu_read_unlock(); 335 rcu_read_unlock();
336} 336}
337 337
338static int klp_disable_func(struct klp_func *func) 338static void klp_disable_func(struct klp_func *func)
339{ 339{
340 struct klp_ops *ops; 340 struct klp_ops *ops;
341 int ret;
342
343 if (WARN_ON(func->state != KLP_ENABLED))
344 return -EINVAL;
345 341
346 if (WARN_ON(!func->old_addr)) 342 WARN_ON(func->state != KLP_ENABLED);
347 return -EINVAL; 343 WARN_ON(!func->old_addr);
348 344
349 ops = klp_find_ops(func->old_addr); 345 ops = klp_find_ops(func->old_addr);
350 if (WARN_ON(!ops)) 346 if (WARN_ON(!ops))
351 return -EINVAL; 347 return;
352 348
353 if (list_is_singular(&ops->func_stack)) { 349 if (list_is_singular(&ops->func_stack)) {
354 ret = unregister_ftrace_function(&ops->fops); 350 WARN_ON(unregister_ftrace_function(&ops->fops));
355 if (ret) { 351 WARN_ON(ftrace_set_filter_ip(&ops->fops, func->old_addr, 1, 0));
356 pr_err("failed to unregister ftrace handler for function '%s' (%d)\n",
357 func->old_name, ret);
358 return ret;
359 }
360
361 ret = ftrace_set_filter_ip(&ops->fops, func->old_addr, 1, 0);
362 if (ret)
363 pr_warn("function unregister succeeded but failed to clear the filter\n");
364 352
365 list_del_rcu(&func->stack_node); 353 list_del_rcu(&func->stack_node);
366 list_del(&ops->node); 354 list_del(&ops->node);
@@ -370,8 +358,6 @@ static int klp_disable_func(struct klp_func *func)
370 } 358 }
371 359
372 func->state = KLP_DISABLED; 360 func->state = KLP_DISABLED;
373
374 return 0;
375} 361}
376 362
377static int klp_enable_func(struct klp_func *func) 363static int klp_enable_func(struct klp_func *func)
@@ -432,23 +418,15 @@ err:
432 return ret; 418 return ret;
433} 419}
434 420
435static int klp_disable_object(struct klp_object *obj) 421static void klp_disable_object(struct klp_object *obj)
436{ 422{
437 struct klp_func *func; 423 struct klp_func *func;
438 int ret;
439 424
440 for (func = obj->funcs; func->old_name; func++) { 425 for (func = obj->funcs; func->old_name; func++)
441 if (func->state != KLP_ENABLED) 426 if (func->state == KLP_ENABLED)
442 continue; 427 klp_disable_func(func);
443
444 ret = klp_disable_func(func);
445 if (ret)
446 return ret;
447 }
448 428
449 obj->state = KLP_DISABLED; 429 obj->state = KLP_DISABLED;
450
451 return 0;
452} 430}
453 431
454static int klp_enable_object(struct klp_object *obj) 432static int klp_enable_object(struct klp_object *obj)
@@ -464,22 +442,19 @@ static int klp_enable_object(struct klp_object *obj)
464 442
465 for (func = obj->funcs; func->old_name; func++) { 443 for (func = obj->funcs; func->old_name; func++) {
466 ret = klp_enable_func(func); 444 ret = klp_enable_func(func);
467 if (ret) 445 if (ret) {
468 goto unregister; 446 klp_disable_object(obj);
447 return ret;
448 }
469 } 449 }
470 obj->state = KLP_ENABLED; 450 obj->state = KLP_ENABLED;
471 451
472 return 0; 452 return 0;
473
474unregister:
475 WARN_ON(klp_disable_object(obj));
476 return ret;
477} 453}
478 454
479static int __klp_disable_patch(struct klp_patch *patch) 455static int __klp_disable_patch(struct klp_patch *patch)
480{ 456{
481 struct klp_object *obj; 457 struct klp_object *obj;
482 int ret;
483 458
484 /* enforce stacking: only the last enabled patch can be disabled */ 459 /* enforce stacking: only the last enabled patch can be disabled */
485 if (!list_is_last(&patch->list, &klp_patches) && 460 if (!list_is_last(&patch->list, &klp_patches) &&
@@ -489,12 +464,8 @@ static int __klp_disable_patch(struct klp_patch *patch)
489 pr_notice("disabling patch '%s'\n", patch->mod->name); 464 pr_notice("disabling patch '%s'\n", patch->mod->name);
490 465
491 for (obj = patch->objs; obj->funcs; obj++) { 466 for (obj = patch->objs; obj->funcs; obj++) {
492 if (obj->state != KLP_ENABLED) 467 if (obj->state == KLP_ENABLED)
493 continue; 468 klp_disable_object(obj);
494
495 ret = klp_disable_object(obj);
496 if (ret)
497 return ret;
498 } 469 }
499 470
500 patch->state = KLP_DISABLED; 471 patch->state = KLP_DISABLED;
@@ -553,8 +524,6 @@ static int __klp_enable_patch(struct klp_patch *patch)
553 pr_notice("enabling patch '%s'\n", patch->mod->name); 524 pr_notice("enabling patch '%s'\n", patch->mod->name);
554 525
555 for (obj = patch->objs; obj->funcs; obj++) { 526 for (obj = patch->objs; obj->funcs; obj++) {
556 klp_find_object_module(obj);
557
558 if (!klp_is_object_loaded(obj)) 527 if (!klp_is_object_loaded(obj))
559 continue; 528 continue;
560 529
@@ -945,7 +914,6 @@ static void klp_module_notify_going(struct klp_patch *patch,
945{ 914{
946 struct module *pmod = patch->mod; 915 struct module *pmod = patch->mod;
947 struct module *mod = obj->mod; 916 struct module *mod = obj->mod;
948 int ret;
949 917
950 if (patch->state == KLP_DISABLED) 918 if (patch->state == KLP_DISABLED)
951 goto disabled; 919 goto disabled;
@@ -953,10 +921,7 @@ static void klp_module_notify_going(struct klp_patch *patch,
953 pr_notice("reverting patch '%s' on unloading module '%s'\n", 921 pr_notice("reverting patch '%s' on unloading module '%s'\n",
954 pmod->name, mod->name); 922 pmod->name, mod->name);
955 923
956 ret = klp_disable_object(obj); 924 klp_disable_object(obj);
957 if (ret)
958 pr_warn("failed to revert patch '%s' on module '%s' (%d)\n",
959 pmod->name, mod->name, ret);
960 925
961disabled: 926disabled:
962 klp_free_object_loaded(obj); 927 klp_free_object_loaded(obj);