Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

riscv, bpf: Fix incorrect runtime stats

When __bpf_prog_enter() returns zero, the s1 register is not set to zero,
resulting in incorrect runtime stats. Fix it by setting s1 immediately upon
the return of __bpf_prog_enter().

Fixes: 49b5e77ae3e2 ("riscv, bpf: Add bpf trampoline support for RV64")
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Pu Lehui <pulehui@huawei.com>
Acked-by: Björn Töpel <bjorn@kernel.org>
Link: https://lore.kernel.org/bpf/20240416064208.2919073-3-xukuohai@huaweicloud.com

authored by

Xu Kuohai and committed by
Daniel Borkmann
10541b37 dc7d7447

+3 -3
+3 -3
arch/riscv/net/bpf_jit_comp64.c
··· 722 722 if (ret) 723 723 return ret; 724 724 725 + /* store prog start time */ 726 + emit_mv(RV_REG_S1, RV_REG_A0, ctx); 727 + 725 728 /* if (__bpf_prog_enter(prog) == 0) 726 729 * goto skip_exec_of_prog; 727 730 */ 728 731 branch_off = ctx->ninsns; 729 732 /* nop reserved for conditional jump */ 730 733 emit(rv_nop(), ctx); 731 - 732 - /* store prog start time */ 733 - emit_mv(RV_REG_S1, RV_REG_A0, ctx); 734 734 735 735 /* arg1: &args_off */ 736 736 emit_addi(RV_REG_A0, RV_REG_FP, -args_off, ctx);