From patchwork Fri Jul 10 00:57:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Song Bao Hua (Barry Song)" X-Patchwork-Id: 11655373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9372F14B7 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 62ED520774 for ; Fri, 10 Jul 2020 00:59:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62ED520774 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) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 55DC56B0005; Thu, 9 Jul 2020 20:59:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org 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-Original-To: linux-mm@kvack.org 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-Spam-Summary: 1,0,0,41f84f91162f8a89,d41d8cd98f00b204,song.bao.hua@hisilicon.com,,RULES_HIT:41:355:379:541:582:800:960:973:988:989:1152:1260:1261:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1541:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2731:3138:3139:3140:3141:3142:3352:3867:3868:3871:4250:4321:5007:6261:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:13069:13311:13357:13894:14093:14097:14181:14394:14721:21080:21451:21627:21990:30003:30054:30064:30070,0,RBL:45.249.212.35:@hisilicon.com:.lbl8.mailshell.net-64.100.201.201 62.2.2.100;04yfx5tyrwqgyb5njsz7k13xkz8ueypuqwsa9imutszttno6appzqffp1nehckt.4k3619nwbcw1s3hc8szfgbs1fwckm644etwc66fwr49ef8i7uroaketsnj5p4th.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none 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 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 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 Reviewed-by: Mike Kravetz --- 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]; static struct cma *hugetlb_cma[MAX_NUMNODES]; +static unsigned long hugetlb_cma_size __initdata; /* * Minimum page order among possible hugepage sizes, set to a proper value @@ -2571,7 +2572,7 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) for (i = 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 allocation\n"); break; } @@ -5654,7 +5655,6 @@ void move_hugetlb_state(struct page *oldpage, struct page *newpage, int reason) } #ifdef CONFIG_CMA -static unsigned long hugetlb_cma_size __initdata; static bool cma_reserve_called __initdata; static int __init cmdline_parse_hugetlb_cma(char *p)