From: Pu Lehui Now that the preceding commit extends bpf_arch_text_poke() to cover the functionality of arch_bpf_trampoline_skip(), the RV64-specific implementation is redundant. Remove it in favor of the generic weak implementation which calls bpf_arch_text_poke(). Also align the skip nop in invoke_bpf_prog() to 4 bytes with c.nop when RVC is enabled, as bpf_arch_text_poke() requires 4-byte alignment for atomic single-instruction patching. Signed-off-by: Pu Lehui --- arch/riscv/net/bpf_jit_comp64.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index ac655db5239f..7d15617aee1b 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -918,24 +917,6 @@ static int gen_poke_insn(void *target, void *ip, void *plt_slot, u32 *insn, return 0; } -int arch_bpf_trampoline_skip(void *nop, void *target) -{ - u32 old_insn = rv_nop(); - u32 new_insn = rv_jal(RV_REG_ZERO, (target - nop) >> 1); - int ret; - - if (memcmp(nop, &old_insn, sizeof(old_insn))) - return -EFAULT; - - cpus_read_lock(); - mutex_lock(&text_mutex); - ret = patch_text(nop, &new_insn, sizeof(new_insn)); - mutex_unlock(&text_mutex); - cpus_read_unlock(); - - return ret; -} - int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t, enum bpf_text_poke_type new_t, void *old_addr, void *new_addr) @@ -1083,8 +1064,12 @@ static int invoke_bpf_prog(struct bpf_tramp_image *im, struct bpf_tramp_node *no int ret, branch_off; struct bpf_prog *p = node->link->prog; int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie); - void *skip = ctx->ro_insns + ctx->ninsns; + void *skip; + /* make sure skip address is 4-byte aligned */ + if (rvc_enabled() && (ninsns_rvoff(ctx->ninsns) & 2)) + emitc(rvc_nop(), ctx); + skip = ctx->ro_insns + ctx->ninsns; /* nop, patched to a jal over this prog when it is detached */ emit(rv_nop(), ctx); -- 2.34.1