Linux-HyperV List
 help / color / mirror / Atom feed
* [PATCH net] net: hv_netvsc: Preserve RSS indirection table across device recreation
@ 2026-11-25  6:56 Aditya Garg
  2026-11-26  6:56 ` sashiko-bot
  2026-11-29  7:10 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Aditya Garg @ 2026-11-25  6:56 UTC (permalink / raw)
  To: haiyangz, wei.liu, decui, andrew+netdev, davem, edumazet, kuba,
	pabeni, shradhagupta, horms, linux-hyperv, netdev, gargaditya,
	gargaditya, ssengar
  Cc: Amir Boussejra

Changing the MTU recreates the RNDIS device and frees the RSS indirection
table. The replacement is zeroed, but the user-configured flag survives
and prevents default initialization, directing all RX traffic to queue 0.

Save the custom table before teardown and restore it after host queue
negotiation if its size and queue indices remain valid. Otherwise use
defaults and report the lost configuration only after attachment succeeds.
Preserve the cached RSS key and zero table entries on single-queue error
fallbacks.

If subchannel setup or RSS programming fails, keep the device usable but
clear the active table and key caches and report the custom table lost
after attachment succeeds. This prevents nonzero netlink retries from
being skipped because they match settings that were not restored.

Fixes: 4cab498f33f7 ("hv_netvsc: Allocate rx indirection table size dynamically")
Reported-by: Amir Boussejra <amir@boussejra.com>
Closes: https://lore.kernel.org/all/40fb2352-4859-4334-849b-f6a4229605a1@boussejra.com/
Signed-off-by: Aditya Garg <gargaditya@linux.microsoft.com>
---
 drivers/net/hyperv/hyperv_net.h   |  2 ++
 drivers/net/hyperv/netvsc_drv.c   | 44 +++++++++++++++++++++++++++++++
 drivers/net/hyperv/rndis_filter.c | 33 ++++++++++++++++-------
 3 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 4841367fdab2..aef30cb52010 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -182,6 +182,8 @@ struct netvsc_device_info {
 	struct bpf_prog *bprog;
 
 	u8 rss_key[NETVSC_HASH_KEYLEN];
+	u16 *rss_indir_table;
+	u32 rss_indir_size;
 };
 
 enum rndis_device_state {
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 1d43c73fd73f..f51e7b349d7f 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -928,6 +928,7 @@ static void netvsc_get_channels(struct net_device *net,
 static
 struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev)
 {
+	struct net_device_context *ndc;
 	struct netvsc_device_info *dev_info;
 	struct bpf_prog *prog;
 
@@ -939,6 +940,21 @@ struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev)
 	if (nvdev) {
 		ASSERT_RTNL();
 
+		ndc = netdev_priv(nvdev->extension->ndev);
+		if (netif_is_rxfh_configured(nvdev->extension->ndev) &&
+		    ndc->rx_table_sz) {
+			dev_info->rss_indir_table =
+				kmemdup(ndc->rx_table,
+					ndc->rx_table_sz * sizeof(*ndc->rx_table),
+					GFP_ATOMIC);
+			if (!dev_info->rss_indir_table) {
+				kfree(dev_info);
+				return NULL;
+			}
+
+			dev_info->rss_indir_size = ndc->rx_table_sz;
+		}
+
 		dev_info->num_chn = nvdev->num_chn;
 		dev_info->send_sections = nvdev->send_section_cnt;
 		dev_info->send_section_size = nvdev->send_section_size;
@@ -973,6 +989,7 @@ static void netvsc_devinfo_put(struct netvsc_device_info *dev_info)
 		bpf_prog_put(dev_info->bprog);
 	}
 
+	kfree(dev_info->rss_indir_table);
 	kfree(dev_info);
 }
 
@@ -1023,6 +1040,7 @@ static int netvsc_attach(struct net_device *ndev,
 	struct netvsc_device *nvdev;
 	struct rndis_device *rdev;
 	struct bpf_prog *prog;
+	bool rss_failed = false;
 	int ret = 0;
 
 	nvdev = rndis_filter_device_add(hdev, dev_info);
@@ -1036,6 +1054,19 @@ static int netvsc_attach(struct net_device *ndev,
 		if (ret) {
 			nvdev->max_chn = 1;
 			nvdev->num_chn = 1;
+		} else {
+			ret = rndis_filter_set_rss_param(nvdev->extension, dev_info->rss_key);
+		}
+
+		if (ret) {
+			netdev_err(ndev,
+				   "unable to restore RSS parameters (ret %d).\n",
+				   ret);
+			/* Do not report the saved parameters as restored. */
+			memset(ndev_ctx->rx_table, 0,
+			       ndev_ctx->rx_table_sz * sizeof(*ndev_ctx->rx_table));
+			memset(nvdev->extension->rss_key, 0, NETVSC_HASH_KEYLEN);
+			rss_failed = true;
 		}
 	}
 
@@ -1066,6 +1097,14 @@ static int netvsc_attach(struct net_device *ndev,
 			netif_carrier_on(ndev);
 	}
 
+	/* Check whether the custom RSS table was lost and notify ethtool. */
+	if (netif_is_rxfh_configured(ndev) &&
+	    (rss_failed || !ndev_ctx->rx_table_sz ||
+	     ndev_ctx->rx_table_sz != dev_info->rss_indir_size ||
+	     memcmp(ndev_ctx->rx_table, dev_info->rss_indir_table,
+		    dev_info->rss_indir_size * sizeof(*ndev_ctx->rx_table))))
+		ethtool_rxfh_indir_lost(ndev);
+
 	return 0;
 
 err2:
@@ -2719,6 +2758,11 @@ static int netvsc_suspend(struct hv_device *dev)
 		goto out;
 	}
 	ret = netvsc_detach(net, nvdev);
+	if (ret) {
+		netvsc_devinfo_put(ndev_ctx->saved_netvsc_dev_info);
+		ndev_ctx->saved_netvsc_dev_info = NULL;
+	}
+
 out:
 	rtnl_unlock();
 
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 962251327506..9c0f01b6af1c 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1290,6 +1290,7 @@ int rndis_set_subchannel(struct net_device *ndev,
 	struct net_device_context *ndev_ctx = netdev_priv(ndev);
 	struct hv_device *hv_dev = ndev_ctx->device_ctx;
 	struct rndis_device *rdev = nvdev->extension;
+	bool restore_rss_table;
 	int i, ret;
 
 	ASSERT_RTNL();
@@ -1332,11 +1333,23 @@ int rndis_set_subchannel(struct net_device *ndev,
 	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
 		ndev_ctx->tx_table[i] = i % nvdev->num_chn;
 
-	/* ignore failures from setting rss parameters, still have channels */
-	if (dev_info)
-		rndis_filter_set_rss_param(rdev, dev_info->rss_key);
-	else
+	if (dev_info) {
+		/* Validate the whole saved table against the granted channels. */
+		restore_rss_table = netif_is_rxfh_configured(ndev) &&
+				    dev_info->rss_indir_size == ndev_ctx->rx_table_sz;
+		for (i = 0; restore_rss_table && i < ndev_ctx->rx_table_sz; i++)
+			if (dev_info->rss_indir_table[i] >= nvdev->num_chn)
+				restore_rss_table = false;
+
+		/* Restore the saved table if valid, otherwise use defaults. */
+		for (i = 0; i < ndev_ctx->rx_table_sz; i++)
+			ndev_ctx->rx_table[i] = restore_rss_table ?
+				dev_info->rss_indir_table[i] :
+				ethtool_rxfh_indir_default(i, nvdev->num_chn);
+	} else {
+		/* Set initial RSS parameters; ignore failures to keep the channels. */
 		rndis_filter_set_rss_param(rdev, netvsc_hash_key);
+	}
 
 	netif_set_real_num_tx_queues(ndev, nvdev->num_chn);
 	netif_set_real_num_rx_queues(ndev, nvdev->num_chn);
@@ -1500,6 +1513,8 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
 
 	net_device->extension = rndis_device;
 	rndis_device->ndev = net;
+	memcpy(rndis_device->rss_key, device_info->rss_key,
+	       NETVSC_HASH_KEYLEN);
 
 	/* Send the rndis initialization message */
 	ret = rndis_filter_init_device(rndis_device, net_device);
@@ -1570,11 +1585,8 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
 	/* We will use the given number of channels if available. */
 	net_device->num_chn = min(net_device->max_chn, device_info->num_chn);
 
-	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);
-	}
+	for (i = 0; i < ndc->rx_table_sz; i++)
+		ndc->rx_table[i] = ethtool_rxfh_indir_default(i, net_device->num_chn);
 
 	atomic_set(&net_device->open_chn, 1);
 	vmbus_set_sc_create_callback(dev->channel, netvsc_sc_open);
@@ -1598,6 +1610,9 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev,
 	/* setting up multiple channels failed */
 	net_device->max_chn = 1;
 	net_device->num_chn = 1;
+	if (ndc->rx_table_sz)
+		memset(ndc->rx_table, 0,
+		       ndc->rx_table_sz * sizeof(*ndc->rx_table));
 	return net_device;
 
 err_dev_remv:
-- 
2.43.0


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

* Re: [PATCH net] net: hv_netvsc: Preserve RSS indirection table across device recreation
  2026-11-25  6:56 [PATCH net] net: hv_netvsc: Preserve RSS indirection table across device recreation Aditya Garg
@ 2026-11-26  6:56 ` sashiko-bot
  2026-11-29  7:10 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-26  6:56 UTC (permalink / raw)
  To: Aditya Garg, linux-hyperv

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: hv_netvsc: zeroing rss_key and rx_table in
  netvsc_attach() breaks RSS
--

commit a79f79b300587b1f53e9f4a583c55f0d45f71328
Author: Aditya Garg <gargaditya@linux.microsoft.com>

net: hv_netvsc: Preserve RSS indirection table across device recreation

This commit saves and restores a user-configured RSS indirection table
and cached RSS hash key across RNDIS device recreation, and notifies
ethtool if the custom table cannot be restored.

> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index 1d43c73fd73f1..f51e7b349d7f7 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c

[ ... ]

> @@ -1036,6 +1054,19 @@ static int netvsc_attach(struct net_device *ndev,
>  		if (ret) {
>  			nvdev->max_chn = 1;
>  			nvdev->num_chn = 1;
> +		} else {
> +			ret = rndis_filter_set_rss_param(nvdev->extension, dev_info->rss_key);
> +		}
> +
> +		if (ret) {
> +			netdev_err(ndev,
> +				   "unable to restore RSS parameters (ret %d).\n",
> +				   ret);
> +			/* Do not report the saved parameters as restored. */
> +			memset(ndev_ctx->rx_table, 0,
> +			       ndev_ctx->rx_table_sz * sizeof(*ndev_ctx->rx_table));
> +			memset(nvdev->extension->rss_key, 0, NETVSC_HASH_KEYLEN);
> +			rss_failed = true;
>  		}
>  	}

[Severity: Medium]
Does zeroing nvdev->extension->rss_key and ndev_ctx->rx_table here break
later RSS updates and re-attachments?

rndis_set_rss_param_msg() always sends both ndc->rx_table and the 40-byte
hash key to the host together, and netvsc_set_rxfh() uses the cached
values whenever userspace updates only one of them:

drivers/net/hyperv/netvsc_drv.c:netvsc_set_rxfh() {
    ...
	if (rxfh->indir) {
		for (i = 0; i < ndc->rx_table_sz; i++)
			if (rxfh->indir[i] >= ndev->num_chn)
				return -EINVAL;

		for (i = 0; i < ndc->rx_table_sz; i++)
			ndc->rx_table[i] = rxfh->indir[i];
	}

	if (!key) {
		if (!rxfh->indir)
			return 0;

		key = rndis_dev->rss_key;
	}

	return rndis_filter_set_rss_param(rndis_dev, key);
}

If userspace responds to ethtool_rxfh_indir_lost() by setting or
resetting only the indirection table, netvsc_set_rxfh() falls back to
rndis_dev->rss_key and programs an all-zero Toeplitz key into the host,
hashing all RX traffic to queue 0; future re-attachments via
netvsc_devinfo_get() also save and program that zeroed key.  Similarly,
if rndis_set_subchannel() succeeded with multiple channels but
rndis_filter_set_rss_param() failed, updating only the hash key sends the
zeroed ndev_ctx->rx_table instead of the default round-robin table.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125065620.1604647-1-gargaditya@linux.microsoft.com?part=1

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

* Re: [PATCH net] net: hv_netvsc: Preserve RSS indirection table across device recreation
  2026-11-25  6:56 [PATCH net] net: hv_netvsc: Preserve RSS indirection table across device recreation Aditya Garg
  2026-11-26  6:56 ` sashiko-bot
@ 2026-11-29  7:10 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29  7:10 UTC (permalink / raw)
  To: gargaditya
  Cc: haiyangz, wei.liu, decui, andrew+netdev, davem, edumazet, kuba,
	pabeni, shradhagupta, horms, linux-hyperv, netdev, gargaditya,
	ssengar, amir

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 3

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).

- [Medium] When subchannel setup or RSS programming fails,
  netvsc_attach() runs memset(nvdev->extension->rss_key, 0,…
- [Medium] When rndis_set_subchannel() succeeds, so num_chn > 1 and the
  real RX queue count is already raised, but…
- [Low] The commit message understates what the patch changes.
- [Low] The Fixes: tag points to 4cab498f33f7 (June 2023, v6.5 era).
- [Low] netvsc_devinfo_get() adds a kmemdup() of the RSS indirection
  table (rx_table_sz u16 entries, at most ITAB_NUM_MAX = 256, so up to…

--

net: hv_netvsc: Preserve RSS indirection table across device recreation

This patch saves the user-configured RSS indirection table before the
RNDIS device is torn down. It restores the table after subchannel
negotiation if the table is still valid, and also carries the cached RSS
key across recreation. If RSS restore fails, it clears the cached table
and key and reports the table lost via ethtool_rxfh_indir_lost().

Closes: https://lore.kernel.org/all/40fb2352-4859-4334-849b-f6a4229605a1@boussejra.com/

> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index 1d43c73fd73f1..f51e7b349d7f7 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c

[ ... ]

> @@ -939,6 +940,21 @@ struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev)
>  	if (nvdev) {
>  		ASSERT_RTNL();
>  
> +		ndc = netdev_priv(nvdev->extension->ndev);
> +		if (netif_is_rxfh_configured(nvdev->extension->ndev) &&
> +		    ndc->rx_table_sz) {
> +			dev_info->rss_indir_table =
> +				kmemdup(ndc->rx_table,
> +					ndc->rx_table_sz * sizeof(*ndc->rx_table),
> +					GFP_ATOMIC);

[Severity: Low]
Does this kmemdup() need GFP_ATOMIC? Only four callers reach this
branch: netvsc_set_channels(), netvsc_change_mtu(),
netvsc_set_ringparam() and netvsc_suspend(). All of them run in process
context with RTNL held, as the ASSERT_RTNL() above shows.

If this allocation fails, the MTU, channel or ring change now returns
-ENOMEM, or suspend is aborted. GFP_KERNEL would be less likely to fail
here.

> +			if (!dev_info->rss_indir_table) {
> +				kfree(dev_info);
> +				return NULL;
> +			}

[ ... ]

> @@ -1036,6 +1054,19 @@ static int netvsc_attach(struct net_device *ndev,
>  		if (ret) {
>  			nvdev->max_chn = 1;
>  			nvdev->num_chn = 1;
> +		} else {
> +			ret = rndis_filter_set_rss_param(nvdev->extension, dev_info->rss_key);
> +		}
> +
> +		if (ret) {
> +			netdev_err(ndev,
> +				   "unable to restore RSS parameters (ret %d).\n",
> +				   ret);
> +			/* Do not report the saved parameters as restored. */
> +			memset(ndev_ctx->rx_table, 0,
> +			       ndev_ctx->rx_table_sz * sizeof(*ndev_ctx->rx_table));

[Severity: Medium]
What happens to RX steering when rndis_set_subchannel() succeeds but
rndis_filter_set_rss_param() fails?

In that case num_chn is still greater than one and the real RX queue
count has already been raised. Every entry in ndev_ctx->rx_table now
points to queue 0.

If a user table was configured, ethtool_rxfh_indir_lost() is called
later. That tells the core the table is unconfigured, so the core
assumes the default spread. netvsc_get_rxfh() reports the all-zero
table instead.

If no user table was configured, nothing is reported. Before this patch,
that case kept the ethtool_rxfh_indir_default() table.

A later key-only change such as "ethtool -X ethX hkey ..." reaches
netvsc_set_rxfh() with rxfh->indir == NULL. rndis_set_rss_param_msg()
then sends the table unchanged:

rndis_set_rss_param_msg() {
    ...
    itab[i] = ndc->rx_table[i];
    ...
}

Would that program an all-zero indirection table while several channels
are open? All RX would go to queue 0 while ethtool reports the default
table.

> +			memset(nvdev->extension->rss_key, 0, NETVSC_HASH_KEYLEN);

[Severity: Medium]
Can this zeroed key later be programmed into the host as the real
Toeplitz key? Nothing in the driver treats an all-zero rss_key as
invalid.

The next recreation can be an MTU change, ethtool -L, ethtool -G, or a
resume. In each case netvsc_devinfo_get() copies the zero key into
dev_info->rss_key. The new memcpy() in rndis_filter_device_add() then
copies it into the new rndis_device, and netvsc_attach() programs it:

netvsc_attach()
    rndis_set_subchannel()   /* succeeds this time */
    rndis_filter_set_rss_param(nvdev->extension, dev_info->rss_key)

A table-only "ethtool -X" retry also uses the zero key. When no hkey is
given, netvsc_set_rxfh() gets rxfh->key == NULL and falls back to the
cached key:

netvsc_set_rxfh() {
    ...
    key = rndis_dev->rss_key;
    ...
}

rndis_set_rss_param_msg() copies the key into an NDIS_HASH_FUNC_TOEPLITZ
request. A Toeplitz hash with an all-zero key is 0 for every packet, so
every flow would select indirection entry 0. Isn't that the same
all-RX-on-one-queue symptom this patch is fixing?

On success, rndis_set_rss_param_msg() also writes the key back into
rdev->rss_key. The zero key would then persist across later recreations
until the user sets a key explicitly.

The commit message says the caches are cleared so that netlink retries
are not skipped as matching. Could the driver keep the last valid key
(or netvsc_hash_key) for programming, and track the "not applied" state
separately?

> +			rss_failed = true;
>  		}
>  	}

[ ... ]

> @@ -1066,6 +1097,14 @@ static int netvsc_attach(struct net_device *ndev,
>  			netif_carrier_on(ndev);
>  	}
>  
> +	/* Check whether the custom RSS table was lost and notify ethtool. */
> +	if (netif_is_rxfh_configured(ndev) &&
> +	    (rss_failed || !ndev_ctx->rx_table_sz ||
> +	     ndev_ctx->rx_table_sz != dev_info->rss_indir_size ||
> +	     memcmp(ndev_ctx->rx_table, dev_info->rss_indir_table,
> +		    dev_info->rss_indir_size * sizeof(*ndev_ctx->rx_table))))
> +		ethtool_rxfh_indir_lost(ndev);

[Severity: Low]
The Fixes: tag points to 4cab498f33f7 ("hv_netvsc: Allocate rx
indirection table size dynamically"), which is from the v6.5 era. This
fix depends on two things added much later, in commit 0475f9e779b456
(2026): ethtool_rxfh_indir_lost(), and the netif_is_rxfh_configured()
that reads dev->ethtool->rss_indir_user_size.

Stable trees that have 4cab498f33f7 but not 0475f9e779b456 can't take
this patch as written. A backport would need another way to clear the
user-configured state, such as the older IFF_RXFH_CONFIGURED flag.
Should the commit message mention this dependency?

> +
>  	return 0;

[ ... ]

> @@ -2719,6 +2758,11 @@ static int netvsc_suspend(struct hv_device *dev)
>  		goto out;
>  	}
>  	ret = netvsc_detach(net, nvdev);
> +	if (ret) {
> +		netvsc_devinfo_put(ndev_ctx->saved_netvsc_dev_info);
> +		ndev_ctx->saved_netvsc_dev_info = NULL;
> +	}

[Severity: Low]
This isn't a bug, but this hunk is a separate fix that the commit
message doesn't mention. Before this patch, a failed netvsc_detach()
leaked the saved devinfo and its bpf_prog reference.
saved_netvsc_dev_info is otherwise only freed in netvsc_resume(). Could
the commit message describe this change?

The commit message also says:

  "Changing the MTU recreates the RNDIS device and frees the RSS
  indirection table."

MTU changes are not the only trigger. netvsc_set_channels(),
netvsc_set_ringparam() and netvsc_resume() use the same
netvsc_devinfo_get()/netvsc_detach()/netvsc_attach() sequence. They had
the same zeroed-table problem and are fixed here too. Could the commit
message list these triggers as well?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125065620.1604647-1-gargaditya%40linux.microsoft.com

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  6:56 [PATCH net] net: hv_netvsc: Preserve RSS indirection table across device recreation Aditya Garg
2026-11-26  6:56 ` sashiko-bot
2026-11-29  7: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