From patchwork Thu Nov 5 08:51:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 56026 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp278720lbr; Thu, 5 Nov 2015 00:52:07 -0800 (PST) X-Received: by 10.50.73.228 with SMTP id o4mr1749638igv.37.1446713527498; Thu, 05 Nov 2015 00:52:07 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c19si5475881iod.106.2015.11.05.00.52.07; Thu, 05 Nov 2015 00:52:07 -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; 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; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033130AbbKEIwD (ORCPT + 28 others); Thu, 5 Nov 2015 03:52:03 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:33844 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032974AbbKEIvz (ORCPT ); Thu, 5 Nov 2015 03:51:55 -0500 Received: by padhx2 with SMTP id hx2so73538963pad.1 for ; Thu, 05 Nov 2015 00:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=YD5mV/brIWuMBPrh/617z73sYv/PN5JKpibFk7TJRow=; b=tFRRE8MaTVhFbXwkMOG+dWKiNSZ4lVKMMU8N/TAAV2YoFMcBHYhGxI5IHKN0tF5XPj X7lC6YhangY9c99jZyX9rpdpfU7IZGgqDeICna2Ozs8WH3/ygqbgXxQtD/RAjJsncAhk LQCbK3MaRnup6+S3dbimZ3Vt0kg4aj1LejLM0Wa6Fpddo7QYkEHmS2jC843VkoXjy3A6 ldh6v/7vyHAA+z3iKRWke8rJ0lIcXlGK4EgENlox5MYj7/3WMbvaBy6WSEObT6DQshEC WoCoUnN+Ew9KHJFMJKIt42Kl2xtZCg7fUvqPRETd94jZ8dMtYTZ/hXJLHvgHPa/b7LX9 ASsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=YD5mV/brIWuMBPrh/617z73sYv/PN5JKpibFk7TJRow=; b=Pkl9XDF8jGsmqMoOtRBfEvI+2tIacXa6t6Z0715sQOvGKU2m2K4YtxkG1MOokoOoOe QDEnGRX73bXBDsGq8oQTqqAn+XsVg+ceGwk9uNhmhcwG4r2YSmvOGixZRCAOAsaKFB0h Y/B0c3gYrYzTh9UUj2K6fv/BWe+LMKc5ga3aK8dVXFQZhqIQv8vTEOoDMjqXnHGjNH/M H10ivswp5jHV2FmRras/nl7LyMSBbkDvVxfrWeJcGw7/ezGbbIrZ/Gr6dteqpLL38wQP 0KxLIRAxC/jzJtfK5xx+3ldCbHdRg7lvM/OUg9Q7+mNAD7nR9SSm8r1tBbQ+1GT1kJ0p hk1w== X-Gm-Message-State: ALoCoQml5781VyOgPtm1tgKKuW9YUakOrgaiA+k7jX2veYRpCmGAL90tOCs8Mevhd5sxdRyrVYzw X-Received: by 10.68.249.68 with SMTP id ys4mr8047373pbc.124.1446713515008; Thu, 05 Nov 2015 00:51:55 -0800 (PST) Received: from localhost ([122.172.111.169]) by smtp.gmail.com with ESMTPSA id ij3sm6505411pbb.62.2015.11.05.00.51.53 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Nov 2015 00:51:54 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar , "4 . 3 # 4 . 3" , Michael Turquette , Bartlomiej Zolnierkiewicz , Dan Carpenter , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Nishanth Menon , Pavel Machek Subject: [PATCH V2 2/4] PM / OPP: Protect updates to list_dev with mutex Date: Thu, 5 Nov 2015 14:21:19 +0530 Message-Id: <659a9d35df63661e056b1497cf45729afc30db71.1446713282.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.6.2.198.g614a2ac In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dev_opp_list_lock is used everywhere to protect device and OPP lists, but dev_pm_opp_set_sharing_cpus() is missed somehow. And instead we used rcu-lock, which wouldn't help here as we are adding a new list_dev. This also fixes a problem where we have called kzalloc(..., GFP_KERNEL) from within rcu-lock, which isn't allowed as kzalloc can sleep when called with GFP_KERNEL. With CONFIG_DEBUG_ATOMIC_SLEEP set, we get following lockdep-splat: include/linux/rcupdate.h:578 Illegal context switch in RCU read-side critical section! other info that might help us debug this: rcu_scheduler_active = 1, debug_locks = 0 5 locks held by swapper/0/1: #0: (&dev->mutex){......}, at: [] __driver_attach+0x48/0x98 #1: (&dev->mutex){......}, at: [] __driver_attach+0x58/0x98 #2: (cpu_hotplug.lock){++++++}, at: [] get_online_cpus+0x40/0xb0 #3: (subsys mutex#5){+.+.+.}, at: [] subsys_interface_register+0x44/0xdc #4: (rcu_read_lock){......}, at: [] dev_pm_opp_set_sharing_cpus+0x0/0x1e4 stack backtrace: CPU: 1 PID: 1 Comm: swapper/0 Tainted: G W 4.3.0-rc7-00047-g81f5932958a8 #59 Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0x94/0xbc) [] (dump_stack) from [] (___might_sleep+0x24c/0x298) [] (___might_sleep) from [] (kmem_cache_alloc+0xe8/0x164) [] (kmem_cache_alloc) from [] (_add_list_dev+0x30/0x58) [] (_add_list_dev) from [] (dev_pm_opp_set_sharing_cpus+0xd0/0x1e4) [] (dev_pm_opp_set_sharing_cpus) from [] (cpufreq_init+0x4cc/0x62c) [] (cpufreq_init) from [] (cpufreq_online+0xbc/0x73c) [] (cpufreq_online) from [] (subsys_interface_register+0x98/0xdc) [] (subsys_interface_register) from [] (cpufreq_register_driver+0x110/0x17c) [] (cpufreq_register_driver) from [] (dt_cpufreq_probe+0x60/0x8c) [] (dt_cpufreq_probe) from [] (platform_drv_probe+0x44/0xa4) [] (platform_drv_probe) from [] (driver_probe_device+0x208/0x2f4) [] (driver_probe_device) from [] (__driver_attach+0x94/0x98) [] (__driver_attach) from [] (bus_for_each_dev+0x68/0x9c) Cc: 4.3 # 4.3 Reported-by: Michael Turquette Reviewed-by: Stephen Boyd Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 2 +- drivers/base/power/opp/cpu.c | 8 ++++---- drivers/base/power/opp/opp.h | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) -- 2.6.2.198.g614a2ac -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 8fa522f41226..a93a433c9ac5 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -29,7 +29,7 @@ */ static LIST_HEAD(dev_opp_list); /* Lock to allow exclusive modification to the device and opp lists */ -static DEFINE_MUTEX(dev_opp_list_lock); +DEFINE_MUTEX(dev_opp_list_lock); #define opp_rcu_lockdep_assert() \ do { \ diff --git a/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c index 2139c9d4c447..7b445e88a0d5 100644 --- a/drivers/base/power/opp/cpu.c +++ b/drivers/base/power/opp/cpu.c @@ -127,12 +127,12 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask) struct device *dev; int cpu, ret = 0; - rcu_read_lock(); + mutex_lock(&dev_opp_list_lock); dev_opp = _find_device_opp(cpu_dev); if (IS_ERR(dev_opp)) { ret = -EINVAL; - goto out_rcu_read_unlock; + goto unlock; } for_each_cpu(cpu, cpumask) { @@ -153,8 +153,8 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask) continue; } } -out_rcu_read_unlock: - rcu_read_unlock(); +unlock: + mutex_unlock(&dev_opp_list_lock); return ret; } diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index dcb38f78dae4..7366b2aa8997 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -21,6 +21,9 @@ #include #include +/* Lock to allow exclusive modification to the device and opp lists */ +extern struct mutex dev_opp_list_lock; + /* * Internal data structure organization with the OPP layer library is as * follows: