From patchwork Thu Feb 17 23:42:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 12750723 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 5D77EC433EF for ; Thu, 17 Feb 2022 23:43:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46FE36B0074; Thu, 17 Feb 2022 18:43:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41FF76B0075; Thu, 17 Feb 2022 18:43:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2720A6B0078; Thu, 17 Feb 2022 18:43:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id 153316B0074 for ; Thu, 17 Feb 2022 18:43:46 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C41819991D for ; Thu, 17 Feb 2022 23:43:45 +0000 (UTC) X-FDA: 79153901610.28.13023E0 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 18EF840003 for ; Thu, 17 Feb 2022 23:43:44 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21HMOThE014562; Thu, 17 Feb 2022 23:42:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=ke7oQAnvwnloj5cvdoqA9mijRVbumF5HUlIzURe1lnA=; b=JOwWdkSth8M5mKm4t/SRxppdS12HBzqygq8g9dSOSvxdWSJxCE6n7lJFPifzum3oCVUQ UpDPlIw6OQsM4cbhxsNKAaif5Rq6gIPGt7sIJXHu1UQbnEouH0Lmck/nwQX7KfpOF0fA uP81MeCPokbEDhL4vnGixQMXW4+T+677d2gXay0IKq/9Tf//L7MUFhIsAeK1vy2jbvqx teFdzvvgBT2KR5CmIvNFwqW8f7dtxf6o7zg5SN43Ht5eRtXC0MyuM2lwEwTtpaR2vQgi iEsmyvdoDnTZEpeljyp9ZqlYWQUjLVJmkx/0p5RSWm8bFVosbssC68WoS74VDNr3S7q3 0w== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3e8nkdqs27-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 23:42:34 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21HNQpHs055941; Thu, 17 Feb 2022 23:42:33 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2174.outbound.protection.outlook.com [104.47.57.174]) by aserp3030.oracle.com with ESMTP id 3e9brd2yd8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Feb 2022 23:42:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OBbedggoZTka+q9FeBV2DZewQP34i/SBiF6Nq3r1jioWiiOkGzrdHDONn8fR9eZk6hPVUy5d1dmp1jYq5qVsvVxtaNtSrtCJGXJONleGPFYyvlIyoM43p6owitdcTxIpoXqioyVEzTgng7C78yhhqhh2/r0IFnk4Ep5krojr5Aub2McWTrZJ1lrtB9kDFVZwlf0efViX50hagVg/X4f3NtHmPYsCThHimCUC5mxclFNb2pH4MOMGCznEA0kTFFzYnhaojGdTnslxNhx0MjVA9yrZwJOSGOBfGgqtKF6C0VWxQRIr34C0Vd6Tqaky2xsb3Pob3gkkIUGQ43mPccHqCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ke7oQAnvwnloj5cvdoqA9mijRVbumF5HUlIzURe1lnA=; b=aYyH4UNXlpIzgVNDM+Ek1SDIBiN0im0FWZ8Muqzs8z2ZVyTuIgrhD3Ua1vYsA42Aop0vWD+rb5ujSLFqIhMeDDDuoi5frd4MUMb9EWEx01ScSrP03/YP5XFD/vmzQetGXpK0HUFQW3ehgrkSaU5g8PwqK25VL6ZkVDirzTFtHT0LEQ5olVYtoWiherYa1CMHTfJF+Gch+jyHfLkDnXTdjAd4iZu16WYDyDphmwSW2GQ5msg6PC/Wt6YW1TGlN4/OL2EqmBlM7/DOfh/bNP4Abf1ai8oUtbp0q5srx094y7ijm9w0QdyjCq9jejsIc0hKd738ZkYxcUfLrjgLF6gX8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ke7oQAnvwnloj5cvdoqA9mijRVbumF5HUlIzURe1lnA=; b=fNZU3D33/f+wRvV1+vNwV6VXGDkmioRW9dLj4vUzu4/1coXoVeFhQl0+GNDpKIPYVGli3OFvb4L/uWOBBTdcO3TAEqFStR3P3AqHqsgvc/YmvYt/sxfxiNuju9CugbAcPFRtTH0znyuwzUScYjhuXsNjDMfWCoi2BpyFnZpY1Go= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by CH2PR10MB4279.namprd10.prod.outlook.com (2603:10b6:610:a8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Thu, 17 Feb 2022 23:42:32 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::11f6:860e:575a:e6f1]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::11f6:860e:575a:e6f1%5]) with mapi id 15.20.4995.014; Thu, 17 Feb 2022 23:42:31 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Baolin Wang , Zhenguo Yao , Liu Yuntao , Dan Carpenter , Andrew Morton , Mike Kravetz Subject: [PATCH] hugetlb: clean up potential spectre issue warnings Date: Thu, 17 Feb 2022 15:42:18 -0800 Message-Id: <20220217234218.192885-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: MW4PR04CA0263.namprd04.prod.outlook.com (2603:10b6:303:88::28) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1cc1bbef-9c56-4fca-9510-08d9f26f2a19 X-MS-TrafficTypeDiagnostic: CH2PR10MB4279:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1443; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uTat0LoIidY3BKjvIRqK3Jdn2I85q5xtbECMhF22S/xXdLxSLmXkMSdxZOSUr14XGEeUwncgnmSiSioAInfChsF5lmdHusASr2LLx+Pa5fBH5UIC6iws63YgYXqEC0+huFklMbJHLwd/kf284hxYdA6clUnG8EZYAN6GVfakIwr7o/KyaOU3+KIQfoJG0i0fDb7S+paTzb6UKCcoMTZQr/thZFi8LzWbx3QntUB4FJdfSXqFgcHWc+Y4kc+NP2a0xHtuJUeU0jRpRC+tSCsjgVjypA9tlYdvMnCeMg4oauo9T17e2NuuhbspdOGUtbPCdtjoesnhC9cXwzppdqiiqZTUp/EYB7nUn2tlG/tOMgbxg+uRZKagp35B5iFDTO1pIwE+AxSk36OEu2D6VAYt2gVg5JskGGyuBgs76XP1fStV+lQo53p/OOosYKkAsYDA4VGkbBW6JyKxpQvtdx4nhkJatGQyv82xrfyEZ5CkEwN3m7TQ65h4OEBdfSVWsnWtiCaobgPifQWlTlHDagXFS/cRiXk4duHLbU5SRJgIH6WmiidH7mnTlSbyGt0z5n53/MesF1al1GyrcK32WbrEm/UKIGI8XvHGQwNss9BzLxPVZwT/vs5cp2B3lnKgJ4dCeHfydXT1jIE/bv0XMHJ6xEeV+IstPfMc9NC00L0Ejh508lAAfJx2zfmMJtQujSMXXQra4tvT7goJfkFG8SWrSg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(66476007)(2906002)(66946007)(38100700002)(83380400001)(8676002)(4326008)(66556008)(86362001)(6512007)(6506007)(52116002)(6666004)(38350700002)(5660300002)(6486002)(508600001)(8936002)(1076003)(2616005)(186003)(44832011)(26005)(107886003)(316002)(54906003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3HaqzvjVZ4bf0XnJWp9eBbNN0aNRrpXOkgt1gsBCG3rCaxMLkj8F5fvs4vDxejfdLUgBKSNPVC9gGB/j4D3FjENx7P7IsZYkdN5dSWpZH+sUWKo8R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2JajmMfkX7/QF+qLTo4Yk7CpIbXPOX2SMKDEDE3dOG1IOZZrsFaEyFoZ8rpO3HVrIZCYoXEOIxJnVqC9tTFeMTtA0WFBaSSsf3Vbs685CYzKGwyliSxpbkf7GZ62bHHgTg+cm9Z5hrLxq+tDYsimRlShxZm/siFE8607ni1+DUAPo1hjN739VCSrhvOpLZRiXnCGZWBXG166327u+ypnTvwi3v/00OzpkI6W3Ub9hXmE7YLrzect1kQBekwtBy7IWTC4I//njCVaPkVSYeyKun+rtchy0sY4y1eaYbvJ3C9JWoHypMD0CvvBLSArem9kENwrzsNwVkC4ei/2y3lBNWFv13dLcVLN2JZFLLEHY/Mx3V7L0aEP4hJ91/by57VbQQdPVvdgz2FHdsa2uzD0x5Nrb7lwZFtl2fOuXXtYFvjkhhr+h0CuJCcj+vmzsWLl7seR68+lBIY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1cc1bbef-9c56-4fca-9510-08d9f26f2a19 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Feb 2022 23:42:31.3121 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Mu+/Q0PfB70pdvW1XB6u5mgY0MntXJSZPQ3IHl7TrYQDPqspUi2YlD2BFUomiHRST5CWJ4ySyqnoV9JczSz1IA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4279 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10261 signatures=677564 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202170113 X-Proofpoint-ORIG-GUID: HcvNx5Gez_CMHpS1F2BxO8gO6AJQQZx6 X-Proofpoint-GUID: HcvNx5Gez_CMHpS1F2BxO8gO6AJQQZx6 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 18EF840003 X-Stat-Signature: 588k8gy77x7znyapboqdoxxdmxmfx86q Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=JOwWdkSt; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=fNZU3D33; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf01.hostedemail.com: domain of mike.kravetz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=mike.kravetz@oracle.com X-HE-Tag: 1645141424-464560 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: 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: mm/hugetlb.c:4170 hugepages_setup() warn: potential spectre issue 'default_hugepages_in_node' [w] mm/hugetlb.c:4172 hugepages_setup() warn: potential spectre issue 'parsed_hstate->max_huge_pages_node' [w] mm/hugetlb.c:6898 cmdline_parse_hugetlb_cma() warn: potential spectre issue 'hugetlb_cma_size_in_node' [w] (local cap) Clean up by using array_index_nospec to sanitize array indicies. Signed-off-by: Mike Kravetz --- mm/hugetlb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 #include #include @@ -4161,7 +4162,7 @@ static int __init hugepages_setup(char *s) } if (tmp >= nr_online_nodes) goto invalid; - node = tmp; + node = array_index_nospec(tmp, nr_online_nodes); p += count + 1; /* Parse hugepages */ if (sscanf(p, "%lu%n", &tmp, &count) != 1) @@ -6889,9 +6890,9 @@ static int __init cmdline_parse_hugetlb_cma(char *p) break; if (s[count] == ':') { - nid = tmp; - if (nid < 0 || nid >= MAX_NUMNODES) + if (tmp < 0 || tmp >= MAX_NUMNODES) break; + nid = array_index_nospec(tmp, MAX_NUMNODES); s += count + 1; tmp = memparse(s, &s);