selftests/bpf: Fix arena_spin_lock compilation on PowerPC
Subsystems (3)
Kumar Kartikeya Dwivedi
maintainerPATCH 1/1 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/[email protected]
--- .../selftests/bpf/bpf_arena_spin_lock.h | 23 ++++++++++++++++++- .../bpf/prog_tests/arena_spin_lock.c | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/bpf_arena_spin_lock.h +22 -1
@@ -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; */
tools/testing/selftests/bpf/prog_tests/arena_spin_lock.c +2 -2
@@ -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;
--
2.47.1
Kumar Kartikeya Dwivedi
maintainerQuoted 18 lines · Kumar Kartikeya Dwivedi
Venkat reported a compilation error for BPF selftests on PowerPC [0]. The crux of the error is the following message:
In file included fromprogs/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 union122 | old = atomic_read(&lock->val);This is because PowerPC overrides the qspinlock type changing the
lock->valmember's type fromatomic_tto u32.To remedy this, import the asm-generic version in the arena spin lock header, name it
__qspinlock(since it's aliased toarena_spinlock_t, the actual name hardly matters), and adjust the selftest to not depend on the type invmlinux.h.
Quoted 6 lines
[0]: https://lore.kernel.org/bpf/[email protected]
Fixes 0201027a026c ("selftests/bpf: Introduce arena spin lock")Reported-by Venkat Rao Bagalkote <[email protected]>Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>---
Venkat, please help test, as CI and I don't have access to a PowerPC machine.
Thanks!
Venkat Rao Bagalkote
Tested-byQuoted 18 lines · Kumar Kartikeya Dwivedi
Quoted 17 lines · Kumar Kartikeya Dwivedi
Venkat reported a compilation error for BPF selftests on PowerPC [0]. The crux of the error is the following message:
In file included fromprogs/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 union122 | old = atomic_read(&lock->val);This is because PowerPC overrides the qspinlock type changing the
lock->valmember's type fromatomic_tto u32.To remedy this, import the asm-generic version in the arena spin lock header, name it
__qspinlock(since it's aliased toarena_spinlock_t, the actual name hardly matters), and adjust the selftest to not depend on the type invmlinux.h.
Quoted 6 lines
Quoted 6 lines
[0]: https://lore.kernel.org/bpf/[email protected]Fixes 0201027a026c ("selftests/bpf: Introduce arena spin lock")Reported-by Venkat Rao Bagalkote <[email protected]>Signed-off-by Kumar Kartikeya Dwivedi <[email protected]>---
Built the kernel by applying this patch on bpf-next. And selftests/bpf compiles successfully.
Please add below tag.
Quoted 3 lines
Venkat, please help test, as CI and I don't have access to a PowerPC machine.
Thanks!
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 10 lines · On Tue, 11 Mar 2025 08:42:44 -0700 you wrote:
Venkat reported a compilation error for BPF selftests on PowerPC [0]. The crux of the error is the following message:
In file included fromprogs/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 union122 | old = atomic_read(&lock->val);[...]
Here is the summary with links:
- [bpf-next,v1] selftests/bpf: Fix arena_spin_lock compilation on PowerPC
https://git.kernel.org/bpf/bpf-next/c/46d38f489ef0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html