* [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
@ 2024-06-13 7:39 Meng Li
2024-06-13 8:06 ` Greg KH
0 siblings, 1 reply; 8+ messages in thread
From: Meng Li @ 2024-06-13 7:39 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, quic_uaggarwa, linux-usb, linux-kernel; +Cc: 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. Because dwc3_gadget_suspend() also
try to get the lock again when previous invoked dwc3_suspend_common() has
got the lock . This issue is introduced 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.
To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3: Remove
DWC3 locking during gadget suspend/resume"), remove lock of otg mode during
gadget suspend/resume.
Fixes: 61a348857e86 ("Fix NULL pointer dereference in dwc3_gadget_suspend")
Cc: stable@vger.kernel.org
Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
drivers/usb/dwc3/core.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7ee61a89520b..9d47c3aa5777 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
2024-06-13 7:39 [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock Meng Li
@ 2024-06-13 8:06 ` Greg KH
2024-06-13 11:59 ` Li, Meng
0 siblings, 1 reply; 8+ messages in thread
From: Greg KH @ 2024-06-13 8:06 UTC (permalink / raw)
To: Meng Li; +Cc: Thinh.Nguyen, quic_uaggarwa, linux-usb, linux-kernel
On Thu, Jun 13, 2024 at 03:39:59PM +0800, Meng Li wrote:
> 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. Because dwc3_gadget_suspend() also
> try to get the lock again when previous invoked dwc3_suspend_common() has
> got the lock . This issue is introduced 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.
> To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3: Remove
> DWC3 locking during gadget suspend/resume"), remove lock of otg mode during
> gadget suspend/resume.
>
> Fixes: 61a348857e86 ("Fix NULL pointer dereference in dwc3_gadget_suspend")
> Cc: stable@vger.kernel.org
> Signed-off-by: Meng Li <Meng.Li@windriver.com>
> ---
> drivers/usb/dwc3/core.c | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 7ee61a89520b..9d47c3aa5777 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -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;
> --
> 2.34.1
>
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 8+ messages in thread* RE: [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
2024-06-13 8:06 ` Greg KH
@ 2024-06-13 11:59 ` Li, Meng
2024-06-17 23:59 ` Thinh Nguyen
0 siblings, 1 reply; 8+ messages in thread
From: Li, Meng @ 2024-06-13 11:59 UTC (permalink / raw)
To: Greg KH
Cc: Thinh.Nguyen@synopsys.com, quic_uaggarwa@quicinc.com,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Greg KH <gregkh@linuxfoundation.org>
> Sent: Thursday, June 13, 2024 4:06 PM
> To: Li, Meng <Meng.Li@windriver.com>
> Cc: Thinh.Nguyen@synopsys.com; quic_uaggarwa@quicinc.com; linux-
> usb@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [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.
>
> On Thu, Jun 13, 2024 at 03:39:59PM +0800, Meng Li wrote:
> > 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. Because
> > dwc3_gadget_suspend() also try to get the lock again when previous
> > invoked dwc3_suspend_common() has got the lock . This issue is introduced
> 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.
> > To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3:
> > Remove
> > DWC3 locking during gadget suspend/resume"), remove lock of otg mode
> > during gadget suspend/resume.
> >
> > Fixes: 61a348857e86 ("Fix NULL pointer dereference in
> > dwc3_gadget_suspend")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Meng Li <Meng.Li@windriver.com>
> > ---
> > drivers/usb/dwc3/core.c | 6 ------
> > 1 file changed, 6 deletions(-)
> >
> > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index
> > 7ee61a89520b..9d47c3aa5777 100644
> > --- a/drivers/usb/dwc3/core.c
> > +++ b/drivers/usb/dwc3/core.c
> > @@ -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;
> > --
> > 2.34.1
> >
> >
>
> Hi,
>
> This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a
> patch that has triggered this response. He used to manually respond to these
> common problems, but in order to save his sanity (he kept writing the same
> thing over and over, yet to different people), I was created. Hopefully you will
> not take offence and will fix the problem in your patch and resubmit it so that
> it can be accepted into the Linux kernel tree.
>
> You are receiving this message because of the following common error(s) as
> indicated below:
>
> - This looks like a new version of a previously submitted patch, but you
> did not list below the --- line any changes from the previous version.
> Please read the section entitled "The canonical patch format" in the
> kernel file, Documentation/process/submitting-patches.rst for what
> needs to be done here to properly describe this.
>
> If you wish to discuss this problem further, or you have questions about how
> to resolve this issue, please feel free to respond to this email and Greg will
> reply once he has dug out from the pending patches received from other
> developers.
>
Sorry! I sent the patch of linux-stable version firstly, and then I realize my fault, so send a correct version for mainline upstream.
So, I think I received this email from patch-bot to remind me to add the --- for change log.
Let me clarify that this patch is the first version for mainline upstream. And please ignore the previous wrong one for linux-stable.
Best Regards,
Meng
> thanks,
>
> greg k-h's patch email bot
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
2024-06-13 11:59 ` Li, Meng
@ 2024-06-17 23:59 ` Thinh Nguyen
0 siblings, 0 replies; 8+ messages in thread
From: Thinh Nguyen @ 2024-06-17 23:59 UTC (permalink / raw)
To: Li, Meng
Cc: Greg KH, Thinh Nguyen, quic_uaggarwa@quicinc.com, Xu Yang,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
+Xu Yang,
On Thu, Jun 13, 2024, Li, Meng wrote:
>
>
> > -----Original Message-----
> > From: Greg KH <gregkh@linuxfoundation.org>
> > Sent: Thursday, June 13, 2024 4:06 PM
> > To: Li, Meng <Meng.Li@windriver.com>
> > Cc: Thinh.Nguyen@synopsys.com; quic_uaggarwa@quicinc.com; linux-
> > usb@vger.kernel.org; linux-kernel@vger.kernel.org
> > Subject: Re: [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.
> >
> > On Thu, Jun 13, 2024 at 03:39:59PM +0800, Meng Li wrote:
> > > 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. Because
> > > dwc3_gadget_suspend() also try to get the lock again when previous
> > > invoked dwc3_suspend_common() has got the lock . This issue is introduced
> > 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.
> > > To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3:
> > > Remove
> > > DWC3 locking during gadget suspend/resume"), remove lock of otg mode
> > > during gadget suspend/resume.
> > >
> > > Fixes: 61a348857e86 ("Fix NULL pointer dereference in
> > > dwc3_gadget_suspend")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Meng Li <Meng.Li@windriver.com>
> > > ---
> > > drivers/usb/dwc3/core.c | 6 ------
> > > 1 file changed, 6 deletions(-)
> > >
> > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index
> > > 7ee61a89520b..9d47c3aa5777 100644
> > > --- a/drivers/usb/dwc3/core.c
> > > +++ b/drivers/usb/dwc3/core.c
> > > @@ -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;
> > > --
> > > 2.34.1
> > >
> > >
> >
> > Hi,
> >
> > This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a
> > patch that has triggered this response. He used to manually respond to these
> > common problems, but in order to save his sanity (he kept writing the same
> > thing over and over, yet to different people), I was created. Hopefully you will
> > not take offence and will fix the problem in your patch and resubmit it so that
> > it can be accepted into the Linux kernel tree.
> >
> > You are receiving this message because of the following common error(s) as
> > indicated below:
> >
> > - This looks like a new version of a previously submitted patch, but you
> > did not list below the --- line any changes from the previous version.
> > Please read the section entitled "The canonical patch format" in the
> > kernel file, Documentation/process/submitting-patches.rst for what
> > needs to be done here to properly describe this.
> >
> > If you wish to discuss this problem further, or you have questions about how
> > to resolve this issue, please feel free to respond to this email and Greg will
> > reply once he has dug out from the pending patches received from other
> > developers.
> >
>
> Sorry! I sent the patch of linux-stable version firstly, and then I realize my fault, so send a correct version for mainline upstream.
> So, I think I received this email from patch-bot to remind me to add the --- for change log.
> Let me clarify that this patch is the first version for mainline upstream. And please ignore the previous wrong one for linux-stable.
>
> Best Regards,
> Meng
>
Xu Yang reported and sent a patch[*] and I reviewed and Acked a while
ago. However, he and I did missed about removing the lock during
dwc3_resume_common().
Please resend the patch so we can apply the fix.
Thanks,
Thinh
[*] https://lore.kernel.org/linux-usb/20240528230951.23ac5yqwkpalxdzz@synopsys.com/
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
@ 2024-06-13 7:23 Meng Li
2024-06-13 7:25 ` Li, Meng
2024-06-13 8:52 ` Krzysztof Kozlowski
0 siblings, 2 replies; 8+ messages in thread
From: Meng Li @ 2024-06-13 7:23 UTC (permalink / raw)
To: Thinh.Nguyen, gregkh, quic_uaggarwa, linux-usb, linux-kernel; +Cc: 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. Because dwc3_gadget_suspend() also
try to get the lock again when previous invoked dwc3_suspend_common() has
got the lock . This issue is introduced 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.
To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3: Remove
DWC3 locking during gadget suspend/resume"), remove lock of otg mode during
gadget suspend/resume.
Fixes: c7ebd8149ee5 ("Fix NULL pointer dereference in dwc3_gadget_suspend")
Cc: stable@vger.kernel.org
Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
drivers/usb/dwc3/core.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index a8fb10cc65bc..9bb4ab409bbb 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -2112,7 +2112,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;
switch (dwc->current_dr_role) {
@@ -2150,9 +2149,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);
}
@@ -2169,7 +2166,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;
@@ -2227,9 +2223,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;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* RE: [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
2024-06-13 7:23 Meng Li
@ 2024-06-13 7:25 ` Li, Meng
2024-06-13 8:52 ` Krzysztof Kozlowski
1 sibling, 0 replies; 8+ messages in thread
From: Li, Meng @ 2024-06-13 7:25 UTC (permalink / raw)
To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org,
quic_uaggarwa@quicinc.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Sorry! please ignore this patch that is for the linux-stable kernel.
I will create another one for mainline upstream.
Thanks,
LImeng
> -----Original Message-----
> From: Li, Meng <Meng.Li@windriver.com>
> Sent: Thursday, June 13, 2024 3:23 PM
> To: Thinh.Nguyen@synopsys.com; gregkh@linuxfoundation.org;
> quic_uaggarwa@quicinc.com; linux-usb@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Cc: Li, Meng <Meng.Li@windriver.com>
> Subject: [PATCH] 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. Because dwc3_gadget_suspend() also
> try to get the lock again when previous invoked dwc3_suspend_common()
> has got the lock . This issue is introduced 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.
> To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3: Remove
> DWC3 locking during gadget suspend/resume"), remove lock of otg mode
> during gadget suspend/resume.
>
> Fixes: c7ebd8149ee5 ("Fix NULL pointer dereference in
> dwc3_gadget_suspend")
> Cc: stable@vger.kernel.org
> Signed-off-by: Meng Li <Meng.Li@windriver.com>
> ---
> drivers/usb/dwc3/core.c | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index
> a8fb10cc65bc..9bb4ab409bbb 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -2112,7 +2112,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;
>
> switch (dwc->current_dr_role) {
> @@ -2150,9 +2149,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);
> }
>
> @@ -2169,7 +2166,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;
>
> @@ -2227,9 +2223,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;
> --
> 2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
2024-06-13 7:23 Meng Li
2024-06-13 7:25 ` Li, Meng
@ 2024-06-13 8:52 ` Krzysztof Kozlowski
2024-06-13 11:22 ` Li, Meng
1 sibling, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2024-06-13 8:52 UTC (permalink / raw)
To: Meng Li, Thinh.Nguyen, gregkh, quic_uaggarwa, linux-usb,
linux-kernel
On 13/06/2024 09:23, Meng Li wrote:
> 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. Because dwc3_gadget_suspend() also
> try to get the lock again when previous invoked dwc3_suspend_common() has
> got the lock . This issue is introduced 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.
> To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3: Remove
> DWC3 locking during gadget suspend/resume"), remove lock of otg mode during
> gadget suspend/resume.
That's a funny way of fixing deadlocks: remove the lock. Of course it
could be correct way with some justification why locking is not needed.
No such justification here, so following your logic, let's remove
locking everywhere and then no deadlocks possible!
Let me prepare patches for that...
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 8+ messages in thread* RE: [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock
2024-06-13 8:52 ` Krzysztof Kozlowski
@ 2024-06-13 11:22 ` Li, Meng
0 siblings, 0 replies; 8+ messages in thread
From: Li, Meng @ 2024-06-13 11:22 UTC (permalink / raw)
To: Krzysztof Kozlowski, Thinh.Nguyen@synopsys.com,
gregkh@linuxfoundation.org, quic_uaggarwa@quicinc.com,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Krzysztof Kozlowski <krzk@kernel.org>
> Sent: Thursday, June 13, 2024 4:53 PM
> To: Li, Meng <Meng.Li@windriver.com>; Thinh.Nguyen@synopsys.com;
> gregkh@linuxfoundation.org; quic_uaggarwa@quicinc.com; linux-
> usb@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [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.
>
> On 13/06/2024 09:23, Meng Li wrote:
> > 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. Because
> > dwc3_gadget_suspend() also try to get the lock again when previous
> > invoked dwc3_suspend_common() has got the lock . This issue is introduced
> 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.
> > To fix the deadlock issue, refer to commit 5265397f9442("usb: dwc3:
> > Remove
> > DWC3 locking during gadget suspend/resume"), remove lock of otg mode
> > during gadget suspend/resume.
>
> That's a funny way of fixing deadlocks: remove the lock. Of course it could be
> correct way with some justification why locking is not needed.
> No such justification here, so following your logic, let's remove locking
> everywhere and then no deadlocks possible!
>
I don't remove lock arbitrarily. I have show the commit 5265397f9442. It move the spinlock from dwc3_suspend_common() to dwc3_gadget_suspend() for device mode, but maybe forgot the case of otg move.
So, cause deadlock when dwc3_gadget_suspend() try to get the spinlock that has been got by dwc3_suspend_common(). So, I think it also needs to remove the spinlock for otg mode.
> Let me prepare patches for that...
I think you can comment on patch, propose some advice, rather than negate the effort of others without any comment directly.
As a maintainer of some parts of kernel, I think your communication style is not friendly, and not conducive to developers contributing to the community, because their enthusiasm was dampened.
If you create patch, please don't forgot to send to me, I want to learn what good solution you will show, and how much better than this patch.
Regards,
Meng
>
> Best regards,
> Krzysztof
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-06-17 23:59 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 7:39 [PATCH] usb: dwc3: core: remove lock of otg mode during gadget suspend/resume to avoid deadlock Meng Li
2024-06-13 8:06 ` Greg KH
2024-06-13 11:59 ` Li, Meng
2024-06-17 23:59 ` Thinh Nguyen
-- strict thread matches above, loose matches on Subject: below --
2024-06-13 7:23 Meng Li
2024-06-13 7:25 ` Li, Meng
2024-06-13 8:52 ` Krzysztof Kozlowski
2024-06-13 11:22 ` Li, Meng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox