All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v1] bpf: Let the bpf_fastcall boundary cover the longest pattern
@ 2026-11-23 19:45 Kumar Kartikeya Dwivedi
  2026-11-24  0:20 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2026-11-23 19:45 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, Emil Tsalapatis, Ihor Solodrai, kkd,
	kernel-team

From: Alexei Starovoitov <ast@kernel.org>

A subprog can have bpf_fastcall patterns of different length:

  *(u64 *)(r10 - 8) = r2
  *(u64 *)(r10 - 16) = r1
  call bpf_get_smp_processor_id
  r1 = *(u64 *)(r10 - 16)
  r2 = *(u64 *)(r10 - 8)
  *(u64 *)(r10 - 16) = r1
  call bpf_get_smp_processor_id
  r1 = *(u64 *)(r10 - 16)
  r0 = *(u64 *)(r10 - 8)

For each pattern, take the offset just above its highest spill slot: 0 for
the first pattern here, -8 for the second. Currently
mark_fastcall_pattern_for_call() keeps the lowest of these offsets in
fastcall_stack_off, the bpf_fastcall boundary of the subprog, which is -8
here. check_fastcall_stack_contract() looks only at accesses below the
boundary, so the last load, at -8, does not switch the rewrite off.
bpf_remove_fastcall_spills_fills() then removes all three pairs of a spill
and a fill, and the load reads a slot that nothing wrote, while the
verifier took it for a slot with the type of R2.

Keep the highest of these offsets instead: every slot of every pattern is
below it. Start from S16_MIN, the value that says that nothing is
rewritten. Stop at 0, as min() did, because a pattern in code that never
runs may end above the frame pointer.

Fixes: 5b5f51bff1b6 ("bpf: no_caller_saved_registers attribute for helper calls")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 kernel/bpf/verifier.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9b228ffbe3fe..01a74e166e89 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -19933,7 +19933,11 @@ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env,
 		env->insn_aux_data[insn_idx].fastcall_spills_num = i - 1;
 	else
 		subprog->keep_fastcall_stack = 1;
-	subprog->fastcall_stack_off = min(subprog->fastcall_stack_off, off);
+	/*
+	 * The upper end of the longest pattern: no slot of a pattern is above it. Code that never
+	 * runs may have a pattern that ends above the frame pointer.
+	 */
+	subprog->fastcall_stack_off = max(subprog->fastcall_stack_off, min_t(s16, off, 0));
 }
 
 static int mark_fastcall_patterns(struct bpf_verifier_env *env)
@@ -19944,6 +19948,7 @@ static int mark_fastcall_patterns(struct bpf_verifier_env *env)
 	int s, i;
 
 	for (s = 0; s < env->subprog_cnt; ++s, ++subprog) {
+		subprog->fastcall_stack_off = S16_MIN;
 		/* find lowest stack spill offset used in this subprog */
 		lowest_off = 0;
 		for (i = subprog->start; i < (subprog + 1)->start; ++i) {

base-commit: 84afebd853437e44cb71f718be11d90e4c1a59dd
-- 
2.53.0


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

* Re: [PATCH bpf v1] bpf: Let the bpf_fastcall boundary cover the longest pattern
  2026-11-23 19:45 [PATCH bpf v1] bpf: Let the bpf_fastcall boundary cover the longest pattern Kumar Kartikeya Dwivedi
@ 2026-11-24  0:20 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-24  0:20 UTC (permalink / raw)
  To: Kumar Kartikeya Dwivedi
  Cc: bpf, ast, andrii, daniel, eddyz87, emil, ihor.solodrai, kkd,
	kernel-team

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Mon, 23 Nov 2026 20:45:42 +0100 you wrote:
> From: Alexei Starovoitov <ast@kernel.org>
> 
> A subprog can have bpf_fastcall patterns of different length:
> 
>   *(u64 *)(r10 - 8) = r2
>   *(u64 *)(r10 - 16) = r1
>   call bpf_get_smp_processor_id
>   r1 = *(u64 *)(r10 - 16)
>   r2 = *(u64 *)(r10 - 8)
>   *(u64 *)(r10 - 16) = r1
>   call bpf_get_smp_processor_id
>   r1 = *(u64 *)(r10 - 16)
>   r0 = *(u64 *)(r10 - 8)
> 
> [...]

Here is the summary with links:
  - [bpf,v1] bpf: Let the bpf_fastcall boundary cover the longest pattern
    https://git.kernel.org/bpf/bpf/c/95d366cb5775

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-11-24  0:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 19:45 [PATCH bpf v1] bpf: Let the bpf_fastcall boundary cover the longest pattern Kumar Kartikeya Dwivedi
2026-11-24  0:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.