Skip to content

Commit 033ffaf

Browse files
hbathinimpe
authored andcommitted
powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack
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
1 parent 6efc167 commit 033ffaf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,18 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
292292

293293
return err ? ERR_PTR(err) : dst;
294294
}
295+
296+
int bpf_arch_text_invalidate(void *dst, size_t len)
297+
{
298+
u32 insn = BREAKPOINT_INSTRUCTION;
299+
int ret;
300+
301+
if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
302+
return -EINVAL;
303+
304+
mutex_lock(&text_mutex);
305+
ret = patch_instructions(dst, &insn, len, true);
306+
mutex_unlock(&text_mutex);
307+
308+
return ret;
309+
}

0 commit comments

Comments
 (0)