Re: [PATCH] bpf: avoid padding in struct bpf_common_attr
From: Geert Uytterhoeven
Date: Wed May 20 2026 - 04:01:21 EST
Hi Song,
On Tue, 19 May 2026 at 22:52, Song Liu <song@xxxxxxxxxx> wrote:
> On Tue, May 19, 2026 at 1:39 PM Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
> >
> > From: Arnd Bergmann <arnd@xxxxxxxx>
> >
> > Building linux/bpf.h with -Wpadded shows an unintentionally
> > added portion of padding because of the 64-bit alignment:
> >
> > ./usr/include/linux/bpf.h:1510:1: error: padding struct size to alignment boundary with 4 bytes [-Werror=padded]
> >
> > Avoid this by adding explicit padding.
> >
> > Fixes: f28771c0691b ("bpf: Extend BPF syscall with common attributes support")
> > Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> > ---
> > include/uapi/linux/bpf.h | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index cc4c0b62cdfa..0f0ec00cae4a 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -1507,6 +1507,7 @@ struct bpf_common_attr {
> > __u32 log_size;
> > __u32 log_level;
> > __u32 log_true_size;
> > + __u32 __pad;
> > };
>
> Can we instead add "__attribute__((aligned(8)));" here?
That won't help:
1. The structure is already aligned to 8 bytes, as the first member
(out of context) is of type __aligned_u64,
2. Without explicit padding, there would still be an implicit hole
at the end of the structure, causing a warning with -Wpadded.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds