qmi_wwan: avoid RCU stalls on device disconnect when in QMAP mode
authorReinhard Speyerer <rspmn@arcor.de>
Wed, 12 Jun 2019 17:03:15 +0000 (19:03 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 15 Jun 2019 02:05:58 +0000 (19:05 -0700)
Switch qmimux_unregister_device() and qmi_wwan_disconnect() to
use unregister_netdevice_queue() and unregister_netdevice_many()
instead of unregister_netdevice(). This avoids RCU stalls which
have been observed on device disconnect in certain setups otherwise.

Fixes: c6adf77953bc ("net: usb: qmi_wwan: add qmap mux protocol support")
Cc: Daniele Palmas <dnlplm@gmail.com>
Signed-off-by: Reinhard Speyerer <rspmn@arcor.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/usb/qmi_wwan.c

index b0a96459621f333fab4ccde3420f51e3385bea2e..c6fbc2a2a78563bb008c408a3a914fb563f0b7ed 100644 (file)
@@ -312,14 +312,15 @@ out_free_newdev:
        return err;
 }
 
-static void qmimux_unregister_device(struct net_device *dev)
+static void qmimux_unregister_device(struct net_device *dev,
+                                    struct list_head *head)
 {
        struct qmimux_priv *priv = netdev_priv(dev);
        struct net_device *real_dev = priv->real_dev;
 
        free_percpu(priv->stats64);
        netdev_upper_dev_unlink(real_dev, dev);
-       unregister_netdevice(dev);
+       unregister_netdevice_queue(dev, head);
 
        /* Get rid of the reference to real_dev */
        dev_put(real_dev);
@@ -490,7 +491,7 @@ static ssize_t del_mux_store(struct device *d,  struct device_attribute *attr, c
                ret = -EINVAL;
                goto err;
        }
-       qmimux_unregister_device(del_dev);
+       qmimux_unregister_device(del_dev, NULL);
 
        if (!qmimux_has_slaves(dev))
                info->flags &= ~QMI_WWAN_FLAG_MUX;
@@ -1500,6 +1501,7 @@ static void qmi_wwan_disconnect(struct usb_interface *intf)
        struct qmi_wwan_state *info;
        struct list_head *iter;
        struct net_device *ldev;
+       LIST_HEAD(list);
 
        /* called twice if separate control and data intf */
        if (!dev)
@@ -1512,8 +1514,9 @@ static void qmi_wwan_disconnect(struct usb_interface *intf)
                }
                rcu_read_lock();
                netdev_for_each_upper_dev_rcu(dev->net, ldev, iter)
-                       qmimux_unregister_device(ldev);
+                       qmimux_unregister_device(ldev, &list);
                rcu_read_unlock();
+               unregister_netdevice_many(&list);
                rtnl_unlock();
                info->flags &= ~QMI_WWAN_FLAG_MUX;
        }