@@ -69,7 +69,7 @@ static void netvsc_set_multicast_list(struct net_device *net)
6969static int netvsc_open (struct net_device * net )
7070{
7171 struct net_device_context * ndev_ctx = netdev_priv (net );
72- struct netvsc_device * nvdev = ndev_ctx -> nvdev ;
72+ struct netvsc_device * nvdev = rtnl_dereference ( ndev_ctx -> nvdev ) ;
7373 struct rndis_device * rdev ;
7474 int ret = 0 ;
7575
@@ -505,8 +505,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
505505
506506 /* timestamp packet in software */
507507 skb_tx_timestamp (skb );
508- ret = netvsc_send ( net_device_ctx -> device_ctx , packet ,
509- rndis_msg , & pb , skb );
508+
509+ ret = netvsc_send ( net_device_ctx , packet , rndis_msg , & pb , skb );
510510 if (likely (ret == 0 ))
511511 return NETDEV_TX_OK ;
512512
@@ -717,24 +717,24 @@ static int netvsc_set_queues(struct net_device *net, struct hv_device *dev,
717717 u32 num_chn )
718718{
719719 struct netvsc_device_info device_info ;
720+ struct netvsc_device * net_device ;
720721 int ret ;
721722
722723 memset (& device_info , 0 , sizeof (device_info ));
723724 device_info .num_chn = num_chn ;
724725 device_info .ring_size = ring_size ;
725726 device_info .max_num_vrss_chns = num_chn ;
726727
727- ret = rndis_filter_device_add (dev , & device_info );
728- if (ret )
729- return ret ;
730-
731728 ret = netif_set_real_num_tx_queues (net , num_chn );
732729 if (ret )
733730 return ret ;
734731
735732 ret = netif_set_real_num_rx_queues (net , num_chn );
733+ if (ret )
734+ return ret ;
736735
737- return ret ;
736+ net_device = rndis_filter_device_add (dev , & device_info );
737+ return IS_ERR (net_device ) ? PTR_ERR (net_device ) : 0 ;
738738}
739739
740740static int netvsc_set_channels (struct net_device * net ,
@@ -744,7 +744,7 @@ static int netvsc_set_channels(struct net_device *net,
744744 struct hv_device * dev = net_device_ctx -> device_ctx ;
745745 struct netvsc_device * nvdev = rtnl_dereference (net_device_ctx -> nvdev );
746746 unsigned int count = channels -> combined_count ;
747- bool was_running ;
747+ bool was_opened ;
748748 int ret ;
749749
750750 /* We do not support separate count for rx, tx, or other */
@@ -764,12 +764,9 @@ static int netvsc_set_channels(struct net_device *net,
764764 if (count > nvdev -> max_chn )
765765 return - EINVAL ;
766766
767- was_running = netif_running (net );
768- if (was_running ) {
769- ret = netvsc_close (net );
770- if (ret )
771- return ret ;
772- }
767+ was_opened = rndis_filter_opened (nvdev );
768+ if (was_opened )
769+ rndis_filter_close (nvdev );
773770
774771 rndis_filter_device_remove (dev , nvdev );
775772
@@ -779,10 +776,12 @@ static int netvsc_set_channels(struct net_device *net,
779776 else
780777 netvsc_set_queues (net , dev , nvdev -> num_chn );
781778
782- if (was_running )
783- ret = netvsc_open (net );
779+ nvdev = rtnl_dereference (net_device_ctx -> nvdev );
780+ if (was_opened )
781+ rndis_filter_open (nvdev );
784782
785783 /* We may have missed link change notifications */
784+ net_device_ctx -> last_reconfig = 0 ;
786785 schedule_delayed_work (& net_device_ctx -> dwork , 0 );
787786
788787 return ret ;
@@ -848,19 +847,18 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
848847 struct net_device_context * ndevctx = netdev_priv (ndev );
849848 struct netvsc_device * nvdev = rtnl_dereference (ndevctx -> nvdev );
850849 struct hv_device * hdev = ndevctx -> device_ctx ;
850+ int orig_mtu = ndev -> mtu ;
851851 struct netvsc_device_info device_info ;
852- bool was_running ;
852+ bool was_opened ;
853853 int ret = 0 ;
854854
855855 if (!nvdev || nvdev -> destroy )
856856 return - ENODEV ;
857857
858- was_running = netif_running (ndev );
859- if (was_running ) {
860- ret = netvsc_close (ndev );
861- if (ret )
862- return ret ;
863- }
858+ netif_device_detach (ndev );
859+ was_opened = rndis_filter_opened (nvdev );
860+ if (was_opened )
861+ rndis_filter_close (nvdev );
864862
865863 memset (& device_info , 0 , sizeof (device_info ));
866864 device_info .ring_size = ring_size ;
@@ -869,18 +867,21 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
869867
870868 rndis_filter_device_remove (hdev , nvdev );
871869
872- /* 'nvdev' has been freed in rndis_filter_device_remove() ->
873- * netvsc_device_remove () -> free_netvsc_device().
874- * We mustn't access it before it's re-created in
875- * rndis_filter_device_add() -> netvsc_device_add().
876- */
877-
878870 ndev -> mtu = mtu ;
879871
880- rndis_filter_device_add (hdev , & device_info );
872+ nvdev = rndis_filter_device_add (hdev , & device_info );
873+ if (IS_ERR (nvdev )) {
874+ ret = PTR_ERR (nvdev );
875+
876+ /* Attempt rollback to original MTU */
877+ ndev -> mtu = orig_mtu ;
878+ rndis_filter_device_add (hdev , & device_info );
879+ }
880+
881+ if (was_opened )
882+ rndis_filter_open (nvdev );
881883
882- if (was_running )
883- ret = netvsc_open (ndev );
884+ netif_device_attach (ndev );
884885
885886 /* We may have missed link change notifications */
886887 schedule_delayed_work (& ndevctx -> dwork , 0 );
@@ -1363,7 +1364,7 @@ static struct net_device *get_netvsc_byref(struct net_device *vf_netdev)
13631364 continue ; /* not a netvsc device */
13641365
13651366 net_device_ctx = netdev_priv (dev );
1366- if (net_device_ctx -> nvdev == NULL )
1367+ if (! rtnl_dereference ( net_device_ctx -> nvdev ) )
13671368 continue ; /* device is removed */
13681369
13691370 if (rtnl_dereference (net_device_ctx -> vf_netdev ) == vf_netdev )
@@ -1528,8 +1529,10 @@ static int netvsc_probe(struct hv_device *dev,
15281529 memset (& device_info , 0 , sizeof (device_info ));
15291530 device_info .ring_size = ring_size ;
15301531 device_info .num_chn = VRSS_CHANNEL_DEFAULT ;
1531- ret = rndis_filter_device_add (dev , & device_info );
1532- if (ret != 0 ) {
1532+
1533+ nvdev = rndis_filter_device_add (dev , & device_info );
1534+ if (IS_ERR (nvdev )) {
1535+ ret = PTR_ERR (nvdev );
15331536 netdev_err (net , "unable to add netvsc device (ret %d)\n" , ret );
15341537 free_netdev (net );
15351538 hv_set_drvdata (dev , NULL );
@@ -1543,10 +1546,11 @@ static int netvsc_probe(struct hv_device *dev,
15431546 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX ;
15441547 net -> vlan_features = net -> features ;
15451548
1546- /* RCU not necessary here, device not registered */
1547- nvdev = net_device_ctx -> nvdev ;
15481549 netif_set_real_num_tx_queues (net , nvdev -> num_chn );
15491550 netif_set_real_num_rx_queues (net , nvdev -> num_chn );
1551+ rtnl_unlock ();
1552+
1553+ netdev_lockdep_set_classes (net );
15501554
15511555 /* MTU range: 68 - 1500 or 65521 */
15521556 net -> min_mtu = NETVSC_MTU_MIN ;
@@ -1588,7 +1592,8 @@ static int netvsc_remove(struct hv_device *dev)
15881592 * removed. Also blocks mtu and channel changes.
15891593 */
15901594 rtnl_lock ();
1591- rndis_filter_device_remove (dev , ndev_ctx -> nvdev );
1595+ rndis_filter_device_remove (dev ,
1596+ rtnl_dereference (ndev_ctx -> nvdev ));
15921597 rtnl_unlock ();
15931598
15941599 unregister_netdev (net );
0 commit comments