From: Linus Torvalds <torvalds@linux-foundation.org>
To: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Matthew Wilcox <willy@infradead.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux.com>, Linux-MM <linux-mm@kvack.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Kees Cook <keescook@chromium.org>
Subject: Re: [GIT PULL] percpu fix for v5.9-rc6
Date: Fri, 18 Sep 2020 18:28:30 -0700 [thread overview]
Message-ID: <CAHk-=wg+3Poqh_HQ93nPMWOXLQHZhvYNuwScoQ-WaYWuriLYAg@mail.gmail.com> (raw)
In-Reply-To: <20200918223957.GA2964553@rani.riverdale.lan>
On Fri, Sep 18, 2020 at 3:40 PM Arvind Sankar <nivedita@alum.mit.edu> wrote:
>
> Ouch, offsetof() and sizeof() will give different results in the
> presence of alignment padding.
Indeed. But from an allocation standpoint, the offsetof()+size is I
think the correct size. The padding at the end makes very little sense
for something like "struct_size()".
Padding at the end is required for sizeof() for a very simple reason:
arrays. The "sizeof()" needs to be aligned to the alignment of the
entry, because if it isn't, then the standard C array traversal
doesn't work.
But you cannot sanely have arrays of these structures of variable size
entries either - even if standard C cheerfully allows you to declare
them (again: it will not behave like a variable sized array, it will
behave like a zero-sized one).
That was in fact one of the test-cases that I submitted to the sparse
list - the insanity of allowing arrays of structures that have a
flexible array at the end is just the C standard being confused. The C
standard may allow it, but I don't think we should allow it in the
kernel.
Oh, I can see why somebody would want to have an array of those things
- exactly because they want to have some "initializer _without_ the
flexible array part", and they actually don't want that variably-sized
array at all for that case.
But I'm pretty sure we really really don't want that kind of oddities
in the kernel. If we really want a separate "struct head_struct", then
I think we should do so explicitly, and have something like
struct real_struct {
// Unnamed head struct here
struct head_struct {
,,,,
};
unsigned int variable_array[];
};
and if you want the part without the flexible array at the end, then
you use that "struct head_struct".
Instead of depending on the imho broken model of the C standard that
says "in lots of cases, we'll just silently make that flexible array
be a zero-sized one".
Linus
next prev parent reply other threads:[~2020-09-19 1:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-17 20:45 Dennis Zhou
2020-09-18 1:05 ` Linus Torvalds
2020-09-18 16:23 ` Gustavo A. R. Silva
2020-09-18 17:23 ` Linus Torvalds
2020-09-18 19:34 ` Gustavo A. R. Silva
2020-09-18 19:37 ` Linus Torvalds
2020-09-18 20:02 ` Matthew Wilcox
2020-09-18 20:14 ` Linus Torvalds
2020-09-18 20:29 ` Arvind Sankar
2020-09-18 20:40 ` Linus Torvalds
2020-09-18 21:00 ` Arvind Sankar
2020-09-18 21:18 ` Linus Torvalds
2020-09-18 22:39 ` Arvind Sankar
2020-09-19 1:28 ` Linus Torvalds [this message]
2020-09-19 2:53 ` Arvind Sankar
2020-09-19 3:02 ` Matthew Wilcox
2020-09-19 3:04 ` Linus Torvalds
2020-09-19 2:45 ` Matthew Wilcox
2020-09-19 3:37 ` Arvind Sankar
2020-09-19 15:15 ` David Laight
2020-09-18 20:03 ` Gustavo A. R. Silva
2020-09-18 1:10 ` pr-tracker-bot
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='CAHk-=wg+3Poqh_HQ93nPMWOXLQHZhvYNuwScoQ-WaYWuriLYAg@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=gustavoars@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nivedita@alum.mit.edu \
--cc=tj@kernel.org \
--cc=willy@infradead.org \
/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