net: hv_netvsc: Preserve RSS indirection table across device recreation
PATCH v2 1/1 net: hv_netvsc: Preserve RSS indirection table across device recreation
Changing the MTU, channel count or ring sizes, as well as suspend/resume, 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.
Also free the saved device information if detach fails during suspend, releasing the RSS snapshot and any retained BPF program reference.
Use GFP_KERNEL for the saved device information and RSS table allocations, as all callers run in sleepable context.
The lost-table notification uses ethtool_rxfh_indir_lost(), introduced by commit 0475f9e779b456 ("ethtool: Track user-provided RSS indirection table size").
Backports to trees without that commit must adapt the user-configured state handling to the older IFF_RXFH_CONFIGURED mechanism.
---
Changes in v2:
- Use GFP_KERNEL for the RSS table snapshot and the existing device-info allocation.
- Update the commit message to cover all recreation triggers, failed-suspend cleanup, and the lost-table notification dependency for older backports.
v1: https://lore.kernel.org/all/[email protected]/
drivers/net/hyperv/hyperv_net.h | 2 ++ drivers/net/hyperv/netvsc_drv.c | 46 ++++++++++++++++++++++++++++++- drivers/net/hyperv/rndis_filter.c | 33 ++++++++++++++++------ 3 files changed, 71 insertions(+), 10 deletions(-)
drivers/net/hyperv/hyperv_net.h +2 -0
@@ -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 {
drivers/net/hyperv/netvsc_drv.c +45 -1
91 lines not on this page · raw message
drivers/net/hyperv/rndis_filter.c +24 -9
@@ -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:
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: hv_netvsc: zeroing rx_table and rss_key in netvsc_attach() breaks RSS --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: hv_netvsc: zeroing rx_table and rss_key in netvsc_attach() breaks RSS
--
commit 9294af50c8f8757092c38dc965ae71d9b53d00c2
Author: Aditya Garg <[email protected]>
net: hv_netvsc: Preserve RSS indirection table across device recreation
This commit saves and restores user-configured RSS indirection tables across RNDIS device recreation, notifies ethtool via ethtool_rxfh_indir_lost() when a custom table cannot be restored, and cleans up saved device info if detach fails during suspend.
Quoted 4 lines
drivers/net/hyperv/netvsc_drv.c +0
-0
[ ... ]
Quoted 9 lines
drivers/net/hyperv/netvsc_drv.c +5
-0@@ -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) {
drivers/net/hyperv/netvsc_drv.c static int netvsc_attach(struct net_device *ndev, · line 1071
Quoted 10 lines
drivers/net/hyperv/netvsc_drv.c +8
-0+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]
Can zeroing ndev_ctx->rx_table and nvdev->extension->rss_key here cause later RSS updates or device recreations to silently collapse all RX traffic onto a single queue?
rndis_set_rss_param_msg() always sends both ndc->rx_table and rss_key to the host. Since ethtool_rxfh_indir_lost() only signals a lost table, a table-only netvsc_set_rxfh() reuses the zeroed rndis_dev->rss_key and programs an all-zero Toeplitz key that steers all packets to rx_table[0].
Similarly, if rndis_filter_set_rss_param() fails after rndis_set_subchannel() enabled multiple queues, a key-only netvsc_set_rxfh() update programs the zeroed ndc->rx_table. Later recreations also copy the zeroed rss_key via netvsc_devinfo_get().
Tracking the unapplied RSS state separately, or falling back to netvsc_hash_key and ethtool_rxfh_indir_default() when programming omitted parameters or recreating the device, would keep netlink retries working without programming all-zero RSS parameters.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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).
- [Medium] When netvsc_attach() hits its multi-queue error fallback, it zeroes the only cached copy of the RSS Toeplitz key.
- [Medium] If rndis_set_subchannel() succeeds and only the new rndis_filter_set_rss_param() call fails, netvsc_attach() zeroes…
--
net: hv_netvsc: Preserve RSS indirection table across device recreation
This patch saves a user-configured RSS indirection table in netvsc_device_info before the RNDIS device is recreated. The table is restored after subchannel negotiation if it is still valid. Otherwise defaults are used and the loss is reported with ethtool_rxfh_indir_lost(). On subchannel or RSS programming failure in netvsc_attach(), the patch also clears the cached table and key.
Quoted 4 lines
drivers/net/hyperv/netvsc_drv.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/hyperv/netvsc_drv.c +1
-0@@ -1036,6 +1054,19 @@ static int netvsc_attach(struct net_device *ndev,if (ret) { nvdev->max_chn =1 ; nvdev->num_chn =1 ; + }else {
drivers/net/hyperv/netvsc_drv.c static int netvsc_attach(struct net_device *ndev, · line 1067
Quoted 10 lines
drivers/net/hyperv/netvsc_drv.c +10
-0+ 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]
Suppose rndis_set_subchannel() succeeds and only the new rndis_filter_set_rss_param() call fails. This memset then zeroes rx_table, but nvdev->num_chn is still greater than 1, and rndis_set_subchannel() has already set the real rx queue count to num_chn. Is an all-zero table the intended state for a multi-queue device here?
If the table was user-configured, the check further down calls ethtool_rxfh_indir_lost(). That clears rss_indir_user_size, so the ethtool core treats the device as using the default table. The driver, however, holds all zeros, not ethtool_rxfh_indir_default(i, num_chn). The same all-zero table is left behind when no custom table was configured.
A later key-only update such as "ethtool -X ethX hkey ..." reaches netvsc_set_rxfh() with rxfh->indir == NULL. It leaves rx_table untouched and programs it to the host:
drivers/net/hyperv/netvsc_drv.c:netvsc_set_rxfh() {
...
rndis_dev = ndev->extension;
if (rxfh->indir) {
...
}
...
return rndis_filter_set_rss_param(rndis_dev, key);
}rndis_set_rss_param_msg() then copies ndc->rx_table straight into the request:
for (i = 0; i < ndc->rx_table_sz; i++) itab[i] = ndc->rx_table[i];
Wouldn't that enable RSS with every entry pointing at queue 0? ethtool -x would also show an all-zero table on a multi-queue device that the core reports as unconfigured.
Before this patch, rndis_set_subchannel() ignored set_rss_param failures here and rx_table kept valid entries. An all-zero table matches the num_chn == 1 case on the out: path of rndis_filter_device_add(), but this branch keeps the subchannels.
When only RSS programming failed, should rx_table be filled with defaults for num_chn instead?
drivers/net/hyperv/netvsc_drv.c static int netvsc_attach(struct net_device *ndev, · line 1068
Quoted 1 line
drivers/net/hyperv/netvsc_drv.c +1
-0+memset (nvdev->extension->rss_key,0 ,NETVSC_HASH_KEYLEN );
[Severity: Medium]
This memset runs on both the subchannel failure path and the RSS programming failure path, whether or not netif_is_rxfh_configured() is true. Is it safe to clear rdev->rss_key here, when the same cache is the source for later host programming?
On the next recreation (MTU change, ethtool -L, ringparam change or suspend/resume), netvsc_devinfo_get() copies the zeroed key into dev_info:
memcpy(dev_info->rss_key, nvdev->extension->rss_key, NETVSC_HASH_KEYLEN);
The new memcpy in rndis_filter_device_add() carries that key into the new rndis_device:
memcpy(rndis_device->rss_key, device_info->rss_key, NETVSC_HASH_KEYLEN);
netvsc_attach() then calls rndis_filter_set_rss_param(nvdev->extension, dev_info->rss_key). rndis_set_rss_param_msg() copies the 40 zero bytes into the Toeplitz OID_GEN_RECEIVE_SCALE_PARAMETERS request:
memcpy(keyp, rss_key, NETVSC_HASH_KEYLEN);
A table-only retry such as "ethtool -X ethX equal N" without hkey takes this fallback in netvsc_set_rxfh(), so it also programs the zero key:
if (!key) {
if (!rxfh->indir)
return 0;
key = rndis_dev->rss_key;
}A Toeplitz hash with an all-zero key is 0 for every input. If the host accepts the key, wouldn't every flow land on rx_table[0]? That is the all-RX-on-queue-0 symptom this patch is meant to fix. If the host rejects the key, RSS programming would fail on every recreation and the device would stay single-queue.
rndis_set_rss_param_msg() refreshes rdev->rss_key only when the host reports success. netvsc_hash_key is used only on the probe path, where dev_info is NULL. So nothing seems to restore a valid key unless the user supplies an explicit hkey.
The commit message says:
Preserve the cached RSS key and zero table entries on single-queue error fallbacks.
The out: single-queue fallback in rndis_filter_device_add() keeps the key. The single-queue fallback here, after a subchannel failure, clears it. Should these two paths behave the same way?
Quoted 3 lines
drivers/net/hyperv/netvsc_drv.c +1
-0+ rss_failed = true; } }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203071129.396360-1-gargaditya%40linux.microsoft.com