From patchwork Tue Feb 13 20:32:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 128300 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp33654ljc; Tue, 13 Feb 2018 12:35:00 -0800 (PST) X-Google-Smtp-Source: AH8x22566Le97uVWa8yRteNN57Ts24DFUIGjRlzwnqaZV3k9GLxQwMDmZqrBPUvoKWULtgWLRVHa X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr2223776pln.345.1518554100088; Tue, 13 Feb 2018 12:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554100; cv=none; d=google.com; s=arc-20160816; b=SD4XFuRhutkkUsT8nq52zd7JHJoX2tyIj/m2FemiLsKCFIbykBdjQsBMv0jSqVIHhp p45inj5yvs7QpJoGq3/NVFahKxufOAZ97aTlL3gNDoswBVbi6fz73LWxbvokRGnuXPjt WVPGmgsOpG41E3gaXCIZxjWIkXGZXFrOANd8SDtRr1KHyxkFdE+5OL5VPbJhY36vQASs hJ6zjfRBoaDkr0ahEhHIjkxN1Se8R/68f0VyJqiDmijnFSm/gay2uDb2ZGHqs8ajopb2 IlESJN0PNNNXlkc2bbvwGdHX1sfJjsVsateb1HK/ifmEO5OyGgYqXPPlbFuOqte9S9Vh s0bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Rrh4DAOTBW2ljGohKEk/qZ/6oqcBMfBa1z5aftfWH5k=; b=TZvCSOHTGRyHBBLdOlYTvXkTL5l66uTc/KHtsBO2bHI+5D03NEkvkz5DD/JdV6ddae yEbeztkfrgosy9f59ZUz6a1N3OAaeUOCZbORxb70aoEezapQYjjkqdgSTwwLsaQfuWLD CNw4eUxY0t3YnW1KaKFfwsQV7aDl0CG+xCF52mwvHHLejJe4n9S4r9ThDShrmkXSKWoP QUWPPjqynCtg+/Tm9QTtFwfMlFdAb5DTcnpMCSK9A5PJNMjIHsg4mymuZQ3Q2NXlKDW/ PhPYnxDB9KQ6WqqKUgYkCwLkno6ue+38Vudnid0LskeeGMhegd0uSCtcHGbVSS8qDu5M rpfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KeDDm7Th; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t133si281281pgc.158.2018.02.13.12.34.59; Tue, 13 Feb 2018 12:35:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KeDDm7Th; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965918AbeBMUe5 (ORCPT + 28 others); Tue, 13 Feb 2018 15:34:57 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33687 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965795AbeBMUc5 (ORCPT ); Tue, 13 Feb 2018 15:32:57 -0500 Received: by mail-pg0-f66.google.com with SMTP id g12so684354pgs.0 for ; Tue, 13 Feb 2018 12:32:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Rrh4DAOTBW2ljGohKEk/qZ/6oqcBMfBa1z5aftfWH5k=; b=KeDDm7ThA8dMcMlwVymErZqolbPxpadLCV0q56Uh098JOTh9Tzv+GCd8Xnqct8bd8r 10/e+HGlSwMcb/FmkhUis0NGuViB+I8jcQtjEzwquy7BzVKdYrEz1WO/+mDLLt6SDSML NbJgYPR06XBvz6mq6sOAY2dBUyqjQekR9NrZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Rrh4DAOTBW2ljGohKEk/qZ/6oqcBMfBa1z5aftfWH5k=; b=k/OzTSoxFgFDowYAv228BNw+YijCM2oYuJJwyhzk4o3XtYE2GUo4RET1saGhtsT/kx wS6qF7jfjAse4dRjJ343dAiFGQfmB8Tm7MAR/q0BoC40uCwulTQLf3LUa8nTNZR6oT0F P3QP8w2W90fq0tm9ii7HzpcgvWMcMTgZ4d2s86YKfCr7jsNZuA4HUgzIoAhXXisg4UfP ESHM5r06lb9cOi1p2JNa7LkINqlnoVma9nX5/GvjGvhD01ZQoY51ywtJ9z8EwYvtctBX nxY2iEfkqM3rzccjtg/cqEcq3uEiFYrDBltH4Ga8/BSVq7Vre0lDme4j9JIsGk7w6NBv bwTA== X-Gm-Message-State: APf1xPAk2QQSU9zkVD3v+8V4gf3EJMhk+Rm+n2SHAS7g83nfnCMnwyJ3 zVryrJ2qBTX1TvfC7G29Lz9vIg== X-Received: by 10.101.88.205 with SMTP id e13mr1437491pgu.121.1518553977031; Tue, 13 Feb 2018 12:32:57 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id o135sm35540873pfg.45.2018.02.13.12.32.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:32:56 -0800 (PST) From: Mathieu Poirier To: peterz@infradead.org Cc: lizefan@huawei.com, mingo@redhat.com, rostedt@goodmis.org, claudio@evidence.eu.com, bristot@redhat.com, tommaso.cucinotta@santannapisa.it, juri.lelli@redhat.com, luca.abeni@santannapisa.it, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 04/10] sched/core: Prevent race condition between cpuset and __sched_setscheduler() Date: Tue, 13 Feb 2018 13:32:41 -0700 Message-Id: <1518553967-20656-5-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> References: <1518553967-20656-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No synchronisation mechanism exist between the cpuset subsystem and calls to function __sched_setscheduler(). As such it is possible that new root domains are created on the cpuset side while a deadline acceptance test is carried out in __sched_setscheduler(), leading to a potential oversell of CPU bandwidth. By making available the cpuset_mutex to the core scheduler it is possible to prevent situations such as the one described above from happening. Signed-off-by: Mathieu Poirier --- include/linux/cpuset.h | 6 ++++++ kernel/cgroup/cpuset.c | 16 ++++++++++++++++ kernel/sched/core.c | 9 +++++++++ 3 files changed, 31 insertions(+) -- 2.7.4 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index 934633a05d20..4bbb3f5a3020 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h @@ -55,6 +55,8 @@ extern void cpuset_init_smp(void); extern void cpuset_force_rebuild(void); extern void cpuset_update_active_cpus(void); extern void cpuset_wait_for_hotplug(void); +extern void cpuset_lock(void); +extern void cpuset_unlock(void); extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); extern void cpuset_cpus_allowed_fallback(struct task_struct *p); extern nodemask_t cpuset_mems_allowed(struct task_struct *p); @@ -176,6 +178,10 @@ static inline void cpuset_update_active_cpus(void) static inline void cpuset_wait_for_hotplug(void) { } +static inline void cpuset_lock(void) { } + +static inline void cpuset_unlock(void) { } + static inline void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask) { diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index d18c72e83de4..41f8391640e6 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2410,6 +2410,22 @@ void __init cpuset_init_smp(void) } /** + * cpuset_lock - Grab the cpuset_mutex from another subsysytem + */ +void cpuset_lock(void) +{ + mutex_lock(&cpuset_mutex); +} + +/** + * cpuset_unlock - Release the cpuset_mutex from another subsysytem + */ +void cpuset_unlock(void) +{ + mutex_unlock(&cpuset_mutex); +} + +/** * cpuset_cpus_allowed - return cpus_allowed mask from a tasks cpuset. * @tsk: pointer to task_struct from which to obtain cpuset->cpus_allowed. * @pmask: pointer to struct cpumask variable to receive cpus_allowed set. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f727c3d0064c..0d8badcf1f0f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4176,6 +4176,13 @@ static int __sched_setscheduler(struct task_struct *p, } /* + * Make sure we don't race with the cpuset subsystem where root + * domains can be rebuilt or modified while operations like DL + * admission checks are carried out. + */ + cpuset_lock(); + + /* * Make sure no PI-waiters arrive (or leave) while we are * changing the priority of the task: * @@ -4247,6 +4254,7 @@ static int __sched_setscheduler(struct task_struct *p, if (unlikely(oldpolicy != -1 && oldpolicy != p->policy)) { policy = oldpolicy = -1; task_rq_unlock(rq, p, &rf); + cpuset_unlock(); goto recheck; } @@ -4316,6 +4324,7 @@ static int __sched_setscheduler(struct task_struct *p, unlock: task_rq_unlock(rq, p, &rf); + cpuset_unlock(); return retval; }