* [PATCH RFC bpf-next 1/3] selftests/bpf: Add __arch_loongarch macro to limit test cases
2026-04-28 8:00 [PATCH RFC bpf-next 0/3] selftests/bpf: Test inline helpers for LoongArch Tiezhu Yang
@ 2026-04-28 8:00 ` Tiezhu Yang
2026-04-28 8:00 ` [PATCH RFC bpf-next 2/3] selftests/bpf: Test inline_bpf_get_current_task() for LoongArch Tiezhu Yang
2026-04-28 8:00 ` [PATCH RFC bpf-next 3/3] selftests/bpf: Test jited inline of bpf_get_smp_processor_id() Tiezhu Yang
2 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2026-04-28 8:00 UTC (permalink / raw)
To: loongarch, bpf, linux-kernel
Make it possible to limit certain tests to loongarch, just like it is
already done for x86_64, arm64, riscv64, and s390x.
This is a follow up patch of:
commit ee7fe84468b1 ("selftests/bpf: __arch_* macro to limit test cases to specific archs")
commit 1e4e6b9e260d ("selftests/bpf: Add __arch_s390x macro")
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
tools/testing/selftests/bpf/progs/bpf_misc.h | 1 +
tools/testing/selftests/bpf/test_loader.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
index dcd78a3a9052..a8b14be3aa60 100644
--- a/tools/testing/selftests/bpf/progs/bpf_misc.h
+++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
@@ -157,6 +157,7 @@
#define __arch_arm64 __arch("ARM64")
#define __arch_riscv64 __arch("RISCV64")
#define __arch_s390x __arch("s390x")
+#define __arch_loongarch __arch("LOONGARCH")
#define __caps_unpriv(caps) __test_tag("test_caps_unpriv=" EXPAND_QUOTE(caps))
#define __load_if_JITed() __test_tag("load_mode=jited")
#define __load_if_no_JITed() __test_tag("load_mode=no_jited")
diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
index ee637809a1d4..90910fc44f6b 100644
--- a/tools/testing/selftests/bpf/test_loader.c
+++ b/tools/testing/selftests/bpf/test_loader.c
@@ -376,6 +376,7 @@ enum arch {
ARCH_ARM64 = 0x4,
ARCH_RISCV64 = 0x8,
ARCH_S390X = 0x10,
+ ARCH_LOONGARCH = 0x20,
};
static int get_current_arch(void)
@@ -388,6 +389,8 @@ static int get_current_arch(void)
return ARCH_RISCV64;
#elif defined(__s390x__)
return ARCH_S390X;
+#elif defined(__loongarch__)
+ return ARCH_LOONGARCH;
#endif
return ARCH_UNKNOWN;
}
@@ -579,6 +582,8 @@ static int parse_test_spec(struct test_loader *tester,
arch = ARCH_RISCV64;
} else if (strcmp(val, "s390x") == 0) {
arch = ARCH_S390X;
+ } else if (strcmp(val, "LOONGARCH") == 0) {
+ arch = ARCH_LOONGARCH;
} else {
PRINT_FAIL("bad arch spec: '%s'\n", val);
err = -EINVAL;
--
2.42.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RFC bpf-next 2/3] selftests/bpf: Test inline_bpf_get_current_task() for LoongArch
2026-04-28 8:00 [PATCH RFC bpf-next 0/3] selftests/bpf: Test inline helpers for LoongArch Tiezhu Yang
2026-04-28 8:00 ` [PATCH RFC bpf-next 1/3] selftests/bpf: Add __arch_loongarch macro to limit test cases Tiezhu Yang
@ 2026-04-28 8:00 ` Tiezhu Yang
2026-04-28 20:46 ` sashiko-bot
2026-04-28 8:00 ` [PATCH RFC bpf-next 3/3] selftests/bpf: Test jited inline of bpf_get_smp_processor_id() Tiezhu Yang
2 siblings, 1 reply; 6+ messages in thread
From: Tiezhu Yang @ 2026-04-28 8:00 UTC (permalink / raw)
To: loongarch, bpf, linux-kernel
Add the JITed inline instruction of bpf_get_current_task() for LoongArch
to pass the test case.
Before:
$ sudo ./test_progs -t verifier_jit_inline
#570/1 verifier_jit_inline/inline_bpf_get_current_task:SKIP
#570 verifier_jit_inline:SKIP
Summary: 1/0 PASSED, 1 SKIPPED, 0 FAILED
After:
$ sudo ./test_progs -t verifier_jit_inline
#570/1 verifier_jit_inline/inline_bpf_get_current_task:OK
#570 verifier_jit_inline:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
Note that this test will pass only after the JIT inline support for
bpf_get_current_task is merged. While the JIT inlining is still in
the pipeline, adding the changes now will not introduce any build
regressions. It serves to define the expected JIT output for future
validation.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
tools/testing/selftests/bpf/progs/verifier_jit_inline.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
index 4ea254063646..913a1699e42b 100644
--- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
+++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
@@ -10,6 +10,8 @@ __arch_x86_64
__jited(" addq %gs:{{.*}}, %rax")
__arch_arm64
__jited(" mrs x7, SP_EL0")
+__arch_loongarch
+__jited(" move $a5, $tp")
int inline_bpf_get_current_task(void)
{
bpf_get_current_task();
--
2.42.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH RFC bpf-next 2/3] selftests/bpf: Test inline_bpf_get_current_task() for LoongArch
2026-04-28 8:00 ` [PATCH RFC bpf-next 2/3] selftests/bpf: Test inline_bpf_get_current_task() for LoongArch Tiezhu Yang
@ 2026-04-28 20:46 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-04-28 20:46 UTC (permalink / raw)
To: Tiezhu Yang; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The expected BPF JIT inline instruction for `bpf_get_current_task()` on LoongArch incorrectly expects a pointer to `struct thread_info` instead of `struct task_struct`.
- [Medium] Adding test expectations for an unmerged kernel feature will cause the test suite to fail on LoongArch, breaking CI.
--
commit e03cdf4a4a90c2aa3d904cdf264ea432cfe489b9
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
selftests/bpf: Test inline_bpf_get_current_task() for LoongArch
This commit adds the expected JIT inline instruction for bpf_get_current_task()
on LoongArch to the verifier_jit_inline selftest. It defines the expected JIT
output ahead of the actual JIT implementation being merged.
> Note that this test will pass only after the JIT inline support for
> bpf_get_current_task is merged. While the JIT inlining is still in
> the pipeline, adding the changes now will not introduce any build
> regressions.
Will this cause the selftest suite to fail on LoongArch in the meantime?
Since the JIT implementation is not yet merged, the test framework will likely
fall back to emitting a standard helper call instead of the expected inline
instruction. Adding test expectations for unmerged features often results in
test suite regressions until the corresponding feature lands.
> diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
> index 4ea254063646..913a1699e42b 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
> @@ -10,6 +10,8 @@ __arch_x86_64
> __jited(" addq %gs:{{.*}}, %rax")
> __arch_arm64
> __jited(" mrs x7, SP_EL0")
> +__arch_loongarch
> +__jited(" move $a5, $tp")
Does this instruction return a pointer to struct thread_info instead of
struct task_struct?
On LoongArch, it appears the kernel stack holds struct thread_info, and the
$tp register points directly to it rather than to struct task_struct. The task
pointer is the first member of struct thread_info at offset 0.
By using a move instruction, the BPF program would receive the thread_info
pointer. When the program later attempts to access fields like task->pid, it
will read out-of-bounds stack memory relative to the thread_info base.
Should this be a memory load like ld.d $a5, $tp, 0 to dereference the task
pointer instead?
> int inline_bpf_get_current_task(void)
> {
> bpf_get_current_task();
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260428080051.20938-1-yangtiezhu@loongson.cn?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH RFC bpf-next 3/3] selftests/bpf: Test jited inline of bpf_get_smp_processor_id()
2026-04-28 8:00 [PATCH RFC bpf-next 0/3] selftests/bpf: Test inline helpers for LoongArch Tiezhu Yang
2026-04-28 8:00 ` [PATCH RFC bpf-next 1/3] selftests/bpf: Add __arch_loongarch macro to limit test cases Tiezhu Yang
2026-04-28 8:00 ` [PATCH RFC bpf-next 2/3] selftests/bpf: Test inline_bpf_get_current_task() for LoongArch Tiezhu Yang
@ 2026-04-28 8:00 ` Tiezhu Yang
2026-04-28 22:04 ` sashiko-bot
2 siblings, 1 reply; 6+ messages in thread
From: Tiezhu Yang @ 2026-04-28 8:00 UTC (permalink / raw)
To: loongarch, bpf, linux-kernel
Add the testcase for the jited inline of bpf_get_smp_processor_id(),
only for LoongArch currently.
Here is the test result on LoongArch:
$ sudo ./test_progs -t verifier_jit_inline
#570/1 verifier_jit_inline/inline_bpf_get_current_task:OK
#570/2 verifier_jit_inline/inline_bpf_get_smp_processor_id:OK
#570 verifier_jit_inline:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
Note that this test will pass only after the JIT inline support for
bpf_get_smp_processor_id is merged. While the JIT inlining is still
in the pipeline, adding the changes now will not introduce any build
regressions. It serves to define the expected JIT output for future
validation.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
.../testing/selftests/bpf/progs/verifier_jit_inline.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
index 913a1699e42b..e4d683c8cb06 100644
--- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
+++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
@@ -19,4 +19,15 @@ int inline_bpf_get_current_task(void)
return 0;
}
+SEC("fentry/bpf_fentry_test2")
+__success __retval(0)
+__arch_loongarch
+__jited(" ld.w $a5, $tp, 8")
+int inline_bpf_get_smp_processor_id(void)
+{
+ bpf_get_smp_processor_id();
+
+ return 0;
+}
+
char _license[] SEC("license") = "GPL";
--
2.42.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH RFC bpf-next 3/3] selftests/bpf: Test jited inline of bpf_get_smp_processor_id()
2026-04-28 8:00 ` [PATCH RFC bpf-next 3/3] selftests/bpf: Test jited inline of bpf_get_smp_processor_id() Tiezhu Yang
@ 2026-04-28 22:04 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-04-28 22:04 UTC (permalink / raw)
To: Tiezhu Yang; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The expected JIT assembly uses an incorrect struct offset (8 instead of 24), which dictates a memory-corrupting JIT implementation.
- [Medium] Adding a known-failing test breaks BPF CI and git bisection.
--
commit c320ef8cc6d3d14ed32f2590ea486674717257d9
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
selftests/bpf: Test jited inline of bpf_get_smp_processor_id()
Add the testcase for the jited inline of bpf_get_smp_processor_id(),
only for LoongArch currently.
> Note that this test will pass only after the JIT inline support for
> bpf_get_smp_processor_id is merged. While the JIT inlining is still
> in the pipeline, adding the changes now will not introduce any build
> regressions. It serves to define the expected JIT output for future
> validation.
Is it expected that this breaks BPF CI and git bisection?
Introducing a test for a feature that is not yet implemented causes the
test_progs suite to fail on LoongArch, because the BPF test framework's
__jited tag will fail the test when it does not find the expected JIT
instructions.
Tests for new features are typically submitted and merged in the same patch
series as the feature itself to ensure the tree remains fully testable at
every commit.
> diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
> index 913a1699e42b..e4d683c8cb06 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c
> @@ -19,4 +19,15 @@ int inline_bpf_get_current_task(void)
> return 0;
> }
>
> +SEC("fentry/bpf_fentry_test2")
> +__success __retval(0)
> +__arch_loongarch
> +__jited(" ld.w $a5, $tp, 8")
Does this expect an incorrect struct offset?
On LoongArch, $tp holds __current_thread_info (a pointer to struct
thread_info). In the kernel, struct thread_info places the cpu field at
offset 24. Reading from offset 8 will erroneously load the flags field
instead of the cpu ID.
If the BPF JIT implementation matches this test, returning flags instead of
the CPU ID could cause out-of-bounds memory accesses and kernel memory
corruption when bpf_get_smp_processor_id() is used to index per-CPU maps.
> +int inline_bpf_get_smp_processor_id(void)
> +{
> + bpf_get_smp_processor_id();
> +
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260428080051.20938-1-yangtiezhu@loongson.cn?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread