2020-04-06 00:17:35

by Andrea Parri

[permalink] [raw]
Subject: [PATCH 04/11] hv_netvsc: Disable NAPI before closing the VMBus channel

vmbus_chan_sched() might call the netvsc driver callback function that
ends up scheduling NAPI work. This "work" can access the channel ring
buffer, so we must ensure that any such work is completed and that the
ring buffer is no longer being accessed before freeing the ring buffer
data structure in the channel closure path. To this end, disable NAPI
before calling vmbus_close() in netvsc_device_remove().

Suggested-by: Michael Kelley <[email protected]>
Signed-off-by: Andrea Parri (Microsoft) <[email protected]>
Acked-by: Stephen Hemminger <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: <[email protected]>
---
drivers/hv/channel.c | 6 ++++++
drivers/net/hyperv/netvsc.c | 7 +++++--
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 23f358cb7f494..256ee90c74460 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -609,6 +609,12 @@ void vmbus_reset_channel_cb(struct vmbus_channel *channel)
* the former is accessing channel->inbound.ring_buffer, the latter
* could be freeing the ring_buffer pages, so here we must stop it
* first.
+ *
+ * vmbus_chan_sched() might call the netvsc driver callback function
+ * that ends up scheduling NAPI work that accesses the ring buffer.
+ * At this point, we have to ensure that any such work is completed
+ * and that the channel ring buffer is no longer being accessed, cf.
+ * the calls to napi_disable() in netvsc_device_remove().
*/
tasklet_disable(&channel->callback_event);

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 1b320bcf150a4..806cc85d10033 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -635,9 +635,12 @@ void netvsc_device_remove(struct hv_device *device)

RCU_INIT_POINTER(net_device_ctx->nvdev, NULL);

- /* And disassociate NAPI context from device */
- for (i = 0; i < net_device->num_chn; i++)
+ /* Disable NAPI and disassociate its context from the device. */
+ for (i = 0; i < net_device->num_chn; i++) {
+ /* See also vmbus_reset_channel_cb(). */
+ napi_disable(&net_device->chan_table[i].napi);
netif_napi_del(&net_device->chan_table[i].napi);
+ }

/*
* At this point, no one should be accessing net_device
--
2.24.0


2020-04-10 19:21:39

by Michael Kelley (LINUX)

[permalink] [raw]
Subject: RE: [PATCH 04/11] hv_netvsc: Disable NAPI before closing the VMBus channel

From: Andrea Parri (Microsoft) <[email protected]> Sent: Sunday, April 5, 2020 5:15 PM
>
> vmbus_chan_sched() might call the netvsc driver callback function that
> ends up scheduling NAPI work. This "work" can access the channel ring
> buffer, so we must ensure that any such work is completed and that the
> ring buffer is no longer being accessed before freeing the ring buffer
> data structure in the channel closure path. To this end, disable NAPI
> before calling vmbus_close() in netvsc_device_remove().
>
> Suggested-by: Michael Kelley <[email protected]>
> Signed-off-by: Andrea Parri (Microsoft) <[email protected]>
> Acked-by: Stephen Hemminger <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: <[email protected]>
> ---
> drivers/hv/channel.c | 6 ++++++
> drivers/net/hyperv/netvsc.c | 7 +++++--
> 2 files changed, 11 insertions(+), 2 deletions(-)
>

Reviewed-by: Michael Kelley <[email protected]>