Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1456214rwp; Thu, 13 Jul 2023 11:05:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlG9ah6uoA7LYNQuSdAIF8iNDgVMeW4OMdOG12zMH0DGdFaJoFj0d7BjfAjkL8VelvrL20W3 X-Received: by 2002:a1f:e342:0:b0:471:b557:12a with SMTP id a63-20020a1fe342000000b00471b557012amr1332905vkh.11.1689271549952; Thu, 13 Jul 2023 11:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689271549; cv=none; d=google.com; s=arc-20160816; b=kqWb4cNIunYTRXTmJI1sS/wW+r2CL0gLCtNf39aI8GRbVt0FXLno38c8n3GcRPqgQ0 SEKlWBMU7AclnumKteAViP2Tf7mGUfjw1XkLd8ZwF+td7d2b70lO44U1L3r+Q7zckt0X Axnk0APBl/Qu5+2ryyRumhJ5d79mv/gLY32rde//acaKh0ms2yITRTf9Gu0osdTZ4++O yvZSPj76E14vmPVnS81lNLD3tAxxQlHZs66BDYHImRSsNNPU+yN+AyfzwvqmMaIjqnAu aXSuUPKS8Fr5fzS3G0nbE2bQAMdE4yRh/Q5ZGWQIQIj62deUVRrmL69z7Mytq3wxEYRr vj7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YhbHfkkyMLUVZBMfytZR4SEPeF8T5uIgeTwYKIX8mco=; fh=IGWE7vONNjEudoF5laKvjbbc8exivQlU70QG34RcpBk=; b=h+WtfwNC0sF+ai/jIj3JSoLIsk4H86S8Qlib9v/a6BXQiO/SUJWz4idbND8Yh/Ffmg WoRS4Dwnz72asTaRfKdH6pnvxhxIL0S/UgGxxULYjD11kdpYKme/e7DD1TX2l45/9WbF yohWQjK8ZandHFJ/cqhUJDlACXukcXqyLV52S8VOFOV/DIwAlfOwumy2uSL+VJE4pa3W uxdgMQtL0VunbGgkZt8yoPNIBd97XydUusBDPhg5geI67/X4FwE6wWXW5VGGwW2Nn2Lp hQ83z3mQulJCktqfCAJjLrSQN8pQSLt6iPM4D30IIe7HwdxJc809G4gyYxh/H/eVmBLm 7N7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Sy1suUH0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a17090ab00500b00259bbd55d4asi1091152pjq.8.2023.07.13.11.05.37; Thu, 13 Jul 2023 11:05:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Sy1suUH0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231245AbjGMR2N (ORCPT + 99 others); Thu, 13 Jul 2023 13:28:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234227AbjGMR2B (ORCPT ); Thu, 13 Jul 2023 13:28:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35382270B for ; Thu, 13 Jul 2023 10:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689269193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YhbHfkkyMLUVZBMfytZR4SEPeF8T5uIgeTwYKIX8mco=; b=Sy1suUH0oZ5rsYXDYVWVUuFRdvcTIy+/SEcsOpH0AfFatsxH6TxvBVilIGuvCAMalTE51/ rO8r07mssKMd8sse0aVlLoZL8zjoJhZzBNREu+ZdjiedGEzQ8kmhzdT49l3SCPOnKNzyP9 vUh8ruNAyHxkCYFJf+w6NfOceoWsCHY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-365-41RQ09n9OCa81o3eE9Nv3Q-1; Thu, 13 Jul 2023 13:26:28 -0400 X-MC-Unique: 41RQ09n9OCa81o3eE9Nv3Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AAD838D1682; Thu, 13 Jul 2023 17:26:27 +0000 (UTC) Received: from llong.com (unknown [10.22.16.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 056BE2166B26; Thu, 13 Jul 2023 17:26:26 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Christian Brauner , Jonathan Corbet , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Juri Lelli , Dietmar Eggemann , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Giuseppe Scrivano , Waiman Long Subject: [PATCH v5 3/5] cgroup/cpuset: Check partition conflict with housekeeping setup Date: Thu, 13 Jul 2023 13:25:59 -0400 Message-Id: <20230713172601.3285847-4-longman@redhat.com> In-Reply-To: <20230713172601.3285847-1-longman@redhat.com> References: <20230713172601.3285847-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A user can pre-configure certain CPUs in an isolated state at boot time with the "isolcpus" kernel boot command line option. Those CPUs will not be in the housekeeping_cpumask(HK_TYPE_DOMAIN) and so will not be in any sched domains. This may conflict with the partition setup at runtime. Those boot time isolated CPUs should only be used in an isolated partition. This patch adds the necessary check and disallows partition setup if the check fails. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index b1fc8ba3cfbf..ff16fa8b24fb 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -75,6 +75,7 @@ enum prs_errcode { PERR_NOCPUS, PERR_HOTPLUG, PERR_CPUSEMPTY, + PERR_HKEEPING, }; static const char * const perr_strings[] = { @@ -85,6 +86,7 @@ static const char * const perr_strings[] = { [PERR_NOCPUS] = "Parent unable to distribute cpu downstream", [PERR_HOTPLUG] = "No cpu available due to hotplug", [PERR_CPUSEMPTY] = "cpuset.cpus is empty", + [PERR_HKEEPING] = "partition config conflicts with housekeeping setup", }; struct cpuset { @@ -1658,6 +1660,26 @@ static void remote_partition_check(struct cpuset *cs, struct cpumask *newmask, rebuild_sched_domains_locked(); } +/* + * prstate_housekeeping_conflict - check for partition & housekeeping conflicts + * @prstate: partition root state to be checked + * @new_cpus: cpu mask + * Return: true if there is conflict, false otherwise + * + * CPUs outside of housekeeping_cpumask(HK_TYPE_DOMAIN) can only be used in + * an isolated partition. + */ +static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) +{ + const struct cpumask *hk_domain = housekeeping_cpumask(HK_TYPE_DOMAIN); + bool all_in_hk = cpumask_subset(new_cpus, hk_domain); + + if (!all_in_hk && (prstate != PRS_ISOLATED)) + return true; + + return false; +} + /** * update_parent_effective_cpumask - update effective_cpus mask of parent cpuset * @cs: The cpuset that requests change in partition root state @@ -1758,6 +1780,9 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, if (!cpumask_intersects(xcpus, parent->exclusive_cpus)) return PERR_INVCPUS; + if (prstate_housekeeping_conflict(new_prs, xcpus)) + return PERR_HKEEPING; + /* * A parent can be left with no CPU as long as there is no * task directly associated with the parent partition. @@ -2335,6 +2360,9 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, if (cpumask_empty(trialcs->exclusive_cpus)) { invalidate = true; cs->prs_err = PERR_INVCPUS; + } else if (prstate_housekeeping_conflict(old_prs, trialcs->exclusive_cpus)) { + invalidate = true; + cs->prs_err = PERR_HKEEPING; } else if (tasks_nocpu_error(parent, cs, trialcs->exclusive_cpus)) { invalidate = true; cs->prs_err = PERR_NOCPUS; @@ -2473,6 +2501,9 @@ static int update_exclusive_cpumask(struct cpuset *cs, struct cpuset *trialcs, if (cpumask_empty(trialcs->exclusive_cpus)) { invalidate = true; cs->prs_err = PERR_INVCPUS; + } else if (prstate_housekeeping_conflict(old_prs, trialcs->exclusive_cpus)) { + invalidate = true; + cs->prs_err = PERR_HKEEPING; } else if (tasks_nocpu_error(parent, cs, trialcs->exclusive_cpus)) { invalidate = true; cs->prs_err = PERR_NOCPUS; -- 2.31.1