Re: [PATCH bpf-next v2 8/9] selftests/bpf: Add selftests for load-acquire and store-release instructions

From: Peilin Ye
Date: Fri Feb 07 2025 - 21:20:16 EST


On Sat, Feb 08, 2025 at 12:20:58AM +0000, Peilin Ye wrote:
> > --- a/tools/testing/selftests/bpf/progs/arena_atomics.c
> > +++ b/tools/testing/selftests/bpf/progs/arena_atomics.c
> > @@ -6,6 +6,8 @@
> > #include <stdbool.h>
> > #include <stdatomic.h>
> > #include "bpf_arena_common.h"
> > +#include "../../../include/linux/filter.h"
> > +#include "bpf_misc.h"
> >
> > struct {
> > __uint(type, BPF_MAP_TYPE_ARENA);
> > @@ -274,4 +276,90 @@ int uaf(const void *ctx)
> > return 0;
> > }
> >
> > +__u8 __arena_global load_acquire8_value = 0x12;
> ~~~~
>
> CI job x86_64-llvm-17 [1] failed because clang-17 crashed when compiling
> this file (arena_atomics.c):
>
> fatal error: error in backend: unable to write nop sequence of 1 bytes
>
> After some digging, I believe I am hitting a known issue that Yonghong
> described in [2].

> Changing __u8 and __u16 variables to __u32 seems to resolve/work
> around the issue

Sorry, that wasn't very accurate - we need to make sure there are no
"holes" in the .addr_space.1 ELF section, e.g.:

/* 8-byte-aligned */
__u8 __arena_global load_acquire8_value = 0x12;
/* 1-byte hole, causing clang-17 to crash */
__u16 __arena_global load_acquire16_value = 0x1234;

LLVM commit f27c4903c43b ("MC: Add .data. and .rodata. prefixes to
MCContext section classification") fixed this issue.

- - -
For now, I think I should:

1. change existing #if guards to
"#if defined(__TARGET_ARCH_arm64) && __clang_major__ >= 18"

2. additionally, guard "__arena_global" variable definitions behind
"#if __clang_major >= 18" so that clang-17 doesn't try to compile
that part (then crash)

Will fix in v3.

Thanks,
Peilin Ye