提交 745abfaa 编写于 作者: L Luke Nelson 提交者: Alexei Starovoitov

bpf, riscv: Fix tail call count off by one in RV32 BPF JIT

This patch fixes an off by one error in the RV32 JIT handling for BPF
tail call. Currently, the code decrements TCC before checking if it
is less than zero. This limits the maximum number of tail calls to 32
instead of 33 as in other JITs. The fix is to instead check the old
value of TCC before decrementing.

Fixes: 5f316b65 ("riscv, bpf: Add RV32G eBPF JIT")
Signed-off-by: NLuke Nelson <luke.r.nels@gmail.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NXi Wang <xi.wang@gmail.com>
Link: https://lore.kernel.org/bpf/20200421002804.5118-1-luke.r.nels@gmail.com
上级 ae460c02
...@@ -770,12 +770,13 @@ static int emit_bpf_tail_call(int insn, struct rv_jit_context *ctx) ...@@ -770,12 +770,13 @@ static int emit_bpf_tail_call(int insn, struct rv_jit_context *ctx)
emit_bcc(BPF_JGE, lo(idx_reg), RV_REG_T1, off, ctx); emit_bcc(BPF_JGE, lo(idx_reg), RV_REG_T1, off, ctx);
/* /*
* if ((temp_tcc = tcc - 1) < 0) * temp_tcc = tcc - 1;
* if (tcc < 0)
* goto out; * goto out;
*/ */
emit(rv_addi(RV_REG_T1, RV_REG_TCC, -1), ctx); emit(rv_addi(RV_REG_T1, RV_REG_TCC, -1), ctx);
off = (tc_ninsn - (ctx->ninsns - start_insn)) << 2; off = (tc_ninsn - (ctx->ninsns - start_insn)) << 2;
emit_bcc(BPF_JSLT, RV_REG_T1, RV_REG_ZERO, off, ctx); emit_bcc(BPF_JSLT, RV_REG_TCC, RV_REG_ZERO, off, ctx);
/* /*
* prog = array->ptrs[index]; * prog = array->ptrs[index];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册