linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: Fix the issue of task recovery failure caused by USB status when S4 wakes up
@ 2024-09-06  3:05 Duan Chenghao
  2024-09-06 14:05 ` Alan Stern
       [not found] ` <1725931490447646.3.seg@mailgw.kylinos.cn>
  0 siblings, 2 replies; 44+ messages in thread
From: Duan Chenghao @ 2024-09-06  3:05 UTC (permalink / raw)
  To: gregkh, pavel, linux-pm
  Cc: niko.mauno, stanley_chang, tj, linux-kernel, linux-usb,
	duanchenghao

When a device is inserted into the USB port and an S4 wakeup is initiated,
after the USB-hub initialization is completed, it will automatically enter suspend mode.
Upon detecting a device on the USB port, it will proceed with resume and set the hcd to the HCD_FLAG_WAKEUP_PENDING state.
During the S4 wakeup process, peripherals are put into suspend mode, followed by task recovery.
However, upon detecting that the hcd is in the HCD_FLAG_WAKEUP_PENDING state,
it will return an EBUSY status, causing the S4 suspend to fail and subsequent task recovery to not proceed.

This patch makes two modifications in total:
1. The set_bit and clean_bit operations for the HCD_FLAG_WAKEUP_PENDING flag of Hcd,
which were previously split between the top half and bottom half of the interrupt,
are now unified and executed solely in the bottom half of the interrupt.
This prevents the bottom half tasks from being frozen during the S4 process,
ensuring that the clean_bit process can proceed without interruption.

2. Add a condition to the set_bit operation for the hcd status HCD_FLAG_WAKEUP_PENDING.
When the hcd status is HC_STATE_SUSPENDED, perform the setting of the aforementioned status bit.
This prevents a subsequent set_bit from occurring after the clean_bit if the hcd is in the resuming process.

Signed-off-by: Duan Chenghao <duanchenghao@kylinos.cn>
---
 drivers/usb/core/hcd.c | 1 -
 drivers/usb/core/hub.c | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 1ff7d901fede..a6bd0fbd82f4 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2389,7 +2389,6 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
 	spin_lock_irqsave (&hcd_root_hub_lock, flags);
 	if (hcd->rh_registered) {
 		pm_wakeup_event(&hcd->self.root_hub->dev, 0);
-		set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
 		queue_work(pm_wq, &hcd->wakeup_work);
 	}
 	spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 4b93c0bd1d4b..7f847c4afc0d 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -3835,11 +3835,14 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
 
 int usb_remote_wakeup(struct usb_device *udev)
 {
+	struct usb_hcd  *hcd = bus_to_hcd(udev->bus);
 	int	status = 0;
 
 	usb_lock_device(udev);
 	if (udev->state == USB_STATE_SUSPENDED) {
 		dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-");
+		if (hcd->state == HC_STATE_SUSPENDED)
+			set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
 		status = usb_autoresume_device(udev);
 		if (status == 0) {
 			/* Let the drivers do their thing, then... */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2024-11-21 19:11 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06  3:05 [PATCH] USB: Fix the issue of task recovery failure caused by USB status when S4 wakes up Duan Chenghao
2024-09-06 14:05 ` Alan Stern
     [not found] ` <1725931490447646.3.seg@mailgw.kylinos.cn>
2024-09-10  9:34   ` duanchenghao
2024-09-10  9:36   ` duanchenghao
2024-09-11 14:40     ` Alan Stern
2024-09-12  3:21       ` duanchenghao
2024-09-12  6:26         ` [PATCH v2] " Duan Chenghao
2024-09-12 15:00         ` [PATCH] " Alan Stern
2024-09-13  1:51           ` duanchenghao
2024-09-13  9:38             ` duanchenghao
2024-09-14  2:43           ` Hongyu Xie
2024-09-23  8:00             ` duanchenghao
2024-09-24 13:38               ` Alan Stern
2024-09-29  3:14                 ` duanchenghao
2024-10-09  1:19                   ` duanchenghao
2024-10-09  1:54                     ` Alan Stern
2024-10-09  2:35                 ` duanchenghao
2024-10-09  6:29                   ` Gopal, Saranya
2024-10-09 15:50                   ` Alan Stern
2024-10-10  5:53                     ` duanchenghao
2024-10-10  5:59                     ` duanchenghao
2024-10-10 14:21                       ` Alan Stern
2024-10-11  1:42                         ` duanchenghao
2024-10-11 13:53                           ` Alan Stern
2024-10-12  9:46                             ` [PATCH v3] " Duan Chenghao
2024-10-12 12:39                               ` Greg KH
2024-10-12 12:40                               ` Greg KH
2024-10-12 15:06                                 ` Alan Stern
2024-10-12  9:51                             ` [PATCH] " duanchenghao
2024-10-12 15:01                               ` Alan Stern
2024-10-14  1:32                                 ` duanchenghao
2024-10-14  1:41                                 ` duanchenghao
2024-10-14  4:10                                   ` Gopal, Saranya
2024-10-16  8:57                                   ` Gopal, Saranya
2024-10-16  9:06                                     ` duanchenghao
2024-10-24  2:40                                       ` [PATCH v4] " Duan Chenghao
2024-10-24  2:53                                         ` duanchenghao
2024-10-24  7:05                                         ` Greg KH
2024-10-24  8:46                                           ` duanchenghao
2024-10-29  3:27                                             ` Greg KH
2024-10-29  8:01                                               ` duanchenghao
2024-11-06  1:29                                                 ` duanchenghao
2024-11-21 19:09                                                   ` Greg KH
2024-11-20  2:14                                               ` 回复:[PATCH " Duan Chenghao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).