* Re: [PATCH net] hv_netvsc: fall back to one queue when a sub channel fails to open
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-15 22:04 ` sashiko-bot
2026-11-16 2:10 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-15 22:04 UTC (permalink / raw)
To: Julius Bairaktaris, linux-hyperv
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] hv_netvsc: UAF and primary-channel false match in
rndis_subchannel_opened()
- [Medium] hv_netvsc: clamping max_chn to 1 on fallback blocks ethtool
-L recovery
- [Medium] hv_netvsc: stale multi-queue rx_table after
rndis_set_subchannel() fallback
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] Drivers: hv: vmbus: skipped sub-channel callback in
vmbus_add_channel_work() [1]
--
commit 616fd3140681fc7618c2c8a9fe6e8fd4a476a8d1
Author: Julius Bairaktaris <julius@bairaktaris.de>
hv_netvsc: fall back to one queue when a sub channel fails to open
This commit checks whether all VMBus sub-channels opened during
rndis_set_subchannel() and falls back to a single queue, disabling and
deleting sub-channel NAPIs, if any sub-channel failed to open.
Link: https://github.com/microsoft/WSL/issues/41622
> 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);
> }
> }
[Severity: Medium]
Does keeping nvdev->max_chn = 1 here and in netvsc_subchan_work() prevent
raising the channel count back above 1 with ethtool -L after a fallback,
contrary to the commit message?
netvsc_get_channels() reports nvdev->max_chn as channel->max_combined, and
both ethnl_set_channels() and netvsc_set_channels() reject any requested
channel count greater than max_chn with -EINVAL unless another full
reattach (such as an MTU change) happens first to recompute max_chn in
rndis_filter_device_add().
> 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;
> +}
[Severity: High]
Can rndis_subchannel_opened() dereference a freed vmbus_channel or falsely
match the primary channel?
netvsc_sc_open() assigns nvchan->channel = new_sc before calling
vmbus_open(), and leaves it set if vmbus_open() fails (leaving new_sc in
CHANNEL_OPEN_STATE). If that sub-channel is rescinded,
vmbus_onoffer_rescind() sees CHANNEL_OPEN_STATE and immediately frees the
channel once probe_done is set:
CPU0 CPU1
rndis_set_subchannel() vmbus_add_channel_work()
wait_event(nvdev->subchan_open, ...) netvsc_sc_open()
nvchan->channel = new_sc
vmbus_open(new_sc) -> fails
atomic_inc_return(&open_chn)
newchannel->probe_done = true
vmbus_onoffer_rescind()
hv_process_channel_removal()
...
kfree_rcu(channel, rcu)
rndis_subchannel_opened()
chn->state <-- use-after-free
In addition, netvsc_device_add() initializes every
nvdev->chan_table[i].channel slot to the primary channel (device->channel),
which is in CHANNEL_OPENED_STATE. If any slot was not overwritten by
netvsc_sc_open(), rndis_subchannel_opened() returns true for the primary
channel and rndis_disable_subchannels() hangs in napi_disable() on a
sub-channel NAPI that was never enabled.
Clearing nvchan->channel = NULL when vmbus_open() fails in
netvsc_sc_open() and checking is_sub_channel(chn) would avoid both issues.
> +
> +/* 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);
> + }
> +}
[Severity: Medium]
When falling back to one queue here, does ndc->rx_table retain the
multi-queue indices populated earlier by rndis_filter_device_add()?
Because ndc->rx_table is not reset to queue 0 and the opened sub-channels
remain in CHANNEL_OPENED_STATE, ethtool -x reports nonexistent queue
indices, and updating the RSS hash key via ethtool -X (netvsc_set_rxfh()
with rxfh->indir == NULL) sends that multi-queue indirection table to the
host via rndis_filter_set_rss_param(), steering RX traffic onto
sub-channels whose NAPIs have been disabled and deleted.
> @@ -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);
[Severity: High]
This problem wasn't introduced by this patch, but can wait_event() on
nvdev->subchan_open hang forever under rtnl_lock if
vmbus_add_channel_kobj() fails in vmbus_add_channel_work() [1]?
drivers/hv/channel_mgmt.c:vmbus_add_channel_work() {
if (primary_channel != NULL) {
/* newchannel is a sub-channel. */
struct hv_device *dev = primary_channel->device_obj;
if (vmbus_add_channel_kobj(dev, newchannel))
goto err_deq_chan;
if (primary_channel->sc_creation_callback != NULL)
primary_channel->sc_creation_callback(newchannel);
}
When vmbus_add_channel_kobj() fails for a sub-channel offer, jumping to
err_deq_chan skips sc_creation_callback (netvsc_sc_open()), so
nvdev->open_chn is never incremented to nvdev->num_chn and
rndis_set_subchannel() sleeps indefinitely while holding rtnl_lock.
[1] https://sashiko.dev/#/bug/linux-83f4f08e-02b2-4a16-8ce7-6803e9b794d6
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261114220358.5429-1-julius@bairaktaris.de?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] hv_netvsc: fall back to one queue when a sub channel fails to open
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-15 22:04 ` sashiko-bot
@ 2026-11-16 2:10 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 2:10 UTC (permalink / raw)
To: julius
Cc: netdev, linux-hyperv, haiyangz, wei.liu, decui, andrew+netdev,
davem, edumazet, kuba, pabeni, horms, ernis, stephen,
linux-kernel
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 3 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The new check calls rndis_subchannel_opened()
(drivers/net/hyperv/rndis_filter.c:1281-1286), which reads…
- [High] rndis_set_subchannel() lowers nvdev->num_chn to 1 +
num_subchannels from the host reply (rndis_filter.c:1350-1351).
- [Medium] The commit message says the device keeps one queue after the
fallback 'until the channel count is raised with ethtool -L'.
- [Medium] The new fallback leaves the RSS indirection table
(ndc->rx_table) as rndis_filter_device_add() filled it, for the…
- [Medium] On the new fallback path, the sub channels that did open stay
in CHANNEL_OPENED_STATE with onchannel_callback = netvsc_channel_cb,…
--
hv_netvsc: fall back to one queue when a sub channel fails to open
After waiting for the sub channels, rndis_set_subchannel() now checks
that each one reached CHANNEL_OPENED_STATE. If any did not, it disables
the NAPI of the ones that opened and returns -EIO, so callers fall back
to the primary channel. The fallback in netvsc_attach() now also deletes
the sub channel NAPIs and sets the real tx/rx queue counts to 1.
Link: https://github.com/microsoft/WSL/issues/41622
> The device keeps one queue after the fallback, also across later
> reconfiguration, until the channel count is raised with ethtool -L.
[Severity: Medium]
Can the channel count be raised with ethtool -L right after the
fallback?
Both fallback paths, in netvsc_attach() and netvsc_subchan_work(), set
nvdev->max_chn = 1. netvsc_get_channels() then reports max_combined as
nvdev->max_chn, and netvsc_set_channels() rejects the request:
drivers/net/hyperv/netvsc_drv.c:netvsc_set_channels() {
...
if (count > nvdev->max_chn)
return -EINVAL;
...
}
So "ethtool -L ethX combined 16" would fail with -EINVAL.
max_chn is only recomputed from OID_GEN_RECEIVE_SCALE_CAPABILITIES in
rndis_filter_device_add(). That means an unrelated detach/attach cycle,
such as an MTU change, has to happen first. A plain down/up does not
recompute max_chn. The test below the cut did an MTU change before
ethtool -L, which may have hidden this.
Should the commit message say this, or should the fallback leave
max_chn at the value the host advertised?
> 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
[ ... ]
> @@ -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);
> +
[Severity: High]
Can this loop skip some of the NAPIs that rndis_filter_device_add()
added?
rndis_filter_device_add() calls netif_napi_add() for
chan_table[1..N0-1], where N0 is the requested num_chn. Before the new
-EIO return, rndis_set_subchannel() lowers num_chn to the count the
host granted:
nvdev->num_chn = 1 +
init_packet->msg.v5_msg.subchn_comp.num_subchannels;
The check before this only rejects a count larger than requested, so
the host can grant k < N0-1 sub channels. If one of those k then fails
vmbus_open(), this loop only deletes NAPIs 1..k. So does the same loop
in netvsc_subchan_work(). num_chn is then forced to 1, and
netvsc_device_remove() also only walks i < num_chn.
That leaves NAPIs k+1..N0-1 on ndev->napi_list after kfree(nvdev) frees
the netvsc_device that holds them. Could a later netif_napi_add(), a
netdev-genl NAPI dump or free_netdev() then walk freed memory?
The success path has had the same mismatch for a long time. However,
the commit message says this patch fixes the fallback not deleting the
sub channel NAPIs. The new -EIO return also turns what used to be a
hang into a free of nvdev with NAPIs still on the list.
Would it help to track the count that was actually passed to
netif_napi_add()?
> 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;
[Severity: High]
Can chn already be freed by the time this reads chn->state?
netvsc_sc_open() sets nvchan->channel = new_sc before vmbus_open() and
leaves it set when the open fails. The netvsc driver holds no reference
on the channel. Here rndis_set_subchannel() holds only RTNL, not
vmbus_connection.channel_mutex or rcu_read_lock().
vmbus_open() can fail because the host rescinds the channel during the
open. In that case __vmbus_open() returns -ENODEV, and its error path
ends with:
newchannel->state = CHANNEL_OPEN_STATE;
return err;
After netvsc_sc_open() returns, probe_done is set, and
vmbus_onoffer_rescind() can take the sub channel branch:
drivers/hv/channel_mgmt.c:vmbus_onoffer_rescind() {
...
mutex_lock(&vmbus_connection.channel_mutex);
if (channel->state == CHANNEL_OPEN_STATE) {
/*
* The channel is currently not open;
* it is safe for us to cleanup the channel.
*/
hv_process_channel_removal(channel);
...
}
This ends in:
hv_process_channel_removal()->free_channel()->kobject_put()->
vmbus_chan_release()->kfree_rcu(channel)
open_chn has already been incremented for this channel. The waiter can
still be blocked on other sub channels, and each of their vmbus_open()
calls needs a host round trip. By the time this check runs, the channel
may already be freed.
The result then depends on what the freed memory holds. The failed
channel could be treated as opened, which brings back the original
hang. Or rndis_disable_subchannels() could call napi_disable() a second
time on a NAPI that netvsc_sc_open() already disabled. That call never
returns, and RTNL is held.
Would it be safer for netvsc_sc_open() to record the result of the open
in driver-owned state before atomic_inc_return()? For example, it could
clear nvchan->channel on failure or set a per-nvchan flag.
> +}
> +
> +/* 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);
[Severity: Medium]
What happens to the vmbus channels of the sub channels that did open?
They stay in CHANNEL_OPENED_STATE with netvsc_channel_cb() registered
and their ring buffers still allocated. Their NAPI is disabled here and
then deleted by netif_napi_del() in netvsc_attach() or
netvsc_subchan_work().
__netif_napi_del_locked() leaves NAPI_STATE_SCHED set, so
napi_schedule_prep() in netvsc_channel_cb() always fails:
drivers/net/hyperv/netvsc.c:netvsc_channel_cb() {
...
if (napi_schedule_prep(&nvchan->napi)) {
/* disable interrupts from host */
hv_begin_read(rbi);
__napi_schedule_irqoff(&nvchan->napi);
}
}
The inbound ring is never drained. Any recv buffer sections the host
places on these channels are never completed.
A sub channel also cannot be closed on its own, because
vmbus_disconnect_ring() has:
if (channel->primary_channel != NULL)
return -EINVAL;
So these channels and their high-order ring buffers stay armed with no
consumer until the next detach closes the primary channel. That memory
stays allocated under the same memory pressure that caused the
fallback.
If the host sends RX traffic on these channels, could it be dropped
and leak recv buffer sections? Could that starve RX on the primary
channel too?
> + }
> +}
[ ... ]
> @@ -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;
[Severity: Medium]
Does this early return leave ndc->rx_table pointing at queues that no
longer exist?
rndis_filter_device_add() fills rx_table for the requested channel
count:
if (!netif_is_rxfh_configured(net)) {
for (i = 0; i < ndc->rx_table_sz; i++)
ndc->rx_table[i] = ethtool_rxfh_indir_default(
i, net_device->num_chn);
}
This return skips rndis_filter_set_rss_param(). Neither netvsc_attach()
nor netvsc_subchan_work() resets rx_table when it sets num_chn = 1, so
netvsc_get_rxfh() would report queues that do not exist.
A key-only update (ethtool -X ethX hkey ..., so rxfh->indir is NULL)
skips the indir[i] >= num_chn check in netvsc_set_rxfh() and goes
straight to:
return rndis_filter_set_rss_param(rndis_dev, key);
rndis_set_rss_param_msg() then copies the stale table to the host
unchanged:
for (i = 0; i < ndc->rx_table_sz; i++)
itab[i] = ndc->rx_table[i];
Could the host then steer RX flows to the sub channels that this patch
leaves open on vmbus but never polls, so those flows are silently
dropped?
The stale rx_table after a fallback existed before this patch. What is
new is that it can now point at sub channels that are open but not
polled.
The commit message only says the driver falls back to the primary
channel. It does not mention that the opened sub channels stay open, or
how rx_table is handled.
> + }
> + }
> +
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114220358.5429-1-julius%40bairaktaris.de
^ permalink raw reply [flat|nested] 3+ messages in thread