Skip to contentSkip to conversation

selftest/bpf: make pyperf600 a success again

PATCH Applied Andrii Nakryiko 5 participants 5 messages Aug 13 – Aug 14

Subsystems (3)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 selftest/bpf: make pyperf600 a success again

pyperf600 has been running into 8K BPF_COMPLEXITY_LIMIT_JMP_SEQ limitations for a long while now, after some internal compiler changes.

Until BPF verifier is bestowed with scalar evolution logic, make that test actually work by doing what would anyone should do in such situations: by moving repeatable per-iteration work into independently verified global functions.

void * argument is a problem for global funcs, but a static function wrapper doing necessary casts and a bit of __arg_nonnull magic dust is all it takes.

---
 tools/testing/selftests/bpf/progs/pyperf.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/pyperf.h +10 -2
index 86484f07e1d1..fd93a96e5901 100644
@@ -85,9 +85,11 @@ static void *get_thread_state(void *tls_base, PidData *pidData)
 	return thread_state;
 }
 
-static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
-					   FrameData *frame, Symbol *symbol)
+__weak bool __get_frame_data(long frame_ptr_, PidData *pidData __arg_nonnull,
+			     FrameData *frame __arg_nonnull, Symbol *symbol __arg_nonnull)
 {
+	void *frame_ptr = (void *)frame_ptr_;
+
 	// read data from PyFrameObject
 	bpf_probe_read_user(&frame->f_back,
 			    sizeof(frame->f_back),
@@ -119,6 +121,12 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
 	return true;
 }
 
+static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
+					   FrameData *frame, Symbol *symbol)
+{
+	return __get_frame_data((long)frame_ptr, pidData, frame, symbol);
+}
+
 struct {
 	__uint(type, BPF_MAP_TYPE_HASH);
 	__uint(max_entries, 1);
Signature · 1 line
2.53.0-Meta
#1 lore raw
This isn't a bug, but could this sentence be tightened? The phrase "by doing what would anyone should do in such situations: by moving ..." mixes "what would anyone do" with "what anyone should do"…
Quoted 8 lines

pyperf600 has been running into 8K BPF_COMPLEXITY_LIMIT_JMP_SEQ limitations for a long while now, after some internal compiler changes.

Until BPF verifier is bestowed with scalar evolution logic, make that test actually work by doing what would anyone should do in such situations: by moving repeatable per-iteration work into independently verified global functions.

Quoted 4 lines

void * argument is a problem for global funcs, but a static function wrapper doing necessary casts and a bit of __arg_nonnull magic dust is all it takes.

This isn't a bug, but could this sentence be tightened? The phrase "by doing what would anyone should do in such situations: by moving ..." mixes "what would anyone do" with "what anyone should do" and repeats the "by" clause on both sides of the colon. Also, the changelog says "global functions" (plural) while the diff adds exactly one global function (__get_frame_data).

Quoted 18 lines
tools/testing/selftests/bpf/progs/pyperf.h +4 -2
index 86484f07e1d19..fd93a96e59015 100644
@@ -85,9 +85,11 @@ static void *get_thread_state(void *tls_base, PidData *pidData)
 	return thread_state;
 }
 
-static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
-					   FrameData *frame, Symbol *symbol)
+__weak bool __get_frame_data(long frame_ptr_, PidData *pidData __arg_nonnull,
+			     FrameData *frame __arg_nonnull, Symbol *symbol __arg_nonnull)
 {
+	void *frame_ptr = (void *)frame_ptr_;
+
 	// read data from PyFrameObject
 	bpf_probe_read_user(&frame->f_back,
 			    sizeof(frame->f_back),

[ ... ]

tools/testing/selftests/bpf/progs/pyperf.h static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData, · line 132

Quoted 13 lines
tools/testing/selftests/bpf/progs/pyperf.h +6 -0
@@ -119,6 +121,12 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
 	return true;
 }
 
+static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
+					   FrameData *frame, Symbol *symbol)
+{
+	return __get_frame_data((long)frame_ptr, pidData, frame, symbol);
+}
+
 struct {
 	__uint(type, BPF_MAP_TYPE_HASH);
 	__uint(max_entries, 1);

This isn't a bug, but was the intent to change all nine pyperf variants? pyperf.h already carries a per-variant inlining switch used twice in the same file (the #ifdef SUBPROGS block at get_thread_state and the #ifdef GLOBAL_FUNC / #elif SUBPROGS block at __on_event). The new __get_frame_data is unconditionally __weak, so all nine includers change shape at once, including pyperf_subprogs.c and pyperf_global.c whose reason for existing is to exercise the static-noinline-subprog and global-func paths specifically, and pyperf50/100/180 which exercise full unrolling.

The descriptions in prog_tests/bpf_verif_scale.c that document the intended shape of these objects (for pyperf600: "Asm loop count -> 4. 16k insns in loop body. Total program size ~82k insns.") are no longer accurate for the smaller loop body and are not updated here. The changelog only motivates pyperf600.

Would gating the new global function the way get_thread_state()/ __on_event() are already gated keep the subprogs/global/unrolled variants testing what their names suggest? If it is meant to apply everywhere, would it be worth refreshing the size comments in bpf_verif_scale.c?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31754735233

reviewer Acked-by on v1 1/1
#2 lore raw
In reply to Andrii Nakryiko
Quoted 8 lines · Andrii Nakryiko

pyperf600 has been running into 8K BPF_COMPLEXITY_LIMIT_JMP_SEQ limitations for a long while now, after some internal compiler changes.

Until BPF verifier is bestowed with scalar evolution logic, make that test actually work by doing what would anyone should do in such situations: by moving repeatable per-iteration work into independently verified global functions.

Quoted 4 lines

void * argument is a problem for global funcs, but a static function wrapper doing necessary casts and a bit of __arg_nonnull magic dust is all it takes.

Reviewed-by Tested-by on v1 1/1
#3 lore raw
In reply to Andrii Nakryiko
Quoted 37 lines · Andrii Nakryiko

pyperf600 has been running into 8K BPF_COMPLEXITY_LIMIT_JMP_SEQ limitations for a long while now, after some internal compiler changes.

Until BPF verifier is bestowed with scalar evolution logic, make that test actually work by doing what would anyone should do in such situations: by moving repeatable per-iteration work into independently verified global functions.

void * argument is a problem for global funcs, but a static function wrapper doing necessary casts and a bit of __arg_nonnull magic dust is all it takes.

---
  tools/testing/selftests/bpf/progs/pyperf.h | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/pyperf.h +4 -2
index 86484f07e1d1..fd93a96e5901 100644
@@ -85,9 +85,11 @@ static void *get_thread_state(void *tls_base, PidData *pidData)
  	return thread_state;
  }
 
-static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
-					   FrameData *frame, Symbol *symbol)
+__weak bool __get_frame_data(long frame_ptr_, PidData *pidData __arg_nonnull,
+			     FrameData *frame __arg_nonnull, Symbol *symbol __arg_nonnull)
  {
+	void *frame_ptr = (void *)frame_ptr_;
+
  	// read data from PyFrameObject
  	bpf_probe_read_user(&frame->f_back,
  			    sizeof(frame->f_back),
@@ -119,6 +121,12 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
  	return true;
  }

tools/testing/selftests/bpf/progs/pyperf.h static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData, · line 132

Quoted 10 lines
tools/testing/selftests/bpf/progs/pyperf.h +6 -0
 
+static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
+					   FrameData *frame, Symbol *symbol)
+{
+	return __get_frame_data((long)frame_ptr, pidData, frame, symbol);
+}
+
  struct {
  	__uint(type, BPF_MAP_TYPE_HASH);
  	__uint(max_entries, 1);

riscv bpf suffers this issue too, happy to see this fix.

feel free to add:

#4 lore raw
In reply to Andrii Nakryiko
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 9 lines · On Thu, 13 Aug 2026 16:29:43 -0700 you wrote:

pyperf600 has been running into 8K BPF_COMPLEXITY_LIMIT_JMP_SEQ limitations for a long while now, after some internal compiler changes.

Until BPF verifier is bestowed with scalar evolution logic, make that test actually work by doing what would anyone should do in such situations: by moving repeatable per-iteration work into independently verified global functions.

[...]

Here is the summary with links:
- [bpf-next] selftest/bpf: make pyperf600 a success again

    https://git.kernel.org/bpf/bpf-next/c/c7e617552938

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html