Skip to content

Commit e7a7d7e

Browse files
Chenghao Duangregkh
authored andcommitted
LoongArch: BPF: Enhance the bpf_arch_text_poke() function
commit 73721d8 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8453061 commit e7a7d7e

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
@@ -1307,16 +1307,31 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type poke_type,
13071307
void *old_addr, void *new_addr)
13081308
{
13091309
int ret;
1310+
unsigned long size = 0;
1311+
unsigned long offset = 0;
1312+
void *image = NULL;
1313+
char namebuf[KSYM_NAME_LEN];
13101314
bool is_call = (poke_type == BPF_MOD_CALL);
13111315
u32 old_insns[LOONGARCH_LONG_JUMP_NINSNS] = {[0 ... 4] = INSN_NOP};
13121316
u32 new_insns[LOONGARCH_LONG_JUMP_NINSNS] = {[0 ... 4] = INSN_NOP};
13131317

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

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

0 commit comments

Comments
 (0)