Skip to content

Commit 84c1c6a

Browse files
Hou TaoNobody
authored andcommitted
bpf, arm64: calculate offset as byte-offset for bpf line info
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]>
1 parent d0c03e1 commit 84c1c6a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,14 @@ static inline int bpf2a64_offset(int bpf_insn, int off,
153153
/*
154154
* Whereas arm64 branch instructions encode the offset
155155
* from the branch itself, so we must subtract 1 from the
156-
* instruction offset.
156+
* instruction offset. The unit of ctx->offset is byte, so
157+
* subtract AARCH64_INSN_SIZE from it. bpf2a64_offset()
158+
* returns instruction offset, so divide by AARCH64_INSN_SIZE
159+
* at the end.
157160
*/
158-
return ctx->offset[bpf_insn + off] - (ctx->offset[bpf_insn] - 1);
161+
return (ctx->offset[bpf_insn + off] -
162+
(ctx->offset[bpf_insn] - AARCH64_INSN_SIZE)) /
163+
AARCH64_INSN_SIZE;
159164
}
160165

161166
static void jit_fill_hole(void *area, unsigned int size)
@@ -946,13 +951,14 @@ static int build_body(struct jit_ctx *ctx, bool extra_pass)
946951
const struct bpf_insn *insn = &prog->insnsi[i];
947952
int ret;
948953

954+
/* BPF line info needs byte-offset instead of insn-offset */
949955
if (ctx->image == NULL)
950-
ctx->offset[i] = ctx->idx;
956+
ctx->offset[i] = ctx->idx * AARCH64_INSN_SIZE;
951957
ret = build_insn(insn, ctx, extra_pass);
952958
if (ret > 0) {
953959
i++;
954960
if (ctx->image == NULL)
955-
ctx->offset[i] = ctx->idx;
961+
ctx->offset[i] = ctx->idx * AARCH64_INSN_SIZE;
956962
continue;
957963
}
958964
if (ret)
@@ -964,7 +970,7 @@ static int build_body(struct jit_ctx *ctx, bool extra_pass)
964970
* instruction (end of program)
965971
*/
966972
if (ctx->image == NULL)
967-
ctx->offset[i] = ctx->idx;
973+
ctx->offset[i] = ctx->idx * AARCH64_INSN_SIZE;
968974

969975
return 0;
970976
}

0 commit comments

Comments
 (0)