hv_netvsc: avoid races on mtu change/set channels
Subsystems (3)
v2 cover hv_netvsc: avoid races on mtu change/set channels
Changes since v1:
- Rebased to net-next [Haiyang Zhang]
Original description:
MTU change and set channels operations are implemented as netvsc device re-creation destroying internal structures (struct net_device stays). This is really unfortunate but there is no support from Hyper-V host to do it in a different way. Such re-creation is unsurprisingly racy, Haiyang reported a crash when netvsc_change_mtu() is racing with netvsc_link_change() but I was able to identify additional races upon investigation. Both netvsc_set_channels() and netvsc_change_mtu() race against:
1) netvsc_link_change()
2) netvsc_remove()
3) netvsc_send()
To solve these issues without introducing new locks some refactoring is required. We need to get rid of very complex link graph in all the internal structures and avoid traveling through structures which are being removed.
Vitaly Kuznetsov (6):
hv_netvsc: move start_remove flag to net_device_context
hv_netvsc: use start_remove flag to protect netvsc_link_change()
hv_netvsc: untangle the pointer mess
hv_netvsc: get rid of struct net_device pointer in struct
netvsc_device
hv_netvsc: synchronize netvsc_change_mtu()/netvsc_set_channels() with
netvsc_remove()
hv_netvsc: set nvdev link after populating chn_table
drivers/net/hyperv/hyperv_net.h | 17 ++-- drivers/net/hyperv/netvsc.c | 136 +++++++++++++---------------- drivers/net/hyperv/netvsc_drv.c | 178 ++++++++++++++++++++++---------------- drivers/net/hyperv/rndis_filter.c | 82 +++++++++--------- 4 files changed, 215 insertions(+), 198 deletions(-)
Signature · 1 line
2.5.5
PATCH v2 1/6 hv_netvsc: move start_remove flag to net_device_context
struct netvsc_device is destroyed on mtu change so keeping the protection flag there is not a good idea. Move it to struct net_device_context which is preserved.
--- drivers/net/hyperv/hyperv_net.h | 4 +++- drivers/net/hyperv/netvsc.c | 3 +-- drivers/net/hyperv/netvsc_drv.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-)
drivers/net/hyperv/hyperv_net.h +3 -1
@@ -672,6 +672,9 @@ struct net_device_context {/* Ethtool settings */ u8 duplex;u32 speed; + +/* the device is going away */ +bool start_remove; };/* Per netvsc device */
@@ -682,7 +685,6 @@ struct netvsc_device {atomic_t num_outstanding_sends;wait_queue_head_t wait_drain; -bool start_remove;bool destroy;/* Receive buffer allocated by us but manages by NetVSP */
drivers/net/hyperv/netvsc.c +1 -2
@@ -74,7 +74,6 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device) }init_waitqueue_head (&net_device->wait_drain); - net_device->start_remove = false; net_device->destroy = false;atomic_set (&net_device->open_cnt,0 );atomic_set (&net_device->vf_use_cnt,0 );
@@ -691,7 +690,7 @@ static void netvsc_send_completion(struct netvsc_device *net_device,wake_up (&net_device->wait_drain);if (netif_tx_queue_stopped (netdev_get_tx_queue (ndev, q_idx)) && - !net_device->start_remove && + !net_device->nd_ctx->start_remove && (hv_ringbuf_avail_percent (&channel->outbound) >RING_AVAIL_PERCENT_HIWATER || queue_sends <1 )) netif_tx_wake_queue(netdev_get_tx_queue(
drivers/net/hyperv/netvsc_drv.c +9 -3
@@ -793,7 +793,7 @@ static int netvsc_set_channels(struct net_device *net, goto out; do_set: - nvdev->start_remove = true; + net_device_ctx->start_remove = true;rndis_filter_device_remove (dev); nvdev->num_chn = channels->combined_count;
@@ -837,6 +837,7 @@ static int netvsc_set_channels(struct net_device *net, out:netvsc_open (net); + net_device_ctx->start_remove = false;return ret;
@@ -927,7 +928,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu) num_chn = nvdev->num_chn; - nvdev->start_remove = true; + ndevctx->start_remove = true;rndis_filter_device_remove (hdev); ndev->mtu = mtu;
@@ -943,6 +944,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu) out:netvsc_open (ndev); + ndevctx->start_remove = false;return ret; }
@@ -1358,6 +1360,9 @@ static int netvsc_probe(struct hv_device *dev, }hv_set_drvdata (dev, net); + + net_device_ctx->start_remove = false; +INIT_DELAYED_WORK (&net_device_ctx->dwork, netvsc_link_change);INIT_WORK (&net_device_ctx->work, do_set_multicast);INIT_WORK (&net_device_ctx->gwrk.dwrk, netvsc_notify_peers);
@@ -1419,9 +1424,10 @@ static int netvsc_remove(struct hv_device *dev)return 0 ; } - net_device->start_remove = true; ndev_ctx =netdev_priv (net); + ndev_ctx->start_remove = true; +cancel_delayed_work_sync (&ndev_ctx->dwork);cancel_work_sync (&ndev_ctx->work);
Signature · 1 line
2.5.5
PATCH v2 2/6 hv_netvsc: use start_remove flag to protect netvsc_link_change()
In reply to Vitaly Kuznetsovnetvsc_link_change() can race with netvsc_change_mtu() or netvsc_set_channels() as these functions destroy struct netvsc_device and rndis filter. Use start_remove flag for syncronization. As netvsc_change_mtu()/netvsc_set_channels() are called with rtnl lock held we need to take it before checking start_remove value in netvsc_link_change().
--- drivers/net/hyperv/netvsc_drv.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/net/hyperv/netvsc_drv.c +17 -4
@@ -838,6 +838,8 @@ static int netvsc_set_channels(struct net_device *net, out:netvsc_open (net); net_device_ctx->start_remove = false; +/* We may have missed link change notifications */ +schedule_delayed_work (&net_device_ctx->dwork,0 );return ret;
@@ -946,6 +948,9 @@ out:netvsc_open (ndev); ndevctx->start_remove = false; +/* We may have missed link change notifications */ +schedule_delayed_work (&ndevctx->dwork,0 ); +return ret; }
@@ -1066,6 +1071,11 @@ static void netvsc_link_change(struct work_struct *w)unsigned long flags, next_reconfig, delay; ndev_ctx = container_of(w, struct net_device_context, dwork.work); + +rtnl_lock (); +if (ndev_ctx->start_remove) + goto out_unlock; + net_device =hv_get_drvdata (ndev_ctx->device_ctx); rdev = net_device->extension; net = net_device->ndev;
@@ -1079,7 +1089,7 @@ static void netvsc_link_change(struct work_struct *w) delay = next_reconfig - jiffies; delay = delay <LINKCHANGE_INT ? delay :LINKCHANGE_INT ;schedule_delayed_work (&ndev_ctx->dwork, delay); -return ; + goto out_unlock; } ndev_ctx->last_reconfig = jiffies;
@@ -1093,9 +1103,7 @@ static void netvsc_link_change(struct work_struct *w)spin_unlock_irqrestore (&ndev_ctx->lock, flags);if (!event) -return ; - -rtnl_lock (); + goto out_unlock;switch (event->event) {/* Only the following events are possible due to the check in
@@ -1144,6 +1152,11 @@ static void netvsc_link_change(struct work_struct *w)*/ if (reschedule)schedule_delayed_work (&ndev_ctx->dwork,LINKCHANGE_INT ); + +return ; + +out_unlock: +rtnl_unlock (); }static void netvsc_free_netdev (struct net_device *netdev)
Signature · 1 line
2.5.5
PATCH v2 3/6 hv_netvsc: untangle the pointer mess
In reply to Vitaly KuznetsovWe have the following structures keeping netvsc adapter state:
- struct net_device
- struct net_device_context
- struct netvsc_device
- struct rndis_device
- struct hv_device
and there are pointers/dependencies between them:
- struct net_device_context is contained in struct net_device
- struct hv_device has driver_data pointer which points to 'struct net_device' OR 'struct netvsc_device' depending on driver's state (!).
- struct net_device_context has a pointer to 'struct hv_device'.
- struct netvsc_device has pointers to 'struct hv_device' and 'struct net_device_context'.
- struct rndis_device has a pointer to 'struct netvsc_device'.
Different functions get different structures as parameters and use these pointers for traveling. The problem is (in addition to keeping in mind this complex graph) that some of these structures (struct netvsc_device and struct rndis_device) are being removed and re-created on mtu change (as we implement it as re-creation of hyper-v device) so our travel using these pointers is dangerous.
Simplify this to a the following:
- add struct netvsc_device pointer to struct net_device_context (which is a part of struct net_device and thus never disappears)
- remove struct hv_device and struct net_device_context pointers from struct netvsc_device
- replace pointer to 'struct netvsc_device' with pointer to 'struct net_device'.
- always keep 'struct net_device' in hv_device driver_data.
We'll end up with the following 'circular' structure:
net_device:
[net_device_context] -> netvsc_device -> rndis_device -> net_device
-> hv_device -> net_device
On MTU change we'll be removing the 'netvsc_device -> rndis_device' branch and re-creating it making the synchronization easier.
There is one additional redundant pointer left, it is struct net_device link in struct netvsc_device, it is going to be removed in a separate commit.
--- drivers/net/hyperv/hyperv_net.h | 10 ++--- drivers/net/hyperv/netvsc.c | 82 ++++++++++++++++----------------------- drivers/net/hyperv/netvsc_drv.c | 51 ++++++++++-------------- drivers/net/hyperv/rndis_filter.c | 78 +++++++++++++++++++------------------ 4 files changed, 99 insertions(+), 122 deletions(-)
drivers/net/hyperv/hyperv_net.h +4 -6
@@ -158,7 +158,7 @@ enum rndis_device_state { };struct rndis_device { -struct netvsc_device *net_dev; +struct net_device *ndev;enum rndis_device_state state;bool link_state;
@@ -173,6 +173,7 @@ struct rndis_device {/* Interface */ struct rndis_message ; +struct netvsc_device ;int netvsc_device_add (struct hv_device *device,void *additional_info);int netvsc_device_remove (struct hv_device *device); int netvsc_send(struct hv_device *device,
@@ -653,6 +654,8 @@ struct garp_wrk {struct net_device_context {/* point back to our device context */ struct hv_device *device_ctx; +/* netvsc_device */ +struct netvsc_device *nvdev;/* reconfigure work */ struct delayed_work dwork;/* last reconfig time */
@@ -679,8 +682,6 @@ struct net_device_context {/* Per netvsc device */ struct netvsc_device { -struct hv_device *dev; -u32 nvsp_version;atomic_t num_outstanding_sends;
@@ -734,9 +735,6 @@ struct netvsc_device {u32 max_pkt;/* max number of pkt in one send, e.g. 8 */ u32 pkt_align;/* alignment bytes, e.g. 8 */ -/* The net device context */ -struct net_device_context *nd_ctx; -/* 1: allocated, serial number is valid. 0: not allocated */ u32 vf_alloc;/* Serial number of the VF to team with */
drivers/net/hyperv/netvsc.c +33 -49
194 lines not on this page · raw message
drivers/net/hyperv/netvsc_drv.c +21 -30
177 lines not on this page · raw message
drivers/net/hyperv/rndis_filter.c +41 -37
231 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH v2 4/6 hv_netvsc: get rid of struct net_device pointer in struct netvsc_device
In reply to Vitaly KuznetsovSimplify netvsvc pointer graph by getting rid of the redundant ndev pointer. We can always get a pointer to struct net_device from somewhere else.
--- drivers/net/hyperv/hyperv_net.h | 5 +-- drivers/net/hyperv/netvsc.c | 36 +++++++--------- drivers/net/hyperv/netvsc_drv.c | 91 +++++++++++++++++++++++---------------- drivers/net/hyperv/rndis_filter.c | 4 +- 4 files changed, 72 insertions(+), 64 deletions(-)
drivers/net/hyperv/hyperv_net.h +1 -4
@@ -173,7 +173,6 @@ struct rndis_device {/* Interface */ struct rndis_message ; -struct netvsc_device ;int netvsc_device_add (struct hv_device *device,void *additional_info);int netvsc_device_remove (struct hv_device *device); int netvsc_send(struct hv_device *device,
@@ -203,7 +202,7 @@ int rndis_filter_receive(struct hv_device *dev,int rndis_filter_set_packet_filter (struct rndis_device *dev,u32 new_filter);int rndis_filter_set_device_mac (struct hv_device *hdev,char *mac); -void netvsc_switch_datapath (struct netvsc_device *nv_dev,bool vf); +void netvsc_switch_datapath (struct net_device *nv_dev,bool vf);#define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
@@ -711,8 +710,6 @@ struct netvsc_device {struct nvsp_message revoke_packet;/* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ -struct net_device *ndev; -struct vmbus_channel *chn_table[VRSS_CHANNEL_MAX ];u32 send_table[VRSS_SEND_TAB_SIZE ];u32 max_chn;
drivers/net/hyperv/netvsc.c +15 -21
@@ -37,12 +37,12 @@* Switch the data path from the synthetic interface to the VF * interface. */ -void netvsc_switch_datapath (struct netvsc_device *nv_dev,bool vf) +void netvsc_switch_datapath (struct net_device *ndev,bool vf) { -struct nvsp_message *init_pkt = &nv_dev->channel_init_pkt; -struct net_device *ndev = nv_dev->ndev;struct net_device_context *net_device_ctx =netdev_priv (ndev);struct hv_device *dev = net_device_ctx->device_ctx; +struct netvsc_device *nv_dev = net_device_ctx->nvdev; +struct nvsp_message *init_pkt = &nv_dev->channel_init_pkt;memset (init_pkt,0 ,sizeof (struct nvsp_message )); init_pkt->hdr.msg_type =NVSP_MSG4_TYPE_SWITCH_DATA_PATH ;
@@ -80,7 +80,6 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device) net_device->destroy = false;atomic_set (&net_device->open_cnt,0 );atomic_set (&net_device->vf_use_cnt,0 ); - net_device->ndev = ndev; net_device->max_pkt =RNDIS_MAX_PKT_DEFAULT ; net_device->pkt_align =RNDIS_PKT_ALIGN_DEFAULT ;
@@ -263,7 +262,7 @@ static int netvsc_init_buf(struct hv_device *device) net_device =get_outbound_net_device (device);if (!net_device)return -ENODEV ; - ndev = net_device->ndev; + ndev =hv_get_drvdata (device); node =cpu_to_node (device->channel->target_cpu); net_device->recv_buf =vzalloc_node (net_device->recv_buf_size, node);
@@ -453,6 +452,7 @@ static int negotiate_nvsp_ver(struct hv_device *device, struct nvsp_message *init_packet, u32 nvsp_ver) { +struct net_device *ndev =hv_get_drvdata (device);int ret;unsigned long t;
@@ -486,8 +486,7 @@ static int negotiate_nvsp_ver(struct hv_device *device,/* NVSPv2 or later: Send NDIS config */ memset (init_packet,0 ,sizeof (struct nvsp_message )); init_packet->hdr.msg_type =NVSP_MSG2_TYPE_SEND_NDIS_CONFIG ; - init_packet->msg.v2_msg.send_ndis_config.mtu = net_device->ndev->mtu + -ETH_HLEN ; + init_packet->msg.v2_msg.send_ndis_config.mtu = ndev->mtu +ETH_HLEN ; init_packet->msg.v2_msg.send_ndis_config.capability.ieee8021q =1 ;if (nvsp_ver >=NVSP_PROTOCOL_VERSION_5 )
@@ -507,7 +506,6 @@ static int netvsc_connect_vsp(struct hv_device *device)struct netvsc_device *net_device;struct nvsp_message *init_packet;int ndis_version; -struct net_device *ndev;u32 ver_list[] = {NVSP_PROTOCOL_VERSION_1 ,NVSP_PROTOCOL_VERSION_2 ,NVSP_PROTOCOL_VERSION_4 ,NVSP_PROTOCOL_VERSION_5 };int i, num_ver =4 ;/* number of different NVSP versions */
@@ -515,7 +513,6 @@ static int netvsc_connect_vsp(struct hv_device *device) net_device =get_outbound_net_device (device);if (!net_device)return -ENODEV ; - ndev = net_device->ndev; init_packet = &net_device->channel_init_pkt;
@@ -768,6 +765,7 @@ static u32 netvsc_copy_to_send_buf(struct netvsc_device *net_device, } static inline int netvsc_send_pkt( + struct hv_device *device, struct hv_netvsc_packet *packet, struct netvsc_device *net_device, struct hv_page_buffer **pb,
@@ -776,7 +774,7 @@ static inline int netvsc_send_pkt(struct nvsp_message nvmsg;u16 q_idx = packet->q_idx;struct vmbus_channel *out_channel = net_device->chn_table[q_idx]; -struct net_device *ndev = net_device->ndev; +struct net_device *ndev =hv_get_drvdata (device);u64 req_id;int ret;struct hv_page_buffer *pgbuf;
@@ -971,7 +969,8 @@ int netvsc_send(struct hv_device *device, }if (msd_send) { - m_ret =netvsc_send_pkt (msd_send, net_device,NULL , msd_skb); + m_ret =netvsc_send_pkt (device, msd_send, net_device, +NULL , msd_skb);if (m_ret !=0 ) { netvsc_free_send_slot(net_device,
@@ -982,7 +981,7 @@ int netvsc_send(struct hv_device *device, send_now:if (cur_send) - ret =netvsc_send_pkt (cur_send, net_device, pb, skb); + ret =netvsc_send_pkt (device, cur_send, net_device, pb, skb);if (ret !=0 && section_index !=NETVSC_INVALID_INDEX )netvsc_free_send_slot (net_device, section_index);
@@ -998,9 +997,7 @@ static void netvsc_send_recv_completion(struct hv_device *device,struct nvsp_message recvcompMessage;int retries =0 ;int ret; -struct net_device *ndev; - - ndev = net_device->ndev; +struct net_device *ndev =hv_get_drvdata (device); recvcompMessage.hdr.msg_type =NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE ;
@@ -1047,11 +1044,9 @@ static void netvsc_receive(struct netvsc_device *net_device,u32 status =NVSP_STAT_SUCCESS ;int i;int count =0 ; -struct net_device *ndev; +struct net_device *ndev =hv_get_drvdata (device);void *data; - ndev = net_device->ndev; -/* * All inbound packets other than send completion should be xfer page * packet
@@ -1107,14 +1102,13 @@ static void netvsc_send_table(struct hv_device *hdev, struct nvsp_message *nvmsg) {struct netvsc_device *nvscdev; -struct net_device *ndev; +struct net_device *ndev =hv_get_drvdata (hdev);int i;u32 count, *tab; nvscdev =get_outbound_net_device (hdev);if (!nvscdev)return ; - ndev = nvscdev->ndev; count = nvmsg->msg.v5_msg.send_table.count;if (count !=VRSS_SEND_TAB_SIZE ) {
@@ -1173,7 +1167,7 @@ void netvsc_channel_cb(void *context) net_device =get_inbound_net_device (device);if (!net_device)return ; - ndev = net_device->ndev; + ndev =hv_get_drvdata (device); buffer =get_per_channel_state (channel); do {
drivers/net/hyperv/netvsc_drv.c +54 -37
219 lines not on this page · raw message
drivers/net/hyperv/rndis_filter.c +2 -2
@@ -1061,8 +1061,8 @@ int rndis_filter_device_add(struct hv_device *dev, ret =rndis_filter_query_device (rndis_device,RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE , &mtu, &size); -if (ret ==0 && size ==sizeof (u32) && mtu < net_device->ndev->mtu) - net_device->ndev->mtu = mtu; +if (ret ==0 && size ==sizeof (u32) && mtu < net->mtu) + net->mtu = mtu;/* Get the mac address */ ret =rndis_filter_query_device_mac (rndis_device);
Signature · 1 line
2.5.5
PATCH v2 5/6 hv_netvsc: synchronize netvsc_change_mtu()/netvsc_set_channels() with netvsc_remove()
In reply to Vitaly KuznetsovWhen netvsc device is removed during mtu change or channels setup we get into troubles as both paths are trying to remove the device. Synchronize them with start_remove flag and rtnl lock.
--- drivers/net/hyperv/netvsc_drv.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/hyperv/netvsc_drv.c +7 -2
@@ -759,7 +759,7 @@ static int netvsc_set_channels(struct net_device *net,int ret =0 ;bool recovering = false; -if (!nvdev || nvdev->destroy) +if (net_device_ctx->start_remove || !nvdev || nvdev->destroy)return -ENODEV ; num_chn = nvdev->num_chn;
@@ -907,7 +907,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)u32 num_chn;int ret =0 ; -if (nvdev ==NULL || nvdev->destroy) +if (ndevctx->start_remove || !nvdev || nvdev->destroy)return -ENODEV ;if (nvdev->nvsp_version >=NVSP_PROTOCOL_VERSION_2 )
@@ -1445,7 +1445,12 @@ static int netvsc_remove(struct hv_device *dev) ndev_ctx =netdev_priv (net); net_device = ndev_ctx->nvdev; +/* Avoid racing with netvsc_change_mtu()/netvsc_set_channels() +* removing the device. +*/ +rtnl_lock (); ndev_ctx->start_remove = true; +rtnl_unlock ();cancel_delayed_work_sync (&ndev_ctx->dwork);cancel_work_sync (&ndev_ctx->work);
Signature · 1 line
2.5.5
PATCH v2 6/6 hv_netvsc: set nvdev link after populating chn_table
In reply to Vitaly KuznetsovCrash in netvsc_send() is observed when netvsc device is re-created on mtu change/set channels. The crash is caused by dereferencing of NULL channel pointer which comes from chn_table. The root cause is a mixture of two facts:
- we set nvdev pointer in net_device_context in alloc_net_device() before we populate chn_table.
- we populate chn_table[0] only.
The issue could be papered over by checking channel != NULL in netvsc_send() but populating the whole chn_table and writing the nvdev pointer afterwards seems more appropriate.
--- drivers/net/hyperv/netvsc.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/net/hyperv/netvsc.c +18 -11
@@ -60,11 +60,9 @@ void netvsc_switch_datapath(struct net_device *ndev, bool vf) } -static struct netvsc_device *alloc_net_device (struct hv_device *device) +static struct netvsc_device *alloc_net_device (void ) {struct netvsc_device *net_device; -struct net_device *ndev =hv_get_drvdata (device); -struct net_device_context *net_device_ctx =netdev_priv (ndev); net_device =kzalloc (sizeof (struct netvsc_device ),GFP_KERNEL );if (!net_device)
@@ -86,8 +84,6 @@ static struct netvsc_device *alloc_net_device(struct hv_device *device) net_device->vf_netdev =NULL ; net_device->vf_inject = false; - net_device_ctx->nvdev = net_device; -return net_device; }
@@ -1240,20 +1236,19 @@ void netvsc_channel_cb(void *context)*/ int netvsc_device_add (struct hv_device *device,void *additional_info) { -int ret =0 ; +int i, ret =0 ;int ring_size = ((struct netvsc_device_info *)additional_info)->ring_size;struct netvsc_device *net_device; -struct net_device *ndev; +struct net_device *ndev =hv_get_drvdata (device); +struct net_device_context *net_device_ctx =netdev_priv (ndev); - net_device =alloc_net_device (device); + net_device =alloc_net_device ();if (!net_device)return -ENOMEM ; net_device->ring_size = ring_size; - ndev =hv_get_drvdata (device); -/* Initialize the NetVSC channel extension */ init_completion (&net_device->channel_init_wait);
@@ -1272,7 +1267,19 @@ int netvsc_device_add(struct hv_device *device, void *additional_info)/* Channel is opened */ pr_info ("hv_netvsc channel opened successfully\n" ); - net_device->chn_table[0 ] = device->channel; +/* If we're reopening the device we may have multiple queues, fill the +* chn_table with the default channel to use it before subchannels are +* opened. +*/ +for (i =0 ; i <VRSS_CHANNEL_MAX ; i++) + net_device->chn_table[i] = device->channel; + +/* Writing nvdev pointer unlocks netvsc_send(), make sure chn_table is +* populated. +*/ +wmb (); + + net_device_ctx->nvdev = net_device;/* Connect with the NetVsp */ ret =netvsc_connect_vsp (device);
Signature · 1 line
2.5.5
David Miller
maintainerFrom: Vitaly Kuznetsov <[email protected]>
Date: Fri, 13 May 2016 13:55:19 +0200
Quoted 17 lines
Changes since v1:
- Rebased to net-next [Haiyang Zhang]Original description:
MTU change and set channels operations are implemented as netvsc device re-creation destroying internal structures (struct
net_devicestays). This is really unfortunate but there is no support from Hyper-V host to do it in a different way. Such re-creation is unsurprisingly racy, Haiyang reported a crash whennetvsc_change_mtu()is racing withnetvsc_link_change()but I was able to identify additional races upon investigation. Bothnetvsc_set_channels()andnetvsc_change_mtu()race against:
1)netvsc_link_change()
2)netvsc_remove()
3)netvsc_send()
Quoted 4 lines
To solve these issues without introducing new locks some refactoring is required. We need to get rid of very complex link graph in all the internal structures and avoid traveling through structures which are being removed.
Series applied, thanks.