[PATCH bpf-next v1 1/2] selftests/bpf: Include bpf_misc.h in uprobe_autoattach.c

From: Tiezhu Yang

Date: Thu Nov 26 2026 - 00:13:23 EST


Commit bc72742bebec ("selftests/bpf: Validate arch-specific argument
registers limits") originally included the header "progs/bpf_misc.h"
in prog_tests/uprobe_autoattach.c so that FUNC_REG_ARG_CNT is defined
when checking argument assertions (arg4 through arg8).

Commit 8c2b5e90505e ("selftests/bpf: add bpf_for_each(), bpf_for(),
and bpf_repeat() macros") accidentally removed this include, causing
FUNC_REG_ARG_CNT to evaluate to 0 in the preprocessor and silently
skipping all assertions beyond arg3 on every architecture.

Restore #include "progs/bpf_misc.h" in prog_tests/uprobe_autoattach.c,
while guarding __naked and SYS_PREFIX in progs/bpf_misc.h with #ifndef
to avoid redefinition conflicts with user-space headers.

Here are the test results on LoongArch, where default FUNC_REG_ARG_CNT
is 5.

Before:
$ sudo ./test_progs -v -t uprobe_autoattach
...
test_uprobe_autoattach:PASS:arg1 0 nsec
test_uprobe_autoattach:PASS:arg2 0 nsec
test_uprobe_autoattach:PASS:arg3 0 nsec
#656 uprobe_autoattach:OK

After:
$ sudo ./test_progs -v -t uprobe_autoattach
...
test_uprobe_autoattach:PASS:arg1 0 nsec
test_uprobe_autoattach:PASS:arg2 0 nsec
test_uprobe_autoattach:PASS:arg3 0 nsec
test_uprobe_autoattach:PASS:arg4 0 nsec
test_uprobe_autoattach:PASS:arg5 0 nsec
#656 uprobe_autoattach:OK

Fixes: 8c2b5e90505e ("selftests/bpf: add bpf_for_each(), bpf_for(), and bpf_repeat() macros")
Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c | 1 +
tools/testing/selftests/bpf/progs/bpf_misc.h | 4 ++++
2 files changed, 5 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
index d5b3377aa33c..6558c857e620 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
@@ -3,6 +3,7 @@

#include <test_progs.h>
#include "test_uprobe_autoattach.skel.h"
+#include "progs/bpf_misc.h"

/* uprobe attach point */
static noinline int autoattach_trigger_func(int arg1, int arg2, int arg3,
diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
index 6b930cb48f8d..589e68e4fa5c 100644
--- a/tools/testing/selftests/bpf/progs/bpf_misc.h
+++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
@@ -206,7 +206,9 @@
#define CAP_BPF 39

/* Convenience macro for use with 'asm volatile' blocks */
+#ifndef __naked
#define __naked __attribute__((naked))
+#endif
#define __clobber_all "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "memory"
#define __clobber_common "r0", "r1", "r2", "r3", "r4", "r5", "memory"
#define __imm(name) [name]"i"(name)
@@ -231,6 +233,7 @@
#define __used __attribute__((used))
#endif

+#ifndef SYS_PREFIX
#if defined(__TARGET_ARCH_x86)
#define SYSCALL_WRAPPER 1
#define SYS_PREFIX "__x64_"
@@ -250,6 +253,7 @@
#define SYSCALL_WRAPPER 0
#define SYS_PREFIX "__se_"
#endif
+#endif /* SYS_PREFIX */

/* How many arguments are passed to function in register */
#if defined(__TARGET_ARCH_x86) || defined(__x86_64__)
--
2.42.0