Message ID | 20230309180213.180263-4-hbathini@linux.ibm.com (mailing list archive) |
---|---|
State | Not Applicable |
Delegated to: | BPF |
Headers | show |
Series | enable bpf_prog_pack allocator for powerpc | expand |
On Thu, Mar 9, 2023 at 10:02 AM Hari Bathini <hbathini@linux.ibm.com> wrote: > > Implement bpf_arch_text_invalidate and use it to fill unused part of > the bpf_prog_pack with trap instructions when a BPF program is freed. > > Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> > --- > arch/powerpc/net/bpf_jit_comp.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c > index 0a70319116d1..d1794d9f0154 100644 > --- a/arch/powerpc/net/bpf_jit_comp.c > +++ b/arch/powerpc/net/bpf_jit_comp.c > @@ -293,3 +293,18 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len) > > return ret; > } > + > +int bpf_arch_text_invalidate(void *dst, size_t len) > +{ > + u32 inst = BREAKPOINT_INSTRUCTION; > + int ret = -EINVAL; No need to set to -EINVAL here. > + > + if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst))) > + return ret; Just return -EINVAL instead. > + > + mutex_lock(&text_mutex); > + ret = patch_instructions(dst, &inst, true, len); > + mutex_unlock(&text_mutex); > + > + return ret; > +} > -- > 2.39.2 >
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index 0a70319116d1..d1794d9f0154 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -293,3 +293,18 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len) return ret; } + +int bpf_arch_text_invalidate(void *dst, size_t len) +{ + u32 inst = BREAKPOINT_INSTRUCTION; + int ret = -EINVAL; + + if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst))) + return ret; + + mutex_lock(&text_mutex); + ret = patch_instructions(dst, &inst, true, len); + mutex_unlock(&text_mutex); + + return ret; +}
Implement bpf_arch_text_invalidate and use it to fill unused part of the bpf_prog_pack with trap instructions when a BPF program is freed. Signed-off-by: Hari Bathini <hbathini@linux.ibm.com> --- arch/powerpc/net/bpf_jit_comp.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)