Skip to contentSkip to conversation

netvsc hot plug fix

PATCH Superseded Stephen Hemminger 2 participants 4 messages Sep 6, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover netvsc hot plug fix

This is one fix for problems with hot add of network device on Windows Server.

Stephen Hemminger (1):
hv_netvsc: fix deadlock on hotplug

 drivers/net/hyperv/hyperv_net.h   |   1 +
 drivers/net/hyperv/netvsc_drv.c   |   8 +--
 drivers/net/hyperv/rndis_filter.c | 106 ++++++++++++++++++++++++++------------
 3 files changed, 74 insertions(+), 41 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/1 hv_netvsc: fix deadlock on hotplug

When a virtual device is added dynamically (via host console), then the vmbus sends an offer message for the primary channel. The processing of this message for networking causes the network device to then initialize the sub channels.

The problem is that setting up the sub channels needs to wait until the subsequent subchannel offers have been processed. These offers come in on the same ring buffer and work queue as where the primary offer is being processed; leading to a deadlock.

This did not happen in older kernels, because the sub channel waiting logic was broken (it wasn't really waiting).

The solution is to do the sub channel setup in its own work queue context that is scheduled by the primary channel setup; and then happens later.

Fixes 732e49850c5e ("netvsc: fix race on sub channel creation")

---
Should also go to stable, but this version does not apply cleanly to 4.13. Have another patch for that.

 drivers/net/hyperv/hyperv_net.h   |   1 +
 drivers/net/hyperv/netvsc_drv.c   |   8 +--
 drivers/net/hyperv/rndis_filter.c | 106 ++++++++++++++++++++++++++------------
 3 files changed, 74 insertions(+), 41 deletions(-)
drivers/net/hyperv/hyperv_net.h +1 -0
index ec546da86683..d1df5050adfb 100644
@@ -172,6 +172,7 @@ struct rndis_device {
 	struct list_head req_list;
 
 	struct work_struct mcast_work;
+	struct work_struct subchan_work;
 
 	bool link_state;        /* 0 - link up, 1 - link down */
 
drivers/net/hyperv/netvsc_drv.c +1 -7
index 165ba4b3b423..80f45e0f81c8 100644
@@ -853,10 +853,7 @@ static int netvsc_set_channels(struct net_device *net,
 	rndis_filter_device_remove(dev, nvdev);
 
 	nvdev = rndis_filter_device_add(dev, &device_info);
-	if (!IS_ERR(nvdev)) {
-		netif_set_real_num_tx_queues(net, nvdev->num_chn);
-		netif_set_real_num_rx_queues(net, nvdev->num_chn);
-	} else {
+	if (IS_ERR(nvdev)) {
 		ret = PTR_ERR(nvdev);
 		device_info.num_chn = orig;
 		nvdev = rndis_filter_device_add(dev, &device_info);
@@ -1954,9 +1951,6 @@ static int netvsc_probe(struct hv_device *dev,
 		NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
 	net->vlan_features = net->features;
 
-	netif_set_real_num_tx_queues(net, nvdev->num_chn);
-	netif_set_real_num_rx_queues(net, nvdev->num_chn);
-
 	netdev_lockdep_set_classes(net);
 
 	/* MTU range: 68 - 1500 or 65521 */
drivers/net/hyperv/rndis_filter.c +72 -34

150 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#2 lore raw

RE: [PATCH net-next 1/1] hv_netvsc: fix deadlock on hotplug

Quoted 34 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 6, 2017 11:19 AM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]
Subject: [PATCH net-next 1/1] hv_netvsc: fix deadlock on hotplug

When a virtual device is added dynamically (via host console), then the vmbus sends an offer message for the primary channel. The processing of this message for networking causes the network device to then initialize the sub channels.

The problem is that setting up the sub channels needs to wait until the subsequent subchannel offers have been processed. These offers come in on the same ring buffer and work queue as where the primary offer is being processed; leading to a deadlock.

This did not happen in older kernels, because the sub channel waiting logic was broken (it wasn't really waiting).

The solution is to do the sub channel setup in its own work queue context that is scheduled by the primary channel setup; and then happens later.

Fixes 732e49850c5e ("netvsc: fix race on sub channel creation")

---
Should also go to stable, but this version does not apply cleanly to 4.13. Have another patch for that.

Quoted 5 lines
 drivers/net/hyperv/hyperv_net.h   |   1 +
 drivers/net/hyperv/netvsc_drv.c   |   8 +--
 drivers/net/hyperv/rndis_filter.c | 106 ++++++++++++++++++++++++++-----
-------
 3 files changed, 74 insertions(+), 41 deletions(-)

The patch looks overall. I just have a question:

With this patch, after module load and probe is done, there may still be subchannels being processed. If rmmod immediately, the subchannel offers may hit half-way removed device structures... Do we also need to add cancel_work_sync(&dev->subchan_work) to the top of netvsc_remove()?

unregister_netdevice() includes device close, but it's only called later in the netvsc_remove() when rndis is already removed.

Thanks,
- Haiyang

#3 lore raw

Re: [PATCH net-next 1/1] hv_netvsc: fix deadlock on hotplug

Quoted 45 lines · On Wed, 6 Sep 2017 16:23:45 +0000 Haiyang Zhang <[email protected]> wrote:
Quoted 32 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Wednesday, September 6, 2017 11:19 AM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]
Subject: [PATCH net-next 1/1] hv_netvsc: fix deadlock on hotplug

When a virtual device is added dynamically (via host console), then the vmbus sends an offer message for the primary channel. The processing of this message for networking causes the network device to then initialize the sub channels.

The problem is that setting up the sub channels needs to wait until the subsequent subchannel offers have been processed. These offers come in on the same ring buffer and work queue as where the primary offer is being processed; leading to a deadlock.

This did not happen in older kernels, because the sub channel waiting logic was broken (it wasn't really waiting).

The solution is to do the sub channel setup in its own work queue context that is scheduled by the primary channel setup; and then happens later.

Fixes 732e49850c5e ("netvsc: fix race on sub channel creation")

---
Should also go to stable, but this version does not apply cleanly to 4.13. Have another patch for that.

Quoted 5 lines
 drivers/net/hyperv/hyperv_net.h   |   1 +
 drivers/net/hyperv/netvsc_drv.c   |   8 +--
 drivers/net/hyperv/rndis_filter.c | 106 ++++++++++++++++++++++++++-----
-------
 3 files changed, 74 insertions(+), 41 deletions(-)  

The patch looks overall. I just have a question:

With this patch, after module load and probe is done, there may still be subchannels being processed. If rmmod immediately, the subchannel offers may hit half-way removed device structures... Do we also need to add cancel_work_sync(&dev->subchan_work) to the top of netvsc_remove()?

Quoted 5 lines

unregister_netdevice() includes device close, but it's only called later in the netvsc_remove() when rndis is already removed.

Thanks,
- Haiyang

Good catch.
If the driver called unregister_netdevice first before doing rndis_filter_device_remove that would solve the problem. That wouldn't cause additional problems and it makes sense to close the network layer first.