Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752000AbdITPfF (ORCPT ); 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 X-Google-Smtp-Source: AOwi7QAlE//115IsrDUSq2lRo17y+aesr0Sy1de+CAUeC3nkmJSgNXA3rdGHRjf2R1c5wS7blsh1sw== 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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1657 Lines: 46 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(+) 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; } -- 2.7.4