Skip to contentSkip to conversation

usb: core: don't skip system resume for an already suspended device

PATCH New Selvarasu Ganesan 2 participants 2 messages Nov 16 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20261116125643epcas5p17e73b0fa50f1cb7609b1d90d62c5e3f6@epcas5p1.samsung.com

#1 lore raw

PATCH 1/1 usb: core: don't skip system resume for an already suspended device

When offload is active on a USB device, usb_suspend_both() skips suspending it during system suspend so that the port is not pushed into its deep low power state.

The commit bd3d245b0fef ("usb: core: use dedicated spinlock for offload state") made the resume path skip resuming the device whenever offload is active at resume time, instead of only when the corresponding suspend was skipped. That is wrong when the device was already suspended:

1. Streaming is running with offload active and the AP side stops using the device, the user pauses streaming, or the USB interface simply becomes idle.
2. The device auto-suspends. The auto-suspend path (PMSG_AUTO_SUSPEND) does not carry the PM_EVENT_SUSPEND event, so the offload state is not consulted. The port goes into its deep low-power state and the device enters USB_STATE_SUSPENDED.
3. The system enters PM suspend. The device is already suspended, so usb_suspend_both() returns early and the offload skip never takes effect for this sleep.
4. On system resume, usb_resume_both() re-checks usb_offload_check(), which is still true because the offload reference is held. The device resume is skipped even though the device is suspended, so the connected USB device is never resumed and fails to function after the AP resumes.

Skipping the resume is only correct when the suspend was actually skipped, i.e. when the device was not already suspended. Check the device state so that an already suspended device always goes through a normal resume, as before bd3d245b0fef.

Fixes bd3d245b0fef ("usb: core: use dedicated spinlock for offload state")
---
 drivers/usb/core/driver.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/usb/core/driver.c +9 -1
index f21b1e4f9c09..48addbd1a69a 100644
@@ -1552,7 +1552,15 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)
 		goto done;
 	}
 	udev->can_submit = 1;
-	if (msg.event == PM_EVENT_RESUME)
+	/*
+	 * Offload is only relevant if the device was kept active during the
+	 * corresponding suspend.  A device that is already suspended (for
+	 * example auto-suspended during an idle gap) must go through a
+	 * normal resume, otherwise the port would be left in its deep
+	 * low-power state after system resume.
+	 */
+	if (msg.event == PM_EVENT_RESUME &&
+	    udev->state != USB_STATE_SUSPENDED)
 		offload_active = usb_offload_check(udev);
 
 	/* Resume the device */
Signature · 1 line
2.17.1
#2 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 18 lines

When offload is active on a USB device, usb_suspend_both() skips suspending it during system suspend so that the port is not pushed into its deep low power state.

The commit bd3d245b0fef ("usb: core: use dedicated spinlock for offload state") made the resume path skip resuming the device whenever offload is active at resume time, instead of only when the corresponding suspend was skipped. That is wrong when the device was already suspended:

1. Streaming is running with offload active and the AP side stops using the device, the user pauses streaming, or the USB interface simply becomes idle.
2. The device auto-suspends. The auto-suspend path (PMSG_AUTO_SUSPEND) does not carry the PM_EVENT_SUSPEND event, so the offload state is not consulted. The port goes into its deep
[ ... ]
normal resume, as before bd3d245b0fef.

Quoted 3 lines
Fixes bd3d245b0fef ("usb: core: use dedicated spinlock for offload state")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/973576304.21794834003625.JavaMail.epsvc@epcpadp1new?part=1