2015-12-07 16:58:58

by Peter Wu

[permalink] [raw]
Subject: [PATCH] r8152: fix lockup when runtime PM is enabled

When an interface is brought up which was previously suspended (via
runtime PM), it would hang. This happens because napi_disable is called
before napi_enable.

Solve this by avoiding napi_disable before the device is fully up.

While at it, remove WORK_ENABLE check from rtl8152_open (introduced with
the original change) because it cannot happen:

- After this patch, runtime resume will not set it during rtl8152_open.
- When link is up, rtl8152_open is not called.
- When link is down during system/auto suspend/resume, it is not set.

Fixes: 41cec84cf285 ("r8152: don't enable napi before rx ready")
Link: https://lkml.kernel.org/r/20151205105912.GA1766@al
Signed-off-by: Peter Wu <[email protected]>
---
drivers/net/usb/r8152.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index d9427ca..b8b083e 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -3067,17 +3067,6 @@ static int rtl8152_open(struct net_device *netdev)

mutex_lock(&tp->control);

- /* The WORK_ENABLE may be set when autoresume occurs */
- if (test_bit(WORK_ENABLE, &tp->flags)) {
- clear_bit(WORK_ENABLE, &tp->flags);
- usb_kill_urb(tp->intr_urb);
- cancel_delayed_work_sync(&tp->schedule);
-
- /* disable the tx/rx, if the workqueue has enabled them. */
- if (netif_carrier_ok(netdev))
- tp->rtl_ops.disable(tp);
- }
-
tp->rtl_ops.up(tp);

rtl8152_set_speed(tp, AUTONEG_ENABLE,
@@ -3516,11 +3505,13 @@ static int rtl8152_resume(struct usb_interface *intf)
if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
rtl_runtime_suspend_enable(tp, false);
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
- napi_disable(&tp->napi);
- set_bit(WORK_ENABLE, &tp->flags);
- if (netif_carrier_ok(tp->netdev))
- rtl_start_rx(tp);
- napi_enable(&tp->napi);
+ if (tp->netdev->flags & IFF_UP) {
+ napi_disable(&tp->napi);
+ set_bit(WORK_ENABLE, &tp->flags);
+ if (netif_carrier_ok(tp->netdev))
+ rtl_start_rx(tp);
+ napi_enable(&tp->napi);
+ }
} else {
tp->rtl_ops.up(tp);
rtl8152_set_speed(tp, AUTONEG_ENABLE,
--
2.6.3


2015-12-08 03:39:23

by Hayes Wang

[permalink] [raw]
Subject: RE: [PATCH] r8152: fix lockup when runtime PM is enabled

Peter Wu [mailto:[email protected]]
> Sent: Tuesday, December 08, 2015 12:59 AM
[...]
> + if (tp->netdev->flags & IFF_UP) {

Maybe you could just replace the checking of netif_running(tp->netdev) with this.

Excuse me. I have a question. Before the open() is finished, the netif_running() would
be true, but the IFF_UP wouldn't be set. Is it right?

Best Regards,
Hayes

2015-12-08 11:10:35

by Peter Wu

[permalink] [raw]
Subject: Re: [PATCH] r8152: fix lockup when runtime PM is enabled

On Tue, Dec 08, 2015 at 03:18:59AM +0000, Hayes Wang wrote:
> Peter Wu
> > Sent: Tuesday, December 08, 2015 12:59 AM
> [...]
> > + if (tp->netdev->flags & IFF_UP) {
>
> Maybe you could just replace the checking of netif_running(tp->netdev)
> with this.

Simply replacing netif_running by IFF_UP does not work, it hangs during
close when the device is suspended. This patch is correct, but I have a
v2 patch that moves rtl_runtime_suspend_enable from close to suspend.

This is the evaluated scenario (run = netif_running, up = IFF_UP set):

# suspended before open
suspend (run=0, up=0)
open (run=1)
resume (run=1, up=0) <-- fixed by patch
(open ends)

# while up
suspend (run=1, up=1)
resume (run=1, up=1) <-- no issue, values match
suspend (run=1, up=1)

# close while suspended
close (run=0, up=1)
resume (run=0, up=1) <-- fixed in patch v2
(close cont and ends) <-- rtl_runtime_suspend_enable removed in v2
suspend (run=0, up=0)

# while down
resume (run=0, up=0)
suspend (run=0, up=0)

# open while suspended, open fails
open (run=1)
resume (run=1, up=0) <-- fixed by patch
(open fails)
suspend (run=0, up=0)

> Excuse me. I have a question. Before the open() is finished, the
> netif_running() would be true, but the IFF_UP wouldn't be set. Is it
> right?

That is right, this happens behind the scenes:

# open
netif_running = true
open()
if open succeeded
set IFF_UP
else
netif_running = false

# close
netif_running = false
close()
clear IFF_UP
--
Kind regards,
Peter Wu
https://lekensteyn.nl