Skip to content

Commit ea383bf

Browse files
shemmingerdavem330
authored andcommitted
netvsc: change logic for change mtu and set_queues
Use device detach/attach to ensure that no packets are handed to device during state changes. Call rndis_filter_open/close directly as part of later VF related changes. Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a5e1ec3 commit ea383bf

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

drivers/net/hyperv/hyperv_net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ int netvsc_recv_callback(struct net_device *net,
200200
const struct ndis_pkt_8021q_info *vlan);
201201
void netvsc_channel_cb(void *context);
202202
int netvsc_poll(struct napi_struct *napi, int budget);
203+
bool rndis_filter_opened(const struct netvsc_device *nvdev);
203204
int rndis_filter_open(struct netvsc_device *nvdev);
204205
int rndis_filter_close(struct netvsc_device *nvdev);
205206
int rndis_filter_device_add(struct hv_device *dev,

drivers/net/hyperv/netvsc_drv.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ static int netvsc_set_channels(struct net_device *net,
742742
struct hv_device *dev = net_device_ctx->device_ctx;
743743
struct netvsc_device *nvdev = rtnl_dereference(net_device_ctx->nvdev);
744744
unsigned int count = channels->combined_count;
745-
bool was_running;
745+
bool was_opened;
746746
int ret;
747747

748748
/* We do not support separate count for rx, tx, or other */
@@ -762,12 +762,9 @@ static int netvsc_set_channels(struct net_device *net,
762762
if (count > nvdev->max_chn)
763763
return -EINVAL;
764764

765-
was_running = netif_running(net);
766-
if (was_running) {
767-
ret = netvsc_close(net);
768-
if (ret)
769-
return ret;
770-
}
765+
was_opened = rndis_filter_opened(nvdev);
766+
if (was_opened)
767+
rndis_filter_close(nvdev);
771768

772769
rndis_filter_device_remove(dev, nvdev);
773770

@@ -777,8 +774,9 @@ static int netvsc_set_channels(struct net_device *net,
777774
else
778775
netvsc_set_queues(net, dev, nvdev->num_chn);
779776

780-
if (was_running)
781-
ret = netvsc_open(net);
777+
nvdev = rtnl_dereference(net_device_ctx->nvdev);
778+
if (was_opened)
779+
rndis_filter_open(nvdev);
782780

783781
/* We may have missed link change notifications */
784782
net_device_ctx->last_reconfig = 0;
@@ -848,18 +846,15 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
848846
struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev);
849847
struct hv_device *hdev = ndevctx->device_ctx;
850848
struct netvsc_device_info device_info;
851-
bool was_running;
852-
int ret = 0;
849+
bool was_opened;
853850

854851
if (!nvdev || nvdev->destroy)
855852
return -ENODEV;
856853

857-
was_running = netif_running(ndev);
858-
if (was_running) {
859-
ret = netvsc_close(ndev);
860-
if (ret)
861-
return ret;
862-
}
854+
netif_device_detach(ndev);
855+
was_opened = rndis_filter_opened(nvdev);
856+
if (was_opened)
857+
rndis_filter_close(nvdev);
863858

864859
memset(&device_info, 0, sizeof(device_info));
865860
device_info.ring_size = ring_size;
@@ -877,14 +872,17 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
877872
ndev->mtu = mtu;
878873

879874
rndis_filter_device_add(hdev, &device_info);
875+
nvdev = rtnl_dereference(ndevctx->nvdev);
880876

881-
if (was_running)
882-
ret = netvsc_open(ndev);
877+
if (was_opened)
878+
rndis_filter_open(nvdev);
879+
880+
netif_device_attach(ndev);
883881

884882
/* We may have missed link change notifications */
885883
schedule_delayed_work(&ndevctx->dwork, 0);
886884

887-
return ret;
885+
return 0;
888886
}
889887

890888
static void netvsc_get_stats64(struct net_device *net,

drivers/net/hyperv/rndis_filter.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,3 +1302,8 @@ int rndis_filter_close(struct netvsc_device *nvdev)
13021302

13031303
return rndis_filter_close_device(nvdev->extension);
13041304
}
1305+
1306+
bool rndis_filter_opened(const struct netvsc_device *nvdev)
1307+
{
1308+
return atomic_read(&nvdev->open_cnt) > 0;
1309+
}

0 commit comments

Comments
 (0)