[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)"
Jason Gunthorpe
jgg at nvidia.com
Thu Apr 10 17:57:31 UTC 2025
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
More information about the Intel-wired-lan
mailing list