Skip to content

Commit 6efc167

Browse files
hbathinimpe
authored andcommitted
powerpc/bpf: implement bpf_arch_text_copy
bpf_arch_text_copy is used to dump JITed binary to RX page, allowing multiple BPF programs to share the same page. Use the newly introduced patch_instructions() to implement it. 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-3-hbathini@linux.ibm.com
1 parent 465cabc commit 6efc167

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
#include <linux/netdevice.h>
1414
#include <linux/filter.h>
1515
#include <linux/if_vlan.h>
16-
#include <asm/kprobes.h>
16+
#include <linux/kernel.h>
17+
#include <linux/memory.h>
1718
#include <linux/bpf.h>
1819

20+
#include <asm/kprobes.h>
21+
#include <asm/code-patching.h>
22+
1923
#include "bpf_jit.h"
2024

2125
static void bpf_jit_fill_ill_insns(void *area, unsigned int size)
@@ -274,3 +278,17 @@ int bpf_add_extable_entry(struct bpf_prog *fp, u32 *image, int pass, struct code
274278
ctx->exentry_idx++;
275279
return 0;
276280
}
281+
282+
void *bpf_arch_text_copy(void *dst, void *src, size_t len)
283+
{
284+
int err;
285+
286+
if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
287+
return ERR_PTR(-EINVAL);
288+
289+
mutex_lock(&text_mutex);
290+
err = patch_instructions(dst, src, len, false);
291+
mutex_unlock(&text_mutex);
292+
293+
return err ? ERR_PTR(err) : dst;
294+
}

0 commit comments

Comments
 (0)