diff mbox series

[v2,1/2] USB: core: Disable remote wakeup for freeze/quiesce

Message ID 20220418135819.v2.1.I2c636c4decc358f5e6c27b810748904cc69beada@changeid (mailing list archive)
State Superseded
Headers show
Series USB: Quiesce interrupts across pm freeze | expand

Commit Message

Evan Green April 18, 2022, 9 p.m. UTC
The PM_EVENT_FREEZE and PM_EVENT_QUIESCE messages should cause the
device to stop generating interrupts. USB core was previously allowing
devices that were already runtime suspended to keep remote wakeup
enabled if they had gone down that way. This violates the contract with
pm, and can potentially cause MSI interrupts to be lost.

Change that so that if a device is runtime suspended with remote wakeups
enabled, it will be resumed to ensure remote wakeup is always disabled
across a freeze.

Signed-off-by: Evan Green <evgreen@chromium.org>
---

(no changes since v1)

 drivers/usb/core/driver.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

Comments

Alan Stern April 19, 2022, 2:41 p.m. UTC | #1
On Mon, Apr 18, 2022 at 02:00:45PM -0700, Evan Green wrote:
> The PM_EVENT_FREEZE and PM_EVENT_QUIESCE messages should cause the
> device to stop generating interrupts. USB core was previously allowing
> devices that were already runtime suspended to keep remote wakeup
> enabled if they had gone down that way. This violates the contract with
> pm, and can potentially cause MSI interrupts to be lost.
> 
> Change that so that if a device is runtime suspended with remote wakeups
> enabled, it will be resumed to ensure remote wakeup is always disabled
> across a freeze.
> 
> Signed-off-by: Evan Green <evgreen@chromium.org>
> ---
> 
> (no changes since v1)
> 
>  drivers/usb/core/driver.c | 20 +++++++++-----------
>  1 file changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
> index 355ed33a21792b..93c8cf66adccec 100644
> --- a/drivers/usb/core/driver.c
> +++ b/drivers/usb/core/driver.c
> @@ -1533,20 +1533,18 @@ static void choose_wakeup(struct usb_device *udev, pm_message_t msg)
>  {
>  	int	w;
>  
> -	/* Remote wakeup is needed only when we actually go to sleep.
> -	 * For things like FREEZE and QUIESCE, if the device is already
> -	 * autosuspended then its current wakeup setting is okay.
> +	/* For FREEZE/QUIESCE, disable remote wakeups so no interrupts get generated
> +	 * by the device.

You mean "by the host controller".  USB devices don't generate 
interrupts; they generate wakeup requests (which can cause a host 
controller to generate an interrupt).

>  	 */
>  	if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_QUIESCE) {
> -		if (udev->state != USB_STATE_SUSPENDED)
> -			udev->do_remote_wakeup = 0;
> -		return;
> -	}
> +		w = 0;
>  
> -	/* Enable remote wakeup if it is allowed, even if no interface drivers
> -	 * actually want it.
> -	 */
> -	w = device_may_wakeup(&udev->dev);
> +	} else {
> +		/* Enable remote wakeup if it is allowed, even if no interface drivers
> +		 * actually want it.
> +		 */
> +		w = device_may_wakeup(&udev->dev);
> +	}
>  
>  	/* If the device is autosuspended with the wrong wakeup setting,
>  	 * autoresume now so the setting can be changed.
> -- 

I would prefer it if you reformatted the comments to agree with the 
current style:

	/*
	 * Blah blah blah
	 */

and to avoid line wrap beyond 80 columns.  Apart from that:

Acked-by: Alan Stern <stern@rowland.harvard.edu>

Alan Stern
Evan Green April 20, 2022, 7:30 p.m. UTC | #2
On Tue, Apr 19, 2022 at 7:41 AM Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Mon, Apr 18, 2022 at 02:00:45PM -0700, Evan Green wrote:
> > The PM_EVENT_FREEZE and PM_EVENT_QUIESCE messages should cause the
> > device to stop generating interrupts. USB core was previously allowing
> > devices that were already runtime suspended to keep remote wakeup
> > enabled if they had gone down that way. This violates the contract with
> > pm, and can potentially cause MSI interrupts to be lost.
> >
> > Change that so that if a device is runtime suspended with remote wakeups
> > enabled, it will be resumed to ensure remote wakeup is always disabled
> > across a freeze.
> >
> > Signed-off-by: Evan Green <evgreen@chromium.org>
> > ---
> >
> > (no changes since v1)
> >
> >  drivers/usb/core/driver.c | 20 +++++++++-----------
> >  1 file changed, 9 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
> > index 355ed33a21792b..93c8cf66adccec 100644
> > --- a/drivers/usb/core/driver.c
> > +++ b/drivers/usb/core/driver.c
> > @@ -1533,20 +1533,18 @@ static void choose_wakeup(struct usb_device *udev, pm_message_t msg)
> >  {
> >       int     w;
> >
> > -     /* Remote wakeup is needed only when we actually go to sleep.
> > -      * For things like FREEZE and QUIESCE, if the device is already
> > -      * autosuspended then its current wakeup setting is okay.
> > +     /* For FREEZE/QUIESCE, disable remote wakeups so no interrupts get generated
> > +      * by the device.
>
> You mean "by the host controller".  USB devices don't generate
> interrupts; they generate wakeup requests (which can cause a host
> controller to generate an interrupt).

Right, I guess I mean "at the behest of the device". I could probably
just delete "by the device", since the goal of the comment is simply
to highlight that we're trying to kill interrupts, and describing
their provenance isn't as relevant.

>
> >        */
> >       if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_QUIESCE) {
> > -             if (udev->state != USB_STATE_SUSPENDED)
> > -                     udev->do_remote_wakeup = 0;
> > -             return;
> > -     }
> > +             w = 0;
> >
> > -     /* Enable remote wakeup if it is allowed, even if no interface drivers
> > -      * actually want it.
> > -      */
> > -     w = device_may_wakeup(&udev->dev);
> > +     } else {
> > +             /* Enable remote wakeup if it is allowed, even if no interface drivers
> > +              * actually want it.
> > +              */
> > +             w = device_may_wakeup(&udev->dev);
> > +     }
> >
> >       /* If the device is autosuspended with the wrong wakeup setting,
> >        * autoresume now so the setting can be changed.
> > --
>
> I would prefer it if you reformatted the comments to agree with the
> current style:
>
>         /*
>          * Blah blah blah
>          */
>
> and to avoid line wrap beyond 80 columns.  Apart from that:

Sure, I can fix these up, add your tags, and repost.

>
> Acked-by: Alan Stern <stern@rowland.harvard.edu>

Thanks!

>
> Alan Stern
diff mbox series

Patch

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 355ed33a21792b..93c8cf66adccec 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1533,20 +1533,18 @@  static void choose_wakeup(struct usb_device *udev, pm_message_t msg)
 {
 	int	w;
 
-	/* Remote wakeup is needed only when we actually go to sleep.
-	 * For things like FREEZE and QUIESCE, if the device is already
-	 * autosuspended then its current wakeup setting is okay.
+	/* For FREEZE/QUIESCE, disable remote wakeups so no interrupts get generated
+	 * by the device.
 	 */
 	if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_QUIESCE) {
-		if (udev->state != USB_STATE_SUSPENDED)
-			udev->do_remote_wakeup = 0;
-		return;
-	}
+		w = 0;
 
-	/* Enable remote wakeup if it is allowed, even if no interface drivers
-	 * actually want it.
-	 */
-	w = device_may_wakeup(&udev->dev);
+	} else {
+		/* Enable remote wakeup if it is allowed, even if no interface drivers
+		 * actually want it.
+		 */
+		w = device_may_wakeup(&udev->dev);
+	}
 
 	/* If the device is autosuspended with the wrong wakeup setting,
 	 * autoresume now so the setting can be changed.