Skip to content

Commit 73721d8

Browse files
Chenghao Duanchenhuacai
authored andcommitted
LoongArch: BPF: Enhance the bpf_arch_text_poke() function
Enhance the bpf_arch_text_poke() function to enable accurate location of BPF program entry points. When modifying the entry point of a BPF program, skip the "move t0, ra" instruction to ensure the correct logic and copy of the jump address. Cc: stable@vger.kernel.org Fixes: 677e612 ("LoongArch: BPF: Disable trampoline for kernel module function trace") Signed-off-by: Chenghao Duan <duanchenghao@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 2613876 commit 73721d8

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

arch/loongarch/net/bpf_jit.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,15 +1309,30 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
13091309
{
13101310
int ret;
13111311
bool is_call;
1312+
unsigned long size = 0;
1313+
unsigned long offset = 0;
1314+
void *image = NULL;
1315+
char namebuf[KSYM_NAME_LEN];
13121316
u32 old_insns[LOONGARCH_LONG_JUMP_NINSNS] = {[0 ... 4] = INSN_NOP};
13131317
u32 new_insns[LOONGARCH_LONG_JUMP_NINSNS] = {[0 ... 4] = INSN_NOP};
13141318

13151319
/* Only poking bpf text is supported. Since kernel function entry
13161320
* is set up by ftrace, we rely on ftrace to poke kernel functions.
13171321
*/
1318-
if (!is_bpf_text_address((unsigned long)ip))
1322+
if (!__bpf_address_lookup((unsigned long)ip, &size, &offset, namebuf))
13191323
return -ENOTSUPP;
13201324

1325+
image = ip - offset;
1326+
1327+
/* zero offset means we're poking bpf prog entry */
1328+
if (offset == 0) {
1329+
/* skip to the nop instruction in bpf prog entry:
1330+
* move t0, ra
1331+
* nop
1332+
*/
1333+
ip = image + LOONGARCH_INSN_SIZE;
1334+
}
1335+
13211336
is_call = old_t == BPF_MOD_CALL;
13221337
ret = emit_jump_or_nops(old_addr, ip, old_insns, is_call);
13231338
if (ret)

0 commit comments

Comments
 (0)