From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Anton Protopopov <aspsk@isovalent.com>, Arnd Bergmann <arnd@arndb.de>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
"Stanislav Fomichev" <sdf@google.com>, <bpf@vger.kernel.org>,
Naresh Kamboju <naresh.kamboju@linaro.org>
Subject: Re: [PATCH bpf-next] bpf: pack struct bpf_fib_lookup
Date: Thu, 4 Apr 2024 11:04:14 +0200 [thread overview]
Message-ID: <ada87880-4bf4-4528-98ab-d09d39c515c3@intel.com> (raw)
In-Reply-To: <Zg5dQ6KYqVWA2Iia@lavr>
From: Anton Protopopov <aspsk@isovalent.com>
Date: Thu, 4 Apr 2024 09:56:51 +0200
> On 24/04/04 12:31, Arnd Bergmann wrote:
>> On Wed, Apr 3, 2024, at 23:00, Daniel Borkmann wrote:
>>> On 4/3/24 10:09 PM, Arnd Bergmann wrote:
>>>> On Wed, Apr 3, 2024, at 14:33, Anton Protopopov wrote:
>>>>>
>>>>> Declare this inner union as __attribute__((packed, aligned(2))) such
>>>>> that it always is of size 2 and is aligned to 16 bits.
>>>>
>>>> I think you probably want 32-bit alignment for the structure,
>>>> to keep the ABI unchanged on all other architectures.
>>>
>>> Fwiw, on x86 nothing should change on this regard, see below pahole dump
>>> before/after. I think similar might be true for other archs as otherwise
>>> we should have seen a kbuild bot complaint on hitting the size assert.
>>
>> It's not the structure layout that changes, just its alignment.
>> Of course this is unlikely to cause actual bugs, but if there there
>> is no real need to change it, I would leave the alignment the same
>> as before.
>
> I think the struct will now be automatically 4-byte aligned, as it
> has the following layout:
>
> struct {
> u8 a;
> u8 b;
> u16 c;
> u16 d;
> union { u16 e; u16 f; } __aligned__(2);
> ...
> };
>
> So if the union is 2-byte aligned, then the struct is automatically
> 4-byte aligned, because its address is 6 bytes less than the address
> of the union. In fact, as Daniel posted above, pahole shows that the
> struct actually has __aligned__(4) attribute in the patched version.
> I can add explicit __aligned__(4) to make this clear.
I think it would be fine to not introduce an explicit attribute as long
as pahole shows the structure is already 4-byte aligned.
Regarding aligning it to 32 or 64 bytes -- the actual benefit can be
checked via scripts/bloat-o-meter. Usually alignment bigger than 8 bytes
don't change anything in the object code, at least on x86_64.
>
>> Arnd
Thanks,
Olek
next prev parent reply other threads:[~2024-04-04 9:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 12:33 [PATCH bpf-next] bpf: pack struct bpf_fib_lookup Anton Protopopov
2024-04-03 12:37 ` Alexander Lobakin
2024-04-03 13:14 ` Daniel Borkmann
2024-04-03 17:52 ` Andrii Nakryiko
2024-04-03 20:09 ` Arnd Bergmann
2024-04-03 21:00 ` Daniel Borkmann
2024-04-03 22:31 ` Arnd Bergmann
2024-04-04 7:56 ` Anton Protopopov
2024-04-04 9:04 ` Alexander Lobakin [this message]
2024-04-04 9:39 ` Arnd Bergmann
2024-04-04 23:00 ` patchwork-bot+netdevbpf
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=ada87880-4bf4-4528-98ab-d09d39c515c3@intel.com \
--to=aleksander.lobakin@intel.com \
--cc=andrii@kernel.org \
--cc=arnd@arndb.de \
--cc=aspsk@isovalent.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=naresh.kamboju@linaro.org \
--cc=sdf@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.