Enable livepatching on powerpc
Subsystems (2)
PATCH v3 1/1 Enable livepatching on powerpc
Changelog v3:
1. Removed spurious kgdb patch
2. Moved -ENOSYS to -EINVAL in klp_write_module_reloc
3. Moved klp_matchaddr to use ftrace_location_range
Changelog v2:
1. Implement review comments by Michael
2. The previous version compared _NIP from the wrong location to check for whether we are going to a patched location
This applies on top of the patches posted by Michael
https://patchwork.ozlabs.org/patch/589791/
It enables livepatching. This takes patch 6/8 and 7/8 of v8 as the base. Removes the extra strict check in gcc-profile-kernel-notrace.sh and adds logic for checking offset ranges in livepatch with ftrace_location_range.
Comments? Testing? I tested the sample in the livepatch
References
1. https://patchwork.ozlabs.org/patch/581521/
2. https://patchwork.ozlabs.org/patch/587464/
--- arch/powerpc/Kconfig | 3 ++ arch/powerpc/include/asm/livepatch.h | 41 +++++++++++++++++++++++++++ arch/powerpc/kernel/Makefile | 1 + arch/powerpc/kernel/entry_64.S | 50 +++++++++++++++++++++++++++++++++ arch/powerpc/kernel/kgdb.c | 4 +++ arch/powerpc/kernel/livepatch.c | 54 ++++++++++++++++++++++++++++++++++++ include/linux/livepatch.h | 2 ++ kernel/livepatch/core.c | 12 ++++++-- 8 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/include/asm/livepatch.h create mode 100644 arch/powerpc/kernel/livepatch.c
arch/powerpc/Kconfig +3 -0
@@ -159,6 +159,7 @@ config PPC select ARCH_HAS_DEVMEM_IS_ALLOWED select HAVE_ARCH_SECCOMP_FILTER select ARCH_HAS_UBSAN_SANITIZE_ALL + select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS config GENERIC_CSUM def_bool CPU_LITTLE_ENDIAN
@@ -1109,3 +1110,5 @@ config PPC_LIB_RHEAP bool source "arch/powerpc/kvm/Kconfig" + +source "kernel/livepatch/Kconfig"
arch/powerpc/include/asm/livepatch.h new file +41 -0
41 lines not on this page · raw message
arch/powerpc/kernel/Makefile +1 -0
@@ -119,6 +119,7 @@ obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o obj-$(CONFIG_TRACING) += trace_clock.o +obj-$(CONFIG_LIVEPATCH) += livepatch.o ifneq ($(CONFIG_PPC_INDIRECT_PIO),y) obj-y += iomap.o
arch/powerpc/kernel/entry_64.S +50 -0
74 lines not on this page · raw message
arch/powerpc/kernel/kgdb.c +4 -0
@@ -445,7 +445,11 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,* Global data */ struct kgdb_arch arch_kgdb_ops = { +#ifdef __LITTLE_ENDIAN__ + .gdb_bpt_instr = {0x08, 0x10, 0x82, 0x7d}, +#else .gdb_bpt_instr = {0x7d ,0x82 ,0x10 ,0x08 }, +#endif };static int kgdb_not_implemented (struct pt_regs *regs)
arch/powerpc/kernel/livepatch.c new file +54 -0
54 lines not on this page · raw message
include/linux/livepatch.h +2 -0
@@ -134,6 +134,8 @@ int klp_unregister_patch(struct klp_patch *);int klp_enable_patch (struct klp_patch *);int klp_disable_patch (struct klp_patch *); +int klp_matchaddr (struct ftrace_ops *ops,unsigned long ip, +int remove,int reset);#endif /* CONFIG_LIVEPATCH */ #endif /* _LINUX_LIVEPATCH_H_ */
kernel/livepatch/core.c +9 -3
@@ -298,6 +298,12 @@ unlock:rcu_read_unlock (); } +int __weak klp_matchaddr (struct ftrace_ops *ops,unsigned long ip, +int remove,int reset) +{ +return ftrace_set_filter_ip (ops, ip, remove, reset); +} +static void klp_disable_func (struct klp_func *func) {struct klp_ops *ops;
@@ -313,7 +319,7 @@ static void klp_disable_func(struct klp_func *func)if (list_is_singular (&ops->func_stack)) {WARN_ON (unregister_ftrace_function (&ops->fops)); -WARN_ON (ftrace_set_filter_ip (&ops->fops, func->old_addr,1 ,0 )); +WARN_ON (klp_matchaddr (&ops->fops, func->old_addr,1 ,0 ));list_del_rcu (&func->stack_node);list_del (&ops->node);
@@ -352,7 +358,7 @@ static int klp_enable_func(struct klp_func *func)INIT_LIST_HEAD (&ops->func_stack);list_add_rcu (&func->stack_node, &ops->func_stack); - ret =ftrace_set_filter_ip (&ops->fops, func->old_addr,0 ,0 ); + ret =klp_matchaddr (&ops->fops, func->old_addr,0 ,0 );if (ret) {pr_err ("failed to set ftrace filter for function '%s' (%d)\n" , func->old_name, ret);
@@ -363,7 +369,7 @@ static int klp_enable_func(struct klp_func *func)if (ret) {pr_err ("failed to register ftrace handler for function '%s' (%d)\n" , func->old_name, ret); -ftrace_set_filter_ip (&ops->fops, func->old_addr,1 ,0 ); +klp_matchaddr (&ops->fops, func->old_addr,1 ,0 ); goto err; }
Signature · 1 line
2.5.0
Quoted 5 lines · Balbir Singh
Changelog v3:
1. Removed spurious kgdb patch
2. Moved-ENOSYSto-EINVALinklp_write_module_reloc
3. Movedklp_matchaddrto useftrace_location_range
Please ignore -- wrong patch!
Balbir