mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] hv_netvsc: fall back to one queue when a sub channel fails to open
@ 2026-11-14 22:03 Julius Bairaktaris
  2026-11-16  2:10 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Julius Bairaktaris @ 2026-11-14 22:03 UTC (permalink / raw)
  To: netdev, linux-hyperv
  Cc: haiyangz, wei.liu, decui, andrew+netdev, davem, edumazet, kuba,
	pabeni, horms, ernis, stephen, linux-kernel

netvsc_sc_open() counts a sub channel in open_chn even when vmbus_open()
fails, for example when the order-8 ring buffer allocation fails in a
guest with fragmented memory. The channel stays in chan_table with no
ring buffer and a disabled NAPI, and rndis_set_subchannel() goes on as if
it had opened.

The next netvsc_detach() or netvsc_close() then hangs in
netvsc_wait_until_empty(), with RTNL held: napi_synchronize() waits for
NAPI_STATE_SCHED to clear, and a disabled NAPI keeps it set.

  hv_netvsc ... eth0: sub channel open failed: -12
  task:GnsEngine state:D
   msleep+0x38/0x60
   netvsc_wait_until_empty+0x49/0x100
   netvsc_detach+0x135/0x1b0
   netvsc_change_mtu+0xb9/0x120

netvsc_device_remove() would also call napi_disable() on it a second
time, which never returns either.

Check after the wait that every sub channel opened. If one did not,
disable the NAPI of those that did and return an error, so that both
callers fall back to the primary channel. The fallback in
netvsc_attach() did not delete the sub channel NAPIs and left the real
queue counts of the previous device in place; do both, as
netvsc_subchan_work() and netvsc_probe() do.

The device keeps one queue after the fallback, also across later
reconfiguration, until the channel count is raised with ethtool -L.

Fixes: 7b2ee50c0cd5 ("hv_netvsc: common detach logic")
Link: https://github.com/microsoft/WSL/issues/41622
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
Tested in a Hyper-V guest (WSL 2, mirrored networking, 16 vCPUs) on net
aa40afa831ebf, with fail_page_alloc limited to vmbus_alloc_ring() so that
6 of the 15 sub channels of a netvsc device failed to open during an MTU
change. Without this patch, the next MTU change hung in
netvsc_wait_until_empty() with RTNL held. With it, the device fell back
to one queue; a further MTU change, down/up, ping over the device and
ethtool -L back to 16 queues all worked, with no warnings.

I used Claude (Anthropic) to help write these patches.

 drivers/net/hyperv/netvsc_drv.c   |  7 +++++-
 drivers/net/hyperv/rndis_filter.c | 38 +++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 1d43c73fd73f1..ffa5999dc576c 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1023,7 +1023,7 @@ static int netvsc_attach(struct net_device *ndev,
 	struct netvsc_device *nvdev;
 	struct rndis_device *rdev;
 	struct bpf_prog *prog;
-	int ret = 0;
+	int i, ret = 0;
 
 	nvdev = rndis_filter_device_add(hdev, dev_info);
 	if (IS_ERR(nvdev))
@@ -1034,8 +1034,13 @@ static int netvsc_attach(struct net_device *ndev,
 
 		/* if unavailable, just proceed with one queue */
 		if (ret) {
+			for (i = 1; i < nvdev->num_chn; i++)
+				netif_napi_del(&nvdev->chan_table[i].napi);
+
 			nvdev->max_chn = 1;
 			nvdev->num_chn = 1;
+			netif_set_real_num_tx_queues(ndev, 1);
+			netif_set_real_num_rx_queues(ndev, 1);
 		}
 	}
 
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 9622513275069..fe5acce0bb06b 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1278,6 +1278,31 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)
 		wake_up(&nvscdev->subchan_open);
 }
 
+static bool rndis_subchannel_opened(struct netvsc_device *nvdev, int i)
+{
+	struct vmbus_channel *chn = nvdev->chan_table[i].channel;
+
+	return chn && chn->state == CHANNEL_OPENED_STATE;
+}
+
+/* Disable the NAPI of the sub channels that opened. netvsc_sc_open()
+ * already disabled it on the others.
+ */
+static void rndis_disable_subchannels(struct net_device *ndev,
+				      struct netvsc_device *nvdev)
+{
+	int i;
+
+	for (i = 1; i < nvdev->num_chn; i++) {
+		if (!rndis_subchannel_opened(nvdev, i))
+			continue;
+
+		netif_queue_set_napi(ndev, i, NETDEV_QUEUE_TYPE_TX, NULL);
+		netif_queue_set_napi(ndev, i, NETDEV_QUEUE_TYPE_RX, NULL);
+		napi_disable(&nvdev->chan_table[i].napi);
+	}
+}
+
 /* Open sub-channels after completing the handling of the device probe.
  * This breaks overlap of processing the host message for the
  * new primary channel with the initialization of sub-channels.
@@ -1329,6 +1354,19 @@ int rndis_set_subchannel(struct net_device *ndev,
 	wait_event(nvdev->subchan_open,
 		   atomic_read(&nvdev->open_chn) == nvdev->num_chn);
 
+	/* open_chn also counts the sub channels that failed to open. They
+	 * have no ring buffer and a disabled NAPI, so fall back to the
+	 * primary channel.
+	 */
+	for (i = 1; i < nvdev->num_chn; i++) {
+		if (!rndis_subchannel_opened(nvdev, i)) {
+			netdev_warn(ndev, "sub channel %d is not open, using one queue\n",
+				    i);
+			rndis_disable_subchannels(ndev, nvdev);
+			return -EIO;
+		}
+	}
+
 	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
 		ndev_ctx->tx_table[i] = i % nvdev->num_chn;
 

base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
-- 
2.53.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16  2:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 22:03 [PATCH net] hv_netvsc: fall back to one queue when a sub channel fails to open Julius Bairaktaris
2026-11-16  2:10 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®