Skip to contentSkip to conversation

usb: host: xhci-mtk: avoid runtime suspend when removing hcd

PATCH Superseded Macpaul Lin 4 participants 9 messages May 29, 2020 – Jun 4, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: host: xhci-mtk: avoid runtime suspend when removing hcd

When runtime suspend was enabled, runtime suspend might happened when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

Change-Id I70a5dc8006207caeecbac6955ce8e5345dcc70e6
---
 drivers/usb/host/xhci-mtk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +3 -2
index bfbdb3c..641d24e 100644
@@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct usb_hcd  *shared_hcd = xhci->shared_hcd;
 
+	pm_runtime_put_sync(&dev->dev);
+	pm_runtime_disable(&dev->dev);
+
 	usb_remove_hcd(shared_hcd);
 	xhci->shared_hcd = NULL;
 	device_init_wakeup(&dev->dev, false);
@@ -597,8 +600,6 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	xhci_mtk_sch_exit(mtk);
 	xhci_mtk_clks_disable(mtk);
 	xhci_mtk_ldos_disable(mtk);
-	pm_runtime_put_sync(&dev->dev);
-	pm_runtime_disable(&dev->dev);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/1 usb: host: xhci-mtk: avoid runtime suspend when removing hcd

When runtime suspend was enabled, runtime suspend might happened when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

---
 drivers/usb/host/xhci-mtk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +3 -2
index bfbdb3c..641d24e 100644
@@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct usb_hcd  *shared_hcd = xhci->shared_hcd;
 
+	pm_runtime_put_sync(&dev->dev);
+	pm_runtime_disable(&dev->dev);
+
 	usb_remove_hcd(shared_hcd);
 	xhci->shared_hcd = NULL;
 	device_init_wakeup(&dev->dev, false);
@@ -597,8 +600,6 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	xhci_mtk_sch_exit(mtk);
 	xhci_mtk_clks_disable(mtk);
 	xhci_mtk_ldos_disable(mtk);
-	pm_runtime_put_sync(&dev->dev);
-	pm_runtime_disable(&dev->dev);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
maintainer Reviewed-by on v2 1/1
#2 lore raw
Quoted 25 lines · Macpaul Lin

When runtime suspend was enabled, runtime suspend might happened when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

---
 drivers/usb/host/xhci-mtk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +3 -0
index bfbdb3c..641d24e 100644
@@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct usb_hcd  *shared_hcd = xhci->shared_hcd;
 
+	pm_runtime_put_sync(&dev->dev);
+	pm_runtime_disable(&dev->dev);
+
 	usb_remove_hcd(shared_hcd);
 	xhci->shared_hcd = NULL;
 	device_init_wakeup(&dev->dev, false);

drivers/usb/host/xhci-mtk.c static int xhci_mtk_remove(struct platform_device *dev) · line 605

Quoted 8 lines
drivers/usb/host/xhci-mtk.c +0 -2
@@ -597,8 +600,6 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	xhci_mtk_sch_exit(mtk);
 	xhci_mtk_clks_disable(mtk);
 	xhci_mtk_ldos_disable(mtk);
-	pm_runtime_put_sync(&dev->dev);
-	pm_runtime_disable(&dev->dev);
 
 	return 0;
 }

Thanks

#3 lore raw
In reply to Macpaul Lin
Quoted 16 lines · Macpaul Lin

When runtime suspend was enabled, runtime suspend might happened when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

Change-Id I70a5dc8006207caeecbac6955ce8e5345dcc70e6
---
 drivers/usb/host/xhci-mtk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +0 -0
index bfbdb3c..641d24e 100644

drivers/usb/host/xhci-mtk.c static int xhci_mtk_remove(struct platform_device *dev) · line 590

Quoted 4 lines
drivers/usb/host/xhci-mtk.c +1 -0
@@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct usb_hcd  *shared_hcd = xhci->shared_hcd;
 
+	pm_runtime_put_sync(&dev->dev);

Might runtime suspend here.
It's a lot better than before, no panic as hcd isn't released, but a bit unnecessary.

how about this sequence instead:
pm_runtime_disable()
pm_runtime_put_noidle()

drivers/usb/host/xhci-mtk.c static int xhci_mtk_remove(struct platform_device *dev) · line 592

Quoted 2 lines
drivers/usb/host/xhci-mtk.c +2 -0
+	pm_runtime_disable(&dev->dev);
+

-Mathias

#4 lore raw
Quoted 25 lines · Mathias Nyman
Quoted 16 lines · Macpaul Lin

When runtime suspend was enabled, runtime suspend might happened when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

Change-Id I70a5dc8006207caeecbac6955ce8e5345dcc70e6
---
 drivers/usb/host/xhci-mtk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +0 -0
index bfbdb3c..641d24e 100644

drivers/usb/host/xhci-mtk.c static int xhci_mtk_remove(struct platform_device *dev) · line 590

Quoted 4 lines
drivers/usb/host/xhci-mtk.c +1 -0
@@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct usb_hcd  *shared_hcd = xhci->shared_hcd;
 
+	pm_runtime_put_sync(&dev->dev);

Might runtime suspend here.
It's a lot better than before, no panic as hcd isn't released, but a bit unnecessary.

Quoted 8 lines

how about this sequence instead:
pm_runtime_disable()
pm_runtime_put_noidle()

drivers/usb/host/xhci-mtk.c static int xhci_mtk_remove(struct platform_device *dev) · line 592

Quoted 2 lines
drivers/usb/host/xhci-mtk.c +2 -0
+	pm_runtime_disable(&dev->dev);
+

-Mathias

Thanks for your suggestion!
Will it better to put no idle before disable?
pm_runtime_put_noidle()
pm_runtime_disable()

I've found pm_runtime_put_noidle is called in pm_runtime_disable() when there is a pending request.

I will send patch v3 as noidle() called earlier than disable(). Please help to comment it if disable() should go before.

Thanks!
Macpaul Lin

#5 lore raw

PATCH v3 1/1 usb: host: xhci-mtk: avoid runtime suspend when removing hcd

In reply to Mathias Nyman

When runtime suspend was enabled, runtime suspend might happened when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

---
Changes for v3:
- Replace better sequence for disabling the pm_runtime suspend.

 drivers/usb/host/xhci-mtk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +3 -2
index bfbdb3c..641d24e 100644
@@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct usb_hcd  *shared_hcd = xhci->shared_hcd;
 
+	pm_runtime_put_noidle(&dev->dev);
+	pm_runtime_disable(&dev->dev);
+
 	usb_remove_hcd(shared_hcd);
 	xhci->shared_hcd = NULL;
 	device_init_wakeup(&dev->dev, false);
@@ -597,8 +600,6 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	xhci_mtk_sch_exit(mtk);
 	xhci_mtk_clks_disable(mtk);
 	xhci_mtk_ldos_disable(mtk);
-	pm_runtime_put_sync(&dev->dev);
-	pm_runtime_disable(&dev->dev);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#6 lore raw

Hello.

Quoted 1 line · Macpaul Lin

When runtime suspend was enabled, runtime suspend might happened

Happen.

Quoted 6 lines

when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

[...]

MBR, Sergei

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#7 lore raw

PATCH v4 1/1 usb: host: xhci-mtk: avoid runtime suspend when removing hcd

In reply to Macpaul Lin

When runtime suspend was enabled, runtime suspend might happen when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

---
Changes for v3:
- Replace better sequence for disabling the pm_runtime suspend.
Changes for v4:
- Thanks for Sergei's review, typo in commit description has been corrected.

 drivers/usb/host/xhci-mtk.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-mtk.c +3 -2
index bfbdb3c..641d24e 100644
@@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	struct xhci_hcd	*xhci = hcd_to_xhci(hcd);
 	struct usb_hcd  *shared_hcd = xhci->shared_hcd;
 
+	pm_runtime_put_noidle(&dev->dev);
+	pm_runtime_disable(&dev->dev);
+
 	usb_remove_hcd(shared_hcd);
 	xhci->shared_hcd = NULL;
 	device_init_wakeup(&dev->dev, false);
@@ -597,8 +600,6 @@ static int xhci_mtk_remove(struct platform_device *dev)
 	xhci_mtk_sch_exit(mtk);
 	xhci_mtk_clks_disable(mtk);
 	xhci_mtk_ldos_disable(mtk);
-	pm_runtime_put_sync(&dev->dev);
-	pm_runtime_disable(&dev->dev);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#8 lore raw
Quoted 5 lines · Macpaul Lin

When runtime suspend was enabled, runtime suspend might happen when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it.

Quoted 9 lines

---
Changes for v3:
- Replace better sequence for disabling the pm_runtime suspend.
Changes for v4:
- Thanks for Sergei's review, typo in commit description has been corrected.

Thanks, added to queue

-Mathias