From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=13.77.154.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796281895; b=0GYyITXgbPAm5w1TmED8XhempDJWSAU1ku3ZjuGiZbDetKbViT1rd/LrIOeDGUZtkDj2 MWYUi27IjeMn2twIoaaFpDT1GnkGuJNhXxYYSjBUtlhOIUPVkRYU4c/VXDRLLO4k72PPe DJoiwJTw02w6YY1Pgv2AVlwfRMKFP7RnNewcw+9u6v5cA5D60FWGtkI64XrpQM5KPv42L epRIipgMTq2tyBPO+dzB8ORXhQTKM6WASKRtC43Pv+v1HiBsy2e0IL5pMBr4YX380LOgn FusRizO9/eK1B7UZBKA4hDuu6Efdw7sX0y/e/p6ZRgt4FkFqdyeYsgzZf20yF9U9DPg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796281895; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=jFsE9582907cT+MEkE1cyccrN9m7fRlVET+nrfCNf/E=; b=hJA03Xly99KLAwJYwx28kEzt7uT4B1Znp7YBrMDyK2/gTbEIXnmhMF2xNXEbS9BwcpBv lU/kcHmB2kehXSYAwRTBBnjzSGLsb1XJzMu3QbMwcQ/hN8he67vbM/R2fL1DtfiZFYATe ZMlNPqKxKb1z0bgf1yzmhpmMtTXsN3hKaqz5Mlu5qi4Bc+O2zO6gZPGCFAOukhDv1fBJv Cz+ZPnWd6snNeSbxTZdBXFisinqht5mAoycevMlhpOXEs/c7SCdf7cje/4ia75tO6xzwI 6GJ0Od7gM1SMYHUVGvSqjRDH6VHjzhdvAdnLUlw6mVLLcN7wpp2SZ/fBvZta+c4HDfw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=AODUBkD2; arc=none smtp.remote-ip=13.77.154.182 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE076606A322; Thu, 3 Dec 2026 07:11:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CE076606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=AODUBkD2 Received: by linux.microsoft.com (Postfix, from userid 1231) id 3A4AF20B7166; Wed, 2 Dec 2026 23:11:33 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3A4AF20B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796281893; bh=jFsE9582907cT+MEkE1cyccrN9m7fRlVET+nrfCNf/E=; h=From:To:Cc:Subject:Date:From; b=AODUBkD2iVlnQYMP3wC60uyHQq2UdLgbvTWhrRFqCZw/4G/1IWxsXKQHMW98o/Uq4 uodA5sRM8mGs5lyOB4bk/DeCD2pG8Zp8V0l0Owit9MV8FhI4MqacONmGeWS9q4Gs6W DHFAA5K7jTrnqFzLnGi4s6z8r9jbDTce75nlr65o= From: Aditya Garg To: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, shradhagupta@linux.microsoft.com, horms@kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, gargaditya@microsoft.com, gargaditya@linux.microsoft.com, ssengar@linux.microsoft.com Cc: Amir Boussejra Subject: [PATCH net v2] net: hv_netvsc: Preserve RSS indirection table across device recreation Date: Wed, 2 Dec 2026 23:11:21 -0800 Message-ID: <20261203071129.396360-1-gargaditya@linux.microsoft.com> X-Mailer: git-send-email 2.43.7 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Fixes: 4cab498f33f7 ("hv_netvsc: Allocate rx indirection table size dynamically") Reported-by: Amir Boussejra Closes: https://lore.kernel.org/all/40fb2352-4859-4334-849b-f6a4229605a1@boussejra.com/ Signed-off-by: Aditya Garg --- 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/20261125065620.1604647-1-gargaditya@linux.microsoft.com/ 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(-) 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..4df17d7baa30 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -928,10 +928,11 @@ 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; - dev_info = kzalloc_obj(*dev_info, GFP_ATOMIC); + dev_info = kzalloc_obj(*dev_info); if (!dev_info) return NULL; @@ -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_KERNEL); + 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