From: Jason Gunthorpe <jgg@nvidia.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Tony Nguyen <anthony.l.nguyen@intel.com>,
Intel Wired LAN <intel-wired-lan@lists.osuosl.org>,
linux-cxl@vger.kernel.org, oe-kbuild-all@lists.linux.dev
Subject: Re: [Intel-wired-lan] [tnguy-net-queue:dev-queue 2/12] include/linux/build_bug.h:78:41: error: static assertion failed: "sizeof(__uapi_uuid_t) == sizeof(uuid_t) && __alignof__(__uapi_uuid_t) == __alignof__(uuid_t)"
Date: Thu, 10 Apr 2025 14:57:31 -0300 [thread overview]
Message-ID: <20250410175731.GC5121@nvidia.com> (raw)
In-Reply-To: <67f8045059dde_71fe2949d@dwillia2-xfh.jf.intel.com.notmuch>
On Thu, Apr 10, 2025 at 10:48:00AM -0700, Dan Williams wrote:
> Jason Gunthorpe wrote:
> > On Wed, Apr 09, 2025 at 07:01:29PM -0700, Dan Williams wrote:
> >
> > > diff --git a/include/uapi/cxl/features.h b/include/uapi/cxl/features.h
> > > index dd8874860cec..06a1ae3f3fd0 100644
> > > --- a/include/uapi/cxl/features.h
> > > +++ b/include/uapi/cxl/features.h
> > > @@ -14,7 +14,8 @@ typedef unsigned char __uapi_uuid_t[16];
> > > #ifdef __KERNEL__
> > > #include <linux/uuid.h>
> > > static_assert(sizeof(__uapi_uuid_t) == sizeof(uuid_t) &&
> > > - __alignof__(__uapi_uuid_t) == __alignof__(uuid_t));
> > > + __alignof__(struct { __uapi_uuid_t uuid; }) ==
> > > + __alignof__(struct { uuid_t uuid; }));
> >
> > Really? I'm surprised that the struct wrapper increases the
> > alignment..
>
> I was also surprised that gcc has different rules for this alignment
> across compilers. Empirically this change solves the assertion, but I
> admit this was just the result of tinkering until the error goes away.
Hurm.
So the reason to have the align check is to ensure that when it is
embedded in the structs it doesn't change the layout of the struct.
The only use is this:
struct cxl_feat_entry {
uuid_t uuid;
__le16 id;
Which is fine, but if instead it was:
struct cxl_feat_entry {
__le16 id;
uuid_t uuid;
Then you have a problem as the align by 1 version will have no
padding while the align by 4 will have 2 bytes padding.
Wrapping in a struct for the static_assert does not prevent the above
issue..
So maybe the answer is to drop the alignof check entirely and add a
comment explaining that uuid must only be placed on 4 byte aligned
offsets and all structs must have explicit padding.
Jason
WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: kernel test robot <lkp@intel.com>,
oe-kbuild-all@lists.linux.dev,
Intel Wired LAN <intel-wired-lan@lists.osuosl.org>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
linux-cxl@vger.kernel.org
Subject: Re: [tnguy-net-queue:dev-queue 2/12] include/linux/build_bug.h:78:41: error: static assertion failed: "sizeof(__uapi_uuid_t) == sizeof(uuid_t) && __alignof__(__uapi_uuid_t) == __alignof__(uuid_t)"
Date: Thu, 10 Apr 2025 14:57:31 -0300 [thread overview]
Message-ID: <20250410175731.GC5121@nvidia.com> (raw)
In-Reply-To: <67f8045059dde_71fe2949d@dwillia2-xfh.jf.intel.com.notmuch>
On Thu, Apr 10, 2025 at 10:48:00AM -0700, Dan Williams wrote:
> Jason Gunthorpe wrote:
> > On Wed, Apr 09, 2025 at 07:01:29PM -0700, Dan Williams wrote:
> >
> > > diff --git a/include/uapi/cxl/features.h b/include/uapi/cxl/features.h
> > > index dd8874860cec..06a1ae3f3fd0 100644
> > > --- a/include/uapi/cxl/features.h
> > > +++ b/include/uapi/cxl/features.h
> > > @@ -14,7 +14,8 @@ typedef unsigned char __uapi_uuid_t[16];
> > > #ifdef __KERNEL__
> > > #include <linux/uuid.h>
> > > static_assert(sizeof(__uapi_uuid_t) == sizeof(uuid_t) &&
> > > - __alignof__(__uapi_uuid_t) == __alignof__(uuid_t));
> > > + __alignof__(struct { __uapi_uuid_t uuid; }) ==
> > > + __alignof__(struct { uuid_t uuid; }));
> >
> > Really? I'm surprised that the struct wrapper increases the
> > alignment..
>
> I was also surprised that gcc has different rules for this alignment
> across compilers. Empirically this change solves the assertion, but I
> admit this was just the result of tinkering until the error goes away.
Hurm.
So the reason to have the align check is to ensure that when it is
embedded in the structs it doesn't change the layout of the struct.
The only use is this:
struct cxl_feat_entry {
uuid_t uuid;
__le16 id;
Which is fine, but if instead it was:
struct cxl_feat_entry {
__le16 id;
uuid_t uuid;
Then you have a problem as the align by 1 version will have no
padding while the align by 4 will have 2 bytes padding.
Wrapping in a struct for the static_assert does not prevent the above
issue..
So maybe the answer is to drop the alignof check entirely and add a
comment explaining that uuid must only be placed on 4 byte aligned
offsets and all structs must have explicit padding.
Jason
next prev parent reply other threads:[~2025-04-10 17:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 20:30 [Intel-wired-lan] [tnguy-net-queue:dev-queue 2/12] include/linux/build_bug.h:78:41: error: static assertion failed: "sizeof(__uapi_uuid_t) == sizeof(uuid_t) && __alignof__(__uapi_uuid_t) == __alignof__(uuid_t)" kernel test robot
2025-04-04 20:30 ` kernel test robot
2025-04-10 2:01 ` [Intel-wired-lan] " Dan Williams
2025-04-10 2:01 ` Dan Williams
2025-04-10 11:59 ` [Intel-wired-lan] " Jason Gunthorpe
2025-04-10 11:59 ` Jason Gunthorpe
2025-04-10 17:48 ` [Intel-wired-lan] " Dan Williams
2025-04-10 17:48 ` Dan Williams
2025-04-10 17:57 ` Jason Gunthorpe [this message]
2025-04-10 17:57 ` Jason Gunthorpe
2025-04-10 18:09 ` [Intel-wired-lan] " Dan Williams
2025-04-10 18:09 ` Dan Williams
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=20250410175731.GC5121@nvidia.com \
--to=jgg@nvidia.com \
--cc=anthony.l.nguyen@intel.com \
--cc=dan.j.williams@intel.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=linux-cxl@vger.kernel.org \
--cc=oe-kbuild-all@lists.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 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.