bpf, arm64: fix bpf line info
Subsystems (5)
v4 cover bpf, arm64: fix bpf line info
Hi,
The patchset addresses two issues in bpf line info for arm64:
(1) insn_to_jit_off only considers the body itself and ignores prologue before the body. Fixed in patch #1.
(2) insn_to_jit_off passed to bpf_prog_fill_jited_linfo() is calculated in instruction granularity instead of bytes granularity. Fixed in patch #2.
Comments are always welcome.
Regards,
Tao
Change Log:
v4:
* patch #2: convert ctx.offset into byte offset before call bpf_prog_fill_jited_linfo() instead of converting it back and forth.
v3: https://lore.kernel.org/bpf/[email protected]
* patch #2: explain why bpf2a64_offset() needs update
* add Fixes tags in both patches
v2: https://lore.kernel.org/bpf/[email protected]
* split into two independent patches (from Daniel)
* use AARCH64_INSN_SIZE instead of defining INSN_SIZE
v1: https://lore.kernel.org/bpf/[email protected]
Hou Tao (2):
bpf, arm64: call build_prologue() first in first JIT pass bpf, arm64: feed byte-offset into bpf line info
arch/arm64/net/bpf_jit_comp.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
2.18.2
PATCH v4 1/2 bpf, arm64: call build_prologue() first in first JIT pass
BPF line info needs ctx->offset to be the instruction offset in the whole jited image instead of the body itself, so also call build_prologue() first in first JIT pass.
--- arch/arm64/net/bpf_jit_comp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm64/net/bpf_jit_comp.c +8 -5
@@ -1190,15 +1190,18 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) goto out_off; } -/* 1. Initial fake pass to compute ctx->idx. */ - -/* Fake pass to fill in ctx->offset. */ -if (build_body (&ctx, extra_pass)) { +/* +* 1. Initial fake pass to compute ctx->idx and ctx->offset. +* +* BPF line info needs ctx->offset[i] to be the offset of +* instruction[i] in jited image, so build prologue first. +*/ +if (build_prologue (&ctx, was_classic)) { prog = orig_prog; goto out_off; } -if (build_prologue (&ctx, was_classic)) { +if (build_body (&ctx, extra_pass)) { prog = orig_prog; goto out_off; }
Signature · 1 line
2.18.2
PATCH v4 2/2 bpf, arm64: feed byte-offset into bpf line info
In reply to Hou Taoinsn_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.
bpf_prog_fill_jited_linfo() will be the last user of ctx.offset before its free, so convert the offset into byte-offset before call bpf_prog_fill_jited_linfo().
--- arch/arm64/net/bpf_jit_comp.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/net/bpf_jit_comp.c +5 -0
@@ -1274,6 +1274,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) prog->jited_len = prog_size;if (!prog->is_func || extra_pass) { +int i; + +/* offset[prog->len] is the size of program */ +for (i =0 ; i <= prog->len; i++) + ctx.offset[i] *=AARCH64_INSN_SIZE ;bpf_prog_fill_jited_linfo (prog, ctx.offset +1 ); out_off:kfree (ctx.offset);
Signature · 1 line
2.18.2
Hi,
Quoted 13 lines · Hou Tao
Hi,
The patchset addresses two issues in bpf line info for arm64:
(1)
insn_to_jit_offonly considers the body itself and ignores prologue before the body. Fixed in patch #1.(2)
insn_to_jit_offpassed tobpf_prog_fill_jited_linfo()is calculated in instruction granularity instead of bytes granularity. Fixed in patch #2.Comments are always welcome.
Quoted 7 lines
Regards,
TaoChange Log:
v4:
* patch #2: convert ctx.offset into byte offset before callbpf_prog_fill_jited_linfo()instead of converting it back and forth.
Oops, forget to add Acked-by tag from Martin
Quoted 18 lines
v3: https://lore.kernel.org/bpf/[email protected]
* patch #2: explain whybpf2a64_offset()needs update
* add Fixes tags in both patchesv2: https://lore.kernel.org/bpf/[email protected]
* split into two independent patches (from Daniel)
* useAARCH64_INSN_SIZEinstead of definingINSN_SIZEv1: https://lore.kernel.org/bpf/[email protected]
Hou Tao (2):
bpf, arm64: callbuild_prologue()first in first JIT pass bpf, arm64: feed byte-offset into bpf line infoarch/arm64/net/bpf_jit_comp.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
Daniel Borkmann
maintainerQuoted 7 lines · Hou Tao
Hi,
The patchset addresses two issues in bpf line info for arm64:
(1)
insn_to_jit_offonly considers the body itself and ignores prologue before the body. Fixed in patch #1.
Quoted 8 lines
(2)
insn_to_jit_offpassed tobpf_prog_fill_jited_linfo()is calculated in instruction granularity instead of bytes granularity. Fixed in patch #2.Comments are always welcome.
Regards,
Tao
LGTM, applied, thanks Hou!