Re: [PATCH bpf-next v2 1/2] selftests/bpf: Move FUNC_REG_ARG_CNT to bpf_arch_regs.h

From: Alexei Starovoitov

Date: Sat Nov 28 2026 - 12:53:16 EST


On Sat, Nov 28, 2026 at 01:10 AM Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> 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