History

livepatch: Use the default ftrace_ops instead of REGS when ARGS is available

When CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS is available, the ftrace call will be able to set the ip of the calling function. This will improve the performance of live kernel patching where it does not need all the regs to be stored just to change the instruction pointer. If all archs that support live kernel patching also support HAVE_DYNAMIC_FTRACE_WITH_ARGS, then the architecture specific function klp_arch_set_pc() could be made generic. It is possible that an arch can support HAVE_DYNAMIC_FTRACE_WITH_ARGS but not HAVE_DYNAMIC_FTRACE_WITH_REGS and then have access to live patching.

Steven Rostedt (VMware) committed 6 years ago

Commit 2860cd81 parent 02a474c8 files · +29 −9Browse files

Showing the changes to kernel/livepatch/patch.c (1 of 8 files). Show all

Unified · Split

kernel/livepatch/patch.c+5−4
@@ -42,7 +42,6 @@ static void notrace klp_ftrace_handler(unsigned long ip, · 41 unmodified lines
4242 struct ftrace_ops *fops,
4343 struct ftrace_regs *fregs)
4444 {
45− struct pt_regs *regs = ftrace_get_regs(fregs);
4645 struct klp_ops *ops;
4746 struct klp_func *func;
4847 int patch_state;
@@ -118,7 +117,7 @@ static void notrace klp_ftrace_handler(unsigned long ip, · 69 unmodified lines
118117 if (func->nop)
119118 goto unlock;
120119
121− klp_arch_set_pc(regs, (unsigned long)func->new_func);
120+ klp_arch_set_pc(fregs, (unsigned long)func->new_func);
122121
123122 unlock:
124123 preempt_enable_notrace();
@@ -200,8 +199,10 @@ static int klp_patch_func(struct klp_func *func) · 75 unmodified lines
200199 return -ENOMEM;
201200
202201 ops->fops.func = klp_ftrace_handler;
203− ops->fops.flags = FTRACE_OPS_FL_SAVE_REGS |
204− FTRACE_OPS_FL_DYNAMIC |
202+ ops->fops.flags = FTRACE_OPS_FL_DYNAMIC |
203+#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
204+ FTRACE_OPS_FL_SAVE_REGS |
205+#endif
205206 FTRACE_OPS_FL_IPMODIFY |
206207 FTRACE_OPS_FL_PERMANENT;
207208