insn_to_jit_off passed to bpf_prog_fill_jited_linfo() is calculated in instruction granularity instead of bytes granularity, but bpf line info requires byte offset, so fixing it by calculating offset as byte-offset. Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx> --- arch/arm64/net/bpf_jit_comp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 6a83f3070985..7b94e0c5e134 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -152,10 +152,12 @@ static inline int bpf2a64_offset(int bpf_insn, int off, bpf_insn++; /* * Whereas arm64 branch instructions encode the offset - * from the branch itself, so we must subtract 1 from the + * from the branch itself, so we must subtract 4 from the * instruction offset. */ - return ctx->offset[bpf_insn + off] - (ctx->offset[bpf_insn] - 1); + return (ctx->offset[bpf_insn + off] - + (ctx->offset[bpf_insn] - AARCH64_INSN_SIZE)) / + AARCH64_INSN_SIZE; } static void jit_fill_hole(void *area, unsigned int size) @@ -946,13 +948,14 @@ static int build_body(struct jit_ctx *ctx, bool extra_pass) const struct bpf_insn *insn = &prog->insnsi[i]; int ret; + /* BPF line info needs byte-offset instead of insn-offset */ if (ctx->image == NULL) - ctx->offset[i] = ctx->idx; + ctx->offset[i] = ctx->idx * AARCH64_INSN_SIZE; ret = build_insn(insn, ctx, extra_pass); if (ret > 0) { i++; if (ctx->image == NULL) - ctx->offset[i] = ctx->idx; + ctx->offset[i] = ctx->idx * AARCH64_INSN_SIZE; continue; } if (ret) @@ -964,7 +967,7 @@ static int build_body(struct jit_ctx *ctx, bool extra_pass) * instruction (end of program) */ if (ctx->image == NULL) - ctx->offset[i] = ctx->idx; + ctx->offset[i] = ctx->idx * AARCH64_INSN_SIZE; return 0; } -- 2.27.0