From patchwork Mon Sep 9 16:32:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Koutn=C3=BD?= X-Patchwork-Id: 13797306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 297FCECE579 for ; Mon, 9 Sep 2024 16:32:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F5576B00C6; Mon, 9 Sep 2024 12:32:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A7406B0191; Mon, 9 Sep 2024 12:32:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41F6F6B0193; Mon, 9 Sep 2024 12:32:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2155C6B00C6 for ; Mon, 9 Sep 2024 12:32:31 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9F56680ACF for ; Mon, 9 Sep 2024 16:32:30 +0000 (UTC) X-FDA: 82545742860.11.A1755C2 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by imf28.hostedemail.com (Postfix) with ESMTP id B2BF9C000D for ; Mon, 9 Sep 2024 16:32:28 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=ahv4hqVY; spf=pass (imf28.hostedemail.com: domain of mkoutny@suse.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=mkoutny@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725899497; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3hN1sbdsSr5xjIEEi3K2BOZrBarvDPImrotZrDBVesU=; b=HtDrAsQyyjNli1rNOJiWGfbKcTWoqQqoVVqjXR4MMH+aV0nWZw9Gf5zwEwFo3AETk3to9l f8d93IiOnp+FTMDea1D8LCYU6fd1Iq24AO0Bt/EeTiotV2H4QAluKjqfBSC5EO9Ttm4OFe +/gOFX9AqXVbIA0erF7vayKdwhH0iQY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.com header.s=google header.b=ahv4hqVY; spf=pass (imf28.hostedemail.com: domain of mkoutny@suse.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=mkoutny@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725899497; a=rsa-sha256; cv=none; b=0VSyEuSoCsAX+vWopLXVVmrCTWl2FsKbl1RfyP+3HdnYG0yiE24Ljz92zReeBpyKCvDf0T /zr08PKxAYeemyVEhXXHuOaU0wAcaWcRG7BgEAYHemxQm7w9eH4ny02Y9GofpR4PfbgZwe /YfkJdapwx4G+Mezwmzw7Sw/SovtG78= Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-428e1915e18so39228495e9.1 for ; Mon, 09 Sep 2024 09:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1725899547; x=1726504347; darn=kvack.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=3hN1sbdsSr5xjIEEi3K2BOZrBarvDPImrotZrDBVesU=; b=ahv4hqVYeK3XToFHEl+qeRjqr8VcJANwDjqImYBfRmcjEbu8NgiE7zdYoq9F+cH2OR NVdOzno8eYZmw4KDGAa6TNCmXOd8ud8W4zcX2MgfskVV2B2cy61NiQHWqtbdokxs/aKh GwZJOcA3c/OMOhjs4gglnfn2A5TpJd/nA89WDtqrknOV4vrjeKoDl2WYAywiLpQZycWj iRr6YSM0NqCYDXajUw4I6oOQ0T29DCqFB1zDp8YWB+XYypnoiFzdafBGeBmH2MB0jhwZ FAQmQiMZisaNoowYgw7rM9GtJJoLw1iUnWlprqPJJDvPupSs/O2+5JjH3XT/8vBKL5NO D6HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725899547; x=1726504347; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3hN1sbdsSr5xjIEEi3K2BOZrBarvDPImrotZrDBVesU=; b=JZRfpvJQFvh4QgiHVy8WTLp3ZKqNZvfyNwe3I/RtUo92l9DaFFey7Dyvem/3BnN0KT iB9eAupn6YphE7nQSBGfuOPX/OrrpYxxAx87y43lSXitxQlkZS5fFBD3ProHbveV71dE RQnuVpeWifphwjQy9NCmDXe9GxNAVLxC6Nhz+xAtt6DMBUu77lU2qU+U2Pj4JtLcChVl y4QMCflNTTFG/m6BkrsrWhG02xdn3ceOCqc8SHsJtEmQKtPdWX2GpU71bHUlSiLK/pwT CTv1a8c1ZHN5kLaEEHaiju18m3wdzAAstAC8o+dVTp61g4co5Euy/8oL1LnY0+KmvvkD mfig== X-Forwarded-Encrypted: i=1; AJvYcCW26gcWmetT62Qtq0kuOB8LT3ZKwIth+JvuJL+xaR4Bz0wCJJvkIWse7tWqrWTAQLgBOOiIry5VLg==@kvack.org X-Gm-Message-State: AOJu0YzwKGSHEsc2VGP/xIGIiajfNvuAUMrHef1C77bvJxlmFFU/acxL yfyrVqsjsPKnyQNjsnTjDBNExGql1wV+IThO4FJ5dow9fFlWvoTy+mLxfN/g528= X-Google-Smtp-Source: AGHT+IGxjAbrDtFXLx+iO1e9KJ4se6OA7eld34L5kuJJJmD5mvX5+Dcs4EKLQGfBldRlsEeQGM6bsA== X-Received: by 2002:a05:600c:1e02:b0:42c:b949:328e with SMTP id 5b1f17b1804b1-42cb949341dmr21798805e9.31.1725899547259; Mon, 09 Sep 2024 09:32:27 -0700 (PDT) Received: from blackdock.suse.cz ([193.86.92.181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3789564a072sm6478606f8f.2.2024.09.09.09.32.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 09:32:27 -0700 (PDT) From: =?utf-8?q?Michal_Koutn=C3=BD?= To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Tejun Heo , Zefan Li , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Chen Ridong Subject: [PATCH 3/4] cgroup: Disallow mounting v1 hierarchies without controller implementation Date: Mon, 9 Sep 2024 18:32:22 +0200 Message-ID: <20240909163223.3693529-4-mkoutny@suse.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240909163223.3693529-1-mkoutny@suse.com> References: <20240909163223.3693529-1-mkoutny@suse.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: B2BF9C000D X-Stat-Signature: nwm1k98buiuun75u1zmrica1prdogshh X-HE-Tag: 1725899548-437605 X-HE-Meta: U2FsdGVkX190g8Jt6BVEhEBF2UTPz8UBsCPes4LX+RVFfgc7b3DGsiWgoImx7yjQZBhhyBMIsD8NwsCboBNxILZN5Vf4G2LbWAnNByhFCBgMZjrXLKzTxgj3+Glixh/ma/x3tS5h9Topc7COwyHAaF8iN9m+saBXgm8AqEAIp66OjLoMgTwaAVZVF/7AcYSPc+o1TTWzTcFo3hUTOcV+XzvAw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Kvl1Brf40rNZxG5ZXnW9V73Sn6X4JEdWar26SPB43r5ePZhgKMN5JUkIYRTX+Sg8vfiNNat0jfhvSlleI6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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ý --- 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 b9dbf6bf2779d..784337694a4be 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;