[PATCH v4 2/5] powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack
Hari Bathini
hbathini at linux.ibm.com
Fri Sep 8 23:27:37 AEST 2023
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 at 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 4f896222c579..c0036eb171f0 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -313,3 +313,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 insn = BREAKPOINT_INSTRUCTION;
+ void *ret;
+
+ if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
+ return -EINVAL;
+
+ mutex_lock(&text_mutex);
+ ret = bpf_patch_instructions(dst, &insn, len, true);
+ mutex_unlock(&text_mutex);
+
+ return IS_ERR(ret) ? PTR_ERR(ret) : 0;
+}
--
2.41.0
More information about the Linuxppc-dev
mailing list