From patchwork Wed Sep 20 15:34:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 113152 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp909111qgf; Wed, 20 Sep 2017 08:35:07 -0700 (PDT) X-Received: by 10.99.149.84 with SMTP id t20mr2707711pgn.222.1505921707119; Wed, 20 Sep 2017 08:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505921707; cv=none; d=google.com; s=arc-20160816; b=n2rygV3O6ywyg+CkY1yDqbw7YfaJymxxWO4o8i68TXH94WILUX8IK5qIhuFzpUoF3f WMD/xUSLIp5PCiWYA5LDyLDzrbbIuwEVU/BKK31/FLDlwoebfHSz+Gsr/+IJBulIiztJ RRFgRM+u7zH77K9Y8Js82hcoOTmOb+MjqOmvQykdJUCaBAoCeD/IPZ9HTmTssBP9e7ns JkHDndrPPpWKqe9Pij9OnAwtMXFXoQ+aWtnp8X5ClSrJUlFFzUPijsJmIDRyW2GGvm8d zekPPt0qqF1mGv5vTUWvHoasVM9QwKzRr12YH4bTg32K3k2e+sxLXrGBwaMXE0idMZCg rvOw== 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=dWyYJlxHptaWzRM0hTG2IF4Xl5yaYudfXCxHCVvIciU=; b=B/8db/+1jUka6E/GoaUcOpt/NZM2Gdc7KbzhE623kjQIL41/UEr+lHIlDy3WM4HmsD 0BkkPBcGT6ntNvSgkv0WsxFLwTXJFOdYs6bvrLhgNi5bbMOZ2ONc6bMlG62eI8XmyM7R 3f1SDuTahpCj1FVMmSdCmNBffa1NHYrSMbVvnwMK2yzHatrRcpMDV+260uDqUn0q9QC9 ZunjwjoYelc86w6K78Z5+UV0U4+y5WEPW0fsmDbdZRyd1+xc7vrzmMyULBqsT7WCmkXX K1dEFFELyA+Zea2O2YoVzOhH1XDCZjfmrqdj0hEChiVr7Xd/2Q6pvA5Y32dc3oz9F/LX l0NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CebhZvov; 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 p1si1231146pld.599.2017.09.20.08.35.06; Wed, 20 Sep 2017 08:35:07 -0700 (PDT) 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=CebhZvov; 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 S1752001AbdITPfF (ORCPT + 26 others); Wed, 20 Sep 2017 11:35:05 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:54265 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751785AbdITPfD (ORCPT ); Wed, 20 Sep 2017 11:35:03 -0400 Received: by mail-pg0-f43.google.com with SMTP id j70so1867402pgc.10 for ; Wed, 20 Sep 2017 08:35:03 -0700 (PDT) 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=dWyYJlxHptaWzRM0hTG2IF4Xl5yaYudfXCxHCVvIciU=; b=CebhZvovcODguKl3GGHdEwwK3fjSw6sSPW0CFFxJl/02BfxEkzA4A/8+B8SDYfvze0 KykNFemGfAP7XJUO6yX39yWd79E3YPVHPR024BjhNWm8JGqiKdR96ZkN0e5b8KVZg9O6 QU/UzM6faR1avZ9roxTX968tv0/KAUdDKxeY4= 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=dWyYJlxHptaWzRM0hTG2IF4Xl5yaYudfXCxHCVvIciU=; b=RWzyVg3648va74WLQqJEZgLX0VkQ+k1z6lHsISOIV6M8CvGOpHpGnTsIZFjl6l13jP LjoLUFgQS4y0r9QJBoLlsRon2Q6UnWl/MZUJ3mAyu4WGwp1H50y4oOo/YC5MA4STDtaT jwgYFTG26oploc6nyX5sHhmgor3lNGOlOhagiDiYYegAf7tN7dU7FVYgsPsywxBhLNby cDsaL0mDksp6FM5ZMLNdv2Q2hRawAmfih1ZPYlMuebjXJnwfHgtV19QrgfJMlx5aAFmR H6uoY1hr3VF0AT4Z4VUArP12vFaSQfVjnCrOqIvtpPb3sIKtknblq9UFqTQ7VGwt4mtO T9/A== X-Gm-Message-State: AHPjjUhhdEzkwM5s/YCylmTRLBW1EX6M+C7Yl4+xo8FraHtCtfKlF97N 6kot+uRpqJH+ss6ZtAI/idr4cWoTmC0= X-Google-Smtp-Source: AOwi7QAlE//115IsrDUSq2lRo17y+aesr0Sy1de+CAUeC3nkmJSgNXA3rdGHRjf2R1c5wS7blsh1sw== X-Received: by 10.101.68.65 with SMTP id e1mr2664012pgq.134.1505921703001; Wed, 20 Sep 2017 08:35:03 -0700 (PDT) Received: from localhost (cpe-172-88-64-62.socal.res.rr.com. [172.88.64.62]) by smtp.gmail.com with ESMTPSA id h90sm13115641pfj.32.2017.09.20.08.35.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 08:35:02 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , cw00.choi@samsung.com, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , myungjoo.ham@samsung.com, inki.dae@samsung.com, linux-kernel@vger.kernel.org Subject: [PATCH] PM / OPP: Call notifier without holding opp_table->lock Date: Wed, 20 Sep 2017 08:34:51 -0700 Message-Id: <45c7e892a69c4936993c65c9987981dbe4433148.1505920911.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <59C2414E.6020803@samsung.com> References: <59C2414E.6020803@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The notifier callbacks may want to call some OPP helper routines which may try to take the same opp_table->lock again and cause a deadlock. One such usecase was reported by Chanwoo Choi, where calling dev_pm_opp_disable() leads us to the devfreq's OPP notifier handler, which further calls dev_pm_opp_find_freq_floor() and it deadlocks. We don't really need the opp_table->lock to be held across the notifier call though, all we want to make sure is that the 'opp' doesn't get freed while being used from within the notifier chain. We can do it with help of dev_pm_opp_get/put() as well. Lets do it. Reported-by: Chanwoo Choi Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.7.4 diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 4360b4efcd4c..668fd940d362 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -1627,6 +1627,9 @@ static int _opp_set_availability(struct device *dev, unsigned long freq, opp->available = availability_req; + dev_pm_opp_get(opp); + mutex_unlock(&opp_table->lock); + /* Notify the change of the OPP availability */ if (availability_req) blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ENABLE, @@ -1635,8 +1638,12 @@ static int _opp_set_availability(struct device *dev, unsigned long freq, blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_DISABLE, opp); + dev_pm_opp_put(opp); + goto put_table; + unlock: mutex_unlock(&opp_table->lock); +put_table: dev_pm_opp_put_opp_table(opp_table); return r; }