linux-stable/drivers/net
Dexuan Cui 8aa07625eb hv_netvsc: Fix a deadlock by getting rtnl lock earlier in netvsc_probe()
[ Upstream commit e04e7a7bbd ]

This patch fixes the race between netvsc_probe() and
rndis_set_subchannel(), which can cause a deadlock.

These are the related 3 paths which show the deadlock:

path #1:
    Workqueue: hv_vmbus_con vmbus_onmessage_work [hv_vmbus]
    Call Trace:
     schedule
     schedule_preempt_disabled
     __mutex_lock
     __device_attach
     bus_probe_device
     device_add
     vmbus_device_register
     vmbus_onoffer
     vmbus_onmessage_work
     process_one_work
     worker_thread
     kthread
     ret_from_fork

path #2:
    schedule
     schedule_preempt_disabled
     __mutex_lock
     netvsc_probe
     vmbus_probe
     really_probe
     __driver_attach
     bus_for_each_dev
     driver_attach_async
     async_run_entry_fn
     process_one_work
     worker_thread
     kthread
     ret_from_fork

path #3:
    Workqueue: events netvsc_subchan_work [hv_netvsc]
    Call Trace:
     schedule
     rndis_set_subchannel
     netvsc_subchan_work
     process_one_work
     worker_thread
     kthread
     ret_from_fork

Before path #1 finishes, path #2 can start to run, because just before
the "bus_probe_device(dev);" in device_add() in path #1, there is a line
"object_uevent(&dev->kobj, KOBJ_ADD);", so systemd-udevd can
immediately try to load hv_netvsc and hence path #2 can start to run.

Next, path #2 offloads the subchannal's initialization to a workqueue,
i.e. path #3, so we can end up in a deadlock situation like this:

Path #2 gets the device lock, and is trying to get the rtnl lock;
Path #3 gets the rtnl lock and is waiting for all the subchannel messages
to be processed;
Path #1 is trying to get the device lock, but since #2 is not releasing
the device lock, path #1 has to sleep; since the VMBus messages are
processed one by one, this means the sub-channel messages can't be
procedded, so #3 has to sleep with the rtnl lock held, and finally #2
has to sleep... Now all the 3 paths are sleeping and we hit the deadlock.

With the patch, we can make sure #2 gets both the device lock and the
rtnl lock together, gets its job done, and releases the locks, so #1
and #3 will not be blocked for ever.

Fixes: 8195b1396e ("hv_netvsc: fix deadlock on hotplug")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-15 09:45:26 +02:00
..
appletalk
arcnet
bonding bonding: avoid lockdep confusion in bond_get_stats() 2018-08-06 16:20:47 +02:00
caif
can can: m_can: Move accessing of message ram to after clocks are enabled 2018-09-05 09:26:28 +02:00
cris
dsa net: dsa: qca8k: Allow overwriting CPU port setting 2018-08-03 07:50:44 +02:00
ethernet mlxsw: spectrum_switchdev: Do not leak RIFs when removing bridge 2018-09-15 09:45:25 +02:00
fddi
fjes
hamradio net: hamradio: use eth_broadcast_addr 2018-08-24 13:09:02 +02:00
hippi hippi: Fix a Fix a possible sleep-in-atomic bug in rr_close 2018-02-25 11:08:04 +01:00
hyperv hv_netvsc: Fix a deadlock by getting rtnl lock earlier in netvsc_probe() 2018-09-15 09:45:26 +02:00
ieee802154 ieee802154: fakelb: switch from BUG_ON() to WARN_ON() on problem 2018-08-24 13:09:14 +02:00
ipvlan ipvlan: call dev_change_flags when ipvlan mode is reset 2018-08-24 13:09:11 +02:00
phy net: mdio-mux: bcm-iproc: fix wrong getter and setter pair 2018-08-03 07:50:44 +02:00
plip
ppp pppoe: check sockaddr length in pppoe_connect() 2018-04-29 11:33:12 +02:00
slip slip: Check if rstate is initialized before uncompressing 2018-04-19 08:56:16 +02:00
team team: use netdev_features_t instead of u32 2018-06-11 22:49:20 +02:00
usb qmi_wwan: fix interface number for DW5821e production firmware 2018-09-05 09:26:28 +02:00
vmxnet3 vmxnet3: use DMA memory barriers where required 2018-05-25 16:17:25 +02:00
wan drivers: net: lmc: fix case value for target abort error 2018-09-05 09:26:32 +02:00
wimax
wireless libertas: fix suspend and resume for SDIO connected cards 2018-09-09 19:55:53 +02:00
xen-netback
dummy.c
eql.c
geneve.c net: fix use-after-free in GRO with ESP 2018-07-22 14:28:44 +02:00
gtp.c
ifb.c
Kconfig
LICENSE.SRC
loopback.c
macsec.c
macvlan.c macvlan: fix use-after-free in macvlan_common_newlink() 2018-05-30 07:52:02 +02:00
macvtap.c
Makefile
mdio.c
mii.c
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
Space.c
sungem_phy.c
tap.c net: in virtio_net_hdr only add VLAN_HLEN to csum_start if payload holds vlan 2018-06-26 08:06:28 +08:00
tun.c net: in virtio_net_hdr only add VLAN_HLEN to csum_start if payload holds vlan 2018-06-26 08:06:28 +08:00
veth.c veth: set peer GSO values 2018-03-19 08:42:54 +01:00
virtio_net.c net: in virtio_net_hdr only add VLAN_HLEN to csum_start if payload holds vlan 2018-06-26 08:06:28 +08:00
vrf.c vrf: Fix use after free and double free in vrf_finish_output 2018-04-12 12:32:24 +02:00
vsockmon.c
vxlan.c vxlan: fix default fdb entry netlink notify ordering during netdev create 2018-07-28 07:55:43 +02:00
xen-netfront.c xen/netfront: don't cache skb_shinfo() 2018-08-15 18:12:47 +02:00