From nobody Mon Feb 9 15:26:52 2026 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7699334EEE7 for ; Wed, 17 Dec 2025 16:28:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765988885; cv=none; b=ImfoWmfIMS5gQ2RPT+gUC5gP8AI50COrS5/OpJT1hc0kFhfzSr+0Rob93bSaG92WTDXHcge6gZWWfLaBTT2xf7Zq1AdnYLycUnGM7Pnh8heyK1yj803EHBvTg5/74tgMd5OxCM1cQdOge3GDJyqewmV2PtZ5ednpMhpOid1WNMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765988885; c=relaxed/simple; bh=8N1NH3gvQgT8EJmKCkddKOj6r6h0v+SQdz9mI6/X5NU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GUjnLE8HzWuX4DuF1cy1V5BM0vS02AtMHY27ysXl9AFsiDgblmkqaUMyhtQO0BqrvvrZbVtWKg1FuYoiNPeO67jOZRL6dZSsZLj3djh1CBFUAao6Qe4yNo1bX11hrODVIsqfZrDLgyDH3p6x64cTxQyVGNkKqGMQTJ4YTvC6atY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=YSQRfYX4; arc=none smtp.client-ip=209.85.128.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="YSQRfYX4" Received: by mail-wm1-f66.google.com with SMTP id 5b1f17b1804b1-4775e891b5eso26310805e9.2 for ; Wed, 17 Dec 2025 08:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765988881; x=1766593681; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=miS4ss3MDPMSZCVnSoPtKejAYQtVb4qQrc+Jf4/2A6E=; b=YSQRfYX43BQLOzgtpGn5en6mTceK+gUxvdgrUcw/54adk0PAT0twU1rfpNw+LkihDZ xLF9+30DAM8bH9PAdRvaQomTw30Og8NBHsKo4o0ng1fvrxdoTV15+tWb2ZMv8rEFeW0S m3JlE13pXes0pP7tyvbIQqgCZaZ/1qAPXlitL5An5t9knJKSaWg1zwoL+TDE3WuzfoV9 lJ8NoN8cnhdplXHsxGeLhWzRda+WKUKsqHrBke2Jbl9osrkKLdEuV4HAaE9millgRKS4 QsYkKhnT8PvCbnBwCnsrzgHRK76OHdWzkaFREPO1W7FtM7FnpHKKnCy69lOCcUvrxU1A sTFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765988881; x=1766593681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=miS4ss3MDPMSZCVnSoPtKejAYQtVb4qQrc+Jf4/2A6E=; b=kHSMyF+abyGIFyQyNsl9+jM5VYPlYXDGateq/ihQuynxssytN/KAdUxq2jwNP+IaCY zYt8qJBoyDDtwv5nk0jacveS//Up+83bk8KfC8fpB/bnK+2eQNGt+EjUveLXWLU928br MS0jq9tfcQ4itjBHLvp30hbsGbM2+TcxMIGS21DnzHaWsGX/hCkyFqeCdZiYevxpMlmf +3GgHgCxXtj2vlOogH+vb4sE6YkSK4OaRIykFT8h4e4RYVF6sfRHjCVX1yENed73tKf2 F0oav+c6RN3aI4UWDCT7/adnlJTltW06Pz/oqmCkKGY7/QWOJiw+wkdrvREU5ieSPqd+ VO2Q== X-Forwarded-Encrypted: i=1; AJvYcCW0XroKKRmqnaZsoxbhgeoC8AXBvL8byyX/8yAQ9qJccZnUjQm41wy29QsdgYBMq0x/kIslYmRLe1CsK9A=@vger.kernel.org X-Gm-Message-State: AOJu0YwBT7VTAkDE13dOFoaRLtnRtwzUySTynPzfWvFi6J8FqpQXkJWO 1hwG9aeSf1P5a6zx4OTbO1QGyLu5Xboz6wLJHM3UBy8u64ULvKQ55CtOUneVYRPsPLw= X-Gm-Gg: AY/fxX4k+2Whf5zEz6+b7umLU7Pae9whDyKurTzbbthH/Sone5QVs0k11+xAxU79ncq f6APjjFI1wOpQe9qzPI4zPG5VwSqhoH6jCiVMwq4A30/rjjkiz/Rm1F90ofq9QaD592DiwP488m MFm0XGn0pGBm1xhIgsyx+YxIjV0ZotCbdpcbxHjrgT9nGqZ9ZyMJrD6T5C+iq8FJJXd8KSPGFen 4TTcmLPH5LT52EwXQL0F5DqopEqs+13nn2+lb/jgkNd+grRDA16gGG/zQbq4JRyMIV1x2YDPk4V 3QkGbWegHeB3cStc81FxJ6GzPQRvQlssshv9z7QpgYXsi5Tfk/pxwczWfsE3FuMrr3fmVO2qAJf PY01NxcpFfkDs+MHzujCpBvN2KEYTKGFjd7cT/RAk/0qbbRcf2Cj3BTMN9w6PkMgHfDzdaTnItq hnB6m5Z4GdKVUOglPYOY/50tbuCAshKm4= X-Google-Smtp-Source: AGHT+IHcvkh1m9sLAXyNB6eVc7R+7YZBCQwqFGtWv5JoMxfuEBVtQKc5wQlBYiBzOLEKXZOB0xl9aw== X-Received: by 2002:a05:6000:240d:b0:431:9b2:61dd with SMTP id ffacd0b85a97d-43109b2636cmr5805555f8f.38.1765988881299; Wed, 17 Dec 2025 08:28:01 -0800 (PST) Received: from blackdock.suse.cz (nat2.prg.suse.com. [195.250.132.146]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4310adeee0esm5728364f8f.29.2025.12.17.08.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 08:28:00 -0800 (PST) From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Michal=20Koutn=C3=BD?= , "Gustavo A. R. Silva" , David Laight , Tejun Heo , Johannes Weiner Subject: [PATCH 1/4] cgroup: Eliminate cgrp_ancestor_storage in cgroup_root Date: Wed, 17 Dec 2025 17:27:33 +0100 Message-ID: <20251217162744.352391-2-mkoutny@suse.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251217162744.352391-1-mkoutny@suse.com> References: <20251217162744.352391-1-mkoutny@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The cgrp_ancestor_storage has two drawbacks: - it's not guaranteed that the member immediately follows struct cgrp in cgroup_root (root cgroup's ancestors[0] might thus point to a padding and not in cgrp_ancestor_storage proper), - this idiom raises warnings with -Wflex-array-member-not-at-end. Instead of relying on the auxiliary member in cgroup_root, define the 0-th level ancestor inside struct cgroup (needed for static allocation of cgrp_dfl_root), deeper cgroups would allocate flexible _low_ancestors[]. Unionized alias through ancestors[] will transparently join the two ranges (ancestors is wrapped in a struct to avoid 'error: flexible array member in union'). The above change would still leave the flexible array at the end of struct cgroup, so move cgrp also towards the end of cgroup_root to resolve the -Wflex-array-member-not-at-end. Link: https://lore.kernel.org/r/5fb74444-2fbb-476e-b1bf-3f3e279d0ced@embedd= edor.com/ Reported-by: "Gustavo A. R. Silva" Closes: https://lore.kernel.org/r/b3eb050d-9451-4b60-b06c-ace7dab57497@embe= ddedor.com/ Cc: David Laight Signed-off-by: Michal Koutn=C3=BD Acked-by: Gustavo A. R. Silva --- include/linux/cgroup-defs.h | 28 +++++++++++++++++----------- kernel/cgroup/cgroup.c | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index b760a3c470a56..9247e437da5ce 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -626,7 +626,16 @@ struct cgroup { #endif =20 /* All ancestors including self */ - struct cgroup *ancestors[]; + union { + struct { + void *_sentinel[0]; /* XXX to avoid 'flexible array member in a struct = with no named members' */ + struct cgroup *ancestors[]; + }; + struct { + struct cgroup *_root_ancestor; + struct cgroup *_low_ancestors[]; + }; + }; }; =20 /* @@ -647,16 +656,6 @@ struct cgroup_root { struct list_head root_list; struct rcu_head rcu; /* Must be near the top */ =20 - /* - * The root cgroup. The containing cgroup_root will be destroyed on its - * release. cgrp->ancestors[0] will be used overflowing into the - * following field. cgrp_ancestor_storage must immediately follow. - */ - struct cgroup cgrp; - - /* must follow cgrp for cgrp->ancestors[0], see above */ - struct cgroup *cgrp_ancestor_storage; - /* Number of cgroups in the hierarchy, used only for /proc/cgroups */ atomic_t nr_cgrps; =20 @@ -668,6 +667,13 @@ struct cgroup_root { =20 /* The name for this hierarchy - may be empty */ char name[MAX_CGROUP_ROOT_NAMELEN]; + + /* + * The root cgroup. The containing cgroup_root will be destroyed on its + * release. This must be embedded last due to flexible array at the end + * of struct cgroup. + */ + struct cgroup cgrp; }; =20 /* diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index e717208cfb185..554a02ee298ba 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5847,7 +5847,7 @@ static struct cgroup *cgroup_create(struct cgroup *pa= rent, const char *name, int ret; =20 /* allocate the cgroup and its ID, 0 is reserved for the root */ - cgrp =3D kzalloc(struct_size(cgrp, ancestors, (level + 1)), GFP_KERNEL); + cgrp =3D kzalloc(struct_size(cgrp, _low_ancestors, level), GFP_KERNEL); if (!cgrp) return ERR_PTR(-ENOMEM); =20 --=20 2.52.0