BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/3] selftests/bpf: Enable instructions array, indirect calls tests for LoongArch
@ 2026-11-23  4:50 Tiezhu Yang
  2026-11-23  4:50 ` [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test " Tiezhu Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tiezhu Yang @ 2026-11-23  4:50 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: bpf, loongarch, linux-kernel

Tested on the following unmerged JIT patches:

LoongArch: BPF: Support instructions array, indirect jumps and calls
https://lore.kernel.org/loongarch/20261123043907.20225-1-yangtiezhu@loongson.cn/T/#u

here are the test results:

$ sudo ./test_progs -t bpf_insn_array | tail -1
Summary: 1/20 PASSED, 0 SKIPPED, 0/0 FAILED

$ sudo ./test_progs-cpuv4 -t gotox | tail -1
Summary: 2/14 PASSED, 0 SKIPPED, 0/0 FAILED

$ sudo ./test_progs -t callx | tail -1
Summary: 6/89 PASSED, 6 SKIPPED, 0/0 FAILED

Tiezhu Yang (3):
  selftests/bpf: Enable instruction array test for LoongArch
  selftests/bpf: Allow unaligned access in callx_rodata_misaligned_read
  selftests/bpf: Enable callx related testcases for LoongArch

 tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c     | 2 +-
 tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c | 2 +-
 tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c | 2 +-
 tools/testing/selftests/bpf/progs/bpf_misc.h                | 3 ++-
 tools/testing/selftests/bpf/progs/verifier_callx_rodata.c   | 1 +
 5 files changed, 6 insertions(+), 4 deletions(-)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test for LoongArch
  2026-11-23  4:50 [PATCH bpf-next v1 0/3] selftests/bpf: Enable instructions array, indirect calls tests for LoongArch Tiezhu Yang
@ 2026-11-23  4:50 ` Tiezhu Yang
  2026-11-23  5:02   ` sashiko-bot
  2026-11-23  4:50 ` [PATCH bpf-next v1 2/3] selftests/bpf: Allow unaligned access in callx_rodata_misaligned_read Tiezhu Yang
  2026-11-23  4:50 ` [PATCH bpf-next v1 3/3] selftests/bpf: Enable callx related testcases for LoongArch Tiezhu Yang
  2 siblings, 1 reply; 8+ messages in thread
From: Tiezhu Yang @ 2026-11-23  4:50 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: bpf, loongarch, linux-kernel

As the LoongArch JIT supports instruction array (gotox jump tables),
enable the corresponding BPF selftest for LoongArch.

With this patch:
  $ sudo ./test_progs -t bpf_insn_array | tail -1
  Summary: 1/20 PASSED, 0 SKIPPED, 0/0 FAILED

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
index 4ffe4fe6b78e..6b1a426aa4cd 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
@@ -5,7 +5,7 @@
 #include <test_progs.h>
 
 #if defined(__x86_64__) || defined(__powerpc__) || defined(__aarch64__) || \
-	(defined(__riscv) && __riscv_xlen == 64)
+	(defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch__)
 static int map_create(__u32 map_type, __u32 max_entries)
 {
 	const char *map_name = "insn_array";
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH bpf-next v1 2/3] selftests/bpf: Allow unaligned access in callx_rodata_misaligned_read
  2026-11-23  4:50 [PATCH bpf-next v1 0/3] selftests/bpf: Enable instructions array, indirect calls tests for LoongArch Tiezhu Yang
  2026-11-23  4:50 ` [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test " Tiezhu Yang
@ 2026-11-23  4:50 ` Tiezhu Yang
  2026-11-23  4:50 ` [PATCH bpf-next v1 3/3] selftests/bpf: Enable callx related testcases for LoongArch Tiezhu Yang
  2 siblings, 0 replies; 8+ messages in thread
From: Tiezhu Yang @ 2026-11-23  4:50 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: bpf, loongarch, linux-kernel

On architectures that may lack CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
(such as RISC-V and LoongArch), the verifier rejects unaligned 8-byte
loads at offset +4 in callx_rodata_misaligned_read with a "misaligned
value access" error before reaching the intended function pointer
overlap check.

As this test focuses on verifying function pointer overlap rejection
rather than alignment enforcement, add `__flag(BPF_F_ANY_ALIGNMENT)`
to the test case to bypass strict alignment checks on architectures
lacking efficient unaligned access.

Before:
  $ sudo ./test_progs -t verifier_callx_rodata/callx_rodata_misaligned_read
  ...
  5: (79) r0 = *(u64 *)(r6 +4)
  misaligned value access off 352+4 size 8
  ...
  Summary: 0/0 PASSED, 0 SKIPPED, 1/1 FAILED

After:
  $ sudo ./test_progs -t verifier_callx_rodata/callx_rodata_misaligned_read
  ...
  Summary: 1/1 PASSED, 0 SKIPPED, 0/0 FAILED

Fixes: b018e998e645 ("selftests/bpf: Add tests for callx through pointers in read-only data")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/testing/selftests/bpf/progs/verifier_callx_rodata.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
index 0389df720db2..8034e736d03a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
@@ -770,6 +770,7 @@ __naked void callx_rodata_partial_read(void)
 }
 
 SEC("socket")
+__flag(BPF_F_ANY_ALIGNMENT)
 __failure __msg("read of 8 bytes at offset")
 __msg("overlaps with a pointer to a function")
 __naked void callx_rodata_misaligned_read(void)
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH bpf-next v1 3/3] selftests/bpf: Enable callx related testcases for LoongArch
  2026-11-23  4:50 [PATCH bpf-next v1 0/3] selftests/bpf: Enable instructions array, indirect calls tests for LoongArch Tiezhu Yang
  2026-11-23  4:50 ` [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test " Tiezhu Yang
  2026-11-23  4:50 ` [PATCH bpf-next v1 2/3] selftests/bpf: Allow unaligned access in callx_rodata_misaligned_read Tiezhu Yang
@ 2026-11-23  4:50 ` Tiezhu Yang
  2026-11-23  4:59   ` sashiko-bot
  2 siblings, 1 reply; 8+ messages in thread
From: Tiezhu Yang @ 2026-11-23  4:50 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: bpf, loongarch, linux-kernel

As the LoongArch JIT supports indirect calls to subprogs, enable the
corresponding callx BPF selftests for LoongArch.

With this patch:
  $ sudo ./test_progs -t callx | tail -1
  Summary: 6/89 PASSED, 6 SKIPPED, 0/0 FAILED

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c | 2 +-
 tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c | 2 +-
 tools/testing/selftests/bpf/progs/bpf_misc.h                | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
index cc63b84e4d94..c052fa7624e8 100644
--- a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
+++ b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
@@ -9,7 +9,7 @@
 #include <bpf/btf.h>
 
 #if defined(__x86_64__) || defined(__aarch64__) || \
-    (defined(__riscv) && __riscv_xlen == 64)
+    (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch__)
 
 #define CALLEE_INSN	6
 #define DATA		0x1234
diff --git a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
index acd821fb568f..f89bfe3e429d 100644
--- a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
+++ b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
@@ -4,7 +4,7 @@
 #include "callx_rodata.lskel.h"
 
 #if defined(__x86_64__) || defined(__aarch64__) || \
-    (defined(__riscv) && __riscv_xlen == 64)
+    (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch__)
 
 static void run(int prog_fd, int expected, const char *name)
 {
diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
index 6b930cb48f8d..523e54383d7e 100644
--- a/tools/testing/selftests/bpf/progs/bpf_misc.h
+++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
@@ -306,7 +306,8 @@
 
 /* clang always emits callx, gcc only when it defines __BPF_FEATURE_CALLX */
 #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) ||	\
-     (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) &&		\
+     (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) ||		\
+     defined(__TARGET_ARCH_loongarch)) &&				\
 	(defined(__clang__) || defined(__BPF_FEATURE_CALLX))
 #define CAN_USE_CALLX
 #endif
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH bpf-next v1 3/3] selftests/bpf: Enable callx related testcases for LoongArch
  2026-11-23  4:50 ` [PATCH bpf-next v1 3/3] selftests/bpf: Enable callx related testcases for LoongArch Tiezhu Yang
@ 2026-11-23  4:59   ` sashiko-bot
  2026-11-23  5:13     ` Tiezhu Yang
  0 siblings, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-11-23  4:59 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/bpf: callx tests fail on LoongArch due to missing
  JIT callx support
--

commit 89364474c6ac0435e5e06b0462fca0c350392e2f
Author: Tiezhu Yang <yangtiezhu@loongson.cn>

selftests/bpf: Enable callx related testcases for LoongArch

This commit enables the callx BPF selftests and defines CAN_USE_CALLX for
LoongArch.

> diff --git a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
> index cc63b84e4d942..c052fa7624e8d 100644
> --- a/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
> +++ b/tools/testing/selftests/bpf/prog_tests/callx_func_ptr_map.c
> @@ -9,7 +9,7 @@
>  #include <bpf/btf.h>
>  
>  #if defined(__x86_64__) || defined(__aarch64__) || \
> -    (defined(__riscv) && __riscv_xlen == 64)
> +    (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch__)
>  
>  #define CALLEE_INSN	6
>  #define DATA		0x1234
> diff --git a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
> index acd821fb568f5..f89bfe3e429d1 100644
> --- a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
> +++ b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
> @@ -4,7 +4,7 @@
>  #include "callx_rodata.lskel.h"
>  
>  #if defined(__x86_64__) || defined(__aarch64__) || \
> -    (defined(__riscv) && __riscv_xlen == 64)
> +    (defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch__)
>  
>  static void run(int prog_fd, int expected, const char *name)
>  {
> diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
> index 6b930cb48f8d2..523e54383d7e2 100644
> --- a/tools/testing/selftests/bpf/progs/bpf_misc.h
> +++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
> @@ -306,7 +306,8 @@
>  
>  /* clang always emits callx, gcc only when it defines __BPF_FEATURE_CALLX */
>  #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) ||	\
> -     (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64)) &&		\
> +     (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) ||		\
> +     defined(__TARGET_ARCH_loongarch)) &&				\
>  	(defined(__clang__) || defined(__BPF_FEATURE_CALLX))
>  #define CAN_USE_CALLX
>  #endif

[Severity: Medium]
Will these callx selftests fail on LoongArch because the LoongArch BPF JIT
does not yet implement indirect subprog calls?

In this tree, arch/loongarch/net/bpf_jit.c does not override the default
weak bpf_jit_supports_callx() (which returns false) or handle
BPF_JMP | BPF_CALL | BPF_X in build_insn().  As a result,
require_callx_jit() rejects these programs with -EOPNOTSUPP instead of
letting the test suite skip them.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123045008.23691-1-yangtiezhu@loongson.cn?part=3

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test for LoongArch
  2026-11-23  4:50 ` [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test " Tiezhu Yang
@ 2026-11-23  5:02   ` sashiko-bot
  2026-11-23  5:21     ` Tiezhu Yang
  0 siblings, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-11-23  5:02 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: bpf

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

commit a34406fe396aca3cf00c1518cc4013c6dae7154b
Author: Tiezhu Yang <yangtiezhu@loongson.cn>

selftests/bpf: Enable instruction array test for LoongArch

This commit enables the bpf_insn_array selftest suite on LoongArch by
adding defined(__loongarch__) to the architecture guard.

> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
> index 4ffe4fe6b78e9..6b1a426aa4cd5 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_insn_array.c
> @@ -5,7 +5,7 @@
>  #include <test_progs.h>
>  
>  #if defined(__x86_64__) || defined(__powerpc__) || defined(__aarch64__) || \
> -	(defined(__riscv) && __riscv_xlen == 64)
> +	(defined(__riscv) && __riscv_xlen == 64) || defined(__loongarch__)
>  static int map_create(__u32 map_type, __u32 max_entries)
>  {
>  	const char *map_name = "insn_array";

[Severity: Medium]
Does enabling bpf_insn_array on LoongArch depend on a prerequisite JIT
patch that is not in the tree yet?

In arch/loongarch/net/bpf_jit.c, bpf_int_jit_compile() does not call
bpf_prog_update_insn_ptrs(), so insn_array->ips[] stays zeroed and
bpf_insn_array_ready() rejects program loading with -EFAULT.  In addition,
build_insn() only handles BPF_JMP | BPF_JA and BPF_JMP32 | BPF_JA, without
BPF_JMP | BPF_JA | BPF_X (gotox), so the gotox subtests fail to JIT with
-EINVAL (-ENOTSUPP).

Also, HAVE_EBPF_JIT on LoongArch is only selected for 64BIT, while
defined(__loongarch__) matches 32-bit builds as well.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123045008.23691-1-yangtiezhu@loongson.cn?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH bpf-next v1 3/3] selftests/bpf: Enable callx related testcases for LoongArch
  2026-11-23  4:59   ` sashiko-bot
@ 2026-11-23  5:13     ` Tiezhu Yang
  0 siblings, 0 replies; 8+ messages in thread
From: Tiezhu Yang @ 2026-11-23  5:13 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: bpf

On 11/23/26 12:59 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] selftests/bpf: callx tests fail on LoongArch due to missing
>    JIT callx support

...

> [Severity: Medium]
> Will these callx selftests fail on LoongArch because the LoongArch BPF JIT
> does not yet implement indirect subprog calls?
> 
> In this tree, arch/loongarch/net/bpf_jit.c does not override the default
> weak bpf_jit_supports_callx() (which returns false) or handle
> BPF_JMP | BPF_CALL | BPF_X in build_insn().  As a result,
> require_callx_jit() rejects these programs with -EOPNOTSUPP instead of
> letting the test suite skip them.

This series depends on the LoongArch JIT support series:

LoongArch: BPF: Support instructions array, indirect jumps and calls
https://lore.kernel.org/loongarch/20261123043907.20225-1-yangtiezhu@loongson.cn/T/#u

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test for LoongArch
  2026-11-23  5:02   ` sashiko-bot
@ 2026-11-23  5:21     ` Tiezhu Yang
  0 siblings, 0 replies; 8+ messages in thread
From: Tiezhu Yang @ 2026-11-23  5:21 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: bpf

On 11/23/26 1:02 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:

...

> [Severity: Medium]
> Does enabling bpf_insn_array on LoongArch depend on a prerequisite JIT
> patch that is not in the tree yet?
> 
> In arch/loongarch/net/bpf_jit.c, bpf_int_jit_compile() does not call
> bpf_prog_update_insn_ptrs(), so insn_array->ips[] stays zeroed and
> bpf_insn_array_ready() rejects program loading with -EFAULT.  In addition,
> build_insn() only handles BPF_JMP | BPF_JA and BPF_JMP32 | BPF_JA, without
> BPF_JMP | BPF_JA | BPF_X (gotox), so the gotox subtests fail to JIT with
> -EINVAL (-ENOTSUPP).

This series depends on the unmerged LoongArch JIT support series:

LoongArch: BPF: Support instructions array, indirect jumps and calls
https://lore.kernel.org/loongarch/20261123043907.20225-1-yangtiezhu@loongson.cn/T/#u

> Also, HAVE_EBPF_JIT on LoongArch is only selected for 64BIT, while
> defined(__loongarch__) matches 32-bit builds as well.

I will update the guard to
(defined(__loongarch__) && __loongarch_grlen == 64)
in v2 (along with patch 3/3) to match 64-bit LoongArch specifically,
similar to RISC-V.

Thanks,
Tiezhu


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-23  5:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  4:50 [PATCH bpf-next v1 0/3] selftests/bpf: Enable instructions array, indirect calls tests for LoongArch Tiezhu Yang
2026-11-23  4:50 ` [PATCH bpf-next v1 1/3] selftests/bpf: Enable instruction array test " Tiezhu Yang
2026-11-23  5:02   ` sashiko-bot
2026-11-23  5:21     ` Tiezhu Yang
2026-11-23  4:50 ` [PATCH bpf-next v1 2/3] selftests/bpf: Allow unaligned access in callx_rodata_misaligned_read Tiezhu Yang
2026-11-23  4:50 ` [PATCH bpf-next v1 3/3] selftests/bpf: Enable callx related testcases for LoongArch Tiezhu Yang
2026-11-23  4:59   ` sashiko-bot
2026-11-23  5:13     ` Tiezhu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox