From patchwork Thu Sep 21 17:44:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 113924 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp2145249edb; Thu, 21 Sep 2017 10:44:43 -0700 (PDT) X-Received: by 10.99.113.94 with SMTP id b30mr6489401pgn.312.1506015883529; Thu, 21 Sep 2017 10:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506015883; cv=none; d=google.com; s=arc-20160816; b=KldT7/nV1zG69xIji7VetfZzGlDXOQsFtcDNzxdiTZpLn6cwKbR5THdV1ppDfFyfKg L0nI4s/56BJIHVEDAwwjuJdr5I+gGAYxO2HsUVCsjzh7tAw+ab1wI/DRnwLNmFhMmWJ8 lDmuXFZLcBAwDL+bS6oE0r6scg6WcP/K6NiTTPenAGhXL5ox9y/cdVupSTj2v+U5l2XR jWG9dSfOnkwfVfrUE3ZMI9cKxm6Bn+VoBMABPdUPuOAZsAA7R00xa3ar5vJ6N2TGjd0j LtnPwIfK/GUTGL3Y0M+YBw8fuLbG6SOa8AcqcuDmc/Oxt3yfmiFZKWNbvx6K3+iZEqAZ oVGA== 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=YBNsruBlfrNOAXC16jX10dNvz/qoTasKSVEgdkAtRK0=; b=pXh734Es/j5I3tCUdOlYQ51t4bnTnd80k34gsiPdQXi+plB+N5hFButEIkk1yrqU1V iSqXA7u49gvVijlbq1K4fYU6aUIEoqILZlkSifsyiSda1HWD0LkbUgdxhv1q+zksuiuC ZbSkuHjkIAVik8Kl8AGNKpdse9h4rHTyHw3AuqlMECeMbvlg6EH8lqwo/7cYUz8JFOFQ ZGDF8jick8bI7kWw+bqaHr5zfKiMr9AZ/9U3l++VGHjEJOECaD/CrHk9piNYavu9sE6v zcVN4s7/Y88zqjWj021dRzp9or+mFuKyB+lT9LAkiwSFxn1YwOiloTIqhZrK5hSTiBjh P1dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G8FjbUvs; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 k1si1359780pgs.420.2017.09.21.10.44.43; Thu, 21 Sep 2017 10:44:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=G8FjbUvs; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S1751801AbdIURom (ORCPT + 8 others); Thu, 21 Sep 2017 13:44:42 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:49660 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751793AbdIURol (ORCPT ); Thu, 21 Sep 2017 13:44:41 -0400 Received: by mail-pg0-f41.google.com with SMTP id m30so3897858pgn.6 for ; Thu, 21 Sep 2017 10:44:41 -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=YBNsruBlfrNOAXC16jX10dNvz/qoTasKSVEgdkAtRK0=; b=G8FjbUvspA1Wva3QlgDkGZ9O+PcxCpa2nWy9pHTDxV4hnZ44hsbl+sCZD2i31LlitO KE4jRosfI7QDrL75OCKP9baiOM43DYu5pfg4gh0LZA0dCv7L33w65L13CsQ1fpYwTR8M UK7dxHT/vL3Zzo0FlwdO8VeunPl9jNgz4dIlQ= 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=YBNsruBlfrNOAXC16jX10dNvz/qoTasKSVEgdkAtRK0=; b=hTaLTH1DuSnIkdIIt8RlAgDxgDa9T/nQbX9OQ65CumosZfUVoOVVuATDgpuNTM5Ptq xn/uo5jfPcOTJrjrUzchkrMuGOD+d8DD5DeEQ+BVbTh9+LRTB+MN026NqeeEpfwQcSXY O09xee1vpqSzRr/yJC0ePTm8K69M5M3+DhileR9edouHAaocG43/VPAWW8LaUBJQxo1v M4G6mJWDBf9gx+9brO2lWZ4mWeZQnViVCAxF2d2netmzLAgmbbpxPCt7W1FKV4PRrH0U CY6Z8oTlgXezcqBifQbXAGxZB2V68xeD4Zou/HkCkgd+ZrClZ2vYJ2dSri772ClM3qSV I+Ew== X-Gm-Message-State: AHPjjUiThvWbMQ8hjWwgP8KKk9QCQvG2C5EQhb1SY/ZV9o+ymYjtmf6e aDSjbAIigrFA8Zhpd+mKOHrVDQ== X-Google-Smtp-Source: AOwi7QDCRDLZN4/zuW4yHkQfLUmxpElrcXZZa3oyWNVU/JtnwI229iaDT5Jz4VRiG0jCyApsxoykLg== X-Received: by 10.99.121.77 with SMTP id u74mr6349405pgc.180.1506015880829; Thu, 21 Sep 2017 10:44:40 -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 d126sm4222994pgc.85.2017.09.21.10.44.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 10:44:39 -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, "4 . 11+ # 4 . 11+" , linux-kernel@vger.kernel.org Subject: [PATCH V3] PM / OPP: Call notifier without holding opp_table->lock Date: Thu, 21 Sep 2017 10:44:36 -0700 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: <59C2414E.6020803@samsung.com> References: <59C2414E.6020803@samsung.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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. Let's do it. Cc: 4.11+ # 4.11+ Fixes: 5b650b388844 ("PM / OPP: Take kref from _find_opp_table()") Reported-by: Chanwoo Choi Reviewed-by: Stephen Boyd Reviewed-by: Chanwoo Choi Tested-by: Chanwoo Choi Signed-off-by: Viresh Kumar --- V2->V3: - Added fixes, Cc and tags from Chanwoo. 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; }