[PATCH bpf-next v1 1/2] selftests/bpf: Check alignment flag if expected result is REJECT

From: Tiezhu Yang

Date: Tue Mar 10 2026 - 02:46:51 EST


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 <yangtiezhu@xxxxxxxxxxx>
---
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 a8ae03c57bba..a1ae2f044e96 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);
--
2.42.0