From: Chen Ridong <chenridong@huaweicloud.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>
Cc: cgroups@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
linux-hardening@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Subject: Re: [RFC] cgroup: Avoid thousands of -Wflex-array-member-not-at-end warnings
Date: Mon, 1 Sep 2025 09:29:02 +0800 [thread overview]
Message-ID: <9da518ad-9b44-4dbb-98e5-66cf8a3fe7c2@huaweicloud.com> (raw)
In-Reply-To: <b3eb050d-9451-4b60-b06c-ace7dab57497@embeddedor.com>
On 2025/8/30 21:30, Gustavo A. R. Silva wrote:
> Hi all,
>
> I'm working on enabling -Wflex-array-member-not-at-end in mainline, and
> I ran into thousands (yes, 14722 to be precise) of these warnings caused
> by an instance of `struct cgroup` in the middle of `struct cgroup_root`.
> See below:
>
> 620 struct cgroup_root {
> ...
> 633 /*
> 634 * The root cgroup. The containing cgroup_root will be destroyed on its
> 635 * release. cgrp->ancestors[0] will be used overflowing into the
> 636 * following field. cgrp_ancestor_storage must immediately follow.
> 637 */
> 638 struct cgroup cgrp;
> 639
> 640 /* must follow cgrp for cgrp->ancestors[0], see above */
> 641 struct cgroup *cgrp_ancestor_storage;
> ...
> };
>
> Based on the comments above, it seems that the original code was expecting
> cgrp->ancestors[0] and cgrp_ancestor_storage to share the same addres in
> memory.
>
> However when I take a look at the pahole output, I see that these two members
> are actually misaligned by 56 bytes. See below:
>
> struct cgroup_root {
> ...
>
> /* --- cacheline 1 boundary (64 bytes) --- */
> struct cgroup cgrp __attribute__((__aligned__(64))); /* 64 2112 */
>
> /* XXX last struct has 56 bytes of padding */
>
> /* --- cacheline 34 boundary (2176 bytes) --- */
> struct cgroup * cgrp_ancestor_storage; /* 2176 8 */
>
> ...
>
> /* size: 6400, cachelines: 100, members: 11 */
> /* sum members: 6336, holes: 1, sum holes: 16 */
> /* padding: 48 */
> /* paddings: 1, sum paddings: 56 */
> /* forced alignments: 1, forced holes: 1, sum forced holes: 16 */
> } __attribute__((__aligned__(64)));
>
> This is due to the fact that struct cgroup have some tailing padding after
> flexible-array member `ancestors` due to alignment to 64 bytes, see below:
>
> struct cgroup {
> ...
>
> struct cgroup * ancestors[]; /* 2056 0 */
>
Instead of using a flexible array member, could we convert this to a pointer and handle the memory
allocation explicitly?
--
Best regards,
Ridong
next prev parent reply other threads:[~2025-09-01 1:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-30 13:30 [RFC] cgroup: Avoid thousands of -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-09-01 1:29 ` Chen Ridong [this message]
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
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=9da518ad-9b44-4dbb-98e5-66cf8a3fe7c2@huaweicloud.com \
--to=chenridong@huaweicloud.com \
--cc=cgroups@vger.kernel.org \
--cc=gustavo@embeddedor.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;
as well as URLs for NNTP newsgroup(s).