From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: Tejun Heo <tj@kernel.org>, Johannes Weiner <hannes@cmpxchg.org>,
cgroups@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
linux-hardening@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Chen Ridong <chenridong@huaweicloud.com>
Subject: Re: [RFC] cgroup: Avoid thousands of -Wflex-array-member-not-at-end warnings
Date: Tue, 2 Sep 2025 14:37:40 +0200 [thread overview]
Message-ID: <5fb74444-2fbb-476e-b1bf-3f3e279d0ced@embeddedor.com> (raw)
In-Reply-To: <tl6b6chfawtykzrxlmysn6ev7mq7gm764rnlsag7pfme7vhpof@lbwqooaybqmr>
On 9/2/25 13:17, Michal Koutný wrote:
> On Tue, Sep 02, 2025 at 09:56:34AM +0200, "Gustavo A. R. Silva" <gustavo@embeddedor.com> wrote:
>> If the increase in size is not a problem, then something like this
>> works fine (unless there is a problem with moving those two members
>> at the end of cgroup_root?):
>
> Please don't forget to tackle cgroup_root allocators. IIUC, this move
> towards the end shifts the burden to them.
I don't see how placing the TRAILING_OVERLAP() change at the end
of cgroup_root would cause problems in cgroup_create(). I see
this allocation for `struct cgroup *cgrp`:
cgrp = kzalloc(struct_size(cgrp, ancestors, (level + 1)), GFP_KERNEL);
but I don't see why struct cgroup cgrp; and struct cgroup *cgrp_ancestor_storage;
cannot be placed at the end (as long as they're enclosed in TRAILING_OVERLAP()
of course) of cgroup_root. In the end, it seems you're only interested in
having cgrp->ancestors[0] overlap `cgrp_ancestor_storage` so that the latter
points to the start of the FAM in struct cgroup.
>
> There's only the rcu_head we care about.
Based on this commit a7fb0423c201 ("cgroup: Move rcu_head up near the
top of cgroup_root"), as long as rcu_head is not after struct cgroup,
all's fine.
However, this tells me that people were aware of the possibility of
`cgrp.ancestors[]` growing even beyond `cgrp_ancestor_storage`, which
is yet another reason not to have that flex array in the middle of
cgroup_root.
>
> (You seem to be well versed with flex arrays, I was wondering if
> something like this could be rearranged to make it work (assuming the
> union is at the end of its containers):
>
> union {
> struct cgroup *ancestors[];
> struct {
> struct cgroup *_root_ancestor;
> struct cgroup *_low_ancestors[];
> };
> };
> )
Yep, that works (as long as it's always at the very end of any container
or ends last in any nested structs, for instance in struct cgroup_root,
it must also be at the end) for GCC-15+, but for older versions of GCC we
have to use the DECLARE_FLEX_ARRAY() helper as below:
union {
/* All ancestors including self */
DECLARE_FLEX_ARRAY(struct cgroup *, ancestors);
struct {
struct cgroup *_root_ancestor;
struct cgroup *_low_ancestors[];
};
};
Thanks
-Gustavo
next prev parent reply other threads:[~2025-09-02 12:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-30 13:30 Gustavo A. R. Silva
2025-09-01 1:29 ` Chen Ridong
2025-09-01 7:44 ` Gustavo A. R. Silva
2025-09-01 13:37 ` Michal Koutný
2025-09-01 15:21 ` Gustavo A. R. Silva
2025-09-01 15:44 ` Gustavo A. R. Silva
2025-09-01 18:04 ` Michal Koutný
2025-09-01 17:58 ` Michal Koutný
2025-09-02 7:56 ` Gustavo A. R. Silva
2025-09-02 11:17 ` Michal Koutný
2025-09-02 12:37 ` Gustavo A. R. Silva [this message]
2025-09-08 11:53 ` David Laight
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=5fb74444-2fbb-476e-b1bf-3f3e279d0ced@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huaweicloud.com \
--cc=gustavoars@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=tj@kernel.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
all inboxes | Powered by JetHome®