Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5528356rwd; Wed, 24 May 2023 03:12:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6WkaEKu7MRkV5Jum9w6f36Lud0FCiJHNgo0hjvucm82U5Isyc5X+yNUiy2ZOsKv3ZsoM/x X-Received: by 2002:a17:903:456:b0:1af:9b8a:9c79 with SMTP id iw22-20020a170903045600b001af9b8a9c79mr11802871plb.34.1684923122022; Wed, 24 May 2023 03:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684923122; cv=none; d=google.com; s=arc-20160816; b=rBR5qzwhrXaZIhwmKLWudJb1Rbe51MJFiXqs+pzRGeZ3H8ZQljxw1mFyAzOIUyfbGg FJ15B+5WCdTf778k+hygPPtuK/L/VktS2aJ7zbC5lZCmr9t72GJPP+91thWVCPW/fpeC 1Tq41pq5ymG4crYeTnLnQkGEZGUH7Z52WNFlUAMynf2pH0HIks2RlIkdEduQV0ykeNwM wl9LnyNXF9leleA5vE3J/ZtwcHTaECJvB5TT243VystxkNJ5GX6tnqqC8nNwLrZn//sD xeMIQf+gVlyUHxTgATV2D6nkgp/XllhdphjDnC/6LMALFaC8yS+kaysLIoKkbAk0RO46 a7pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=VHd2+HBr/ZdV/++44Xu4iEewGcOk/dRPyk8bgSx8juI=; b=K+jSDreB8o7rAtkoTerGQww4VxHjkMyz4iUBdm4uIIpplFN0mtFDTtWmiHq9l5/uxc rWsCb8nQgjo9xO3YabWI9jr6mudGazmCKuwzpdJu1jTL123tIyA8CexiJSAABbwD1Mi7 dvtmo7Lvz1dPQ6OIUkdT27Y1Wb7ZoIhAg29OBrSztI4wtn4eIbALamDXtqIrKaPBuLVC /2PMAIUpo/7Fc9AX8G76aXB0/1CiqzA+ZM1eAO2yqDBOze1WIAtNvOCDXNDDGXOUVYSY JeCMx/FlcT4fFFMRgHx3XMdo2BxZF0KHth7VSxJ4oTGSEL4LDJLifgH5t/NSqYL459Te L1GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=VzoWUx2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a170902b78b00b001ac7ea55768si363109pls.499.2023.05.24.03.11.46; Wed, 24 May 2023 03:12:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=VzoWUx2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231287AbjEXJ5U (ORCPT + 99 others); Wed, 24 May 2023 05:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbjEXJ5O (ORCPT ); Wed, 24 May 2023 05:57:14 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D954E93; Wed, 24 May 2023 02:57:12 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1134) id 46D4020FB9FB; Wed, 24 May 2023 02:57:12 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 46D4020FB9FB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1684922232; bh=VHd2+HBr/ZdV/++44Xu4iEewGcOk/dRPyk8bgSx8juI=; h=From:To:Cc:Subject:Date:From; b=VzoWUx2YB7ZlOJMsU1/h7rUaRCgihwp+j2cnk/px5bHj5WIHjkjLKkJDXjqjLwvoQ h1J0eGr75Nb7mV4sScZzUOPiIwVTI4td3KgqbP9QhL/AqSIuyncbAr6NTYKZBG74Bk TC2tyGlvnAIUd1XQ1SVcKaiVK9r695jL6y+3l970= 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 v2] hv_netvsc: Allocate rx indirection table size dynamically Date: Wed, 24 May 2023 02:57:10 -0700 Message-Id: <1684922230-24073-1-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in v2: * Added a missing free for rx_table to fix a leak * Corrected alignment around rx table size query * Fixed incorrect error handling for rx_table pointer. --- drivers/net/hyperv/hyperv_net.h | 5 ++++- drivers/net/hyperv/netvsc_drv.c | 18 ++++++++++++++---- drivers/net/hyperv/rndis_filter.c | 22 ++++++++++++++++++---- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h index dd5919ec408b..1dbdb65ca8f0 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_CAPABILITIES */ #define NDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2 40 #define ITAB_NUM 128 +#define ITAB_NUM_MAX 256 struct ndis_recv_scale_param { /* NDIS_RECEIVE_SCALE_PARAMETERS */ struct ndis_obj_header hdr; @@ -1034,7 +1035,9 @@ struct net_device_context { u32 tx_table[VRSS_SEND_TAB_SIZE]; - u16 rx_table[ITAB_NUM]; + u16 *rx_table; + + int rx_table_sz; /* Ethtool settings */ u8 duplex; diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c index 0103ff914024..ab791e4ca63c 100644 --- a/drivers/net/hyperv/netvsc_drv.c +++ b/drivers/net/hyperv/netvsc_drv.c @@ -1040,6 +1040,13 @@ static int netvsc_detach(struct net_device *ndev, rndis_filter_device_remove(hdev, nvdev); + /* + * Free the rx indirection table and reset the table size to 0. + * With the netvsc_attach call it will get allocated again. + */ + ndev_ctx->rx_table_sz = 0; + kfree(ndev_ctx->rx_table); + return 0; } @@ -1747,7 +1754,9 @@ static u32 netvsc_get_rxfh_key_size(struct net_device *dev) static u32 netvsc_rss_indir_size(struct net_device *dev) { - return ITAB_NUM; + struct net_device_context *ndc = netdev_priv(dev); + + return ndc->rx_table_sz; } static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, @@ -1766,7 +1775,7 @@ static int netvsc_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, rndis_dev = ndev->extension; if (indir) { - for (i = 0; i < ITAB_NUM; i++) + for (i = 0; i < ndc->rx_table_sz; i++) indir[i] = ndc->rx_table[i]; } @@ -1792,11 +1801,11 @@ static int netvsc_set_rxfh(struct net_device *dev, const u32 *indir, rndis_dev = ndev->extension; if (indir) { - for (i = 0; i < ITAB_NUM; i++) + for (i = 0; i < ndc->rx_table_sz; i++) if (indir[i] >= ndev->num_chn) return -EINVAL; - for (i = 0; i < ITAB_NUM; i++) + for (i = 0; i < ndc->rx_table_sz; i++) ndc->rx_table[i] = indir[i]; } @@ -2638,6 +2647,7 @@ static void netvsc_remove(struct hv_device *dev) hv_set_drvdata(dev, NULL); + kfree(ndev_ctx->rx_table); free_percpu(ndev_ctx->vf_stats); free_netdev(net); } diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c index eea777ec2541..3695c7d3da3a 100644 --- a/drivers/net/hyperv/rndis_filter.c +++ b/drivers/net/hyperv/rndis_filter.c @@ -927,7 +927,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 = 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 +953,7 @@ static int rndis_set_rss_param_msg(struct rndis_device *rdev, rssp->hashinfo = NDIS_HASH_FUNC_TOEPLITZ | NDIS_HASH_IPV4 | NDIS_HASH_TCP_IPV4 | NDIS_HASH_IPV6 | NDIS_HASH_TCP_IPV6; - rssp->indirect_tabsize = 4*ITAB_NUM; + rssp->indirect_tabsize = 4 * ndc->rx_table_sz; rssp->indirect_taboffset = sizeof(struct ndis_recv_scale_param); rssp->hashkey_size = NETVSC_HASH_KEYLEN; rssp->hashkey_offset = rssp->indirect_taboffset + @@ -961,7 +961,7 @@ static int rndis_set_rss_param_msg(struct rndis_device *rdev, /* Set indirection table entries */ itab = (u32 *)(rssp + 1); - for (i = 0; i < ITAB_NUM; i++) + for (i = 0; i < ndc->rx_table_sz; i++) itab[i] = ndc->rx_table[i]; /* Set hask key values */ @@ -1548,6 +1548,20 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev, if (ret || rsscap.num_recv_que < 2) goto out; + if (rsscap.num_indirect_tabent && + rsscap.num_indirect_tabent <= ITAB_NUM_MAX) + ndc->rx_table_sz = rsscap.num_indirect_tabent; + else + ndc->rx_table_sz = ITAB_NUM; + + ndc->rx_table = kzalloc(sizeof(u16) * ndc->rx_table_sz, + GFP_KERNEL); + if (!ndc->rx_table) { + netdev_err(net, "Error in allocating rx indirection table of size %d\n", + ndc->rx_table_sz); + goto out; + } + /* This guarantees that num_possible_rss_qs <= num_online_cpus */ num_possible_rss_qs = min_t(u32, num_online_cpus(), rsscap.num_recv_que); @@ -1558,7 +1572,7 @@ struct netvsc_device *rndis_filter_device_add(struct hv_device *dev, net_device->num_chn = min(net_device->max_chn, device_info->num_chn); if (!netif_is_rxfh_configured(net)) { - for (i = 0; i < ITAB_NUM; i++) + for (i = 0; i < ndc->rx_table_sz; i++) ndc->rx_table[i] = ethtool_rxfh_indir_default( i, net_device->num_chn); } -- 2.34.1