From: Johan Hovold <johan@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Johan Hovold <johan@kernel.org>, Roger Quadros <rogerq@ti.com>,
balbi@kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [2/2] usb: dwc3: of_simple: don't call pm_runtime_set_active()
Date: Thu, 31 May 2018 16:37:03 +0200 [thread overview]
Message-ID: <20180531143703.GL3259@localhost> (raw)
On Thu, May 31, 2018 at 10:07:05AM -0400, Alan Stern wrote:
> 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 <johan@kernel.org>
> > > 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 <johan@kernel.org>
> > > ---
> > > 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.
Good point. I'll send a v2 for Felipe to consider.
Thanks,
Johan
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Johan Hovold <johan@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Johan Hovold <johan@kernel.org>, Roger Quadros <rogerq@ti.com>,
balbi@kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] usb: dwc3: of_simple: don't call pm_runtime_set_active()
Date: Thu, 31 May 2018 16:37:03 +0200 [thread overview]
Message-ID: <20180531143703.GL3259@localhost> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1805311004260.1607-100000@iolanthe.rowland.org>
On Thu, May 31, 2018 at 10:07:05AM -0400, Alan Stern wrote:
> 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 <johan@kernel.org>
> > > 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 <johan@kernel.org>
> > > ---
> > > 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.
Good point. I'll send a v2 for Felipe to consider.
Thanks,
Johan
next reply other threads:[~2018-05-31 14:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-31 14:37 Johan Hovold [this message]
2018-05-31 14:37 ` [PATCH 2/2] usb: dwc3: of_simple: don't call pm_runtime_set_active() Johan Hovold
-- strict thread matches above, loose matches on Subject: below --
2018-06-14 7:57 [2/2] " Johan Hovold
2018-06-14 7:57 ` [PATCH 2/2] " Johan Hovold
2018-06-13 11:15 [2/2] " Roger Quadros
2018-06-13 11:15 ` [PATCH 2/2] " Roger Quadros
2018-05-31 14:07 [2/2] " Alan Stern
2018-05-31 14:07 ` [PATCH 2/2] " Alan Stern
2018-05-31 13:25 [2/2] " Johan Hovold
2018-05-31 13:25 ` [PATCH 2/2] " Johan Hovold
2018-05-31 7:59 [2/2] " Felipe Balbi
2018-05-31 7:59 ` [PATCH 2/2] " Felipe Balbi
2018-05-31 7:23 [2/2] " Roger Quadros
2018-05-31 7:23 ` [PATCH 2/2] " Roger Quadros
2018-05-30 12:31 [2/2] " Felipe Balbi
2018-05-30 12:31 ` [PATCH 2/2] " Felipe Balbi
2018-05-28 15:41 [2/2] " Johan Hovold
2018-05-28 15:41 ` [PATCH 2/2] " Johan Hovold
2018-05-28 14:36 [2/2] " Roger Quadros
2018-05-28 14:36 ` [PATCH 2/2] " Roger Quadros
2018-05-28 14:36 [1/2] usb: dwc3: of-simple: Don't fail if no clock entries Roger Quadros
2018-05-28 14:36 ` [PATCH 1/2] " Roger Quadros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180531143703.GL3259@localhost \
--to=johan@kernel.org \
--cc=balbi@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rogerq@ti.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.