Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp650819imm; Thu, 31 May 2018 07:07:59 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK6DqXupSoSt609Aqtl5/n7bu2aLSN6WsoRJq9LffEPSYneC8wfUOfOZytMmbNgjZ5ROjcm X-Received: by 2002:a63:87c8:: with SMTP id i191-v6mr5743777pge.124.1527775679344; Thu, 31 May 2018 07:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527775679; cv=none; d=google.com; s=arc-20160816; b=oZz4MBnHt/l3CRQAKy3X89Rg4gmZbkC0bYgAuqMHRlhQFV950KS1hjHUuL2BRW6GXG GQG0K3KwsKno5cIeGfk3e/nm18KD07DG8VVJaHXrjOpRfHbyG94RfzLd2SFTEHCjdco9 KNNpZaQs9JB+jzlcAvwTLKPElXRbhYlcScYtuhDh2Od74FY1JhF1YVzZZyOHyW/VVej9 cN21yAjw1v/W4I9HZH8zBi5pCx/UM189XvslVhp4LYzq/NAwJf5vHsKrna5DmEtiPJr4 QbU8zrhhlZQMvgG4qWCXRbFrCAqDjUbQvCGMWIlCZ4V2wXtiaO2VAVq9yXZRQ4TkioXE clPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=C4HBrgWl+JiYZrNtwe5SxW2aBsqOWknOcGvFeHaHKWg=; b=XagQB5XR0hBfVYTa3WX/EOe7xV4ejxZSNzb46LzoyTMbRphZ/GU8CjYLVCiWUqRB33 ai0clg1w2FYyivmN7aM+UPDR4+2qDkuIb4EvIX5l3oUCFwXnJMPfdnqoyKMBc++Yf9Wd Lg//MEQS1oMUsEg//v4dGK6Ci91jIiIzMZ7/c6Y+YlKaazjLm2Cu5EHs7kGMsvMETjZi GtJ/4cxjQmb+BVFw3AyCwXWwtxndBliZdYNppUtcJPJQTIgb89VCoPqJFUkqsoppN33M PZcKebb2vS9yP58Uo/mnibADiojjfkuqahxnYdVv5RgFWS0KrudheZDmtDeSEi2awUpX 5EzA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x135-v6si1486860pgx.424.2018.05.31.07.07.44; Thu, 31 May 2018 07:07:59 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755335AbeEaOHI (ORCPT + 99 others); Thu, 31 May 2018 10:07:08 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:51352 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1755093AbeEaOHG (ORCPT ); Thu, 31 May 2018 10:07:06 -0400 Received: (qmail 2237 invoked by uid 2102); 31 May 2018 10:07:05 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 31 May 2018 10:07:05 -0400 Date: Thu, 31 May 2018 10:07:05 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Johan Hovold cc: Roger Quadros , , , Subject: Re: [PATCH 2/2] usb: dwc3: of_simple: don't call pm_runtime_set_active() In-Reply-To: <20180531132538.GH3259@localhost> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 31 May 2018, Johan Hovold wrote: > > This breaks runtime pm as you now get a second round of clock enables > > which are never balanced on runtime suspend (the clocks are first > > enabled in dwc3_of_simple_clk_init() above and with your change again in > > dwc3_of_simple_runtime_resume()). > > > > On the other hand, we currently return from probe() with a positive RPM > > count so perhaps the RPM callbacks can just be removed altogether (i.e. > > unless some other entity drops that count at some point before > > remove()). > > > > > ret = of_platform_populate(np, NULL, NULL, dev); > > > if (ret) { > > > for (i = 0; i < simple->num_clocks; i++) { > > > @@ -131,10 +134,6 @@ static int dwc3_of_simple_probe(struct platform_device *pdev) > > > goto err_resetc_assert; > > > } > > > > > > - pm_runtime_set_active(dev); > > > - pm_runtime_enable(dev); > > > - pm_runtime_get_sync(dev); > > > - > > > return 0; > > > > > > err_resetc_assert: > > > > Also note that there's currently a use-after-free in remove(), where > > pm_runtime_put_sync() is called after the clocks have been put. > > Something like the below (untested) patch should fix it. > > What about the use-after-free in remove? Shall I resubmit the fix below > separately? > > Thanks, > Johan > > > From 35c384c31010c344d403c26fc0a1dde0fd68ef4a Mon Sep 17 00:00:00 2001 > > From: Johan Hovold > > Date: Mon, 28 May 2018 17:31:45 +0200 > > Subject: [PATCH] usb: dwc3: of-simple: fix use-after-free on remove > > > > The clocks have already been explicitly disabled and put as part of > > remove() so the runtime suspend callback must not be run when balancing > > the runtime PM usage count before returning. > > > > Fixes: 16adc674d0d6 ("usb: dwc3: add generic OF glue layer") > > Signed-off-by: Johan Hovold > > --- > > drivers/usb/dwc3/dwc3-of-simple.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/usb/dwc3/dwc3-of-simple.c b/drivers/usb/dwc3/dwc3-of-simple.c > > index cb2ee96fd3e8..b9c869cd6585 100644 > > --- a/drivers/usb/dwc3/dwc3-of-simple.c > > +++ b/drivers/usb/dwc3/dwc3-of-simple.c > > @@ -165,8 +165,9 @@ static int dwc3_of_simple_remove(struct platform_device *pdev) > > > > reset_control_put(simple->resets); > > > > - pm_runtime_put_sync(dev); > > + pm_runtime_put_noidle(dev); > > pm_runtime_disable(dev); > > + pm_runtime_set_suspended(dev); > > > > return 0; > > } This is a little racy -- there might be a runtime-suspend callback between the put_noidle and the disable. (The put_noidle itself won't cause a callback to happen, but something else could.) It would be better to do the disable first and then the put_noidle. Alan Stern