From patchwork Wed Sep 20 20:25:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 113173 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp1091088edb; Wed, 20 Sep 2017 13:25:36 -0700 (PDT) X-Received: by 10.99.119.133 with SMTP id s127mr3441515pgc.271.1505939136589; Wed, 20 Sep 2017 13:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505939136; cv=none; d=google.com; s=arc-20160816; b=twiIV5ImpBTn5kaXtmP0UpMFhRQ7WA9AGORMGP7US6/be+Ohgh5ARPuyL20AYaceko T+iWi8ScTLmBfIx5Q9mNYKJ0Lkxj/AY0TPKQE+X5YVGJupgqcgd+5fSi+ad622znyXrz 7O4iEMHVHbeg8nLgRywUmeW+0Mc4XEW/9vab/BT3cuKbfe9lDAM6+4VODh99GtRKqLCY EgeVoporKcmhzU1OrhQeps/It82yEmoeLEXmFscYfDAQ65mvmWLQsz7HqULuCx/FY379 OzVxqS16PEa9+jJP+NORRe+gp7AS6X8AiJ71igzmx2BAclGQ9WMtcRcSNevOFJynNEYH CVmw== 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=DYggL3hLhyMr9D9/jmdhIEIBQvPM/Rlb+VdBAZpgkCw=; b=T9wgv/Q3HJ6lESHFsYdXAbZC+AkBOz3c99571b38slCkqeqM6uWLclKKF3ihatJ22M yenRq2+TDYz5EVVyaTqXjPKiAEic9eknwSoDW+Sf5aExJIE2i5zreJxDqtUAxctYzr3p heiutlNdtIXMW8xaC9l8sIUeS1tWhCVtzT1QXsc7JvpyzGJKEES8ZtdaxVGICUfKr3ke gnXAn9cMpgiyKN3YHJ0WHTNyzGnlf51zTgMU+ztie51igIqzUoKamzvADQp3KucxSSfE VE1VYKH/JaMFM7K8pyRKhjzCuPxMuwxEwH6ZdiQrMfo7Ys7dEG8bLHy3vlbuRC1R0Jv/ yMrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PpfwGzQ5; 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 60si1864172plc.579.2017.09.20.13.25.36; Wed, 20 Sep 2017 13:25:36 -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=PpfwGzQ5; 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 S1751646AbdITUZe (ORCPT + 26 others); Wed, 20 Sep 2017 16:25:34 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:48797 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390AbdITUZc (ORCPT ); Wed, 20 Sep 2017 16:25:32 -0400 Received: by mail-pf0-f171.google.com with SMTP id n24so2086584pfk.5 for ; Wed, 20 Sep 2017 13:25:32 -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=DYggL3hLhyMr9D9/jmdhIEIBQvPM/Rlb+VdBAZpgkCw=; b=PpfwGzQ5mTESSJsC5uvneaBKR0afO97SVmyWxWw9FaCqvawGWXe5SgfdTfDdSoCR3A N77mgZHRfZ1xQ0qYHxEnVsn5+28sPbLiHIaVmcHY/ooxwTPLLLpFxsi6dtEMvuHkq9TG PaLFLbcVzXILmL5uJVMK4VllCpTdhJG2fHdrM= 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=DYggL3hLhyMr9D9/jmdhIEIBQvPM/Rlb+VdBAZpgkCw=; b=RiZjS4L7wfCiwOMvFOk63fB0MO7uStW78QHMOaV/6YXj5NXwAYYldTsj0Hy4nLPufa TeJkmoFYWpL9P9Sq89Pxt2WVajTjvEbpqER6rABagfXdBctxZ9UbNWYVzCQLsdg0dqyH 0WbdiYFDdteGl8BmpMsiWFxurQmeY0d39LNqcFptzPnfAILiQqAAz0O9Rz1xmK6OvIEL 7d3vxn4/RZYDeY2Sd7AVgdqZ6TL8FqOZXXXex2YR7o3vpYbpMAmXcwgztOjrmaaqqLvV huHYeIQLxVzQYb4l0lPwL5ZLytJfU5MHtCgiLuHf0mXZpiKmBSznElXLrDwpi1SjK3D0 HqFQ== X-Gm-Message-State: AHPjjUj6siQVI/B0dED1aEXKASAGemGZGjRSqYl3o5cF5k8JfGDP9pl8 0Vkj/JBeync8pTNn5mQpuzkvbw== X-Google-Smtp-Source: AOwi7QDRNGbr8l+KEN1nDGGWYi7wZ03CGO1NJz2u+f+Kt74poNWWpq1kspsEMKkyjSiPUf0h29+1nw== X-Received: by 10.98.57.129 with SMTP id u1mr3331398pfj.197.1505939131881; Wed, 20 Sep 2017 13:25:31 -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 r68sm9453926pfi.7.2017.09.20.13.25.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 13:25:31 -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 V2] PM / OPP: Call notifier without holding opp_table->lock Date: Wed, 20 Sep 2017 13:25:28 -0700 Message-Id: <5b70f7bdf12975f869a83f77e36bf3a40e0fa4b9.1505939072.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. Let's do it. Reported-by: Chanwoo Choi Reviewed-by: Stephen Boyd Signed-off-by: Viresh Kumar --- V1->V2: - s/Lets/Let's/ in commit log and added Stephen's tag. 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; }