[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9da518ad-9b44-4dbb-98e5-66cf8a3fe7c2@huaweicloud.com>
Date: Mon, 1 Sep 2025 09:29:02 +0800
From: Chen Ridong <chenridong@...weicloud.com>
To: "Gustavo A. R. Silva" <gustavo@...eddedor.com>, Tejun Heo
<tj@...nel.org>, Johannes Weiner <hannes@...xchg.org>,
Michal Koutný <mkoutny@...e.com>
Cc: cgroups@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>,
linux-hardening@...r.kernel.org, "Gustavo A. R. Silva"
<gustavoars@...nel.org>
Subject: Re: [RFC] cgroup: Avoid thousands of -Wflex-array-member-not-at-end
warnings
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
Powered by blists - more mailing lists