The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf, arm64: Fix jited line info off by kCFI hash
@ 2026-09-25 17:53 Jose Fernandez (Anthropic)
  2026-11-27 15:25 ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Jose Fernandez (Anthropic) @ 2026-09-25 17:53 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Xu Kuohai, Catalin Marinas,
	Will Deacon, Mark Rutland, Maxwell Bland, Sami Tolvanen
  Cc: bpf, linux-arm-kernel, linux-kernel, Sashiko,
	Jose Fernandez (Anthropic)

With CONFIG_CFI=y, the jited line info of every arm64 BPF program is
off by one instruction, so tools that use it show the wrong source line.

The JIT counts ctx.offset[] from ctx.ro_image. Since commit
710618c760c0 ("arm64/cfi,bpf: Support kCFI + BPF on arm64"),
prog->bpf_func starts past the 4-byte kCFI hash, and
bpf_prog_fill_jited_linfo() adds the offsets to prog->bpf_func.

Subtract cfi_get_offset() from the offsets before the fill, and move
the fill after bpf_prog_update_insn_ptrs(), which needs the offsets
relative to ctx.ro_image.

Fixes: 710618c760c0 ("arm64/cfi,bpf: Support kCFI + BPF on arm64")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260904014748.C04AA1F000E9@smtp.kernel.org/
Reported-by: Alexei Starovoitov <ast@kernel.org>
Closes: https://lore.kernel.org/all/DLNXZ2WK7TPD.2RZBUNRS4FA4L@gmail.com/
Assisted-by: LLM
Signed-off-by: Jose Fernandez (Anthropic) <jose.fernandez@linux.dev>
---
Tested in an arm64 KVM guest with CONFIG_CFI=y. Without this patch
every line info entry after a function's first was off by one
instruction, and with it every entry was correct.
---
 arch/arm64/net/bpf_jit_comp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index c5f55d6161fee..cdc98efc1acf0 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -2345,14 +2345,21 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
 		/* 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);
 		/*
 		 * The bpf_prog_update_insn_ptrs function expects offsets to
 		 * point to the first byte of the jitted instruction (unlike
-		 * the bpf_prog_fill_jited_linfo above, which, for historical
+		 * the bpf_prog_fill_jited_linfo below, which, for historical
 		 * reasons, expects to point to the next instruction)
 		 */
 		bpf_prog_update_insn_ptrs(prog, ctx.offset, ctx.ro_image);
+		/*
+		 * Line info is relative to prog->bpf_func, which starts
+		 * cfi_get_offset() bytes into ro_image. Shift the offsets here,
+		 * after bpf_prog_update_insn_ptrs(), which needs them unshifted.
+		 */
+		for (i = 0; i <= prog->len; i++)
+			ctx.offset[i] -= cfi_get_offset();
+		bpf_prog_fill_jited_linfo(prog, ctx.offset + 1);
 out_off:
 		if (!ro_header && priv_stack_ptr) {
 			free_percpu(priv_stack_ptr);

---
base-commit: ad139384ecddb6f3e7e3c3c12765aafae0e39670
change-id: 20260925-b4-arm64-bpf-linfo-cfi-f5c3897e408c

Best regards,
--  
Jose Fernandez (Anthropic) <jose.fernandez@linux.dev>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] bpf, arm64: Fix jited line info off by kCFI hash
  2026-09-25 17:53 [PATCH bpf] bpf, arm64: Fix jited line info off by kCFI hash Jose Fernandez (Anthropic)
@ 2026-11-27 15:25 ` Will Deacon
  2026-11-27 17:31   ` Jose Fernandez (Anthropic)
  0 siblings, 1 reply; 4+ messages in thread
From: Will Deacon @ 2026-11-27 15:25 UTC (permalink / raw)
  To: Jose Fernandez (Anthropic)
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Xu Kuohai, Catalin Marinas,
	Mark Rutland, Maxwell Bland, Sami Tolvanen, bpf, linux-arm-kernel,
	linux-kernel, Sashiko

On Fri, Sep 25, 2026 at 05:53:21PM +0000, Jose Fernandez (Anthropic) wrote:
> With CONFIG_CFI=y, the jited line info of every arm64 BPF program is
> off by one instruction, so tools that use it show the wrong source line.
> 
> The JIT counts ctx.offset[] from ctx.ro_image. Since commit
> 710618c760c0 ("arm64/cfi,bpf: Support kCFI + BPF on arm64"),
> prog->bpf_func starts past the 4-byte kCFI hash, and
> bpf_prog_fill_jited_linfo() adds the offsets to prog->bpf_func.
> 
> Subtract cfi_get_offset() from the offsets before the fill, and move
> the fill after bpf_prog_update_insn_ptrs(), which needs the offsets
> relative to ctx.ro_image.
> 
> Fixes: 710618c760c0 ("arm64/cfi,bpf: Support kCFI + BPF on arm64")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/20260904014748.C04AA1F000E9@smtp.kernel.org/
> Reported-by: Alexei Starovoitov <ast@kernel.org>
> Closes: https://lore.kernel.org/all/DLNXZ2WK7TPD.2RZBUNRS4FA4L@gmail.com/
> Assisted-by: LLM
> Signed-off-by: Jose Fernandez (Anthropic) <jose.fernandez@linux.dev>
> ---
> Tested in an arm64 KVM guest with CONFIG_CFI=y. Without this patch
> every line info entry after a function's first was off by one
> instruction, and with it every entry was correct.
> ---
>  arch/arm64/net/bpf_jit_comp.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

I'm just chasing up old patches sitting around in my inbox and noticed
this one. It doesn't _look_ like it's been applied anywhere. Is it still
needed?

Will

> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index c5f55d6161fee..cdc98efc1acf0 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -2345,14 +2345,21 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
>  		/* 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);
>  		/*
>  		 * The bpf_prog_update_insn_ptrs function expects offsets to
>  		 * point to the first byte of the jitted instruction (unlike
> -		 * the bpf_prog_fill_jited_linfo above, which, for historical
> +		 * the bpf_prog_fill_jited_linfo below, which, for historical
>  		 * reasons, expects to point to the next instruction)
>  		 */
>  		bpf_prog_update_insn_ptrs(prog, ctx.offset, ctx.ro_image);
> +		/*
> +		 * Line info is relative to prog->bpf_func, which starts
> +		 * cfi_get_offset() bytes into ro_image. Shift the offsets here,
> +		 * after bpf_prog_update_insn_ptrs(), which needs them unshifted.
> +		 */
> +		for (i = 0; i <= prog->len; i++)
> +			ctx.offset[i] -= cfi_get_offset();
> +		bpf_prog_fill_jited_linfo(prog, ctx.offset + 1);
>  out_off:
>  		if (!ro_header && priv_stack_ptr) {
>  			free_percpu(priv_stack_ptr);
> 
> ---
> base-commit: ad139384ecddb6f3e7e3c3c12765aafae0e39670
> change-id: 20260925-b4-arm64-bpf-linfo-cfi-f5c3897e408c
> 
> Best regards,
> --  
> Jose Fernandez (Anthropic) <jose.fernandez@linux.dev>
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] bpf, arm64: Fix jited line info off by kCFI hash
  2026-11-27 15:25 ` Will Deacon
@ 2026-11-27 17:31   ` Jose Fernandez (Anthropic)
  2026-11-27 17:47     ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Jose Fernandez (Anthropic) @ 2026-11-27 17:31 UTC (permalink / raw)
  To: Will Deacon
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Xu Kuohai, Catalin Marinas,
	Mark Rutland, Maxwell Bland, Sami Tolvanen, bpf, linux-arm-kernel,
	linux-kernel, Sashiko

On Fri, Nov 27, 2026 at 03:25:52PM +0000, Will Deacon wrote:
> I'm just chasing up old patches sitting around in my inbox and noticed
> this one. It doesn't _look_ like it's been applied anywhere. Is it still
> needed?

No, please drop it. v2 fixed this in the BPF core and landed in
v7.4-rc2 as commit 3e4279dc5144 ("bpf: Fix jited line info off by the
CFI preamble").

- Jose

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] bpf, arm64: Fix jited line info off by kCFI hash
  2026-11-27 17:31   ` Jose Fernandez (Anthropic)
@ 2026-11-27 17:47     ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2026-11-27 17:47 UTC (permalink / raw)
  To: Jose Fernandez (Anthropic)
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Puranjay Mohan, Xu Kuohai, Catalin Marinas,
	Mark Rutland, Maxwell Bland, Sami Tolvanen, bpf, linux-arm-kernel,
	linux-kernel, Sashiko

On Fri, Nov 27, 2026 at 05:31:35PM +0000, Jose Fernandez (Anthropic) wrote:
> On Fri, Nov 27, 2026 at 03:25:52PM +0000, Will Deacon wrote:
> > I'm just chasing up old patches sitting around in my inbox and noticed
> > this one. It doesn't _look_ like it's been applied anywhere. Is it still
> > needed?
> 
> No, please drop it. v2 fixed this in the BPF core and landed in
> v7.4-rc2 as commit 3e4279dc5144 ("bpf: Fix jited line info off by the
> CFI preamble").

Ah, thanks for the pointer. That looks like a much nicer fix :)

Will

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-27 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-25 17:53 [PATCH bpf] bpf, arm64: Fix jited line info off by kCFI hash Jose Fernandez (Anthropic)
2026-11-27 15:25 ` Will Deacon
2026-11-27 17:31   ` Jose Fernandez (Anthropic)
2026-11-27 17:47     ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox