Skip to contentSkip to conversation

usb: dwc3: core: remove spin_lock/unlock_* to avoid deadlock when suspend gadget

PATCH In review Xu Yang 3 participants 4 messages May 27, 2024 – Jul 31, 2024

Subsystems (3)
lore
Share & tools
lore

Xu Yang

author
#0 lore raw

PATCH v2 1/1 usb: dwc3: core: remove spin_lock/unlock_* to avoid deadlock when suspend gadget

In current design, spin_lock_irqsave() will run twice when suspend gadget device if the controller is using OTG block:

dwc3_suspend_common()
spin_lock_irqsave(&dwc->lock, flags); <-- 1st

  dwc3_gadget_suspend(dwc);
    dwc3_gadget_soft_disconnect(dwc);
      spin_lock_irqsave(&dwc->lock, flags);  <-- 2nd

This will cause deadlock on the suspend path. To let it work, just remove spin_lock/unlock_* in dwc3_suspend_common() since they are redundant.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")

---
Changes in v2:
- add fix tag and stable list

---
 drivers/usb/dwc3/core.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/usb/dwc3/core.c +0 -3
index 7ee61a89520b..b8193edc41bd 100644
@@ -2250,7 +2250,6 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
 
 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 {
-	unsigned long	flags;
 	u32 reg;
 	int i;
 
@@ -2293,9 +2292,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 			break;
 
 		if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-			spin_lock_irqsave(&dwc->lock, flags);
 			dwc3_gadget_suspend(dwc);
-			spin_unlock_irqrestore(&dwc->lock, flags);
 			synchronize_irq(dwc->irq_gadget);
 		}
 
Signature · 1 line
2.34.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 48 lines · Xu Yang

In current design, spin_lock_irqsave() will run twice when suspend gadget device if the controller is using OTG block:

dwc3_suspend_common()
spin_lock_irqsave(&dwc->lock, flags); <-- 1st

  dwc3_gadget_suspend(dwc);
    dwc3_gadget_soft_disconnect(dwc);
      spin_lock_irqsave(&dwc->lock, flags);  <-- 2nd

This will cause deadlock on the suspend path. To let it work, just remove spin_lock/unlock_* in dwc3_suspend_common() since they are redundant.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")

---
Changes in v2:
- add fix tag and stable list

---
 drivers/usb/dwc3/core.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/usb/dwc3/core.c +0 -3
index 7ee61a89520b..b8193edc41bd 100644
@@ -2250,7 +2250,6 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
 
 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 {
-	unsigned long	flags;
 	u32 reg;
 	int i;
 
@@ -2293,9 +2292,7 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 			break;
 
 		if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-			spin_lock_irqsave(&dwc->lock, flags);
 			dwc3_gadget_suspend(dwc);
-			spin_unlock_irqrestore(&dwc->lock, flags);
 			synchronize_irq(dwc->irq_gadget);
 		}
 
Signature · 1 line
2.34.1

Thanks,
Thinh

maintainer
#2 lore raw
In reply to Xu Yang
Quoted 16 lines · Xu Yang

In current design, spin_lock_irqsave() will run twice when suspend gadget device if the controller is using OTG block:

dwc3_suspend_common()
spin_lock_irqsave(&dwc->lock, flags); <-- 1st

  dwc3_gadget_suspend(dwc);
    dwc3_gadget_soft_disconnect(dwc);
      spin_lock_irqsave(&dwc->lock, flags);  <-- 2nd

This will cause deadlock on the suspend path. To let it work, just remove spin_lock/unlock_* in dwc3_suspend_common() since they are redundant.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")
Quoted 6 lines

---
Changes in v2:
- add fix tag and stable list

---
 drivers/usb/dwc3/core.c | 3 ---
 1 file changed, 3 deletions(-)

Is this still needed? if so, can you rebase and resubmit?

thanks,

greg k-h

author
#3 lore raw
Quoted 17 lines · Greg KH
Quoted 16 lines · Xu Yang

In current design, spin_lock_irqsave() will run twice when suspend gadget device if the controller is using OTG block:

dwc3_suspend_common()
spin_lock_irqsave(&dwc->lock, flags); <-- 1st

  dwc3_gadget_suspend(dwc);
    dwc3_gadget_soft_disconnect(dwc);
      spin_lock_irqsave(&dwc->lock, flags);  <-- 2nd

This will cause deadlock on the suspend path. To let it work, just remove spin_lock/unlock_* in dwc3_suspend_common() since they are redundant.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")
Quoted 8 lines
Quoted 6 lines

---
Changes in v2:
- add fix tag and stable list

---
 drivers/usb/dwc3/core.c | 3 ---
 1 file changed, 3 deletions(-)

Is this still needed? if so, can you rebase and resubmit?

It's not needed now.
Meng Li sent a better one and it's already accepted.
https://lore.kernel.org/r/[email protected]

Thanks,
Xu Yang

Quoted 4 lines

thanks,

greg k-h