* [PATCH bpf-next v2 0/2] selftests/bpf: Fix uprobe_autoattach test @ 2026-11-28 9:10 Tiezhu Yang 2026-11-28 9:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h Tiezhu Yang 2026-11-28 9:10 ` [PATCH bpf-next v2 2/2] selftests/bpf: Define FUNC_REG_ARG_CNT for LoongArch Tiezhu Yang 0 siblings, 2 replies; 4+ messages in thread From: Tiezhu Yang @ 2026-11-28 9:10 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi Cc: bpf, linux-kernel Changes in v2: - Move the definitions of FUNC_REG_ARG_CNT into a new shared header bpf_arch_regs.h instead of including progs/bpf_misc.h from user-space, and add bpf_arch_regs.h as a dependency of test_uprobe_autoattach.bpf.o in Makefile.skel. - Name it bpf_arch_regs.h rather than uprobe_autoattach.h for better generality, even though it is currently only used by uprobe_autoattach. Tiezhu Yang (2): selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h selftests/bpf: Define FUNC_REG_ARG_CNT for LoongArch tools/testing/selftests/bpf/Makefile.skel | 2 ++ tools/testing/selftests/bpf/bpf_arch_regs.h | 31 +++++++++++++++++++ .../bpf/prog_tests/uprobe_autoattach.c | 1 + tools/testing/selftests/bpf/progs/bpf_misc.h | 24 -------------- .../bpf/progs/test_uprobe_autoattach.c | 2 +- 5 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 tools/testing/selftests/bpf/bpf_arch_regs.h -- 2.42.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH bpf-next v2 1/2] selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h 2026-11-28 9:10 [PATCH bpf-next v2 0/2] selftests/bpf: Fix uprobe_autoattach test Tiezhu Yang @ 2026-11-28 9:10 ` Tiezhu Yang 2026-11-28 17:53 ` Alexei Starovoitov 2026-11-28 9:10 ` [PATCH bpf-next v2 2/2] selftests/bpf: Define FUNC_REG_ARG_CNT for LoongArch Tiezhu Yang 1 sibling, 1 reply; 4+ messages in thread From: Tiezhu Yang @ 2026-11-28 9:10 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi Cc: bpf, linux-kernel 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") removed this include, causing the macro FUNC_REG_ARG_CNT to evaluate to 0 in the preprocessor and silently skipping all assertions beyond arg3 on every architecture. Move the definitions of FUNC_REG_ARG_CNT into a new shared header bpf_arch_regs.h, also add the new bpf_arch_regs.h as a dependency of test_uprobe_autoattach.bpf.o in Makefile.skel to ensure it is properly rebuilt when this header changes, and then include it in prog_tests/uprobe_autoattach.c and progs/test_uprobe_autoattach.c to fix silent assertion skips. Here are the test results on LoongArch (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 #659 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 #659 uprobe_autoattach:OK Fixes: 8c2b5e90505e ("selftests/bpf: add bpf_for_each(), bpf_for(), and bpf_repeat() macros") Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- tools/testing/selftests/bpf/Makefile.skel | 2 ++ tools/testing/selftests/bpf/bpf_arch_regs.h | 29 +++++++++++++++++++ .../bpf/prog_tests/uprobe_autoattach.c | 1 + tools/testing/selftests/bpf/progs/bpf_misc.h | 24 --------------- .../bpf/progs/test_uprobe_autoattach.c | 2 +- 5 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 tools/testing/selftests/bpf/bpf_arch_regs.h diff --git a/tools/testing/selftests/bpf/Makefile.skel b/tools/testing/selftests/bpf/Makefile.skel index 45e4ce5dca4d..ccd9565b90cf 100644 --- a/tools/testing/selftests/bpf/Makefile.skel +++ b/tools/testing/selftests/bpf/Makefile.skel @@ -149,4 +149,6 @@ $(CXX_OBJS): $(RDIR)/%.bpf.o: progs/%.cpp | $(RDIR) $(BPF_CC_FLAGS) -c $< -o $@ $(call skip_on_fail,BPF) endif +$(RDIR)/test_uprobe_autoattach.bpf.o: bpf_arch_regs.h + endif # BPF_CC diff --git a/tools/testing/selftests/bpf/bpf_arch_regs.h b/tools/testing/selftests/bpf/bpf_arch_regs.h new file mode 100644 index 000000000000..4b5744f941bd --- /dev/null +++ b/tools/testing/selftests/bpf/bpf_arch_regs.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BPF_ARCH_REGS_H +#define __BPF_ARCH_REGS_H + +/* How many arguments are passed to function in register */ +#if defined(__TARGET_ARCH_x86) || defined(__x86_64__) +#define FUNC_REG_ARG_CNT 6 +#elif defined(__i386__) +#define FUNC_REG_ARG_CNT 3 +#elif defined(__TARGET_ARCH_s390) || defined(__s390x__) +#define FUNC_REG_ARG_CNT 5 +#elif defined(__TARGET_ARCH_arm) || defined(__arm__) +#define FUNC_REG_ARG_CNT 4 +#elif defined(__TARGET_ARCH_arm64) || defined(__aarch64__) +#define FUNC_REG_ARG_CNT 8 +#elif defined(__TARGET_ARCH_mips) || defined(__mips__) +#define FUNC_REG_ARG_CNT 8 +#elif defined(__TARGET_ARCH_powerpc) || defined(__powerpc__) || defined(__powerpc64__) +#define FUNC_REG_ARG_CNT 8 +#elif defined(__TARGET_ARCH_sparc) || defined(__sparc__) +#define FUNC_REG_ARG_CNT 6 +#elif defined(__TARGET_ARCH_riscv) || defined(__riscv__) +#define FUNC_REG_ARG_CNT 8 +#else +/* default to 5 for others */ +#define FUNC_REG_ARG_CNT 5 +#endif + +#endif /* __BPF_ARCH_REGS_H */ diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c index d5b3377aa33c..b5ea9b18ccc6 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c @@ -2,6 +2,7 @@ /* Copyright (c) 2022, Oracle and/or its affiliates. */ #include <test_progs.h> +#include "bpf_arch_regs.h" #include "test_uprobe_autoattach.skel.h" /* uprobe attach point */ diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h index 6b930cb48f8d..28668ecf7e83 100644 --- a/tools/testing/selftests/bpf/progs/bpf_misc.h +++ b/tools/testing/selftests/bpf/progs/bpf_misc.h @@ -251,30 +251,6 @@ #define SYS_PREFIX "__se_" #endif -/* How many arguments are passed to function in register */ -#if defined(__TARGET_ARCH_x86) || defined(__x86_64__) -#define FUNC_REG_ARG_CNT 6 -#elif defined(__i386__) -#define FUNC_REG_ARG_CNT 3 -#elif defined(__TARGET_ARCH_s390) || defined(__s390x__) -#define FUNC_REG_ARG_CNT 5 -#elif defined(__TARGET_ARCH_arm) || defined(__arm__) -#define FUNC_REG_ARG_CNT 4 -#elif defined(__TARGET_ARCH_arm64) || defined(__aarch64__) -#define FUNC_REG_ARG_CNT 8 -#elif defined(__TARGET_ARCH_mips) || defined(__mips__) -#define FUNC_REG_ARG_CNT 8 -#elif defined(__TARGET_ARCH_powerpc) || defined(__powerpc__) || defined(__powerpc64__) -#define FUNC_REG_ARG_CNT 8 -#elif defined(__TARGET_ARCH_sparc) || defined(__sparc__) -#define FUNC_REG_ARG_CNT 6 -#elif defined(__TARGET_ARCH_riscv) || defined(__riscv__) -#define FUNC_REG_ARG_CNT 8 -#else -/* default to 5 for others */ -#define FUNC_REG_ARG_CNT 5 -#endif - /* make it look to compiler like value is read and written */ #define __sink(expr) asm volatile("" : "+g"(expr)) diff --git a/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c index da4bf89d004c..b953f18b6b7d 100644 --- a/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c +++ b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c @@ -6,7 +6,7 @@ #include <bpf/bpf_core_read.h> #include <bpf/bpf_helpers.h> #include <bpf/bpf_tracing.h> -#include "bpf_misc.h" +#include "bpf_arch_regs.h" int uprobe_byname_parm1 = 0; int uprobe_byname_ran = 0; -- 2.42.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next v2 1/2] selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h 2026-11-28 9:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h Tiezhu Yang @ 2026-11-28 17:53 ` Alexei Starovoitov 0 siblings, 0 replies; 4+ messages in thread From: Alexei Starovoitov @ 2026-11-28 17:53 UTC (permalink / raw) To: Tiezhu Yang, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi Cc: bpf, linux-kernel On Sat, Nov 28, 2026 at 01:10 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > prog_tests/uprobe_autoattach.c and progs/test_uprobe_autoattach.c > to fix silent assertion skips. riscv still skips arg6, arg7 and arg8. > +#elif defined(__TARGET_ARCH_riscv) || defined(__riscv__) > +#define FUNC_REG_ARG_CNT 8 > +#else > +/* default to 5 for others */ > +#define FUNC_REG_ARG_CNT 5 > +#endif User space doesn't need this macro. The skeleton takes the size of a[] from BTF. No need for a new header and a Makefile.skel rule. The diff replaces both patches. diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c index d5b3377..5d9e016 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c @@ -17,7 +17,7 @@ void test_uprobe_autoattach(void) { const char *devnull_str = "/dev/null"; struct test_uprobe_autoattach *skel; - int trigger_ret; + int trigger_ret, i; FILE *devnull; skel = test_uprobe_autoattach__open_and_load(); @@ -49,24 +49,8 @@ void test_uprobe_autoattach(void) "check_uretprobe_byname2_rc"); ASSERT_EQ(skel->bss->uretprobe_byname2_ran, 4, "check_uretprobe_byname2_ran"); - ASSERT_EQ(skel->bss->a[0], 1, "arg1"); - ASSERT_EQ(skel->bss->a[1], 2, "arg2"); - ASSERT_EQ(skel->bss->a[2], 3, "arg3"); -#if FUNC_REG_ARG_CNT > 3 - ASSERT_EQ(skel->bss->a[3], 4, "arg4"); -#endif -#if FUNC_REG_ARG_CNT > 4 - ASSERT_EQ(skel->bss->a[4], 5, "arg5"); -#endif -#if FUNC_REG_ARG_CNT > 5 - ASSERT_EQ(skel->bss->a[5], 6, "arg6"); -#endif -#if FUNC_REG_ARG_CNT > 6 - ASSERT_EQ(skel->bss->a[6], 7, "arg7"); -#endif -#if FUNC_REG_ARG_CNT > 7 - ASSERT_EQ(skel->bss->a[7], 8, "arg8"); -#endif + for (i = 0; i < ARRAY_SIZE(skel->bss->a); i++) + ASSERT_EQ(skel->bss->a[i], i + 1, "arg"); fclose(devnull); cleanup: diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h index 6b930cb..8a30827 100644 --- a/tools/testing/selftests/bpf/progs/bpf_misc.h +++ b/tools/testing/selftests/bpf/progs/bpf_misc.h @@ -270,6 +270,8 @@ #define FUNC_REG_ARG_CNT 6 #elif defined(__TARGET_ARCH_riscv) || defined(__riscv__) #define FUNC_REG_ARG_CNT 8 +#elif defined(__TARGET_ARCH_loongarch) +#define FUNC_REG_ARG_CNT 8 #else /* default to 5 for others */ #define FUNC_REG_ARG_CNT 5 diff --git a/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c index da4bf89..e59a4b8 100644 --- a/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c +++ b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c @@ -20,7 +20,7 @@ int uretprobe_byname2_ran = 0; int test_pid; -int a[8]; +int a[FUNC_REG_ARG_CNT]; /* This program cannot auto-attach, but that should not stop other * programs from attaching. pw-bot: cr ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH bpf-next v2 2/2] selftests/bpf: Define FUNC_REG_ARG_CNT for LoongArch 2026-11-28 9:10 [PATCH bpf-next v2 0/2] selftests/bpf: Fix uprobe_autoattach test Tiezhu Yang 2026-11-28 9:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h Tiezhu Yang @ 2026-11-28 9:10 ` Tiezhu Yang 1 sibling, 0 replies; 4+ messages in thread From: Tiezhu Yang @ 2026-11-28 9:10 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi Cc: bpf, linux-kernel According to the Procedure Call Standard for the LoongArch Architecture, LoongArch uses 8 general-purpose argument registers ($a0 - $a7) to pass function arguments on both 32-bit and 64-bit ABIs. Define FUNC_REG_ARG_CNT as 8 for LoongArch in bpf_arch_regs.h instead of falling back to the default value of 5, so that uprobe_autoattach can test all 8 register arguments ($a0 - $a7) on LoongArch. 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 test_uprobe_autoattach:PASS:arg4 0 nsec test_uprobe_autoattach:PASS:arg5 0 nsec #659 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 test_uprobe_autoattach:PASS:arg6 0 nsec test_uprobe_autoattach:PASS:arg7 0 nsec test_uprobe_autoattach:PASS:arg8 0 nsec #659 uprobe_autoattach:OK Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- tools/testing/selftests/bpf/bpf_arch_regs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/bpf/bpf_arch_regs.h b/tools/testing/selftests/bpf/bpf_arch_regs.h index 4b5744f941bd..a49686323e8f 100644 --- a/tools/testing/selftests/bpf/bpf_arch_regs.h +++ b/tools/testing/selftests/bpf/bpf_arch_regs.h @@ -21,6 +21,8 @@ #define FUNC_REG_ARG_CNT 6 #elif defined(__TARGET_ARCH_riscv) || defined(__riscv__) #define FUNC_REG_ARG_CNT 8 +#elif defined(__TARGET_ARCH_loongarch) || defined(__loongarch__) +#define FUNC_REG_ARG_CNT 8 #else /* default to 5 for others */ #define FUNC_REG_ARG_CNT 5 -- 2.42.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-28 17:53 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-28 9:10 [PATCH bpf-next v2 0/2] selftests/bpf: Fix uprobe_autoattach test Tiezhu Yang 2026-11-28 9:10 ` [PATCH bpf-next v2 1/2] selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h Tiezhu Yang 2026-11-28 17:53 ` Alexei Starovoitov 2026-11-28 9:10 ` [PATCH bpf-next v2 2/2] selftests/bpf: Define FUNC_REG_ARG_CNT for LoongArch Tiezhu Yang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox