Skip to contentSkip to conversation

usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock

PATCH In review Meng Li 3 participants 10 messages Jun 18, 2024 – Jun 22, 2024

Subsystems (2)
lore
Share & tools
lore

Meng Li

author
#0 lore raw

PATCH v2 1/1 usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger system to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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 issue is exposed by commit c7ebd8149ee5 ("usb: dwc3: gadget: Fix NULL pointer dereference in dwc3_gadget_suspend") that removes the code of checking whether dwc->gadget_driver is NULL or not. It causes the following code is executed and deadlock occurs when trying to get the spinlock. In fact, the root cause is the commit 5265397f9442("usb: dwc3:
Remove DWC3 locking during gadget suspend/resume") that forgot to remove the lock of otg mode. So, remove the redundant lock of otg mode during gadget suspend/resume.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")
Cc Xu Yang <[email protected]>

---
v1->v2:
- improve commit log, correct the Fixes commit id.

---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/usb/dwc3/core.c +0 -6
index 7ee61a89520b..9d47c3aa5777 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);
 		}
 
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 {
-	unsigned long	flags;
 	int		ret;
 	u32		reg;
 	int		i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
 			dwc3_otg_host_init(dwc);
 		} else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-			spin_lock_irqsave(&dwc->lock, flags);
 			dwc3_gadget_resume(dwc);
-			spin_unlock_irqrestore(&dwc->lock, flags);
 		}
 
 		break;
Signature · 1 line
2.34.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 75 lines · Meng Li

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger system to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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 issue is exposed by commit c7ebd8149ee5 ("usb: dwc3: gadget: Fix NULL pointer dereference in dwc3_gadget_suspend") that removes the code of checking whether dwc->gadget_driver is NULL or not. It causes the following code is executed and deadlock occurs when trying to get the spinlock. In fact, the root cause is the commit 5265397f9442("usb: dwc3:
Remove DWC3 locking during gadget suspend/resume") that forgot to remove the lock of otg mode. So, remove the redundant lock of otg mode during gadget suspend/resume.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")
Cc Xu Yang <[email protected]>

---
v1->v2:
- improve commit log, correct the Fixes commit id.

---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/usb/dwc3/core.c +0 -6
index 7ee61a89520b..9d47c3aa5777 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);
 		}
 
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 {
-	unsigned long	flags;
 	int		ret;
 	u32		reg;
 	int		i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 		if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
 			dwc3_otg_host_init(dwc);
 		} else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-			spin_lock_irqsave(&dwc->lock, flags);
 			dwc3_gadget_resume(dwc);
-			spin_unlock_irqrestore(&dwc->lock, flags);
 		}
 
 		break;
Signature · 1 line
2.34.1

Did you use "git format-patch -v"? The $subject version prefix order is different. In any case,

Thanks,
Thinh

#2 lore raw

Hi

Quoted 12 lines · Thinh Nguyen
Quoted 10 lines · Meng Li

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger system to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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

In resume path the spinlock was taken too and I see that there is a call dwc3_gadget_soft_connect that call the dwc3_core_soft_reset that can poll using msleep for time. I don't know if this is a valid fix but seems does not fix
only commit c7ebd8149ee5

Michael

Quoted 73 lines
Quoted 63 lines

This issue is exposed by commit c7ebd8149ee5 ("usb: dwc3: gadget: Fix NULL pointer dereference in dwc3_gadget_suspend") that removes the code of checking whether dwc->gadget_driver is NULL or not. It causes the following code is executed and deadlock occurs when trying to get the spinlock. In fact, the root cause is the commit 5265397f9442("usb: dwc3:
Remove DWC3 locking during gadget suspend/resume") that forgot to remove the lock of otg mode. So, remove the redundant lock of otg mode during gadget suspend/resume.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")
Cc Xu Yang <[email protected]>

---
v1->v2:
- improve commit log, correct the Fixes commit id.

---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/usb/dwc3/core.c +0 -7
index 7ee61a89520b..9d47c3aa5777 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);
              }
 
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 {
-     unsigned long   flags;
      int             ret;
      u32             reg;
      int             i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
              if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
                      dwc3_otg_host_init(dwc);
              } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-                     spin_lock_irqsave(&dwc->lock, flags);
                      dwc3_gadget_resume(dwc);
-                     spin_unlock_irqrestore(&dwc->lock, flags);
              }
 
              break;
--
Quoted 2 lines

2.34.1

Did you use "git format-patch -v"? The $subject version prefix order is different. In any case,

Thanks,
Thinh

maintainer
#3 lore raw

Hi,

Quoted 17 lines · Michael Nazzareno Trimarchi

Hi

Quoted 12 lines · Thinh Nguyen
Quoted 10 lines · Meng Li

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger system to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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
Quoted 6 lines

In resume path the spinlock was taken too and I see that there is a call dwc3_gadget_soft_connect that call the dwc3_core_soft_reset that can poll using msleep for time. I don't know if this is a valid fix but seems does not fix
only commit c7ebd8149ee5

Meng did take the resume path into account. Can you clarify what you meant with "does not fix only commit c7ebd8149ee5"?

Thanks,
Thinh

Quoted 74 lines
Quoted 74 lines
Quoted 64 lines

This issue is exposed by commit c7ebd8149ee5 ("usb: dwc3: gadget: Fix NULL pointer dereference in dwc3_gadget_suspend") that removes the code of checking whether dwc->gadget_driver is NULL or not. It causes the following code is executed and deadlock occurs when trying to get the spinlock. In fact, the root cause is the commit 5265397f9442("usb: dwc3:
Remove DWC3 locking during gadget suspend/resume") that forgot to remove the lock of otg mode. So, remove the redundant lock of otg mode during gadget suspend/resume.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")
Cc Xu Yang <[email protected]>

---
v1->v2:
- improve commit log, correct the Fixes commit id.

---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/usb/dwc3/core.c +0 -7
index 7ee61a89520b..9d47c3aa5777 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);
              }
 
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 {
-     unsigned long   flags;
      int             ret;
      u32             reg;
      int             i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
              if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
                      dwc3_otg_host_init(dwc);
              } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-                     spin_lock_irqsave(&dwc->lock, flags);
                      dwc3_gadget_resume(dwc);
-                     spin_unlock_irqrestore(&dwc->lock, flags);
              }
 
              break;
--
Quoted 2 lines

2.34.1

Did you use "git format-patch -v"? The $subject version prefix order is different. In any case,

Thanks,
Thinh

#4 lore raw

Hi

Quoted 28 lines · Thinh Nguyen

Hi,

Quoted 17 lines · Michael Nazzareno Trimarchi

Hi

Quoted 12 lines · Thinh Nguyen
Quoted 10 lines · Meng Li

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger system to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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
Quoted 6 lines

In resume path the spinlock was taken too and I see that there is a call dwc3_gadget_soft_connect that call the dwc3_core_soft_reset that can poll using msleep for time. I don't know if this is a valid fix but seems does not fix
only commit c7ebd8149ee5

Quoted 2 lines

Meng did take the resume path into account. Can you clarify what you meant with "does not fix only commit c7ebd8149ee5"?

I have seen that is suppose to fix something introduced by that commit but I think
that resume path was already broken before

spinlock_irqsave()
dwc3_gadget_resume -> dwc3_gadget_soft_connect -> dwc3_core_soft_reset (can sleep)

Michael

Quoted 78 lines

Thanks,
Thinh

Quoted 74 lines
Quoted 74 lines
Quoted 64 lines

This issue is exposed by commit c7ebd8149ee5 ("usb: dwc3: gadget: Fix NULL pointer dereference in dwc3_gadget_suspend") that removes the code of checking whether dwc->gadget_driver is NULL or not. It causes the following code is executed and deadlock occurs when trying to get the spinlock. In fact, the root cause is the commit 5265397f9442("usb: dwc3:
Remove DWC3 locking during gadget suspend/resume") that forgot to remove the lock of otg mode. So, remove the redundant lock of otg mode during gadget suspend/resume.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget suspend/resume")
Cc Xu Yang <[email protected]>

---
v1->v2:
- improve commit log, correct the Fixes commit id.

---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/usb/dwc3/core.c +0 -7
index 7ee61a89520b..9d47c3aa5777 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);
              }
 
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
 {
-     unsigned long   flags;
      int             ret;
      u32             reg;
      int             i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)
              if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
                      dwc3_otg_host_init(dwc);
              } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-                     spin_lock_irqsave(&dwc->lock, flags);
                      dwc3_gadget_resume(dwc);
-                     spin_unlock_irqrestore(&dwc->lock, flags);
              }
 
              break;
--
Quoted 2 lines

2.34.1

Did you use "git format-patch -v"? The $subject version prefix order is different. In any case,

Thanks,
Thinh

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
maintainer
#5 lore raw
Quoted 34 lines · Michael Nazzareno Trimarchi

Hi

Quoted 28 lines · Thinh Nguyen

Hi,

Quoted 17 lines · Michael Nazzareno Trimarchi

Hi

Quoted 12 lines · Thinh Nguyen
Quoted 10 lines · Meng Li

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger system to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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
Quoted 6 lines

In resume path the spinlock was taken too and I see that there is a call dwc3_gadget_soft_connect that call the dwc3_core_soft_reset that can poll using msleep for time. I don't know if this is a valid fix but seems does not fix
only commit c7ebd8149ee5

Quoted 2 lines

Meng did take the resume path into account. Can you clarify what you meant with "does not fix only commit c7ebd8149ee5"?

Quoted 8 lines

I have seen that is suppose to fix something introduced by that commit but I think
that resume path was already broken before

spinlock_irqsave()
dwc3_gadget_resume -> dwc3_gadget_soft_connect -> dwc3_core_soft_reset (can sleep)

The code path for OTG should not hit that sleep. The sleep is only applicable to DWC_usb31 and DWC_usb32. Technically, it wasn't broken before. But we should remove this spinlock on resume as it is done here.

BR,
Thinh

author
#6 lore raw
In reply to Thinh Nguyen
Quoted 96 lines

-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Wednesday, June 19, 2024 5:54 AM
To: Li, Meng <[email protected]>
Cc: Thinh Nguyen <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [v2 PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock

CAUTION: This email comes from a non Wind River email account! Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 1 line · Meng Li

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger

system

Quoted 9 lines

to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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
Quoted 5 lines

This issue is exposed by commit c7ebd8149ee5 ("usb: dwc3: gadget: Fix NULL pointer dereference in dwc3_gadget_suspend") that removes the code of checking whether dwc->gadget_driver is NULL or not. It causes the following code is executed and deadlock occurs when trying to get the spinlock. In fact, the root cause is the commit 5265397f9442("usb:

dwc3:

drivers/usb/dwc3/core.c static int dwc3_core_init_for_resume(struct

Quoted 23 lines

Remove DWC3 locking during gadget suspend/resume") that forgot to remove the lock of otg mode. So, remove the redundant lock of otg mode during gadget suspend/resume.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget

suspend/resume")

---
v1->v2:
- improve commit log, correct the Fixes commit id.

---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/usb/dwc3/core.c index renamed from drivers/usb/dwc3/core.c +0 -0

7ee61a89520b..9d47c3aa5777 100644

drivers/usb/dwc3/core.c +0 -0
@@ -2250,7 +2250,6 @@ static int dwc3_core_init_for_resume(struct

dwc3

drivers/usb/dwc3/core.c static int dwc3_core_init_for_resume(struct dwc3 *dwc) · line 2251

Quoted 3 lines
drivers/usb/dwc3/core.c +0 -0
 *dwc)
 
 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)

{

drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3

Quoted 5 lines
drivers/usb/dwc3/core.c +0 -1
-     unsigned long   flags;
      u32 reg;
      int i;
 
@@ -2293,9 +2292,7 @@ static int dwc3_suspend_common(struct dwc3

*dwc, pm_message_t msg)

drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3

Quoted 10 lines
drivers/usb/dwc3/core.c +0 -2
                      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);
              }
 
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3

*dwc,

drivers/usb/dwc3/core.c static int dwc3_resume_common(struct dwc3

Quoted 8 lines
drivers/usb/dwc3/core.c +0 -1
 pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)  {
-     unsigned long   flags;
      int             ret;
      u32             reg;
      int             i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3

*dwc, pm_message_t msg)

Quoted 8 lines
drivers/usb/dwc3/core.c +0 -2
              if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
                      dwc3_otg_host_init(dwc);
              } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-                     spin_lock_irqsave(&dwc->lock, flags);
                      dwc3_gadget_resume(dwc);
-                     spin_unlock_irqrestore(&dwc->lock, flags);
              }
 
Quoted 8 lines
Quoted 4 lines
drivers/usb/dwc3/core.c +0 -1
              break;
--

2.34.1

Did you use "git format-patch -v"? The $subject version prefix order is different. In any case,

Sorry! I use --subject-prefix="v2 PATCH".
I will correct it in next patch pull request.

Thanks,
Limeng

Quoted 4 lines

Thanks,
Thinh

author
#7 lore raw
Quoted 119 lines

-----Original Message-----
From: Li, Meng
Sent: Wednesday, June 19, 2024 9:49 AM
To: Thinh Nguyen <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: RE: [v2 PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock

Quoted 10 lines

-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Wednesday, June 19, 2024 5:54 AM
To: Li, Meng <[email protected]>
Cc: Thinh Nguyen <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [v2 PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock

Quoted 21 lines

CAUTION: This email comes from a non Wind River email account! Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 1 line · Meng Li

When config CONFIG_USB_DWC3_DUAL_ROLE is selected, and trigger

system

Quoted 14 lines

to enter suspend status with below command:
echo mem > /sys/power/state
There will be a deadlock issue occurring. Detailed invoking path as below:
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 issue is exposed by commit c7ebd8149ee5 ("usb: dwc3: gadget:
Fix NULL pointer dereference in dwc3_gadget_suspend") that removes the code of checking whether dwc->gadget_driver is NULL or not. It causes the following code is executed and deadlock occurs when trying to get the spinlock. In fact, the root cause is the commit

5265397f9442("usb:

Quoted 19 lines

dwc3:

Quoted 18 lines

Remove DWC3 locking during gadget suspend/resume") that forgot to remove the lock of otg mode. So, remove the redundant lock of otg mode during gadget suspend/resume.

Fixes 5265397f9442 ("usb: dwc3: Remove DWC3 locking during gadget

suspend/resume")

---
v1->v2:
- improve commit log, correct the Fixes commit id.

---
 drivers/usb/dwc3/core.c | 6 ------
 1 file changed, 6 deletions(-)
Quoted 9 lines

drivers/usb/dwc3/core.c static int dwc3_core_init_for_resume(struct

Quoted 5 lines
drivers/usb/dwc3/core.c index renamed from drivers/usb/dwc3/core.c +0 -0

7ee61a89520b..9d47c3aa5777 100644

drivers/usb/dwc3/core.c +0 -0
@@ -2250,7 +2250,6 @@ static int dwc3_core_init_for_resume(struct

dwc3

Quoted 3 lines
drivers/usb/dwc3/core.c +0 -0
 *dwc)
 
 static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t

msg)

Quoted 16 lines

{

drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3

Quoted 5 lines
drivers/usb/dwc3/core.c +0 -1
-     unsigned long   flags;
      u32 reg;
      int i;
 
@@ -2293,9 +2292,7 @@ static int dwc3_suspend_common(struct dwc3

*dwc, pm_message_t msg)

Quoted 9 lines
drivers/usb/dwc3/core.c +0 -2
                      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);
              }
 
Quoted 5 lines

drivers/usb/dwc3/core.c static int dwc3_suspend_common(struct dwc3

Quoted 1 line
drivers/usb/dwc3/core.c +0 -0
@@ -2312,7 +2309,6 @@ static int dwc3_suspend_common(struct dwc3

*dwc,

Quoted 3 lines
drivers/usb/dwc3/core.c +0 -0
 pm_message_t msg)
 
 static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg)

{

Quoted 14 lines

drivers/usb/dwc3/core.c static int dwc3_resume_common(struct dwc3

Quoted 5 lines
drivers/usb/dwc3/core.c +0 -1
-     unsigned long   flags;
      int             ret;
      u32             reg;
      int             i;
@@ -2366,9 +2362,7 @@ static int dwc3_resume_common(struct dwc3

*dwc, pm_message_t msg)

Quoted 8 lines
drivers/usb/dwc3/core.c +0 -2
              if (dwc->current_otg_role == DWC3_OTG_ROLE_HOST) {
                      dwc3_otg_host_init(dwc);
              } else if (dwc->current_otg_role == DWC3_OTG_ROLE_DEVICE) {
-                     spin_lock_irqsave(&dwc->lock, flags);
                      dwc3_gadget_resume(dwc);
-                     spin_unlock_irqrestore(&dwc->lock, flags);
              }
 
Quoted 8 lines
Quoted 4 lines
drivers/usb/dwc3/core.c +0 -1
              break;
--

2.34.1

Did you use "git format-patch -v"? The $subject version prefix order is different. In any case,

Quoted 6 lines

Sorry! I use --subject-prefix="v2 PATCH".
I will correct it in next patch pull request.

Thanks,
Limeng

Do I need to send another v3 pull request?

Thanks,
LImeng

Quoted 4 lines
Quoted 4 lines

Thanks,
Thinh

maintainer
#8 lore raw
Quoted 3 lines · Meng

Do I need to send another v3 pull request?

No. Greg already picked this up.

Thanks,
Thinh

author
#9 lore raw
Quoted 16 lines

-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, June 22, 2024 7:15 AM
To: Li, Meng <[email protected]>
Cc: Thinh Nguyen <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [v2 PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock

CAUTION: This email comes from a non Wind River email account! Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 7 lines
Quoted 3 lines · Meng

Do I need to send another v3 pull request?

No. Greg already picked this up.

Thanks for reviewing and accepting my patch.
You have given me great enthusiasm to contribute to the community

regards,
Limeng

Quoted 2 lines

Thanks,
Thinh