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.
Showing the changes to kernel/livepatch/patch.c (1 of 8 files). Show all
Unified · Split
| @@ -42,7 +42,6 @@ static void notrace klp_ftrace_handler(unsigned long ip, · 41 unmodified lines | |||
| 42 | struct ftrace_ops *fops, | 42 | struct ftrace_ops *fops, |
| 43 | struct ftrace_regs *fregs) | 43 | struct ftrace_regs *fregs) |
| 44 | { | 44 | { |
| 45 | struct pt_regs *regs = ftrace_get_regs(fregs); | ||
| 46 | struct klp_ops *ops; | 45 | struct klp_ops *ops; |
| 47 | struct klp_func *func; | 46 | struct klp_func *func; |
| 48 | int patch_state; | 47 | int patch_state; |
| @@ -118,7 +117,7 @@ static void notrace klp_ftrace_handler(unsigned long ip, · 69 unmodified lines | |||
| 118 | if (func->nop) | 117 | if (func->nop) |
| 119 | goto unlock; | 118 | goto unlock; |
| 120 | 119 | ||
| 121 | klp_arch_set_pc(regs, (unsigned long)func->new_func); | 120 | klp_arch_set_pc(fregs, (unsigned long)func->new_func); |
| 122 | 121 | ||
| 123 | unlock: | 122 | unlock: |
| 124 | preempt_enable_notrace(); | 123 | preempt_enable_notrace(); |
| @@ -200,8 +199,10 @@ static int klp_patch_func(struct klp_func *func) · 75 unmodified lines | |||
| 200 | return -ENOMEM; | 199 | return -ENOMEM; |
| 201 | 200 | ||
| 202 | ops->fops.func = klp_ftrace_handler; | 201 | ops->fops.func = klp_ftrace_handler; |
| 203 | ops->fops.flags = FTRACE_OPS_FL_SAVE_REGS | | 202 | ops->fops.flags = FTRACE_OPS_FL_DYNAMIC | |
| 204 | FTRACE_OPS_FL_DYNAMIC | | 203 | #ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS |
| 204 | FTRACE_OPS_FL_SAVE_REGS | | ||
| 205 | #endif | ||
| 205 | FTRACE_OPS_FL_IPMODIFY | | 206 | FTRACE_OPS_FL_IPMODIFY | |
| 206 | FTRACE_OPS_FL_PERMANENT; | 207 | FTRACE_OPS_FL_PERMANENT; |
| 207 | 208 | ||