aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorWenqi Ma <wenqi_ma@trendmicro.com.cn>2012-04-18 20:39:37 -0400
committerDavid S. Miller <davem@davemloft.net>2012-04-21 15:38:10 -0400
commit792df87228965c58c307877af00498641584bd47 (patch)
tree50a3f378d461b209d24db1bc83b655ce2359af8c /drivers/net
parentc5a99937a9cf74a623384023201a7d98b51e7e3b (diff)
net/hyperv: Adding cancellation to ensure rndis filter is closed
Although the network interface is down, the RX packets number which could be observed by ifconfig may keep on increasing. This is because the WORK scheduled in netvsc_set_multicast_list() may be executed after netvsc_close(). That means the rndis filter may be re-enabled by do_set_multicast() even if it was closed by netvsc_close(). By canceling possible WORK before close the rndis filter, the issue could be never happened. Signed-off-by: Wenqi Ma <wenqi_ma@trendmicro.com.cn> Reviewed-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/hyperv/netvsc_drv.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index dd294783b5c5..2d59138db7f3 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -44,6 +44,7 @@ struct net_device_context {
44 /* point back to our device context */ 44 /* point back to our device context */
45 struct hv_device *device_ctx; 45 struct hv_device *device_ctx;
46 struct delayed_work dwork; 46 struct delayed_work dwork;
47 struct work_struct work;
47}; 48};
48 49
49 50
@@ -51,30 +52,22 @@ static int ring_size = 128;
51module_param(ring_size, int, S_IRUGO); 52module_param(ring_size, int, S_IRUGO);
52MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); 53MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
53 54
54struct set_multicast_work {
55 struct work_struct work;
56 struct net_device *net;
57};
58
59static void do_set_multicast(struct work_struct *w) 55static void do_set_multicast(struct work_struct *w)
60{ 56{
61 struct set_multicast_work *swk = 57 struct net_device_context *ndevctx =
62 container_of(w, struct set_multicast_work, work); 58 container_of(w, struct net_device_context, work);
63 struct net_device *net = swk->net;
64
65 struct net_device_context *ndevctx = netdev_priv(net);
66 struct netvsc_device *nvdev; 59 struct netvsc_device *nvdev;
67 struct rndis_device *rdev; 60 struct rndis_device *rdev;
68 61
69 nvdev = hv_get_drvdata(ndevctx->device_ctx); 62 nvdev = hv_get_drvdata(ndevctx->device_ctx);
70 if (nvdev == NULL) 63 if (nvdev == NULL || nvdev->ndev == NULL)
71 goto out; 64 return;
72 65
73 rdev = nvdev->extension; 66 rdev = nvdev->extension;
74 if (rdev == NULL) 67 if (rdev == NULL)
75 goto out; 68 return;
76 69
77 if (net->flags & IFF_PROMISC) 70 if (nvdev->ndev->flags & IFF_PROMISC)
78 rndis_filter_set_packet_filter(rdev, 71 rndis_filter_set_packet_filter(rdev,
79 NDIS_PACKET_TYPE_PROMISCUOUS); 72 NDIS_PACKET_TYPE_PROMISCUOUS);
80 else 73 else
@@ -82,21 +75,13 @@ static void do_set_multicast(struct work_struct *w)
82 NDIS_PACKET_TYPE_BROADCAST | 75 NDIS_PACKET_TYPE_BROADCAST |
83 NDIS_PACKET_TYPE_ALL_MULTICAST | 76 NDIS_PACKET_TYPE_ALL_MULTICAST |
84 NDIS_PACKET_TYPE_DIRECTED); 77 NDIS_PACKET_TYPE_DIRECTED);
85
86out:
87 kfree(w);
88} 78}
89 79
90static void netvsc_set_multicast_list(struct net_device *net) 80static void netvsc_set_multicast_list(struct net_device *net)
91{ 81{
92 struct set_multicast_work *swk = 82 struct net_device_context *net_device_ctx = netdev_priv(net);
93 kmalloc(sizeof(struct set_multicast_work), GFP_ATOMIC);
94 if (swk == NULL)
95 return;
96 83
97 swk->net = net; 84 schedule_work(&net_device_ctx->work);
98 INIT_WORK(&swk->work, do_set_multicast);
99 schedule_work(&swk->work);
100} 85}
101 86
102static int netvsc_open(struct net_device *net) 87static int netvsc_open(struct net_device *net)
@@ -125,6 +110,8 @@ static int netvsc_close(struct net_device *net)
125 110
126 netif_tx_disable(net); 111 netif_tx_disable(net);
127 112
113 /* Make sure netvsc_set_multicast_list doesn't re-enable filter! */
114 cancel_work_sync(&net_device_ctx->work);
128 ret = rndis_filter_close(device_obj); 115 ret = rndis_filter_close(device_obj);
129 if (ret != 0) 116 if (ret != 0)
130 netdev_err(net, "unable to close device (ret %d).\n", ret); 117 netdev_err(net, "unable to close device (ret %d).\n", ret);
@@ -335,6 +322,7 @@ static int netvsc_change_mtu(struct net_device *ndev, int mtu)
335 322
336 nvdev->start_remove = true; 323 nvdev->start_remove = true;
337 cancel_delayed_work_sync(&ndevctx->dwork); 324 cancel_delayed_work_sync(&ndevctx->dwork);
325 cancel_work_sync(&ndevctx->work);
338 netif_tx_disable(ndev); 326 netif_tx_disable(ndev);
339 rndis_filter_device_remove(hdev); 327 rndis_filter_device_remove(hdev);
340 328
@@ -403,6 +391,7 @@ static int netvsc_probe(struct hv_device *dev,
403 net_device_ctx->device_ctx = dev; 391 net_device_ctx->device_ctx = dev;
404 hv_set_drvdata(dev, net); 392 hv_set_drvdata(dev, net);
405 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_send_garp); 393 INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_send_garp);
394 INIT_WORK(&net_device_ctx->work, do_set_multicast);
406 395
407 net->netdev_ops = &device_ops; 396 net->netdev_ops = &device_ops;
408 397
@@ -456,6 +445,7 @@ static int netvsc_remove(struct hv_device *dev)
456 445
457 ndev_ctx = netdev_priv(net); 446 ndev_ctx = netdev_priv(net);
458 cancel_delayed_work_sync(&ndev_ctx->dwork); 447 cancel_delayed_work_sync(&ndev_ctx->dwork);
448 cancel_work_sync(&ndev_ctx->work);
459 449
460 /* Stop outbound asap */ 450 /* Stop outbound asap */
461 netif_tx_disable(net); 451 netif_tx_disable(net);