powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack
authorHari Bathini <hbathini@linux.ibm.com>
Fri, 20 Oct 2023 14:13:56 +0000 (19:43 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 23 Oct 2023 09:33:19 +0000 (20:33 +1100)
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>
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231020141358.643575-4-hbathini@linux.ibm.com
arch/powerpc/net/bpf_jit_comp.c

index c21cb88b09e436163a32d649229aa6e3919da36d..0a5a9758903a2d667eff5eb920d24c18ac91fe96 100644 (file)
@@ -292,3 +292,18 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
 
        return err ? ERR_PTR(err) : dst;
 }
+
+int bpf_arch_text_invalidate(void *dst, size_t len)
+{
+       u32 insn = BREAKPOINT_INSTRUCTION;
+       int ret;
+
+       if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
+               return -EINVAL;
+
+       mutex_lock(&text_mutex);
+       ret = patch_instructions(dst, &insn, len, true);
+       mutex_unlock(&text_mutex);
+
+       return ret;
+}