Re: [GIT PULL] percpu fix for v5.9-rc6
From: Matthew Wilcox
Date: Fri Sep 18 2020 - 22:46:11 EST
On Fri, Sep 18, 2020 at 06:39:57PM -0400, Arvind Sankar wrote:
> On Fri, Sep 18, 2020 at 02:18:20PM -0700, Linus Torvalds wrote:
> > On Fri, Sep 18, 2020 at 2:00 PM Arvind Sankar <nivedita@xxxxxxxxxxxx> wrote:
> > >
> > > You could just assert that offsetof(typeof(s),flex) == sizeof(s), no?
> >
> > No, because the whole point is that I want that "sizeof(s)" to *WARN*.
>
> Ouch, offsetof() and sizeof() will give different results in the
> presence of alignment padding.
>
> https://godbolt.org/z/rqnxTK
We really should be using offsetof() then. It's harmless because we're
currently overallocating, not underallocating. The test case I did was:
struct s {
int count;
char *p[];
};
struct_size(&s, p, 5); (48 bytes)
struct_size2(&s, p, 5); (also 48 bytes)
struct_size2 uses offsetof instead of sizeof.
Your case is different because the chars fit in the padding at the end
of the struct.