Skip to contentSkip to conversation

selftests/bpf: Fix selftests fails with clang23

PATCH Applied KaFai Wan 2 participants 6 messages Oct 18

Subsystems (4)
lore
Share & tools
lore

KaFai Wan

author
#0 lore raw

v3 cover selftests/bpf: Fix selftests fails with clang23

Building with clang/LLVM 23 breaks several selftests. Patches #1 to #4 fix those failures.

Changes in v3:
- Remove the patch already applied.

Changes in v2:
- https://lore.kernel.org/bpf/[email protected]/
- Collect the selftest fixes from the two patches in v1
patches: #1, #5, #6 and #7.
- Add three new patches: #2, #3 and #4.

Changes in v1:
- https://lore.kernel.org/bpf/[email protected]/T/
- https://lore.kernel.org/bpf/[email protected]/T/

---
KaFai Wan (4):
bpf: Determine freplace staticness from BTF linkage selftests/bpf: Fix stack_arg precision backtracking log expectation selftests/bpf: Fix stack arg pruning test JOIN log expectation selftests/bpf: Use _exit() in uprobe_multi_test clone-ed child

 kernel/bpf/verifier.c                                      | 3 ++-
 tools/testing/selftests/bpf/prog_tests/exceptions.c        | 2 +-
 tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 ++--
 tools/testing/selftests/bpf/progs/stack_arg_precision.c    | 4 ++--
 tools/testing/selftests/bpf/progs/verifier_stack_arg.c     | 4 ++--
 5 files changed, 9 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v3 1/4 bpf: Determine freplace staticness from BTF linkage

bpf_check_attach_target() rejects a freplace whose target is a static function, using the subprog "unreliable" flag as a proxy for "static". That flag is raised whenever a subprogram's BTF prototype disagrees with the registers at its call site.

147400e9c27c ("bpf: Compute parameters liveness in bpf_compute_live_registers()") made that work for static callees: a static function with an unused argument no longer matches its BTF prototype at the call site and is marked unreliable.

Since LLVM commit 29b36a16f111 ("[BPF] Emit ABI-accurate BTF prototypes for DW_CC_nocall") in 23.1 [1] that premise is gone:
BTFDebug may now drop arguments removed by the optimizer, so for

	__noinline static int subprog(struct __sk_buff *ctx)
	{
		return bpf_ktime_get_ns();
	}

compiled with clang 23 the BTF describes subprog() as

	[75] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
	[76] FUNC 'subprog' type_id=75 linkage=static

There is then no argument left to compare, the subprog stays reliable, and the check in bpf_check_attach_target() is skipped. The freplace is then rejected by the later linkage check instead, reporting "subprog() is not a global function", and the selftest "exceptions" fails.

Determine staticness from the BTF linkage instead, and keep the unreliable check for global functions whose BTF does not match their call site.

There is no functional change: freplacing a static function was rejected before and is still rejected with the same -EINVAL. Selftest "exceptions" is updated to match.

[1] https://github.com/llvm/llvm-project/pull/198426

Fixes 147400e9c27c ("bpf: Compute parameters liveness in bpf_compute_live_registers()")
---
 kernel/bpf/verifier.c                               | 3 ++-
 tools/testing/selftests/bpf/prog_tests/exceptions.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +2 -1
index 2c812a5f1da87..519af2766032a 100644
@@ -22228,7 +22228,8 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
 		}
 		conservative = aux->func_info_aux[subprog].unreliable;
 		if (prog_extension) {
-			if (conservative) {
+			if (aux->func_info_aux[subprog].linkage != BTF_FUNC_GLOBAL ||
+			    conservative) {
 				bpf_log(log,
 					"Cannot replace static functions\n");
 				return -EINVAL;
tools/testing/selftests/bpf/prog_tests/exceptions.c +1 -1
index cea01d638f6fc..1bd15c4c125ba 100644
@@ -333,7 +333,7 @@ static void test_exceptions_success(void)
 				       bpf_program__fd(skel->progs.exception_throw_subprog),
 				       "throwing_subprog"), "set_attach_target"))
 				goto done;
-		}), "throwing_subprog() is not a global function", 0);
+		}), "Cannot replace static functions", 0);
 
 	if (test__start_subtest("non-throwing extension -> non-throwing subprog"))
 		/* non-throwing extension -> non-throwing global subprog : OK */
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v3 2/4 selftests/bpf: Fix stack_arg precision backtracking log expectation

In reply to KaFai Wan

Commit 147400e9c27c ("bpf: Compute parameters liveness in bpf_compute_live_registers()") stopped assuming that a call to a static subprogram reads r1..r5 and now uses the callee's entry live-in. R1-R5 are not live at these call insns, so __clean_func_state() clears them from the caller state and the backtracked parent state prints as:

mark_precise: frame0: parent state regs= stack=: R10=fp0

Update both expectations accordingly.

Fixes 147400e9c27c ("bpf: Compute parameters liveness in bpf_compute_live_registers()")
---
 tools/testing/selftests/bpf/progs/stack_arg_precision.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/stack_arg_precision.c +2 -2
index 7baa9c1c8e31e..c9564776d7333 100644
@@ -74,7 +74,7 @@ __msg("mark_precise: frame1: parent state regs= stack=:  frame1: R10=fp0")
 __msg("mark_precise: frame0: parent state regs= stack=:  R10=fp0")
 __msg("mark_precise: frame1: last_idx 11 first_idx 11 subseq_idx 13")
 __msg("mark_precise: frame1: regs= stack= before 11: (85) call pc+1")
-__msg("mark_precise: frame0: parent state regs= stack=:  R1=1 R2=2 R3=3 R4=4 R5=5 R10=fp0")
+__msg("mark_precise: frame0: parent state regs= stack=:  R10=fp0")
 __msg("mark_precise: frame0: last_idx 9 first_idx 7 subseq_idx 11")
 __msg("mark_precise: frame0: regs= stack= before 9: (05) goto pc+1")
 __msg("mark_precise: frame0: regs= stack= before 8: (7a) *(u64 *)(r11 -8) = 4")
@@ -95,7 +95,7 @@ __msg("mark_precise: frame1: parent state regs= stack=:  frame1: R10=fp0")
 __msg("mark_precise: frame0: parent state regs= stack=:  R10=fp0")
 __msg("mark_precise: frame1: last_idx 11 first_idx 11 subseq_idx 13 ")
 __msg("mark_precise: frame1: regs= stack= before 11: (85) call pc+1")
-__msg("mark_precise: frame0: parent state regs= stack=:  R1=1 R2=2 R3=3 R4=4 R5=5 R10=fp0")
+__msg("mark_precise: frame0: parent state regs= stack=:  R10=fp0")
 __msg("mark_precise: frame0: last_idx 10 first_idx 10 subseq_idx 11 ")
 __msg("mark_precise: frame0: regs= stack= before 10: (7a) *(u64 *)(r11 -8) = 6")
 __naked void stack_arg_precision_bpf2bpf(void)
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v3 3/4 selftests/bpf: Fix stack arg pruning test JOIN log expectation

In reply to KaFai Wan

Commit f414d20879ae ("bpf: Save DFS postorder numbers for program instructions") changed bpf_compute_postorder() to use a real DFS, which changes the postorder of this test's instructions and thus the insn edge the arg track join at insn 10 is reported on:

arg JOIN insn 8 -> 10 r1: _ + fp0-8 => fp0-8|fp0+0 arg JOIN insn 8 -> 10 sa0: _ + fp0-8 => fp0-8|fp0+0

Update the r1 and sa0 expectations to the new output.

Fixes f414d20879ae ("bpf: Save DFS postorder numbers for program instructions")
---
 tools/testing/selftests/bpf/progs/verifier_stack_arg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/verifier_stack_arg.c +2 -2
index f6a4a6aa0e617..b9f799f6e4051 100644
@@ -117,8 +117,8 @@ SEC("tc")
 __description("stack_arg: pruning with different stack arg types")
 __failure __log_level(2)
 __flag(BPF_F_TEST_STATE_FREQ)
-__msg("arg JOIN insn 9 -> 10 r1: fp0-8 + _ => fp0-8|fp0+0")
-__msg("arg JOIN insn 9 -> 10 sa0: fp0-8 + _ => fp0-8|fp0+0")
+__msg("arg JOIN insn 8 -> 10 r1: _ + fp0-8 => fp0-8|fp0+0")
+__msg("arg JOIN insn 8 -> 10 sa0: _ + fp0-8 => fp0-8|fp0+0")
 __msg("R{{[0-9]}} invalid mem access 'scalar'")
 __naked void stack_arg_pruning_type_mismatch(void)
 {
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v3 4/4 selftests/bpf: Use _exit() in uprobe_multi_test clone-ed child

In reply to KaFai Wan

child_func() terminates with exit(), but spawn_child_flag() also starts it via clone(CLONE_VM), which shares the parent's address space. That exit() then runs atexit handlers and static destructors against globals the parent is still using.

LLVM commit 3c3ed59c6a2a ("[llvm] Add format check for MCSubtargetFeatures") [1], included in the LLVM 23.1 releases, added Target::isValidFeatureListFormat() with a function-local static holding the compiled regex:

	static const llvm::Regex pattern("^([+-][^,]+)(,[+-][^,]+)*,?$");
	return pattern.match(Features);

The child exit destroys that static while its guard variable still marks it as initialized, so the regex is never rebuilt in the parent. From that point on, get_jited_program_text() gets NULL from LLVMCreateDisasmCPUFeatures(), so every jited program text check in the tests running after filter_clone_vm fails, e.g. "verifier_jit_convergence", "verifier_private_stack", "verifier_tailcall_jit" and "verifier_jit_inline".

Use _exit(), which runs neither atexit handlers nor static destructors, as uprobe_syscall.c already does for its own CLONE_VM child.

[1] https://github.com/llvm/llvm-project/pull/180943

Fixes d2520bdb1932f ("selftests/bpf: Add uprobe multi pid filter test for clone-ed processes")
---
 tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c +2 -2
index f0baf5738b751..7fbcfddc3cc36 100644
@@ -94,14 +94,14 @@ static int child_func(void *arg)
 	/* wait for parent's kick */
 	err = read(child->go[0], &c, 1);
 	if (err != 1)
-		exit(err);
+		_exit(err);
 
 	uprobe_multi_func_1();
 	uprobe_multi_func_2();
 	uprobe_multi_func_3();
 	usdt_trigger();
 
-	exit(errno);
+	_exit(errno);
 }
 
 static int spawn_child_flag(struct child *child, bool clone_vm)
Signature · 1 line
2.43.0
#5 lore raw
In reply to KaFai Wan
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 6 lines · On Sun, 18 Oct 2026 08:53:44 +0800 you wrote:

Building with clang/LLVM 23 breaks several selftests. Patches #1 to #4 fix those failures.

Changes in v3:
- Remove the patch already applied.

Quoted 7 lines

Changes in v2:
- https://lore.kernel.org/bpf/[email protected]/
- Collect the selftest fixes from the two patches in v1
patches: #1, #5, #6 and #7.
- Add three new patches: #2, #3 and #4.

[...]

Here is the summary with links:
- [bpf-next,v3,1/4] bpf: Determine freplace staticness from BTF linkage

    https://git.kernel.org/bpf/bpf-next/c/0ceb2f21d3e0
  - [bpf-next,v3,2/4] selftests/bpf: Fix stack_arg precision backtracking log expectation
    https://git.kernel.org/bpf/bpf-next/c/8d637d4c62c1
  - [bpf-next,v3,3/4] selftests/bpf: Fix stack arg pruning test JOIN log expectation
    https://git.kernel.org/bpf/bpf-next/c/8342d47ad791
  - [bpf-next,v3,4/4] selftests/bpf: Use _exit() in uprobe_multi_test clone-ed child
    https://git.kernel.org/bpf/bpf-next/c/ce42271dc517

You are awesome, thank you!

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