From: Tobias Philipp <tphilipp@gmail.com>
To: bpf@vger.kernel.org
Cc: "Tobias Philipp" <tphilipp@gmail.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Shuah Khan" <shuah@kernel.org>, "Felix Fietkau" <nbd@nbd.name>,
"Thibaut VARÈNE" <hacks@slashdirt.org>,
"Stijn Tintel" <stijn@linux-ipv6.be>,
"Daniel Mack" <daniel@zonque.org>,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH bpf-next v2 3/4] bpf: Align devmap values to 8 bytes
Date: Tue, 24 Nov 2026 23:50:54 +0100 [thread overview]
Message-ID: <20261124225055.87344-4-tphilipp@gmail.com> (raw)
In-Reply-To: <20261124225055.87344-1-tphilipp@gmail.com>
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 a misaligned
address. FEAT_LSE2 does not change that, because Linux does not set
SCTLR_EL1.nAA. 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@gmail.com>
---
kernel/bpf/devmap.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
index 1b8f0d7f8..0ef24e3f9 100644
--- a/kernel/bpf/devmap.c
+++ b/kernel/bpf/devmap.c
@@ -70,7 +70,10 @@ struct bpf_dtab_netdev {
struct bpf_prog *xdp_prog;
struct rcu_head rcu;
unsigned int idx;
- struct bpf_devmap_val val;
+ /* Returned to BPF programs as the map value, which the verifier
+ * assumes to be 8-byte aligned.
+ */
+ struct bpf_devmap_val val __aligned(8);
};
struct bpf_dtab {
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-11-24 22:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 22:50 [PATCH bpf-next v2 0/4] bpf: Fix 8-byte alignment of map values Tobias Philipp
2026-11-24 22:50 ` [PATCH bpf-next v2 1/4] bpf: Fix alignment of memory allocator objects on 32-bit archs Tobias Philipp
2026-11-24 22:50 ` [PATCH bpf-next v2 2/4] bpf: Align lpm_trie map values to 8 bytes Tobias Philipp
2026-11-24 22:56 ` sashiko-bot
2026-11-24 22:50 ` Tobias Philipp [this message]
2026-11-24 22:55 ` [PATCH bpf-next v2 3/4] bpf: Align devmap " sashiko-bot
2026-11-24 22:50 ` [PATCH bpf-next v2 4/4] selftests/bpf: Check that map values are 8-byte aligned Tobias Philipp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124225055.87344-4-tphilipp@gmail.com \
--to=tphilipp@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=daniel@zonque.org \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hacks@slashdirt.org \
--cc=hawk@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=nbd@nbd.name \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=stijn@linux-ipv6.be \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox