Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3355712pxb; Sat, 9 Oct 2021 08:17:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwkdobKNjN1UBX+7IKnH8CpiaeIDHZ1C0UPoOibXQDHLyGMTgpq+P2DRRU7+RMAs1GH1Oo X-Received: by 2002:a50:cf41:: with SMTP id d1mr24049833edk.219.1633792637390; Sat, 09 Oct 2021 08:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633792637; cv=none; d=google.com; s=arc-20160816; b=Z6+wZsTeUX79WKAYacJOIQB63CqIfud/A+qYY6DmjbUPEeggZg9e4A8ow2leOGazaG ZI5BcBXqUrIjoeozsXF7Z18fSjoDLS7BDrv4WAa7iZGgFdmEXbFXBdNrBVxsKyZLe4TL nPE73+5GkiWGUhcy78hblO9Gqrm744zxBA7LYGX6kinL5Okw+jJcwqeKXc7xq4Doucfs KrRLfQMnIDyDd3ZrO8goFSzl4EPBmVAwJapVPV3z7Zs9s5dBZ3KOGRiQ9EgRQCcQkCLJ 6x41t0SUHSpcHUg5Bltpcj3a7jOkb2tA/nbRfcA00E5mJrHLbZW32WoKK5ps9T6woj3P TUyA== 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:to:from :dkim-signature; bh=qaKVf2iG3jJrJdTiPzN0ACJ6YGlKml1RY1+qmab/pd4=; b=FseyuRw6A3LvnpfiKCF2TzqGFcFI6vQYi4NOSK1KH4Ekln173OyBCy7MR4XmF9XQrK 0lDAsmHEMpkVBOaR6/6dst67uPs3jljbnqZt3L6oH3T40C7fBcIKzsKie56ugf79ueLg 6sFGemrKTM9ZTxmzI6DofIw9w3Lmqoqcm/XYSmysWYho71JlCtKObLOhcHLYGksomB+g KePlIq6Wxsbsdpf4kr7PiaZvfv4+YXWpjWDnXeD0hB9ROSJ3DKDFZadQuqSNicssHX3V ocI4Ha4xl+NlIQFx0i4/JA5Yaszy3vfMIHspf+F2kJXqein4S9Gxk/pcE+hcVJMtfBXj vtLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=aRTT0GYC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si3458290ejj.365.2021.10.09.08.16.53; Sat, 09 Oct 2021 08:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=aRTT0GYC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234697AbhJIPP0 (ORCPT + 99 others); Sat, 9 Oct 2021 11:15:26 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37136 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234609AbhJIPPX (ORCPT ); Sat, 9 Oct 2021 11:15:23 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1999Ccws020949; Sat, 9 Oct 2021 11:13:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=qaKVf2iG3jJrJdTiPzN0ACJ6YGlKml1RY1+qmab/pd4=; b=aRTT0GYC6A4Rrx/GXzW1CpLNwxLZSD37TyFEKMyE63m57ioB3Eq7XPEBiYkOlAY3dIWV JL/FkNEhwfOC9ApafaVLAUKnPeUwbWupFndhQ7blr1/dENaZCFP0Zk768GUcedVxRpYX dTK/51ooNsf8P1u2Qrx7XOt3UaCATEmicaQW4awzjsbU5WoWsDAZYh3UwoHyNWFnoXNW jE8PvAb2ONsyycVQyiyt6e2DQOl6uqnsJEuNQwFFuOGGP2znlmeE3uKG1vUzj42uMQZs CXWoDPPr93PZiNNoWrE9sC8JiwlQHVBjljNIKh1RFqXxIQ1kmAE7pHrQXYth7UjEKhnV Cg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3bk884c1f0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 09 Oct 2021 11:13:11 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 199FDBbe026498; Sat, 9 Oct 2021 11:13:11 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3bk884c1ee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 09 Oct 2021 11:13:11 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 199FCgkB020870; Sat, 9 Oct 2021 15:13:08 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3bk2q9a4ac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 09 Oct 2021 15:13:08 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 199FD6s038207782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 9 Oct 2021 15:13:06 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3470142041; Sat, 9 Oct 2021 15:13:06 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 79F3642042; Sat, 9 Oct 2021 15:13:01 +0000 (GMT) Received: from pratiks-thinkpad.ibm.com (unknown [9.43.17.147]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Sat, 9 Oct 2021 15:13:01 +0000 (GMT) From: "Pratik R. Sampat" To: bristot@redhat.com, christian@brauner.io, ebiederm@xmission.com, lizefan.x@bytedance.com, tj@kernel.org, hannes@cmpxchg.org, mingo@kernel.org, juri.lelli@redhat.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org, containers@lists.linux.dev, containers@lists.linux-foundation.org, psampat@linux.ibm.com, pratik.r.sampat@gmail.com Subject: [RFC 3/5] cpuset/cpuns: Make cgroup CPUset CPU namespace aware Date: Sat, 9 Oct 2021 20:42:41 +0530 Message-Id: <20211009151243.8825-4-psampat@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211009151243.8825-1-psampat@linux.ibm.com> References: <20211009151243.8825-1-psampat@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: gv42oO6GxrsSd85JyLdvic8EAmPwXLVy X-Proofpoint-GUID: Za2OcdZR6J49PblbNW8XI7MUw-qFoZla X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-09_04,2021-10-07_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 spamscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110090109 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a new cgroup is created or a cpuset is updated, the mask supplied to it looks for its corresponding CPU translations for the restrictions to apply on. The patch also updates the display interface such that tasks within the namespace can view the corresponding virtual CPUset based on the requested CPU namespace context. Signed-off-by: Pratik R. Sampat --- kernel/cgroup/cpuset.c | 57 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index adb5190c4429..eb1e950543cf 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -65,6 +65,7 @@ #include #include #include +#include DEFINE_STATIC_KEY_FALSE(cpusets_pre_enable_key); DEFINE_STATIC_KEY_FALSE(cpusets_enabled_key); @@ -1061,8 +1062,19 @@ static void update_tasks_cpumask(struct cpuset *cs) struct task_struct *task; css_task_iter_start(&cs->css, 0, &it); - while ((task = css_task_iter_next(&it))) + while ((task = css_task_iter_next(&it))) { +#ifdef CONFIG_CPU_NS + cpumask_t pcpus; + cpumask_t vcpus; + + pcpus = get_pcpus_cpuns(current->nsproxy->cpu_ns, cs->effective_cpus); + vcpus = get_vcpus_cpuns(task->nsproxy->cpu_ns, &pcpus); + cpumask_copy(&task->nsproxy->cpu_ns->v_cpuset_cpus, &vcpus); + set_cpus_allowed_ptr(task, &pcpus); +#else set_cpus_allowed_ptr(task, cs->effective_cpus); +#endif + } css_task_iter_end(&it); } @@ -2212,8 +2224,18 @@ static void cpuset_attach(struct cgroup_taskset *tset) * can_attach beforehand should guarantee that this doesn't * fail. TODO: have a better way to handle failure here */ - WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach)); +#ifdef CONFIG_CPU_NS + cpumask_t pcpus; + cpumask_t vcpus; + pcpus = get_pcpus_cpuns(current->nsproxy->cpu_ns, cpus_attach); + vcpus = get_vcpus_cpuns(task->nsproxy->cpu_ns, &pcpus); + cpumask_copy(&task->nsproxy->cpu_ns->v_cpuset_cpus, &vcpus); + + WARN_ON_ONCE(set_cpus_allowed_ptr(task, &pcpus)); +#else + WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach)); +#endif cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to); cpuset_update_task_spread_flag(cs, task); } @@ -2436,13 +2458,33 @@ static int cpuset_common_seq_show(struct seq_file *sf, void *v) switch (type) { case FILE_CPULIST: +#ifdef CONFIG_CPU_NS + if (current->nsproxy->cpu_ns == &init_cpu_ns) { + seq_printf(sf, "%*pbl\n", + cpumask_pr_args(cs->cpus_allowed)); + } else { + seq_printf(sf, "%*pbl\n", + cpumask_pr_args(¤t->nsproxy->cpu_ns->v_cpuset_cpus)); + } +#else seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->cpus_allowed)); +#endif break; case FILE_MEMLIST: seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->mems_allowed)); break; case FILE_EFFECTIVE_CPULIST: +#ifdef CONFIG_CPU_NS + if (current->nsproxy->cpu_ns == &init_cpu_ns) { + seq_printf(sf, "%*pbl\n", + cpumask_pr_args(cs->effective_cpus)); + } else { + seq_printf(sf, "%*pbl\n", + cpumask_pr_args(¤t->nsproxy->cpu_ns->v_cpuset_cpus)); + } +#else seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->effective_cpus)); +#endif break; case FILE_EFFECTIVE_MEMLIST: seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems)); @@ -2884,9 +2926,18 @@ static void cpuset_bind(struct cgroup_subsys_state *root_css) */ static void cpuset_fork(struct task_struct *task) { +#ifdef CONFIG_CPU_NS + cpumask_t vcpus; +#endif + if (task_css_is_root(task, cpuset_cgrp_id)) return; - +#ifdef CONFIG_CPU_NS + if (task->nsproxy->cpu_ns != &init_cpu_ns) { + vcpus = get_vcpus_cpuns(task->nsproxy->cpu_ns, current->cpus_ptr); + cpumask_copy(&task->nsproxy->cpu_ns->v_cpuset_cpus, &vcpus); + } +#endif set_cpus_allowed_ptr(task, current->cpus_ptr); task->mems_allowed = current->mems_allowed; } -- 2.31.1