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

From: Emil Tsalapatis

Date: Wed Mar 11 2026 - 11:57:32 EST


On Tue Mar 10, 2026 at 2:45 AM EDT, Tiezhu Yang wrote:
> 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

This doesn't look like it's breaking anything, but it will cause all
tests with F_NEEDS_EFFICIENT_UNALIGNED ACCESS to be reported as failing
due to unaligned accesses even if they actually failed due to expected
errors at load time.

Which test programs is this fix targeted towards? Can't we just skip
those tests for riscv/loongarch instead of adding this workaround?

> 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);