powerpc64/bpf: support direct_call on livepatch function
Hari Bathini
maintainerPATCH v2 1/1 powerpc64/bpf: support direct_call on livepatch function
Today, livepatch takes precedence over direct_call. Instead, save the state and make direct_call before handling livepatch. This change inadvertly skips livepatch stack restore, when an attached fmod_ret program fails. To handle this scenario, set cr0.eq bit to indicate livepatch is active while making the direct_call, save the expected livepatch stack state on the trampoline stack and restore it, if and when required, during do_fexit in the trampoline code.
Reported-by Shung-Hsi Yu <[email protected]>
Closes https://lore.kernel.org/all/rwmwrvvtg3pd7qrnt3of6dideioohwhsplancoc2gdrjran7bg@j5tqng6loymr/ open here
Signed-off-by Hari Bathini <[email protected]>
---
Changes in v2:
* Fixed compile error reported by kernel test bot for !CONFIG_LIVEPATCH
arch/powerpc/include/asm/livepatch.h | 15 +++++ arch/powerpc/kernel/trace/ftrace_entry.S | 74 +++++++++++++++++++---- arch/powerpc/net/bpf_jit_comp.c | 75 ++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/livepatch.h +15 -0
@@ -7,6 +7,20 @@#ifndef _ASM_POWERPC_LIVEPATCH_H#define _ASM_POWERPC_LIVEPATCH_H +#ifdef CONFIG_LIVEPATCH_64 +#define LIVEPATCH_STACK_MAGIC_OFFSET 8 +#define LIVEPATCH_STACK_LR_OFFSET 16 +#define LIVEPATCH_STACK_TOC_OFFSET 24 + +#if defined(CONFIG_PPC_FTRACE_OUT_OF_LINE ) && defined(CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS ) +#define LIVEPATCH_STACK_FRAME_SIZE 32/* Allocate 4 x 8 bytes (to save new NIP as well) */ +#define LIVEPATCH_STACK_NIP_OFFSET 32 +#else +#define LIVEPATCH_STACK_FRAME_SIZE 24/* Allocate 3 x 8 bytes */ +#endif +#endif + +#ifndef __ASSEMBLY__#include <linux/sched.h> #include <linux/sched/task_stack.h>
@@ -20,4 +34,5 @@ static inline void klp_init_thread_info(struct task_struct *p)static inline void klp_init_thread_info (struct task_struct *p) { }#endif +#endif /* !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_LIVEPATCH_H */
arch/powerpc/kernel/trace/ftrace_entry.S +64 -10
129 lines not on this page · raw message
arch/powerpc/net/bpf_jit_comp.c +75 -0
116 lines not on this page · raw message
Signature · 1 line
2.51.0