diff options
author | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2025-03-11 08:42:44 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2025-03-15 11:48:59 -0700 |
commit | 1f375aef6cc0ae03ea714bff58ba7be1ca95997c (patch) | |
tree | 5bb1d1839e9873ec55d17db82d55021f1a529b42 | |
parent | 38c6104e0bc7c8af20ab4897cb0504e3339e4fe4 (diff) |
selftests/bpf: Fix arena_spin_lock compilation on PowerPC
Venkat reported a compilation error for BPF selftests on PowerPC [0].
The crux of the error is the following message:
In file included from progs/arena_spin_lock.c:7:
/root/bpf-next/tools/testing/selftests/bpf/bpf_arena_spin_lock.h:122:8:
error: member reference base type '__attribute__((address_space(1)))
u32' (aka '__attribute__((address_space(1))) unsigned int') is not a
structure or union
122 | old = atomic_read(&lock->val);
This is because PowerPC overrides the qspinlock type changing the
lock->val member's type from atomic_t to u32.
To remedy this, import the asm-generic version in the arena spin lock
header, name it __qspinlock (since it's aliased to arena_spinlock_t, the
actual name hardly matters), and adjust the selftest to not depend on
the type in vmlinux.h.
[0]: https://lore.kernel.org/bpf/7bc80a3b-d708-4735-aa3b-6a8c21720f9d@linux.ibm.com
Fixes: 88d706ba7cc5 ("selftests/bpf: Introduce arena spin lock")
Reported-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Link: https://lore.kernel.org/bpf/20250311154244.3775505-1-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/testing/selftests/bpf/bpf_arena_spin_lock.h | 23 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/arena_spin_lock.c | 4 |
2 files changed, 24 insertions, 3 deletions
diff --git a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h index 3aca389ce424..fb8dc0768999 100644 --- a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h +++ b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h @@ -22,7 +22,28 @@ extern unsigned long CONFIG_NR_CPUS __kconfig; -#define arena_spinlock_t struct qspinlock +/* + * Typically, we'd just rely on the definition in vmlinux.h for qspinlock, but + * PowerPC overrides the definition to define lock->val as u32 instead of + * atomic_t, leading to compilation errors. Import a local definition below so + * that we don't depend on the vmlinux.h version. + */ + +struct __qspinlock { + union { + atomic_t val; + struct { + u8 locked; + u8 pending; + }; + struct { + u16 locked_pending; + u16 tail; + }; + }; +}; + +#define arena_spinlock_t struct __qspinlock /* FIXME: Using typedef causes CO-RE relocation error */ /* typedef struct qspinlock arena_spinlock_t; */ diff --git a/tools/testing/selftests/bpf/prog_tests/arena_spin_lock.c b/tools/testing/selftests/bpf/prog_tests/arena_spin_lock.c index bc3616ba891c..7565fc7690c2 100644 --- a/tools/testing/selftests/bpf/prog_tests/arena_spin_lock.c +++ b/tools/testing/selftests/bpf/prog_tests/arena_spin_lock.c @@ -4,8 +4,8 @@ #include <network_helpers.h> #include <sys/sysinfo.h> -struct qspinlock { int val; }; -typedef struct qspinlock arena_spinlock_t; +struct __qspinlock { int val; }; +typedef struct __qspinlock arena_spinlock_t; struct arena_qnode { unsigned long next; |