Skip to contentSkip to conversation

selftests/bpf: Enable private stack, large stack and arena tests for LoongArch

PATCH In review George Guo 3 participants 11 messages Nov 26

Subsystems (4)
lore
Share & tools
lore

George Guo

author
#0 lore raw

cover selftests/bpf: Enable private stack, large stack and arena tests for LoongArch

From: George Guo <[email protected]>

This series enables the BPF selftests for the new LoongArch JIT features, and fixes a libarena build failure with clang 19.

Patch 1 fixes the build of the libarena buddy allocator selftests with clang 19, which refuses the signed remainder in test_buddy_alloc_free().

Patches 2-5 enable the following tests for LoongArch:

- the 2 KiB private stack test in verifier_large_stack
- the struct_ops private stack tests
- the arena LDSX tests in verifier_ldsx
- the arena load-acquire and store-release tests in arena_atomics, and the libarena spmc and bitmap parallel tests

The LoongArch JIT support for these features is in the following series, which goes through the LoongArch tree:

LoongArch: BPF: Add private stack, exceptions, large stack and arena support
https://lore.kernel.org/loongarch/[email protected]/T/#u

These patches were part of v2 of the LoongArch BPF series:
https://lore.kernel.org/loongarch/[email protected]/

Since then:
- Split the selftests patches out of the LoongArch series and rebase them onto bpf-next.
- New patch 1: use an unsigned loop counter in test_buddy_alloc_free.
- New patch 2: enable the 2 KiB private stack test.
- Patch 5: also enable the libarena spmc test, which has the same guard as arena_atomics (Sashiko), and the libarena bitmap test, which needs cmpxchg on arena too.
- Drop "selftests/bpf: Add LoongArch deny list" (Tiezhu).
- Reword the subjects and commit messages.

George Guo (5):
selftests/bpf: Use unsigned loop counter in test_buddy_alloc_free selftests/bpf: Enable 2 KiB private stack test for LoongArch selftests/bpf: Enable struct_ops private stack tests for LoongArch selftests/bpf: Enable arena LDSX tests for LoongArch selftests/bpf: Enable arena atomics tests for LoongArch

 .../bpf/libarena/selftests/test_buddy.bpf.c     |  3 ++-
 .../selftests/test_parallel_bitmap.bpf.c        |  1 +
 .../libarena/selftests/test_parallel_spmc.bpf.c |  1 +
 .../bpf/prog_tests/struct_ops_private_stack.c   |  3 ++-
 .../testing/selftests/bpf/progs/arena_atomics.c |  3 +++
 .../selftests/bpf/progs/verifier_large_stack.c  |  1 +
 .../testing/selftests/bpf/progs/verifier_ldsx.c | 17 +++++++++++++++++
 7 files changed, 27 insertions(+), 2 deletions(-)

base-commit: 486b5ce7184f7449ef2fe1e951455b0b8a114060

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/5 selftests/bpf: Use unsigned loop counter in test_buddy_alloc_free

From: George Guo <[email protected]>

test_buddy_alloc_free() picks an allocation size with alloc_free_sizes[(i * 5) % 8], where i is a signed int. That is a signed remainder, which clang 19 refuses to compile for BPF without -mcpu=v4:

test_buddy.bpf.c:80:54: error: unsupported signed division, please convert to unsigned div/mod.

i only counts up from zero, so make it a u32, like the loop counter in test_buddy_alloc_multiple() and the u32 zero it starts from. The remainder becomes unsigned and the selected sizes are unchanged.

Fixes b1487dc1b181 ("selftests/bpf: Add selftests for libarena buddy allocator")
---
 .../testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c +2 -1
index 886a09019566..00f1efe931af 100644
@@ -99,7 +99,8 @@ __weak int test_buddy_alloc_free(void)
 {
 	const int iters = 800;
 	void __arena *mem;
-	int ret, i;
+	int ret;
+	u32 i;
 
 	ret = buddy_init(&buddy);
 	if (ret)
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH 2/5 selftests/bpf: Enable 2 KiB private stack test for LoongArch

In reply to George Guo

From: George Guo <[email protected]>

As the LoongArch JIT supports both private stack and large stack, enable the "private stack: two frames of 2048 bytes" test in verifier_large_stack for LoongArch.

With this patch:

  $ sudo ./test_progs -a "verifier_large_stack/private stack: two frames of 2048 bytes" | tail -1
  Summary: 1/1 PASSED, 0 SKIPPED, 0/0 FAILED
---
 tools/testing/selftests/bpf/progs/verifier_large_stack.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/progs/verifier_large_stack.c +1 -0
index cbabb41d973c..f25455d628d5 100644
@@ -248,6 +248,7 @@ __description("private stack: two frames of 2048 bytes")
 __load_if_large_stack()
 __arch_x86_64
 __arch_arm64
+__arch_loongarch
 __success __log_level(4)
 __msg("stack depth max 2048")
 __msg("subprog 0 (private_stack_two_frames) main {{.*}} stack 2048")
Signature · 1 line
2.53.0
author
#4 lore raw

PATCH 3/5 selftests/bpf: Enable struct_ops private stack tests for LoongArch

In reply to George Guo

From: George Guo <[email protected]>

As the LoongArch JIT supports private stack, enable the struct_ops private stack tests for LoongArch.

With this patch:

  $ sudo ./test_progs -t struct_ops_private_stack | tail -1
  Summary: 1/4 PASSED, 0 SKIPPED, 0/0 FAILED
---
 .../selftests/bpf/prog_tests/struct_ops_private_stack.c        | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c +2 -1
index 103179ff8733..730d5741591c 100644
@@ -7,7 +7,8 @@
 #include "struct_ops_private_stack_large.skel.h"
 
 #if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || \
-	(defined(__riscv) && __riscv_xlen == 64)
+	(defined(__riscv) && __riscv_xlen == 64) || \
+	(defined(__loongarch__) && __loongarch_grlen == 64)
 static void test_private_stack(void)
 {
 	struct struct_ops_private_stack *skel;
Signature · 1 line
2.53.0
author
#6 lore raw

PATCH 4/5 selftests/bpf: Enable arena LDSX tests for LoongArch

In reply to George Guo

From: George Guo <[email protected]>

As the LoongArch JIT supports signed arena loads, enable the arena LDSX tests in verifier_ldsx for LoongArch, and add the expected LoongArch JIT disassembly for the arena_ldsx_disasm test.

With this patch:

  $ sudo ./test_progs -t verifier_ldsx | tail -1
  Summary: 1/24 PASSED, 0 SKIPPED, 0/0 FAILED
---
 .../testing/selftests/bpf/progs/verifier_ldsx.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
tools/testing/selftests/bpf/progs/verifier_ldsx.c +17 -0
index 232082428cb9..ad7ae015b39d 100644
@@ -299,6 +299,19 @@ __jited("add	t2, a0, s7")
 __jited("lh	s4, 0x18(t2)")
 __jited("add	t2, a0, s7")
 __jited("lb	s4, 0x20(t2)")
+__arch_loongarch
+__jited("add.d	$t2, $a5, $s6")
+__jited("ld.w	$s2, $t2, 16")
+__jited("add.d	$t2, $a5, $s6")
+__jited("ld.h	$s2, $t2, 24")
+__jited("add.d	$t2, $a5, $s6")
+__jited("ld.b	$s2, $t2, 32")
+__jited("add.d	$t2, $a0, $s6")
+__jited("ld.w	$s3, $t2, 16")
+__jited("add.d	$t2, $a0, $s6")
+__jited("ld.h	$s3, $t2, 24")
+__jited("add.d	$t2, $a0, $s6")
+__jited("ld.b	$s3, $t2, 32")
 __naked void arena_ldsx_disasm(void *ctx)
 {
 	asm volatile (
@@ -331,6 +344,7 @@ __success __retval(0)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_exception(void *ctx)
 {
 	asm volatile (
@@ -353,6 +367,7 @@ __success __retval(-1)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_s8(void *ctx)
 {
 	asm volatile (
@@ -385,6 +400,7 @@ __success __retval(-1)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_s16(void *ctx)
 {
 	asm volatile (
@@ -417,6 +433,7 @@ __success __retval(-1)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_s32(void *ctx)
 {
 	asm volatile (
Signature · 1 line
2.53.0
author
#8 lore raw

PATCH 5/5 selftests/bpf: Enable arena atomics tests for LoongArch

In reply to George Guo

From: George Guo <[email protected]>

As the LoongArch JIT supports arena atomics, add LoongArch to the architecture guards of the load-acquire and store-release tests in arena_atomics, and of the spmc and bitmap parallel tests in libarena, which use atomics on arena too.

With this patch:

  $ sudo ./test_progs -t arena_atomics | tail -1
  Summary: 1/11 PASSED, 0 SKIPPED, 0/0 FAILED
  $ sudo ./test_progs -t libarena | tail -1
  Summary: 2/43 PASSED, 0 SKIPPED, 0/0 FAILED
---
 .../bpf/libarena/selftests/test_parallel_bitmap.bpf.c          | 1 +
 .../selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c  | 1 +
 tools/testing/selftests/bpf/progs/arena_atomics.c              | 3 +++
 3 files changed, 5 insertions(+)
tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c +1 -0
index 017add229bef..722971b1eba8 100644
@@ -24,6 +24,7 @@ static volatile bool test_abort;
 	(defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
 	 defined(__TARGET_ARCH_s390) || \
 	 defined(__TARGET_ARCH_powerpc) ||				  \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
 static bool bitmap_tests_enabled(void)
 {
tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c +1 -0
index 5fa96eb74095..af577e1e5050 100644
@@ -70,6 +70,7 @@ static volatile u64 round_steals;
  */
 #if defined(ENABLE_ATOMICS_TESTS) &&		  \
 	(defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
 static bool spmc_tests_enabled(void)
 {
tools/testing/selftests/bpf/progs/arena_atomics.c +3 -0
index 2a9664f54399..fcb70b984434 100644
@@ -30,6 +30,7 @@ bool skip_all_tests = true;
 	defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \
 	(defined(__TARGET_ARCH_arm64) || \
 	 defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
 	 defined(__TARGET_ARCH_s390))
 bool skip_lacq_srel_tests __attribute((__section__(".data"))) = false;
@@ -454,6 +455,7 @@ int load_acquire(const void *ctx)
 	defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \
 	(defined(__TARGET_ARCH_arm64) || \
 	 defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
 	 defined(__TARGET_ARCH_s390))
 
@@ -508,6 +510,7 @@ int store_release(const void *ctx)
 	defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \
 	(defined(__TARGET_ARCH_arm64) || \
 	 defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
 	 defined(__TARGET_ARCH_s390))
 
Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH bpf-next v1 4/5] selftests/bpf: Enable arena LDSX tests for LoongArch

In reply to George Guo
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] selftests/bpf: arena LDSX tests enabled on LoongArch without JIT support --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] selftests/bpf: arena LDSX tests enabled on LoongArch without JIT support
--

commit b68bf732b641a949e70ea34125906397162f4821
Author: George Guo <[email protected]>

selftests/bpf: Enable arena LDSX tests for LoongArch

This commit enables the arena signed-load tests in verifier_ldsx on LoongArch and adds the expected LoongArch JIT disassembly for arena_ldsx_disasm.

Quoted 49 lines
tools/testing/selftests/bpf/progs/verifier_ldsx.c +16 -0
index 232082428cb96..ad7ae015b39d9 100644
@@ -299,6 +299,19 @@ __jited("add	t2, a0, s7")
 __jited("lh	s4, 0x18(t2)")
 __jited("add	t2, a0, s7")
 __jited("lb	s4, 0x20(t2)")
+__arch_loongarch
+__jited("add.d	$t2, $a5, $s6")
+__jited("ld.w	$s2, $t2, 16")
+__jited("add.d	$t2, $a5, $s6")
+__jited("ld.h	$s2, $t2, 24")
+__jited("add.d	$t2, $a5, $s6")
+__jited("ld.b	$s2, $t2, 32")
+__jited("add.d	$t2, $a0, $s6")
+__jited("ld.w	$s3, $t2, 16")
+__jited("add.d	$t2, $a0, $s6")
+__jited("ld.h	$s3, $t2, 24")
+__jited("add.d	$t2, $a0, $s6")
+__jited("ld.b	$s3, $t2, 32")
 __naked void arena_ldsx_disasm(void *ctx)
 {
 	asm volatile (
@@ -331,6 +344,7 @@ __success __retval(0)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_exception(void *ctx)
 {
 	asm volatile (
@@ -353,6 +367,7 @@ __success __retval(-1)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_s8(void *ctx)
 {
 	asm volatile (
@@ -385,6 +400,7 @@ __success __retval(-1)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_s16(void *ctx)
 {
 	asm volatile (

tools/testing/selftests/bpf/progs/verifier_ldsx.c __success __retval(-1) · line 439

Quoted 7 lines
tools/testing/selftests/bpf/progs/verifier_ldsx.c +1 -0
@@ -417,6 +433,7 @@ __success __retval(-1)
 __arch_x86_64
 __arch_arm64
 __arch_riscv64
+__arch_loongarch
 __naked void arena_ldsx_s32(void *ctx)
 {
 	asm volatile (

[Severity: Medium]
Does enabling these five arena signed-load tests depend on a missing LoongArch JIT patch?

In convert_ctx_accesses(), BPF_MEMSX loads on PTR_TO_ARENA require bpf_jit_supports_insn(insn, true) to return true before rewriting the instruction to BPF_PROBE_MEM32SX:

kernel/bpf/fixups.c:convert_ctx_accesses() {
    ...
		case PTR_TO_ARENA:
			if (BPF_MODE(insn->code) == BPF_MEMSX) {
				if (!bpf_jit_supports_insn(insn, true)) {
					verbose(env, "sign extending loads from arena are not supported yet\n");
					return -EOPNOTSUPP;
				}
				insn->code = BPF_CLASS(insn->code) | BPF_PROBE_MEM32SX | BPF_SIZE(insn->code);
    ...
}

arch/loongarch/net/bpf_jit.c does not implement bpf_jit_supports_insn() or handle BPF_PROBE_MEM32SX in build_insn() and add_exception_handler(), so LoongArch falls back to the weak default bpf_jit_supports_insn() in kernel/bpf/core.c that returns false. As a result, the verifier rejects all five programs with -EOPNOTSUPP and verifier_ldsx fails on LoongArch instead of skipping them.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#3 lore raw

Re: [PATCH bpf-next v1 2/5] selftests/bpf: Enable 2 KiB private stack test for LoongArch

In reply to George Guo
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] selftests/bpf: private_stack_two_frames() enabled for unsupported LoongArch JIT --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] selftests/bpf: private_stack_two_frames() enabled for unsupported LoongArch JIT
--

commit 65d887cfcad54f20dce9c27e1aed6c9c9985bbb9
Author: George Guo <[email protected]>

selftests/bpf: Enable 2 KiB private stack test for LoongArch

This commit adds __arch_loongarch to the private_stack_two_frames test in verifier_large_stack.c.

tools/testing/selftests/bpf/progs/verifier_large_stack.c __description("private stack: two frames of 2048 bytes") · line 254

Quoted 12 lines
tools/testing/selftests/bpf/progs/verifier_large_stack.c +1 -0
index cbabb41d973c8..f25455d628d5c 100644
@@ -248,6 +248,7 @@ __description("private stack: two frames of 2048 bytes")
 __load_if_large_stack()
 __arch_x86_64
 __arch_arm64
+__arch_loongarch
 __success __log_level(4)
 __msg("stack depth max 2048")
 __msg("subprog 0 (private_stack_two_frames) main {{.*}} stack 2048")

[Severity: Medium]
Does this depend on LoongArch JIT patches that are not in the tree yet?

arch/loongarch/net/bpf_jit.c implements neither bpf_jit_supports_large_stack() nor bpf_jit_supports_private_stack(), so both use the weak defaults in kernel/bpf/core.c that return false. As a result, is_large_stack_supported() returns false and __load_if_large_stack() still causes run_subtest() to skip private_stack_two_frames on LoongArch, and if large stack support is later added before private stack support, bpf_enable_priv_stack() will return NO_PRIV_STACK and the verifier will reject the two 2048-byte frames.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

Re: [PATCH bpf-next v1 3/5] selftests/bpf: Enable struct_ops private stack tests for LoongArch

In reply to George Guo
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] selftests/bpf: test_private_stack() fails on LoongArch lacking JIT support --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] selftests/bpf: test_private_stack() fails on LoongArch lacking JIT support
--

commit a704d33c4d953257fca9dfdc057e22e872b058cc
Author: George Guo <[email protected]>

selftests/bpf: Enable struct_ops private stack tests for LoongArch

This commit enables the struct_ops private stack selftests on 64-bit LoongArch.

Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c +0 -0
index 103179ff8733b..730d5741591c5 100644

tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c line 14

Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/struct_ops_private_stack.c +2 -1
@@ -7,7 +7,8 @@
 #include "struct_ops_private_stack_large.skel.h"
 
 #if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || \
-	(defined(__riscv) && __riscv_xlen == 64)
+	(defined(__riscv) && __riscv_xlen == 64) || \
+	(defined(__loongarch__) && __loongarch_grlen == 64)
 static void test_private_stack(void)
 {
 	struct struct_ops_private_stack *skel;

[Severity: Medium]
Will test_private_stack() and test_private_stack_recur() fail to load with -EACCES on 64-bit LoongArch instead of skipping?

Both tests attach struct_ops programs to bpf_testmod_ops3.test_1, for which st_ops3_check_member() sets prog->aux->priv_stack_requested = true. arch/loongarch/net/bpf_jit.c does not implement private stack support or override bpf_jit_supports_private_stack(), so it falls back to the weak default returning false and check_struct_ops_btf_id() rejects the load:

kernel/bpf/verifier.c:check_struct_ops_btf_id() {
	...
	if (prog->aux->priv_stack_requested && !bpf_jit_supports_private_stack()) {
		verbose(env, "Private stack not supported by jit\n");
		return -EACCES;
	}
	...
}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw

Re: [PATCH bpf-next v1 5/5] selftests/bpf: Enable arena atomics tests for LoongArch

In reply to George Guo
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] selftests/bpf: arena atomics enabled on LoongArch without JIT support --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] selftests/bpf: arena atomics enabled on LoongArch without JIT support
--

commit 981cacb8f524da5a2f9e574371d2773a0e55c40e
Author: George Guo <[email protected]>

selftests/bpf: Enable arena atomics tests for LoongArch

This commit enables the load-acquire and store-release arena atomics selftests, as well as the libarena parallel bitmap and spmc selftests, on LoongArch.

Quoted 45 lines
tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c +1 -0
index 017add229befe..722971b1eba8f 100644
@@ -24,6 +24,7 @@ static volatile bool test_abort;
 	(defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
 	 defined(__TARGET_ARCH_s390) || \
 	 defined(__TARGET_ARCH_powerpc) ||				  \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
 static bool bitmap_tests_enabled(void)
 {
tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c +1 -0
index 5fa96eb740951..af577e1e50508 100644
@@ -70,6 +70,7 @@ static volatile u64 round_steals;
  */
 #if defined(ENABLE_ATOMICS_TESTS) &&		  \
 	(defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
 static bool spmc_tests_enabled(void)
 {
tools/testing/selftests/bpf/progs/arena_atomics.c +2 -0
index 2a9664f543993..fcb70b9844346 100644
@@ -30,6 +30,7 @@ bool skip_all_tests = true;
 	defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \
 	(defined(__TARGET_ARCH_arm64) || \
 	 defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
 	 defined(__TARGET_ARCH_s390))
 bool skip_lacq_srel_tests __attribute((__section__(".data"))) = false;
@@ -454,6 +455,7 @@ int load_acquire(const void *ctx)
 	defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \
 	(defined(__TARGET_ARCH_arm64) || \
 	 defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
 	 defined(__TARGET_ARCH_s390))
 

tools/testing/selftests/bpf/progs/arena_atomics.c int store_release(const void *ctx) · line 515

Quoted 6 lines
tools/testing/selftests/bpf/progs/arena_atomics.c +1 -0
@@ -508,6 +510,7 @@ int store_release(const void *ctx)
 	defined(__BPF_FEATURE_ADDR_SPACE_CAST) && \
 	(defined(__TARGET_ARCH_arm64) || \
 	 defined(__TARGET_ARCH_x86) || \
+	 defined(__TARGET_ARCH_loongarch) || \
 	 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
 	 defined(__TARGET_ARCH_s390))

[Severity: Medium]
Does enabling these arena atomics tests on LoongArch fail verification and program loading because the LoongArch BPF JIT does not yet support arena atomics?

For atomic instructions targeting PTR_TO_ARENA, atomic_ptr_type_ok() in kernel/bpf/verifier.c checks bpf_jit_supports_insn(insn, true):

kernel/bpf/verifier.c:atomic_ptr_type_ok() {
    ...
	if (is_arena_reg(env, regno))
		return bpf_jit_supports_insn(insn, true);
    ...
}

arch/loongarch/net/bpf_jit.c does not implement bpf_jit_supports_insn(), so LoongArch falls back to the weak default in kernel/bpf/core.c that returns false, causing the verifier to reject any BPF_ATOMIC instruction on an arena pointer with -EACCES.

In addition, do_misc_fixups() in kernel/bpf/fixups.c rewrites atomic instructions on PTR_TO_ARENA to BPF_STX | BPF_PROBE_ATOMIC | BPF_SIZE(insn->code), which build_insn() in arch/loongarch/net/bpf_jit.c does not handle.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#10 lore raw
In reply to George Guo
Quoted 2 lines · George Guo

This series enables the BPF selftests for the new LoongArch JIT features, and fixes a libarena build failure with clang 19.

loongarch folks take JIT patches, so pls don't post anything to bpf* until trees converge.

pw-bot: cr