Skip to content

Commit

Permalink
bpf, arm64: calculate offset as byte-offset for bpf line info
Browse files Browse the repository at this point in the history
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 ctx->offset
as byte-offset. bpf2a64_offset() needs to return relative instruction
offset by using ctx->offfset, so update it accordingly.

Fixes: 37ab566 ("bpf: arm64: Enable arm64 jit to provide bpf_line_info")
Signed-off-by: Hou Tao <[email protected]>
  • Loading branch information
Hou Tao authored and Nobody committed Feb 16, 2022
1 parent 2066183 commit 4a4a2e3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions arch/arm64/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ static inline int bpf2a64_offset(int bpf_insn, int off,
/*
* Whereas arm64 branch instructions encode the offset
* from the branch itself, so we must subtract 1 from the
* instruction offset.
* instruction offset. The unit of ctx->offset is byte, so
* subtract AARCH64_INSN_SIZE from it. bpf2a64_offset()
* returns instruction offset, so divide by AARCH64_INSN_SIZE
* at the end.
*/
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)
Expand Down Expand Up @@ -946,13 +951,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)
Expand All @@ -964,7 +970,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;
}
Expand Down

0 comments on commit 4a4a2e3

Please sign in to comment.