From nobody Sat Feb 7 16:06:09 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C503BC7EE23 for ; Fri, 26 May 2023 06:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241976AbjEZGCk (ORCPT ); Fri, 26 May 2023 02:02:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjEZGCd (ORCPT ); Fri, 26 May 2023 02:02:33 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 20D0D13D; Thu, 25 May 2023 23:02:31 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1134) id 9141E20FBE9A; Thu, 25 May 2023 23:02:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9141E20FBE9A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1685080950; bh=vd+EgRw6TJnREEayB4qrZRl70IwLD9SmZ0ByIXVuIQY=; h=From:To:Cc:Subject:Date:From; b=AWS3HI0hx6OT2mJkJJcnJVj/Rc9sf/PNtUvNqnvZDR87Lvlf74C/4XdQlY+ipaqEX lLN6a0gigsfYJos61Mo+FctLt3foI1/+Uy7oz8djFMjdwjxeP3FQL12EpXDcEyXc49 IAyb2/UUiNonWEWePsSkFBuFrekJLbNL9Zi86Gk8= From: Shradha Gupta To: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org Cc: Shradha Gupta , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Michael Kelley , "David S. Miller" , Steen Hegelund , Simon Horman Subject: [PATCH v3] hv_netvsc: Allocate rx indirection table size dynamically Date: Thu, 25 May 2023 23:02:29 -0700 Message-Id: <1685080949-18316-1-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Allocate the size of rx indirection table dynamically in netvsc from the value of size provided by OID_GEN_RECEIVE_SCALE_CAPABILITIES query instead of using a constant value of ITAB_NUM. Signed-off-by: Shradha Gupta Tested-on: Ubuntu22 (azure VM, SKU size: Standard_F72s_v2) Testcases: 1. ethtool -x eth0 output 2. LISA testcase:PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION-NTTTCP-Synthet= ic 3. LISA testcase:PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION-NTTTCP-SRIOV Reviewed-by: Haiyang Zhang Reviewed-by: Praveen Kumar --- Changes in v3: * Changed the data type of rx_table_sz to u32 * Moved the rx indirection table free to rndis_filter_device_remove() * Device add will fail with error if not enough memory is available * Changed kzmalloc to kcalloc as suggested in checkpatch script * Removed redundant log if memory allocation failed. --- drivers/net/hyperv/hyperv_net.h | 5 ++++- drivers/net/hyperv/netvsc_drv.c | 10 ++++++---- drivers/net/hyperv/rndis_filter.c | 27 +++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_ne= t.h index dd5919ec408b..c40868f287a9 100644 --- a/drivers/net/hyperv/hyperv_net.h +++ b/drivers/net/hyperv/hyperv_net.h @@ -74,6 +74,7 @@ struct ndis_recv_scale_cap { /* NDIS_RECEIVE_SCALE_CAPABI= LITIES */ #define NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2 40 =20 #define ITAB_NUM 128 +#define ITAB_NUM_MAX 256 =20 struct ndis_recv_scale_param { /* NDIS_RECEIVE_SCALE_PARAMETERS */ struct ndis_obj_header hdr; @@ -1034,7 +1035,9 @@ struct net_device_context { =20 u32 tx_table[VRSS_SEND_TAB_SIZE]; =20 - u16 rx_table[ITAB_NUM]; + u16 *rx_table; + + u32 rx_table_sz; =20 /* Ethtool settings */ u8 duplex; diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_dr= v.c index 0103ff914024..3ba3c8fb28a5 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1747,7 +1747,9 @@ static u32 netvsc_get_rxfh_key_size(struct net_device= *dev) =20 static u32 netvsc_rss_indir_size(struct net_device *dev) { - return ITAB_NUM; + struct net_device_context *ndc =3D netdev_priv(dev); + + return ndc->rx_table_sz; } =20 static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, @@ -1766,7 +1768,7 @@ static int netvsc_get_rxfh(struct net_device *dev, u3= 2 *indir, u8 *key, =20 rndis_dev =3D ndev->extension; if (indir) { - for (i =3D 0; i < ITAB_NUM; i++) + for (i =3D 0; i < ndc->rx_table_sz; i++) indir[i] =3D ndc->rx_table[i]; } =20 @@ -1792,11 +1794,11 @@ static int netvsc_set_rxfh(struct net_device *dev, = const u32 *indir, =20 rndis_dev =3D ndev->extension; if (indir) { - for (i =3D 0; i < ITAB_NUM; i++) + for (i =3D 0; i < ndc->rx_table_sz; i++) if (indir[i] >=3D ndev->num_chn) return -EINVAL; =20 - for (i =3D 0; i < ITAB_NUM; i++) + for (i =3D 0; i < ndc->rx_table_sz; i++) ndc->rx_table[i] =3D indir[i]; } =20 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_f= ilter.c index eea777ec2541..dc7b9b326690 100644 --- a/drivers/net/hyperv/rndis_filter.c +++ b/drivers/net/hyperv/rndis_filter.c @@ -21,6 +21,7 @@ #include #include #include +#include =20 #include "hyperv_net.h" #include "netvsc_trace.h" @@ -927,7 +928,7 @@ static int rndis_set_rss_param_msg(struct rndis_device = *rdev, struct rndis_set_request *set; struct rndis_set_complete *set_complete; u32 extlen =3D sizeof(struct ndis_recv_scale_param) + - 4 * ITAB_NUM + NETVSC_HASH_KEYLEN; + 4 * ndc->rx_table_sz + NETVSC_HASH_KEYLEN; struct ndis_recv_scale_param *rssp; u32 *itab; u8 *keyp; @@ -953,7 +954,7 @@ static int rndis_set_rss_param_msg(struct rndis_device = *rdev, rssp->hashinfo =3D NDIS_HASH_FUNC_TOEPLITZ | NDIS_HASH_IPV4 | NDIS_HASH_TCP_IPV4 | NDIS_HASH_IPV6 | NDIS_HASH_TCP_IPV6; - rssp->indirect_tabsize =3D 4*ITAB_NUM; + rssp->indirect_tabsize =3D 4 * ndc->rx_table_sz; rssp->indirect_taboffset =3D sizeof(struct ndis_recv_scale_param); rssp->hashkey_size =3D NETVSC_HASH_KEYLEN; rssp->hashkey_offset =3D rssp->indirect_taboffset + @@ -961,7 +962,7 @@ static int rndis_set_rss_param_msg(struct rndis_device = *rdev, =20 /* Set indirection table entries */ itab =3D (u32 *)(rssp + 1); - for (i =3D 0; i < ITAB_NUM; i++) + for (i =3D 0; i < ndc->rx_table_sz; i++) itab[i] =3D ndc->rx_table[i]; =20 /* Set hask key values */ @@ -1548,6 +1549,17 @@ struct netvsc_device *rndis_filter_device_add(struct= hv_device *dev, if (ret || rsscap.num_recv_que < 2) goto out; =20 + if (rsscap.num_indirect_tabent && + rsscap.num_indirect_tabent <=3D ITAB_NUM_MAX) + ndc->rx_table_sz =3D rsscap.num_indirect_tabent; + else + ndc->rx_table_sz =3D ITAB_NUM; + + ndc->rx_table =3D kcalloc(ndc->rx_table_sz, sizeof(u16), + GFP_KERNEL); + if (!ndc->rx_table) + goto err_dev_remv; + /* This guarantees that num_possible_rss_qs <=3D num_online_cpus */ num_possible_rss_qs =3D min_t(u32, num_online_cpus(), rsscap.num_recv_que); @@ -1558,7 +1570,7 @@ struct netvsc_device *rndis_filter_device_add(struct = hv_device *dev, net_device->num_chn =3D min(net_device->max_chn, device_info->num_chn); =20 if (!netif_is_rxfh_configured(net)) { - for (i =3D 0; i < ITAB_NUM; i++) + for (i =3D 0; i < ndc->rx_table_sz; i++) ndc->rx_table[i] =3D ethtool_rxfh_indir_default( i, net_device->num_chn); } @@ -1596,11 +1608,18 @@ void rndis_filter_device_remove(struct hv_device *d= ev, struct netvsc_device *net_dev) { struct rndis_device *rndis_dev =3D net_dev->extension; + struct net_device *net =3D hv_get_drvdata(dev); + struct net_device_context *ndc =3D netdev_priv(net); =20 /* Halt and release the rndis device */ rndis_filter_halt_device(net_dev, rndis_dev); =20 netvsc_device_remove(dev); + + ndc->rx_table_sz =3D 0; + kfree(ndc->rx_table); + ndc->rx_table =3D NULL; + } =20 int rndis_filter_open(struct netvsc_device *nvdev) --=20 2.34.1