Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2162289rwb; Sat, 29 Jul 2023 00:48:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlF1vYBWuyFWt5s7JyGTua7vr/fKvh/5dQvmM+X1TFvQpGcSql/eyGTlbyaagWIRLcO4ufmd X-Received: by 2002:a05:6a20:160b:b0:133:bf18:ef7b with SMTP id l11-20020a056a20160b00b00133bf18ef7bmr5115022pzj.24.1690616932164; Sat, 29 Jul 2023 00:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690616932; cv=none; d=google.com; s=arc-20160816; b=jacYNPXEOLPm7QQGb0qHfuI8BvVasvZXDxflmnRafL+wDDzefxv1CDnLgixXZDTYk1 O0iF803R4b8dRahJrTdIKh0mb1nXoDyK3lXQ67nzJHKFCxiuh4zEaBaVltwkHnFy4L1O MG7TJzxf1WI78XsyoKowfsgQdf4Azgs9ToXyOT/Ntc/u2UDqXsRFAEfRQSFpobQVmxRn g6hKG54G1bDFzee/7dnCGj8HLr44dfQfBXip0P2y1OuO/M02pJ6+YgUnGJ1y/zv44yP/ pTpMttYNerXMRyGrUjWWfGSKKe0bt4/zd9bnbIacE21Vp2yApC/ysgWivtuYl4+Xlvjz n4xw== 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 :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=a1THmJOCu49GPCKvhoanPdVoYCEOCv4C3Q1nyG9tf+A=; fh=W2sZb1suOWnhNsNQ4biNwEUmDBY2aDUxQh0enfmJrCw=; b=TA9lLO7G+7bkBgiIWnI6veNignB82sr0egX+FNas8tX/Wn75mhmpfoRMqU4qufRcf1 EtEq40mRexmk9E9I+zqcPk4aIYxVT5i6NKVpS7w2xpI6xh46g0nqjG8KHXJ5hA6MnQyt 1klMcX4id4Zk9y8tdW6sjG1DOwxrmhINA59+DQhZ+Z+1v0ze9Rui/wGv57RCs/5E3svY h1DaCdwiRT7Y7DhCszRxYe9humm8HQQsqJDUpZhTNIbGjmpslqJM+u7/S1NOsCeerzA/ Yeepm2wc+w+h7sWH7tavdw9Hfyl7gfTbq5Jf6k+DCDRPrRkNBRlsmNt82JtpxioU3Qr+ Lo2A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a6543c7000000b00543e36736d3si2596348pgp.628.2023.07.29.00.48.40; Sat, 29 Jul 2023 00:48:52 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229668AbjG2C70 (ORCPT + 99 others); Fri, 28 Jul 2023 22:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbjG2C7Z (ORCPT ); Fri, 28 Jul 2023 22:59:25 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9CA75253; Fri, 28 Jul 2023 19:58:49 -0700 (PDT) Received: from kwepemm600007.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RCTfR5y4Xz1GDFb; Sat, 29 Jul 2023 10:56:15 +0800 (CST) Received: from [10.69.136.139] (10.69.136.139) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 29 Jul 2023 10:57:11 +0800 Message-ID: Date: Sat, 29 Jul 2023 10:57:10 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net 1/6] net: hns3: fix side effects passed to min_t() To: David Laight , "yisen.zhuang@huawei.com" , "salil.mehta@huawei.com" , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , "pabeni@redhat.com" CC: "shenjian15@huawei.com" , "wangjie125@huawei.com" , "liuyonglong@huawei.com" , "wangpeiyang1@huawei.com" , "netdev@vger.kernel.org" , "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20230728075840.4022760-1-shaojijie@huawei.com> <20230728075840.4022760-2-shaojijie@huawei.com> <85e3c423aa5a400981ae5c53a29ee280@AcuMS.aculab.com> From: Jijie Shao In-Reply-To: <85e3c423aa5a400981ae5c53a29ee280@AcuMS.aculab.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.69.136.139] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600007.china.huawei.com (7.193.23.208) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Hi David: Yes, you're right, min_t() evaluates the arguments only once. In the actual scenario, the number of cpu is far less than 65535. Therefore, the minimum value will not convert to zero. Thanks for your advice, this patch will be withdrawn.   Jijie Shao on 2023/7/28 16:29, David Laight wrote: > From: Jijie Shao >> Sent: 28 July 2023 08:59 >> >> num_online_cpus() may call more than once when passing to min_t(), >> between calls, it may return different values, so move num_online_cpus() >> out of min_t(). > Nope, wrong bug: > min() (and friends) are careful to only evaluate their arguments once. > The bug is using min_t() - especially with a small type. > > If/when the number of cpu hits 65536 the (u16) cast will convert > it to zero. > > Looking at the code a lot of the local variables should be > 'unsigned int' not 'u16. > Just because the domain of a value is small doesn't mean > you should use a small type (unless you are saving space in > a structure). > > David > >> Signed-off-by: Yonglong Liu >> Signed-off-by: Jijie Shao >> --- >> drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c >> b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c >> index 9f6890059666..823e6d2e85f5 100644 >> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c >> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c >> @@ -4757,6 +4757,7 @@ static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv) >> { >> struct hnae3_handle *h = priv->ae_handle; >> struct hns3_enet_tqp_vector *tqp_vector; >> + u32 online_cpus = num_online_cpus(); >> struct hnae3_vector_info *vector; >> struct pci_dev *pdev = h->pdev; >> u16 tqp_num = h->kinfo.num_tqps; >> @@ -4766,7 +4767,7 @@ static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv) >> >> /* RSS size, cpu online and vector_num should be the same */ >> /* Should consider 2p/4p later */ >> - vector_num = min_t(u16, num_online_cpus(), tqp_num); >> + vector_num = min_t(u16, online_cpus, tqp_num); >> >> vector = devm_kcalloc(&pdev->dev, vector_num, sizeof(*vector), >> GFP_KERNEL); >> -- >> 2.30.0 > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) > >