Skip to content

Commit a488442

Browse files
image-dragonKernel Patches Daemon
authored andcommitted
bpf,x86: implement bpf_arch_text_poke_type for x86_64
Implement the bpf_arch_text_poke_type() for x86_64. Signed-off-by: Menglong Dong <[email protected]>
1 parent e1583a4 commit a488442

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

arch/x86/net/bpf_jit_comp.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,9 @@ static int emit_jump(u8 **pprog, void *func, void *ip)
597597
return emit_patch(pprog, func, ip, 0xE9);
598598
}
599599

600-
static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
601-
void *old_addr, void *new_addr)
600+
static int ___bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
601+
enum bpf_text_poke_type new_t,
602+
void *old_addr, void *new_addr)
602603
{
603604
const u8 *nop_insn = x86_nops[5];
604605
u8 old_insn[X86_PATCH_SIZE];
@@ -609,7 +610,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
609610
memcpy(old_insn, nop_insn, X86_PATCH_SIZE);
610611
if (old_addr) {
611612
prog = old_insn;
612-
ret = t == BPF_MOD_CALL ?
613+
ret = old_t == BPF_MOD_CALL ?
613614
emit_call(&prog, old_addr, ip) :
614615
emit_jump(&prog, old_addr, ip);
615616
if (ret)
@@ -619,7 +620,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
619620
memcpy(new_insn, nop_insn, X86_PATCH_SIZE);
620621
if (new_addr) {
621622
prog = new_insn;
622-
ret = t == BPF_MOD_CALL ?
623+
ret = new_t == BPF_MOD_CALL ?
623624
emit_call(&prog, new_addr, ip) :
624625
emit_jump(&prog, new_addr, ip);
625626
if (ret)
@@ -640,8 +641,15 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
640641
return ret;
641642
}
642643

643-
int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
644-
void *old_addr, void *new_addr)
644+
static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
645+
void *old_addr, void *new_addr)
646+
{
647+
return ___bpf_arch_text_poke(ip, t, t, old_addr, new_addr);
648+
}
649+
650+
int bpf_arch_text_poke_type(void *ip, enum bpf_text_poke_type old_t,
651+
enum bpf_text_poke_type new_t, void *old_addr,
652+
void *new_addr)
645653
{
646654
if (!is_kernel_text((long)ip) &&
647655
!is_bpf_text_address((long)ip))
@@ -655,7 +663,13 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
655663
if (is_endbr(ip))
656664
ip += ENDBR_INSN_SIZE;
657665

658-
return __bpf_arch_text_poke(ip, t, old_addr, new_addr);
666+
return ___bpf_arch_text_poke(ip, old_t, new_t, old_addr, new_addr);
667+
}
668+
669+
int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
670+
void *old_addr, void *new_addr)
671+
{
672+
return bpf_arch_text_poke_type(ip, t, t, old_addr, new_addr);
659673
}
660674

661675
#define EMIT_LFENCE() EMIT3(0x0F, 0xAE, 0xE8)

0 commit comments

Comments
 (0)