Received: by 10.223.164.202 with SMTP id h10csp2924637wrb; Tue, 28 Nov 2017 03:38:39 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ7quqRuuBB2vP0uNtANV4qykmHQamPTZhZYYw1ufmUROvI/Gkcz30DfkqHShNe06SF8rqv X-Received: by 10.84.174.131 with SMTP id r3mr33316935plb.358.1511869119272; Tue, 28 Nov 2017 03:38:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511869119; cv=none; d=google.com; s=arc-20160816; b=S1IJz5o1Hv5z+t+NA3xPz0BkJssavSWUNtzuse3LFTbfPx2kSlDk22s4KLUMvZGxpn 4OZXxc1tyyG7Wv5J/86RpqZT4nF6tlZD/AbjcGGBqD3Y/3S0MuAiPqUXRqfndNwvJNvJ fw1mmsqQySSQVwLVu2o2eUnNZf7RI2nGU95eLFYqoqYeAuZfVdudtEfQHgs7zpJttZT/ hFm8wCZ0GdHaEPcE2jHW0LtFJP2+uU7VcbE6jf4BkrNQicft89SMIgCERJYHT9a6EZ0Z 3UvyqBPy9mzMKasj8+ya2TvecgIeFI1Ej5UpQPPlI8S6YtwsYws8SKIsyo7kLlZlx3lq dY8w== 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:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=ceO8lrKYI5m4/N1jPdnZQqdZg1kwZzV02scgLR3ExaA=; b=zEhPVFSAY4+uljxDUGPQw4r5eORZOqYImlenJ0PllWHd3tDO8b3xMx4ecjRPk3oiBq 2Mn1zGSWdVZx8wfd/sEjpaDi6qSlSJlYbfrpKmNs1e/1xiqSBnpuVD5YUoZ6TkAHm5/F +ajgmWRn+6Y1k9gRZQakCkLfK60CqcdAfgx8PCqh7Nx77hJRjLl5duitJvXYykUzbwAu qoY1NewY4IaU+UO/kcjUzuLYx8YDx0xIszcK7955UZoeLKxWgV+nRdPHfEFJ+NKW82kn i1DnQM7sGG/TTm6HH5XOFXL+NcETHkpN8aN1HfTAeeNZsXzgMadFBlDp08+5ZYrFXgBG yreg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=nNAqplFQ; dkim=pass header.i=@codeaurora.org header.s=default header.b=nNAqplFQ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si8262115plc.483.2017.11.28.03.38.27; Tue, 28 Nov 2017 03:38:39 -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=@codeaurora.org header.s=default header.b=nNAqplFQ; dkim=pass header.i=@codeaurora.org header.s=default header.b=nNAqplFQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755245AbdK1LgJ (ORCPT + 78 others); Tue, 28 Nov 2017 06:36:09 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:50558 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752118AbdK1LgH (ORCPT ); Tue, 28 Nov 2017 06:36:07 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B72D2629DA; Tue, 28 Nov 2017 11:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511868966; bh=x8CDmJx3Nu2ejOPlJ3X8ZV8pF/pKycbDCIr8nuCXgDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nNAqplFQsCMtULN1yadHBCHZclmqsu7UtkXoRCBSryUOBOguVywd6LLh/LAtLAOdF Zjf6PIK+Iu6gRscmBuy3fEtH9NYrQ+MfpWZ3nLmRyBlHkPCLi8LEsKDmUUIbRhwswa 1ILCm6nACXg/WxTW3LNISe0rHO7I7nF2ZJ20mmfQ= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from prsood-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: prsood@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id B6CCD60D88; Tue, 28 Nov 2017 11:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511868966; bh=x8CDmJx3Nu2ejOPlJ3X8ZV8pF/pKycbDCIr8nuCXgDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nNAqplFQsCMtULN1yadHBCHZclmqsu7UtkXoRCBSryUOBOguVywd6LLh/LAtLAOdF Zjf6PIK+Iu6gRscmBuy3fEtH9NYrQ+MfpWZ3nLmRyBlHkPCLi8LEsKDmUUIbRhwswa 1ILCm6nACXg/WxTW3LNISe0rHO7I7nF2ZJ20mmfQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B6CCD60D88 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=prsood@codeaurora.org From: Prateek Sood To: tj@kernel.org, avagin@gmail.com, mingo@kernel.org, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, sramana@codeaurora.org, Prateek Sood Subject: [PATCH] cgroup/cpuset: fix circular locking dependency Date: Tue, 28 Nov 2017 17:05:46 +0530 Message-Id: <1511868946-23959-1-git-send-email-prsood@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CPU1 cpus_read_lock+0x3e/0x80 static_key_slow_inc+0xe/0xa0 cpuset_css_online+0x62/0x330 online_css+0x26/0x80 cgroup_apply_control_enable+0x266/0x3d0 cgroup_mkdir+0x37d/0x4f0 kernfs_iop_mkdir+0x53/0x80 vfs_mkdir+0x10e/0x1a0 SyS_mkdirat+0xb3/0xe0 entry_SYSCALL_64_fastpath+0x23/0x9a CPU0 lock_acquire+0xec/0x1e0 __mutex_lock+0x89/0x920 cpuset_write_resmask+0x61/0x1100 cgroup_file_write+0x7b/0x200 kernfs_fop_write+0x112/0x1a0 __vfs_write+0x23/0x150 vfs_write+0xc8/0x1c0 SyS_write+0x45/0xa0 entry_SYSCALL_64_fastpath+0x23/0x9a CPU0 CPU1 ---- ---- lock(cpu_hotplug_lock.rw_sem); lock(cpuset_mutex); lock(cpu_hotplug_lock.rw_sem); lock(cpuset_mutex); Change locking order of cpu_hotplug_lock.rw_sem and cpuset_mutex in cpuset_css_online(). Use _cpuslocked() version for static_branch_inc/static_branch_dec in cpuset_inc()/cpuset_dec(). Signed-off-by: Prateek Sood --- include/linux/cpuset.h | 8 ++++---- include/linux/jump_label.h | 10 ++++++++-- kernel/cgroup/cpuset.c | 4 ++-- kernel/jump_label.c | 13 +++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index 2ab910f..5aadc25 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h @@ -40,14 +40,14 @@ static inline bool cpusets_enabled(void) static inline void cpuset_inc(void) { - static_branch_inc(&cpusets_pre_enable_key); - static_branch_inc(&cpusets_enabled_key); + static_branch_inc_cpuslocked(&cpusets_pre_enable_key); + static_branch_inc_cpuslocked(&cpusets_enabled_key); } static inline void cpuset_dec(void) { - static_branch_dec(&cpusets_enabled_key); - static_branch_dec(&cpusets_pre_enable_key); + static_branch_dec_cpuslocked(&cpusets_enabled_key); + static_branch_dec_cpuslocked(&cpusets_pre_enable_key); } extern int cpuset_init(void); diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index c7b368c..890e21c 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -160,6 +160,8 @@ extern void arch_jump_label_transform_static(struct jump_entry *entry, extern int jump_label_text_reserved(void *start, void *end); extern void static_key_slow_inc(struct static_key *key); extern void static_key_slow_dec(struct static_key *key); +extern void static_key_slow_incr_cpuslocked(struct static_key *key); +extern void static_key_slow_decr_cpuslocked(struct static_key *key); extern void jump_label_apply_nops(struct module *mod); extern int static_key_count(struct static_key *key); extern void static_key_enable(struct static_key *key); @@ -259,6 +261,8 @@ static inline void static_key_disable(struct static_key *key) #define static_key_enable_cpuslocked(k) static_key_enable((k)) #define static_key_disable_cpuslocked(k) static_key_disable((k)) +#define static_key_slow_incr_cpuslocked(k) static_key_slow_inc((k)) +#define static_key_slow_decr_cpuslocked(k) static_key_slow_dec((k)) #define STATIC_KEY_INIT_TRUE { .enabled = ATOMIC_INIT(1) } #define STATIC_KEY_INIT_FALSE { .enabled = ATOMIC_INIT(0) } @@ -414,8 +418,10 @@ struct static_key_false { * Advanced usage; refcount, branch is enabled when: count != 0 */ -#define static_branch_inc(x) static_key_slow_inc(&(x)->key) -#define static_branch_dec(x) static_key_slow_dec(&(x)->key) +#define static_branch_inc(x) static_key_slow_inc(&(x)->key) +#define static_branch_dec(x) static_key_slow_dec(&(x)->key) +#define static_branch_inc_cpuslocked(x) static_key_slow_incr_cpuslocked(&(x)->key) +#define static_branch_dec_cpuslocked(x) static_key_slow_decr_cpuslocked(&(x)->key) /* * Normal usage; boolean enable/disable. diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 227bc25..4ad8bae 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1985,7 +1985,7 @@ static int cpuset_css_online(struct cgroup_subsys_state *css) if (!parent) return 0; - mutex_lock(&cpuset_mutex); + cpuset_sched_change_begin(); set_bit(CS_ONLINE, &cs->flags); if (is_spread_page(parent)) @@ -2034,7 +2034,7 @@ static int cpuset_css_online(struct cgroup_subsys_state *css) cpumask_copy(cs->effective_cpus, parent->cpus_allowed); spin_unlock_irq(&callback_lock); out_unlock: - mutex_unlock(&cpuset_mutex); + cpuset_sched_change_end(); return 0; } diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 8594d24..dde0eaa 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -126,6 +126,12 @@ void static_key_slow_inc(struct static_key *key) } EXPORT_SYMBOL_GPL(static_key_slow_inc); +void static_key_slow_incr_cpuslocked(struct static_key *key) +{ + static_key_slow_inc_cpuslocked(key); +} +EXPORT_SYMBOL_GPL(static_key_slow_incr_cpuslocked); + void static_key_enable_cpuslocked(struct static_key *key) { STATIC_KEY_CHECK_USE(key); @@ -229,6 +235,13 @@ void static_key_slow_dec(struct static_key *key) } EXPORT_SYMBOL_GPL(static_key_slow_dec); +void static_key_slow_decr_cpuslocked(struct static_key *key) +{ + STATIC_KEY_CHECK_USE(key); + static_key_slow_dec_cpuslocked(key, 0, NULL); +} +EXPORT_SYMBOL_GPL(static_key_slow_decr_cpuslocked); + void static_key_slow_dec_deferred(struct static_key_deferred *key) { STATIC_KEY_CHECK_USE(key); -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project. From 1586076571287604507@xxx Wed Dec 06 22:48:09 +0000 2017 X-GM-THRID: 1586076571287604507 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread