From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C41062225A2; Wed, 25 Sep 2024 12:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727266518; cv=none; b=FLppD77K9DlHDkXAHWnuJoEIbR/3YZk8zaG8Sh9W8cE4xO4af5EugY8ozszPAwconfi2wri2EVxVzmJW+vj/RgmkA5+u7Aaul/RcLy01aIM8z9cAIwNEPUZrt3VpS7KqbELVY6wyRw+O27VF2t8vHCyhHXfhoLLaQfseT1p50lU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727266518; c=relaxed/simple; bh=2QsXvxIzmY/soKU9ltxARFqrs8sEr76VyVnjWZsYaE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=obczRS7noutzfarEN/tVdNPFvuDW8JzTXS841G3tDTP15cyEMyxdk8X7e1VCqS5DTzGpkGuuRYFaN+6gtsc41MEh5eikGzdl+JtFmtlVDjIu+v0WGn5yp2PO2NXNRetuKAx1izi3oPPLmHMUHDtTc9V5fwvC6Y794WwCBOqWCKY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PBs+pHeQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PBs+pHeQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93A25C4CECE; Wed, 25 Sep 2024 12:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727266518; bh=2QsXvxIzmY/soKU9ltxARFqrs8sEr76VyVnjWZsYaE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PBs+pHeQkkpHSkInt2q0SAzMf6ZH5R89b/0qFHzpG40wnunJrZFvzcX7LmTZfZz3g 9NvyHWEBF9d5kVotB2FI4HQA51wOqggl4EFSrmB0yVDiv1J70xa1q+on0ORtNrH6xi D3iFLpgTtqzzohGXqKTKLWsaLTBFEuhBS2BR7I1DGVeAls/sTNWldT8jTlxZZp64kK a6HlTCWuZ/YaFm+wxQiHwdRPZfebiD1A2z6wXNmdZsLNhMx6D2g79u5I2jCTv+phuC rVPft9T31oWlfehRisE7havyyK76wJ86teAr5+ls1/UlZ5Y3cIsRaiQkVoKkcLFm4h opesXdL5WOB5Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Michal=20Koutn=C3=BD?= , Tejun Heo , Sasha Levin , lizefan.x@bytedance.com, hannes@cmpxchg.org, cgroups@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 083/139] cgroup: Disallow mounting v1 hierarchies without controller implementation Date: Wed, 25 Sep 2024 08:08:23 -0400 Message-ID: <20240925121137.1307574-83-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925121137.1307574-1-sashal@kernel.org> References: <20240925121137.1307574-1-sashal@kernel.org> 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 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.52 Content-Transfer-Encoding: 8bit From: Michal Koutný [ Upstream commit 3c41382e920f1dd5c9f432948fe799c07af1cced ] The configs that disable some v1 controllers would still allow mounting them but with no controller-specific files. (Making such hierarchies equivalent to named v1 hierarchies.) To achieve behavior consistent with actual out-compilation of a whole controller, the mounts should treat respective controllers as non-existent. Wrap implementation into a helper function, leverage legacy_files to detect compiled out controllers. The effect is that mounts on v1 would fail and produce a message like: [ 1543.999081] cgroup: Unknown subsys name 'memory' Signed-off-by: Michal Koutný Signed-off-by: Tejun Heo Signed-off-by: Sasha Levin --- kernel/cgroup/cgroup-v1.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 9cb00ebe9ac6d..01149e47e1a72 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -46,6 +46,12 @@ bool cgroup1_ssid_disabled(int ssid) return cgroup_no_v1_mask & (1 << ssid); } +static bool cgroup1_subsys_absent(struct cgroup_subsys *ss) +{ + /* Check also dfl_cftypes for file-less controllers, i.e. perf_event */ + return ss->legacy_cftypes == NULL && ss->dfl_cftypes; +} + /** * cgroup_attach_task_all - attach task 'tsk' to all cgroups of task 'from' * @from: attach to all cgroups of a given task @@ -932,7 +938,8 @@ int cgroup1_parse_param(struct fs_context *fc, struct fs_parameter *param) if (ret != -ENOPARAM) return ret; for_each_subsys(ss, i) { - if (strcmp(param->key, ss->legacy_name)) + if (strcmp(param->key, ss->legacy_name) || + cgroup1_subsys_absent(ss)) continue; if (!cgroup_ssid_enabled(i) || cgroup1_ssid_disabled(i)) return invalfc(fc, "Disabled controller '%s'", @@ -1024,7 +1031,8 @@ static int check_cgroupfs_options(struct fs_context *fc) mask = ~((u16)1 << cpuset_cgrp_id); #endif for_each_subsys(ss, i) - if (cgroup_ssid_enabled(i) && !cgroup1_ssid_disabled(i)) + if (cgroup_ssid_enabled(i) && !cgroup1_ssid_disabled(i) && + !cgroup1_subsys_absent(ss)) enabled |= 1 << i; ctx->subsys_mask &= enabled; -- 2.43.0