From 5a3f6254c2f3be94bbc99036402f48103ec69785 Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Tue, 10 Mar 2026 14:45:06 +0800 Subject: [PATCH 1/2] selftests/bpf: Check alignment flag if expected result is REJECT CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set unconditionally for the most archs such as x86_64, aarch64, ppc64el and s390x, but this config may be not set by users for riscv64 and loongarch64. If CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is not set, the BPF verifier detects if a program has unaligned access and then rejects them. So it should also check the flag F_NEEDS_EFFICIENT_UNALIGNED_ACCESS if the expected result is REJECT and set alignment_prevented_execution as 1, then the message "(NOTE: not executed due to unknown alignment)" can be printed for some testcases of test_verifier to reflect the reality. Signed-off-by: Tiezhu Yang --- tools/testing/selftests/bpf/test_verifier.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index a8ae03c57bbae..a1ae2f044e96a 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -1640,6 +1640,11 @@ static void do_test_single(struct bpf_test *test, bool unpriv, printf("FAIL\nUnexpected success to load!\n"); goto fail_log; } +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS + if (fd_prog < 0 && + (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS)) + alignment_prevented_execution = 1; +#endif if (!expected_err || !cmp_str_seq(bpf_vlog, expected_err)) { printf("FAIL\nUnexpected error message!\n\tEXP: %s\n\tRES: %s\n", expected_err, bpf_vlog); From 509e17fc3f89bae4ae715535a589733cb19e32c1 Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Tue, 10 Mar 2026 14:45:07 +0800 Subject: [PATCH 2/2] selftests/bpf: Add alignment flag for test_verifier 190 testcase There exists failure when executing the testcase "./test_verifier 190" if CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is not set on LoongArch. #190/p calls: two calls that return map_value with incorrect bool check FAIL ... misaligned access off (0x0; 0xffffffffffffffff)+0 size 8 ... Summary: 0 PASSED, 0 SKIPPED, 1 FAILED It means that the program has unaligned accesses, but the kernel sets CONFIG_ARCH_STRICT_ALIGN by default to enable -mstrict-align to prevent unaligned accesses, so add a flag F_NEEDS_EFFICIENT_UNALIGNED_ACCESS into the testcase to avoid the failure. This is somehow similar with the commit ce1f289f541e ("selftests/bpf: Add F_NEEDS_EFFICIENT_UNALIGNED_ACCESS to some tests"). Signed-off-by: Tiezhu Yang --- tools/testing/selftests/bpf/verifier/calls.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c index 86887130a0efb..29e57f0e56c3a 100644 --- a/tools/testing/selftests/bpf/verifier/calls.c +++ b/tools/testing/selftests/bpf/verifier/calls.c @@ -1521,6 +1521,7 @@ .errstr = "R0 invalid mem access 'scalar'", .result_unpriv = REJECT, .errstr_unpriv = "invalid read from stack R7 off=-16 size=8", + .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS, }, { "calls: two calls that receive map_value via arg=ptr_stack_of_caller. test1",