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 X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7921BC433E0 for ; Fri, 10 Jul 2020 00:59:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F0642073A for ; Fri, 10 Jul 2020 00:59:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F0642073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hisilicon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5ADD56B0002; Thu, 9 Jul 2020 20:59:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55DC56B0005; Thu, 9 Jul 2020 20:59:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 425CB6B0006; Thu, 9 Jul 2020 20:59:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id 29C486B0002 for ; Thu, 9 Jul 2020 20:59:33 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C05C62C68 for ; Fri, 10 Jul 2020 00:59:32 +0000 (UTC) X-FDA: 77020358184.16.joke28_480fc2f26eca Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 7B949100E690B for ; Fri, 10 Jul 2020 00:59:32 +0000 (UTC) X-HE-Tag: joke28_480fc2f26eca X-Filterd-Recvd-Size: 3017 Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 10 Jul 2020 00:59:31 +0000 (UTC) Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 3B2835AE0537B2A909B2; Fri, 10 Jul 2020 08:59:28 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.201.26) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Fri, 10 Jul 2020 08:59:21 +0800 From: Barry Song To: CC: , , , Barry Song , Mike Kravetz , Jonathan Cameron , Roman Gushchin Subject: [PATCH v4] mm/hugetlb: avoid hardcoding while checking if cma is enabled Date: Fri, 10 Jul 2020 12:57:26 +1200 Message-ID: <20200710005726.36068-1-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.201.26] X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 7B949100E690B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: hugetlb_cma[0] can be NULL due to various reasons, for example, node0 has no memory. so NULL hugetlb_cma[0] doesn't necessarily mean cma is not enabled. gigantic pages might have been reserved on other nodes. This patch fixes possible double reservation and CMA leak. Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages= using cma") Cc: Mike Kravetz Cc: Jonathan Cameron Acked-by: Roman Gushchin Signed-off-by: Barry Song --- v4: address linux-next issue; use hugetlb_cma_size to check if cma is enabled mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 57ece74e3aae..bc3304af40d0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -46,6 +46,7 @@ unsigned int default_hstate_idx; struct hstate hstates[HUGE_MAX_HSTATE]; =20 static struct cma *hugetlb_cma[MAX_NUMNODES]; +static unsigned long hugetlb_cma_size __initdata; =20 /* * Minimum page order among possible hugepage sizes, set to a proper val= ue @@ -2571,7 +2572,7 @@ static void __init hugetlb_hstate_alloc_pages(struc= t hstate *h) =20 for (i =3D 0; i < h->max_huge_pages; ++i) { if (hstate_is_gigantic(h)) { - if (IS_ENABLED(CONFIG_CMA) && hugetlb_cma[0]) { + if (hugetlb_cma_size) { pr_warn_once("HugeTLB: hugetlb_cma is enabled, skip boot time alloca= tion\n"); break; } @@ -5654,7 +5655,6 @@ void move_hugetlb_state(struct page *oldpage, struc= t page *newpage, int reason) } =20 #ifdef CONFIG_CMA -static unsigned long hugetlb_cma_size __initdata; static bool cma_reserve_called __initdata; =20 static int __init cmdline_parse_hugetlb_cma(char *p) --=20 2.27.0