From: David Laight <David.Laight@ACULAB.COM>
To: 'Jijie Shao' <shaojijie@huawei.com>,
"yisen.zhuang@huawei.com" <yisen.zhuang@huawei.com>,
"salil.mehta@huawei.com" <salil.mehta@huawei.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>
Cc: "shenjian15@huawei.com" <shenjian15@huawei.com>,
"wangjie125@huawei.com" <wangjie125@huawei.com>,
"liuyonglong@huawei.com" <liuyonglong@huawei.com>,
"wangpeiyang1@huawei.com" <wangpeiyang1@huawei.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH net 1/6] net: hns3: fix side effects passed to min_t()
Date: Fri, 28 Jul 2023 08:29:48 +0000 [thread overview]
Message-ID: <85e3c423aa5a400981ae5c53a29ee280@AcuMS.aculab.com> (raw)
In-Reply-To: <20230728075840.4022760-2-shaojijie@huawei.com>
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 <liuyonglong@huawei.com>
> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
> ---
> 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)
next prev parent reply other threads:[~2023-07-28 8:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 7:58 [PATCH net 0/6] There are some bugfix for the HNS3 ethernet driver Jijie Shao
2023-07-28 7:58 ` [PATCH net 1/6] net: hns3: fix side effects passed to min_t() Jijie Shao
2023-07-28 8:29 ` David Laight [this message]
2023-07-29 2:57 ` Jijie Shao
2023-07-28 7:58 ` [PATCH net 2/6] net: hns3: restore user pause configure when disable autoneg Jijie Shao
2023-07-28 8:05 ` kernel test robot
2023-07-28 7:58 ` [PATCH net 3/6] net: hns3: refactor hclge_mac_link_status_wait for interface reuse Jijie Shao
2023-07-28 7:58 ` [PATCH net 4/6] net: hns3: add wait until mac link down Jijie Shao
2023-07-28 7:58 ` [PATCH net 5/6] net: hns3: fix wrong print link down up Jijie Shao
2023-07-28 8:57 ` Andrew Lunn
2023-07-29 3:11 ` Jijie Shao
2023-07-29 7:57 ` Andrew Lunn
[not found] ` <ef5489f9-43b4-ee59-699b-3f54a30c00aa@huawei.com>
2023-07-29 18:23 ` Andrew Lunn
2023-07-31 9:10 ` Jijie Shao
2023-08-10 8:06 ` Jijie Shao
2023-10-17 13:03 ` Jijie Shao
2023-10-17 13:59 ` Andrew Lunn
2023-10-18 12:25 ` Jijie Shao
2023-07-28 7:58 ` [PATCH net 6/6] net: hns3: fix deadlock issue when externel_lb and reset are executed together Jijie Shao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=85e3c423aa5a400981ae5c53a29ee280@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuyonglong@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=salil.mehta@huawei.com \
--cc=shaojijie@huawei.com \
--cc=shenjian15@huawei.com \
--cc=stable@vger.kernel.org \
--cc=wangjie125@huawei.com \
--cc=wangpeiyang1@huawei.com \
--cc=yisen.zhuang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox