Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2906140rwd; Mon, 29 May 2023 02:45:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iznRbvshQ7xiIUAg7m0Rd/4OXCNWzD/g4BKlYlFLB9YzvR55ttweA0EYLjO/ug7jSdzyU X-Received: by 2002:a17:902:ef92:b0:1b0:295b:f192 with SMTP id iz18-20020a170902ef9200b001b0295bf192mr5047238plb.3.1685353535764; Mon, 29 May 2023 02:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685353535; cv=none; d=google.com; s=arc-20160816; b=HVVgwsBkVWG1NOAVvdjVKtESVIxWFPFSOE4PeV4tDCtSyXwBmWxOkDM/DcuhSEvYVJ gzuPnT2JJf+FY4XFqorN3DkLuZ7xxBt7vjHXVOGmzgbdnNPz8uUJllOgDxMEIw+PpOqS /m4KviGZca1zZC3Vt/S+1dK0noWWbboUtx0DojzKAEq37KRVdLlpFns8ZxgQLMvyw5TR 6+l+dNCXxM93I3N/XODDY4j/rogPqaskpyQpgMqiV3SlIJQi5NWj4bkSv/kPT0ozn1sC IDH1a/KobaztRPyq0rn0NwcHoNnqas3iwPe4PXtwlOosiYnhu2KhI7WYzve1PSPlw2dT m9zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=yiZxolf6CNnqCDZ6kanHPZ3rKzn2RzjeTJMF4sEG44k=; b=IqFQblK+Zp8Pf2HoGMTUl9NHztXJSoE97Dd2AhI2Jmqhn8Ns5uNHLNirIQMMN2CASp 8x0kJhoFRm3OXS+LEL9NIR3j7CoyPwgEV6qwcQDcJrpjux6M8PLPc9M+HFLiqPKFh7QM Ph8xJbhzEkztJ2D72si7exFXj7aJjKuEslxgqXTVg0x3UOcvKDAlBdJLcdvPrjNFb1YA MtbzvRRKDFwxo4Btme1hFy/9CDqoSOCxFfGhcmavxuqfbRj/b8CvTkGjWbjJQseHnFEF 7RYQ9OLj8jZ9Ch4dVXEOkQNG1UfcYhZcp6S+mcZDKAH1tyxNJa+dwhCjffv2GW/+Cv6W h6Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=HPNuAmlB; 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 t8-20020a170902b20800b0019a95ab6b4esi311215plr.407.2023.05.29.02.45.23; Mon, 29 May 2023 02:45:35 -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=HPNuAmlB; 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 S231688AbjE2JkB (ORCPT + 99 others); Mon, 29 May 2023 05:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjE2Jj6 (ORCPT ); Mon, 29 May 2023 05:39:58 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C20D90; Mon, 29 May 2023 02:39:57 -0700 (PDT) Received: from [10.156.157.27] (unknown [167.220.238.91]) by linux.microsoft.com (Postfix) with ESMTPSA id 93A0020FC3C1; Mon, 29 May 2023 02:39:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 93A0020FC3C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1685353196; bh=yiZxolf6CNnqCDZ6kanHPZ3rKzn2RzjeTJMF4sEG44k=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=HPNuAmlB7I1ONM02O7nUeoZNT/iv1ooCPx0y/OgzRrJs3hDofW/UHAbWf8Wt72uuW iGDJuViL468Ii8e8tsSuS4JBpRxA1DsgNjZeaM5HyN7l9tgQroctf9e0MTuGKsVWmX CdDegD8UI7RRxfcxr+DUGbM8h5PlC1DN3NDJ2/38= Message-ID: <5fc413e5-77d2-814d-250a-7ddf8eb6d6ad@linux.microsoft.com> Date: Mon, 29 May 2023 15:09:49 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH v3] hv_netvsc: Allocate rx indirection table size dynamically To: Shradha Gupta , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org Cc: 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 References: <1685080949-18316-1-git-send-email-shradhagupta@linux.microsoft.com> Content-Language: en-US From: Praveen Kumar In-Reply-To: <1685080949-18316-1-git-send-email-shradhagupta@linux.microsoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-19.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A, 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 On 5/26/2023 11:32 AM, Shradha Gupta wrote: > 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-Synthetic > 3. LISA testcase:PERF-NETWORK-TCP-THROUGHPUT-MULTICONNECTION-NTTTCP-SRIOV > > --- > 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_net.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_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; > + > + u32 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..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) > > 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 +1768,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 +1794,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]; > } > > diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.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 > > #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 = 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 = 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 +962,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 +1549,17 @@ 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 = kcalloc(ndc->rx_table_sz, sizeof(u16), > + GFP_KERNEL); > + if (!ndc->rx_table) > + goto err_dev_remv; > + > /* 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 +1570,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); > } > @@ -1596,11 +1608,18 @@ void rndis_filter_device_remove(struct hv_device *dev, > struct netvsc_device *net_dev) > { > struct rndis_device *rndis_dev = net_dev->extension; > + struct net_device *net = hv_get_drvdata(dev); > + struct net_device_context *ndc = netdev_priv(net); > > /* Halt and release the rndis device */ > rndis_filter_halt_device(net_dev, rndis_dev); > > netvsc_device_remove(dev); Shouldn't the netvsc_device_remove be called post table cleanup ? or better, the cleanup should happen as part of netvsc_device_remove operation ? This looks a bug to me as with remove operation, we already cleaned up the device and the association between context and device is removed. > + > + ndc->rx_table_sz = 0; > + kfree(ndc->rx_table); > + ndc->rx_table = NULL; > + > } > > int rndis_filter_open(struct netvsc_device *nvdev)