From patchwork Fri Oct 30 11:56:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 55831 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp1160774lbr; Fri, 30 Oct 2015 04:56:26 -0700 (PDT) X-Received: by 10.67.8.34 with SMTP id dh2mr8425625pad.70.1446206186425; Fri, 30 Oct 2015 04:56:26 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qg3si10506326pbb.100.2015.10.30.04.56.26; Fri, 30 Oct 2015 04:56:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1759469AbbJ3L4Z (ORCPT + 11 others); Fri, 30 Oct 2015 07:56:25 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:35579 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758999AbbJ3L4Y (ORCPT ); Fri, 30 Oct 2015 07:56:24 -0400 Received: by pasz6 with SMTP id z6so72955520pas.2 for ; Fri, 30 Oct 2015 04:56:23 -0700 (PDT) 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; bh=YP6ieJSbsgFbqBdfOv4WMsXHKKxea6AzK7rrelDG50E=; b=tvOzjj7fwYc6PjgVw7XZAThaj9eBzE538FhOFDTcTsfdEOg/9X/PHLE9B5VFNd1NPO 8YZO3hervdHx//9zFr9Ya7/kNOTQr87dI1ZjZabiWoZKJJdwmamYZhC+A//PIIWCkK8X 3DhphvsGz0nze6QNo4usEY0LgGYGDF3AhyrfGBq9DRm9YkV2gbxeoH9f6lR32IRPoGFX ad9PGKQchJWr7TnsbIO94TzPU1Xul9X/tjIJHHqku1QpRPUf+YuADmLYvvlpEx0I/5cD veJGl1bTGIudvbFjxC+5LeJ5B/oEmL3+O0fTB4SLg6EjvKqnJz/q1zRjf/MQWVUXa+kz sCHQ== 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; bh=YP6ieJSbsgFbqBdfOv4WMsXHKKxea6AzK7rrelDG50E=; b=DwUYvAvvgwK2YRXGotIl2Oh10X/vkxpWStPdwRyi3U1z3zV65HEmke+NPKd7behI0H hWUq8YjKpUmXkwV9tyA/jxfcBTY+E4CXXthJ8693SeC8VPucxUK7YzUQm6140bcNPK4A b1L6peTnSqHyCtwyuOfYfmT/L0/hSA33c67kkSwebZXdlmyFIjIrrclcO/DZg7PtSQ97 bD/NFY3tdPxaimJ0fagBhhWA9xIDk/Q/VAAvF4i0uWvekSGimAT35qcZpnQCHHrel2ce bIkM92Glr7c983zpXHf76qc1ech0CjZ7dbamd8Zg4DqPqLEIlXEVe70ShhrJntjYiwjp IAuQ== X-Gm-Message-State: ALoCoQk0PbNdaH+x+a/PceTbxhpXCbJztbuEfNuy+oe2K06f92nuA1Wvjc7aJfUThLeXWf2aA2tu X-Received: by 10.66.170.238 with SMTP id ap14mr8205500pac.128.1446206183700; Fri, 30 Oct 2015 04:56:23 -0700 (PDT) Received: from localhost ([122.172.111.169]) by smtp.gmail.com with ESMTPSA id lo9sm7878430pab.19.2015.10.30.04.56.22 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 30 Oct 2015 04:56:23 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , mturquette@baylibre.com Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Viresh Kumar , Bartlomiej Zolnierkiewicz , Dan Carpenter , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Nishanth Menon , Pavel Machek , Stephen Boyd Subject: [PATCH] PM / OPP: Protect updates to list_dev with mutex Date: Fri, 30 Oct 2015 17:26:06 +0530 Message-Id: <5f8fac4ad84716ef68fc50ab0b78e11ad2837524.1446205160.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.6.2.198.g614a2ac Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 will see the caller vomiting. Fixes: 8d4d4e98acd6 ("PM / OPP: Add helpers for initializing CPU OPPs") Reported-by: Michael Turquette Signed-off-by: Viresh Kumar --- Mike: Can you please verify if this fixes it for you.. 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-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index d5c1149ff123..69f83cbe37b2 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -27,7 +27,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 7654c5606307..91f15b2e25ee 100644 --- a/drivers/base/power/opp/cpu.c +++ b/drivers/base/power/opp/cpu.c @@ -124,12 +124,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) { @@ -150,8 +150,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 0; } 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: