netvsc: Initialize all channel related state prior to opening the channel
authorK. Y. Srinivasan <kys@microsoft.com>
Thu, 6 Apr 2017 21:59:21 +0000 (14:59 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 8 Apr 2017 15:33:03 +0000 (08:33 -0700)
Prior to opening the channel we should have all the state setup to handle
interrupts. The current code does not do that; fix the bug. This bug
can result in faults in the interrupt path.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/hyperv/netvsc.c
drivers/net/hyperv/rndis_filter.c

index e998e2f7a619785215309d5620e4512c287738e1..7ab06b338a14716b6fb20db963c547b7a5cdcc9f 100644 (file)
@@ -1289,6 +1289,21 @@ int netvsc_device_add(struct hv_device *device,
         */
        set_channel_read_mode(device->channel, HV_CALL_ISR);
 
+       /* 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.
+        * Initialize the channel state before we open;
+        * we can be interrupted as soon as we open the channel.
+        */
+
+       for (i = 0; i < VRSS_CHANNEL_MAX; i++) {
+               struct netvsc_channel *nvchan = &net_device->chan_table[i];
+
+               nvchan->channel = device->channel;
+               netif_napi_add(ndev, &nvchan->napi,
+                              netvsc_poll, NAPI_POLL_WEIGHT);
+       }
+
        /* Open the channel */
        ret = vmbus_open(device->channel, ring_size * PAGE_SIZE,
                         ring_size * PAGE_SIZE, NULL, 0,
@@ -1303,18 +1318,6 @@ int netvsc_device_add(struct hv_device *device,
        /* Channel is opened */
        netdev_dbg(ndev, "hv_netvsc channel opened successfully\n");
 
-       /* 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++) {
-               struct netvsc_channel *nvchan = &net_device->chan_table[i];
-
-               nvchan->channel = device->channel;
-               netif_napi_add(ndev, &nvchan->napi,
-                              netvsc_poll, NAPI_POLL_WEIGHT);
-       }
-
        /* Enable NAPI handler for init callbacks */
        napi_enable(&net_device->chan_table[0].napi);
 
index 983582526b37ffbfe258ab3d603a63f20f34ad08..1e9445bc45391195a9f15fbda7bf56fa2d3b762e 100644 (file)
@@ -1007,12 +1007,13 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)
         */
        set_channel_read_mode(new_sc, HV_CALL_ISR);
 
+       /* Set the channel before opening.*/
+       nvchan->channel = new_sc;
+
        ret = vmbus_open(new_sc, nvscdev->ring_size * PAGE_SIZE,
                         nvscdev->ring_size * PAGE_SIZE, NULL, 0,
                         netvsc_channel_cb, nvchan);
 
-       if (ret == 0)
-               nvchan->channel = new_sc;
 
        napi_enable(&nvchan->napi);