From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CDF3C433EF for ; Fri, 18 Feb 2022 03:41:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6F1C6B0074; Thu, 17 Feb 2022 22:41:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A1E0D6B0075; Thu, 17 Feb 2022 22:41:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90C3F6B0078; Thu, 17 Feb 2022 22:41:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id 823F56B0074 for ; Thu, 17 Feb 2022 22:41:02 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1E5E6987A6 for ; Fri, 18 Feb 2022 03:41:02 +0000 (UTC) X-FDA: 79154499564.11.3C3DF66 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf11.hostedemail.com (Postfix) with ESMTP id C0EF040007 for ; Fri, 18 Feb 2022 03:40:58 +0000 (UTC) Received: from kwepemi100019.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K0HWC075RzbkZg; Fri, 18 Feb 2022 11:39:34 +0800 (CST) Received: from kwepemm600012.china.huawei.com (7.193.23.74) by kwepemi100019.china.huawei.com (7.221.188.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 18 Feb 2022 11:40:42 +0800 Received: from huawei.com (10.174.177.28) by kwepemm600012.china.huawei.com (7.193.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 18 Feb 2022 11:40:42 +0800 From: liuyuntao To: CC: , , , , , , Subject: Re: [PATCH] hugetlb: clean up potential spectre issue warnings Date: Fri, 18 Feb 2022 11:40:25 +0800 Message-ID: <20220218034025.17687-1-liuyuntao10@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220217234218.192885-1-mike.kravetz@oracle.com> References: <20220217234218.192885-1-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.177.28] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600012.china.huawei.com (7.193.23.74) X-CFilter-Loop: Reflected X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of liuyuntao10@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liuyuntao10@huawei.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C0EF040007 X-Stat-Signature: pzec5fks1azziy4wsza5fr18gz45y4sx X-HE-Tag: 1645155658-830131 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 17 Feb 2022 15:42:18 -0800, Mike Kravetz wrote: > Recently introduced code allows numa nodes to be specified on the > kernel command line for hugetlb allocations or CMA reservations. The > node values are user specified and used as indicies into arrays. This > generated the following smatch warnings: >=20 > mm/hugetlb.c:4170 hugepages_setup() warn: potential spectre issue 'defa= ult_hugepages_in_node' [w] > mm/hugetlb.c:4172 hugepages_setup() warn: potential spectre issue 'pars= ed_hstate->max_huge_pages_node' [w] > mm/hugetlb.c:6898 cmdline_parse_hugetlb_cma() warn: potential spectre i= ssue 'hugetlb_cma_size_in_node' [w] (local cap) >=20 > Clean up by using array_index_nospec to sanitize array indicies. >=20 > Signed-off-by: Mike Kravetz > --- > mm/hugetlb.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) >=20 > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 1f0cca036f7f..6b14d0791cb4 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -31,6 +31,7 @@ > #include > #include > #include > +#include > =20 > #include > #include > @@ -4161,7 +4162,7 @@ static int __init hugepages_setup(char *s) > } > if (tmp >=3D nr_online_nodes) > goto invalid; > - node =3D tmp; > + node =3D array_index_nospec(tmp, nr_online_nodes); > p +=3D count + 1; > /* Parse hugepages */ > if (sscanf(p, "%lu%n", &tmp, &count) !=3D 1) > @@ -6889,9 +6890,9 @@ static int __init cmdline_parse_hugetlb_cma(char = *p) > break; > =20 > if (s[count] =3D=3D ':') { > - nid =3D tmp; > - if (nid < 0 || nid >=3D MAX_NUMNODES) > + if (tmp < 0 || tmp >=3D MAX_NUMNODES) Here tmp is unsigned, no need to check if less than 0. Do we really have any automated checking? lol > break; > + nid =3D array_index_nospec(tmp, MAX_NUMNODES); > =20 > s +=3D count + 1; > tmp =3D memparse(s, &s); > --=20 > 2.34.1