@@ -69,7 +69,7 @@ static void netvsc_set_multicast_list(struct net_device *net)
69
69
static int netvsc_open (struct net_device * net )
70
70
{
71
71
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 ) ;
73
73
struct rndis_device * rdev ;
74
74
int ret = 0 ;
75
75
@@ -505,8 +505,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
505
505
506
506
/* timestamp packet in software */
507
507
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 );
510
510
if (likely (ret == 0 ))
511
511
return NETDEV_TX_OK ;
512
512
@@ -717,24 +717,24 @@ static int netvsc_set_queues(struct net_device *net, struct hv_device *dev,
717
717
u32 num_chn )
718
718
{
719
719
struct netvsc_device_info device_info ;
720
+ struct netvsc_device * net_device ;
720
721
int ret ;
721
722
722
723
memset (& device_info , 0 , sizeof (device_info ));
723
724
device_info .num_chn = num_chn ;
724
725
device_info .ring_size = ring_size ;
725
726
device_info .max_num_vrss_chns = num_chn ;
726
727
727
- ret = rndis_filter_device_add (dev , & device_info );
728
- if (ret )
729
- return ret ;
730
-
731
728
ret = netif_set_real_num_tx_queues (net , num_chn );
732
729
if (ret )
733
730
return ret ;
734
731
735
732
ret = netif_set_real_num_rx_queues (net , num_chn );
733
+ if (ret )
734
+ return ret ;
736
735
737
- return ret ;
736
+ net_device = rndis_filter_device_add (dev , & device_info );
737
+ return IS_ERR (net_device ) ? PTR_ERR (net_device ) : 0 ;
738
738
}
739
739
740
740
static int netvsc_set_channels (struct net_device * net ,
@@ -744,7 +744,7 @@ static int netvsc_set_channels(struct net_device *net,
744
744
struct hv_device * dev = net_device_ctx -> device_ctx ;
745
745
struct netvsc_device * nvdev = rtnl_dereference (net_device_ctx -> nvdev );
746
746
unsigned int count = channels -> combined_count ;
747
- bool was_running ;
747
+ bool was_opened ;
748
748
int ret ;
749
749
750
750
/* We do not support separate count for rx, tx, or other */
@@ -764,12 +764,9 @@ static int netvsc_set_channels(struct net_device *net,
764
764
if (count > nvdev -> max_chn )
765
765
return - EINVAL ;
766
766
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 );
773
770
774
771
rndis_filter_device_remove (dev , nvdev );
775
772
@@ -779,10 +776,12 @@ static int netvsc_set_channels(struct net_device *net,
779
776
else
780
777
netvsc_set_queues (net , dev , nvdev -> num_chn );
781
778
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 );
784
782
785
783
/* We may have missed link change notifications */
784
+ net_device_ctx -> last_reconfig = 0 ;
786
785
schedule_delayed_work (& net_device_ctx -> dwork , 0 );
787
786
788
787
return ret ;
@@ -848,19 +847,18 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
848
847
struct net_device_context * ndevctx = netdev_priv (ndev );
849
848
struct netvsc_device * nvdev = rtnl_dereference (ndevctx -> nvdev );
850
849
struct hv_device * hdev = ndevctx -> device_ctx ;
850
+ int orig_mtu = ndev -> mtu ;
851
851
struct netvsc_device_info device_info ;
852
- bool was_running ;
852
+ bool was_opened ;
853
853
int ret = 0 ;
854
854
855
855
if (!nvdev || nvdev -> destroy )
856
856
return - ENODEV ;
857
857
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 );
864
862
865
863
memset (& device_info , 0 , sizeof (device_info ));
866
864
device_info .ring_size = ring_size ;
@@ -869,18 +867,21 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
869
867
870
868
rndis_filter_device_remove (hdev , nvdev );
871
869
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
-
878
870
ndev -> mtu = mtu ;
879
871
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 );
881
883
882
- if (was_running )
883
- ret = netvsc_open (ndev );
884
+ netif_device_attach (ndev );
884
885
885
886
/* We may have missed link change notifications */
886
887
schedule_delayed_work (& ndevctx -> dwork , 0 );
@@ -1363,7 +1364,7 @@ static struct net_device *get_netvsc_byref(struct net_device *vf_netdev)
1363
1364
continue ; /* not a netvsc device */
1364
1365
1365
1366
net_device_ctx = netdev_priv (dev );
1366
- if (net_device_ctx -> nvdev == NULL )
1367
+ if (! rtnl_dereference ( net_device_ctx -> nvdev ) )
1367
1368
continue ; /* device is removed */
1368
1369
1369
1370
if (rtnl_dereference (net_device_ctx -> vf_netdev ) == vf_netdev )
@@ -1528,8 +1529,10 @@ static int netvsc_probe(struct hv_device *dev,
1528
1529
memset (& device_info , 0 , sizeof (device_info ));
1529
1530
device_info .ring_size = ring_size ;
1530
1531
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 );
1533
1536
netdev_err (net , "unable to add netvsc device (ret %d)\n" , ret );
1534
1537
free_netdev (net );
1535
1538
hv_set_drvdata (dev , NULL );
@@ -1543,10 +1546,11 @@ static int netvsc_probe(struct hv_device *dev,
1543
1546
NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX ;
1544
1547
net -> vlan_features = net -> features ;
1545
1548
1546
- /* RCU not necessary here, device not registered */
1547
- nvdev = net_device_ctx -> nvdev ;
1548
1549
netif_set_real_num_tx_queues (net , nvdev -> num_chn );
1549
1550
netif_set_real_num_rx_queues (net , nvdev -> num_chn );
1551
+ rtnl_unlock ();
1552
+
1553
+ netdev_lockdep_set_classes (net );
1550
1554
1551
1555
/* MTU range: 68 - 1500 or 65521 */
1552
1556
net -> min_mtu = NETVSC_MTU_MIN ;
@@ -1588,7 +1592,8 @@ static int netvsc_remove(struct hv_device *dev)
1588
1592
* removed. Also blocks mtu and channel changes.
1589
1593
*/
1590
1594
rtnl_lock ();
1591
- rndis_filter_device_remove (dev , ndev_ctx -> nvdev );
1595
+ rndis_filter_device_remove (dev ,
1596
+ rtnl_dereference (ndev_ctx -> nvdev ));
1592
1597
rtnl_unlock ();
1593
1598
1594
1599
unregister_netdev (net );
0 commit comments