Skip to contentSkip to conversation

bpf, arm64: fix bpf line info

PATCH In review Hou Tao 2 participants 5 messages Feb 26, 2022 – Feb 28, 2022

Subsystems (5)
Networking Network drivers BPF arm64 +1 more subsystems
lore
Share & tools
lore

Hou Tao

author
#0 lore raw

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
author
#1 lore raw

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.

Fixes 37ab566c178d ("bpf: arm64: Enable arm64 jit to provide bpf_line_info")
---
 arch/arm64/net/bpf_jit_comp.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm64/net/bpf_jit_comp.c +8 -5
index 2375ed3e4c8a..68b35c83e637 100644
@@ -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
author
#2 lore raw

PATCH v4 2/2 bpf, arm64: feed byte-offset into bpf line info

In reply to Hou Tao

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.

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().

Fixes 37ab566c178d ("bpf: arm64: Enable arm64 jit to provide bpf_line_info")
---
 arch/arm64/net/bpf_jit_comp.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/net/bpf_jit_comp.c +5 -0
index 68b35c83e637..e850c69e128c 100644
@@ -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
author
#3 lore raw
In reply to Hou Tao

Hi,

Quoted 13 lines · Hou Tao

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.

Quoted 7 lines

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.

Oops, forget to add Acked-by tag from Martin

Quoted 18 lines

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(-)
maintainer
#4 lore raw
In reply to Hou Tao
Quoted 7 lines · Hou Tao

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.

Quoted 8 lines

(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

LGTM, applied, thanks Hou!