[PATCH bpf-next v3 3/4] bpf: Align devmap values to 8 bytes
From: Tobias Philipp
Date: Thu Nov 26 2026 - 14:44:11 EST
dev_map_lookup_elem() and dev_map_hash_lookup_elem() return &obj->val
as the map value. In struct bpf_dtab_netdev, val follows
"unsigned int idx" and is at offset 52 on 64-bit and 28 on 32-bit
architectures, so it is only 4-byte aligned.
devmap is read-only for BPF programs, but the verifier assumes that map
values are 8-byte aligned and accepts a 64-bit load-acquire at offset 0
of a struct bpf_devmap_val value on 64-bit architectures. The arm64 JIT
emits LDAR for it, which raises an alignment fault on CPUs without
FEAT_LSE2. The fault is not fixed up.
Mark val as __aligned(8). On 64-bit it moves to offset 56 and the size
of struct bpf_dtab_netdev stays 64 bytes. On 32-bit the verifier
rejects 64-bit load-acquire, so the misaligned value is harmless there.
Aligning it anyway keeps all map values 8-byte aligned and grows the
struct from 36 to 40 bytes. Entries are allocated with kmalloc, which
provides at least 8-byte alignment.
This patch was written with the help of an AI coding assistant
(Claude Opus 5.5).
Fixes: 880442305a39 ("bpf: Introduce load-acquire and store-release instructions")
Signed-off-by: Tobias Philipp <tphilipp@xxxxxxxxx>
---
kernel/bpf/devmap.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 1b8f0d7f8..c92aa81e4 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -70,7 +70,8 @@ struct bpf_dtab_netdev {
struct bpf_prog *xdp_prog;
struct rcu_head rcu;
unsigned int idx;
- struct bpf_devmap_val val;
+ /* The verifier assumes that map values are 8-byte aligned */
+ struct bpf_devmap_val val __aligned(8);
};
struct bpf_dtab {
--
2.54.0 (Apple Git-157)