From: Alan Maguire <alan.maguire@oracle.com>
To: Antoine Tenart <atenart@kernel.org>, dwarves@vger.kernel.org
Cc: pvalerio@redhat.com
Subject: Re: [PATCH 1/2] btf_loader: infer alignment for zero-length arrays
Date: Fri, 4 Jul 2025 17:34:47 +0100 [thread overview]
Message-ID: <a43307cd-bfb8-4ff1-b03e-2d6732af85ce@oracle.com> (raw)
In-Reply-To: <20250625152329.28601-2-atenart@kernel.org>
On 25/06/2025 16:23, Antoine Tenart wrote:
> Zero sized arrays do not go through the bitfield fixup logic, which in
> turn makes them to skip the alignment infer logic. The result is
> zero-length arrays being incorrectly aligned when an explicit statement
> is needed. E.g. this happens for variable length arrays at end of
> structures, or for 0-length ones.
>
> Before this patch we can see:
>
> struct skb_ext {
> refcount_t refcnt; /* 0 4 */
> u8 offset[4]; /* 4 4 */
> u8 chunks; /* 8 1 */
>
> /* XXX 7 bytes hole, try to pack */
>
> char data[]; /* 16 0 */
>
> /* size: 16, cachelines: 1, members: 4 */
> /* sum members: 9, holes: 1, sum holes: 7 */
> /* last cacheline: 16 bytes */
> } __attribute__((__aligned__(8)));
>
> offsetof(struct skb_ext, data) returns 9.
>
> After this patch we get:
>
> struct skb_ext {
> refcount_t refcnt; /* 0 4 */
> u8 offset[4]; /* 4 4 */
> u8 chunks; /* 8 1 */
>
> /* XXX 7 bytes hole, try to pack */
>
> char data[] __attribute__((__aligned__(8))); /* 16 0 */
>
> /* size: 16, cachelines: 1, members: 4 */
> /* sum members: 9, holes: 1, sum holes: 7 */
> /* forced alignments: 1, forced holes: 1, sum forced holes: 7 */
> /* last cacheline: 16 bytes */
> } __attribute__((__aligned__(8)));
>
> offsetof(struct skb_ext, data) returns 16.
>
> Signed-off-by: Antoine Tenart <atenart@kernel.org>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
with a small suggestion below..
> ---
> btf_loader.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/btf_loader.c b/btf_loader.c
> index f4f9f65289b5..76771afedd95 100644
> --- a/btf_loader.c
> +++ b/btf_loader.c
> @@ -648,6 +648,10 @@ static int class__fixup_btf_bitfields(const struct conf_load *conf, struct tag *
> /* if BTF data is incorrect and has size == 0, skip field,
> * instead of crashing */
nit: could we update the comment here to reflect the change, adding
something like "however we still need to infer alignment for cases like
zero/variable-length arays".
> if (pos->byte_size == 0) {
> + pos->alignment = class__infer_alignment(conf,
> + pos->byte_offset,
> + tag__natural_alignment(type, cu),
> + smallest_offset);
> continue;
> }
>
next prev parent reply other threads:[~2025-07-04 16:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-25 15:23 [PATCH 0/2] pahole: BTF alignment inference improvements Antoine Tenart
2025-06-25 15:23 ` [PATCH 1/2] btf_loader: infer alignment for zero-length arrays Antoine Tenart
2025-07-04 16:34 ` Alan Maguire [this message]
2025-07-08 13:55 ` Antoine Tenart
2025-06-25 15:23 ` [PATCH 2/2] btf_loader: fix smallest offset in case of bitfields Antoine Tenart
2025-07-04 16:40 ` Alan Maguire
2025-07-08 14:01 ` Antoine Tenart
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=a43307cd-bfb8-4ff1-b03e-2d6732af85ce@oracle.com \
--to=alan.maguire@oracle.com \
--cc=atenart@kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=pvalerio@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox