From nobody Fri Jun 19 15:47:30 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15FD5C433F5 for ; Fri, 1 Apr 2022 09:54:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344820AbiDAJ4E (ORCPT ); Fri, 1 Apr 2022 05:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244173AbiDAJz4 (ORCPT ); Fri, 1 Apr 2022 05:55:56 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44DA4146B57; Fri, 1 Apr 2022 02:54:02 -0700 (PDT) Received: from kwepemi500014.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KVFnw6vckzgY8Z; Fri, 1 Apr 2022 17:52:20 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi500014.china.huawei.com (7.221.188.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 17:54:00 +0800 Received: from localhost.localdomain (10.175.112.125) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 17:54:00 +0800 From: Peng Liu To: , , , , , CC: Subject: [PATCH v2 1/2] hugetlb: Fix hugepages_setup when deal with pernode Date: Fri, 1 Apr 2022 10:12:31 +0000 Message-ID: <20220401101232.2790280-2-liupeng256@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220401101232.2790280-1-liupeng256@huawei.com> References: <20220401101232.2790280-1-liupeng256@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hugepages can be specified to pernode since "hugetlbfs: extend the definition of hugepages parameter to support node allocation", but the following problem is observed. Confusing behavior is observed when both 1G and 2M hugepage is set after "numa=3Doff". cmdline hugepage settings: hugepagesz=3D1G hugepages=3D0:3,1:3 hugepagesz=3D2M hugepages=3D0:1024,1:1024 results: HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages HugeTLB registered 2.00 MiB page size, pre-allocated 1024 pages Furthermore, confusing behavior can be also observed when invalid node behind valid node. To fix this, hugetlb_hstate_alloc_pages should be called even when hugepages_setup going to invalid. Cc: Fixes: b5389086ad7b ("hugetlbfs: extend the definition of hugepages paramet= er to support node allocation") Signed-off-by: Peng Liu --- mm/hugetlb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b34f50156f7e..9cd746432ca9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4131,6 +4131,7 @@ static int __init hugepages_setup(char *s) int count; unsigned long tmp; char *p =3D s; + int ret =3D 1; =20 if (!parsed_valid_hugepagesz) { pr_warn("HugeTLB: hugepages=3D%s does not follow a valid hugepagesz, ign= oring\n", s); @@ -4189,6 +4190,7 @@ static int __init hugepages_setup(char *s) } } =20 +out: /* * Global state is always initialized later in hugetlb_init. * But we need to allocate gigantic hstates here early to still @@ -4199,11 +4201,12 @@ static int __init hugepages_setup(char *s) =20 last_mhp =3D mhp; =20 - return 1; + return ret; =20 invalid: pr_warn("HugeTLB: Invalid hugepages parameter %s\n", p); - return 0; + ret =3D 0; + goto out; } __setup("hugepages=3D", hugepages_setup); =20 --=20 2.18.0.huawei.25 From nobody Fri Jun 19 15:47:30 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34227C433F5 for ; Fri, 1 Apr 2022 09:54:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344799AbiDAJz5 (ORCPT ); Fri, 1 Apr 2022 05:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344787AbiDAJz4 (ORCPT ); Fri, 1 Apr 2022 05:55:56 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33EFF105AAE; Fri, 1 Apr 2022 02:54:03 -0700 (PDT) Received: from kwepemi500017.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KVFqT2nVqzdZLt; Fri, 1 Apr 2022 17:53:41 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi500017.china.huawei.com (7.221.188.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 17:54:01 +0800 Received: from localhost.localdomain (10.175.112.125) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 1 Apr 2022 17:54:00 +0800 From: Peng Liu To: , , , , , CC: Subject: [PATCH v2 2/2] hugetlb: Fix return value of __setup handlers Date: Fri, 1 Apr 2022 10:12:32 +0000 Message-ID: <20220401101232.2790280-3-liupeng256@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220401101232.2790280-1-liupeng256@huawei.com> References: <20220401101232.2790280-1-liupeng256@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When __setup() return '0', using invalid option values causes the entire kernel boot option string to be reported as Unknown. Hugetlb calls __setup() and will return '0' when set invalid parameter string. The following phenomenon is observed: cmdline: hugepagesz=3D1Y hugepages=3D1 dmesg: HugeTLB: unsupported hugepagesz=3D1Y HugeTLB: hugepages=3D1 does not follow a valid hugepagesz, ignoring Unknown kernel command line parameters "hugepagesz=3D1Y hugepages=3D1" Since hugetlb will print warn or error information before return for invalid parameter string, just use return '1' to avoid print again. Signed-off-by: Peng Liu --- mm/hugetlb.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9cd746432ca9..6dde34c115c9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4131,12 +4131,11 @@ static int __init hugepages_setup(char *s) int count; unsigned long tmp; char *p =3D s; - int ret =3D 1; =20 if (!parsed_valid_hugepagesz) { pr_warn("HugeTLB: hugepages=3D%s does not follow a valid hugepagesz, ign= oring\n", s); parsed_valid_hugepagesz =3D true; - return 0; + return 1; } =20 /* @@ -4152,7 +4151,7 @@ static int __init hugepages_setup(char *s) =20 if (mhp =3D=3D last_mhp) { pr_warn("HugeTLB: hugepages=3D specified twice without interleaving huge= pagesz=3D, ignoring hugepages=3D%s\n", s); - return 0; + return 1; } =20 while (*p) { @@ -4163,7 +4162,7 @@ static int __init hugepages_setup(char *s) if (p[count] =3D=3D ':') { if (!hugetlb_node_alloc_supported()) { pr_warn("HugeTLB: architecture can't support node specific alloc, igno= ring!\n"); - return 0; + return 1; } if (tmp >=3D nr_online_nodes) goto invalid; @@ -4201,11 +4200,10 @@ static int __init hugepages_setup(char *s) =20 last_mhp =3D mhp; =20 - return ret; + return 1; =20 invalid: pr_warn("HugeTLB: Invalid hugepages parameter %s\n", p); - ret =3D 0; goto out; } __setup("hugepages=3D", hugepages_setup); @@ -4227,7 +4225,7 @@ static int __init hugepagesz_setup(char *s) =20 if (!arch_hugetlb_valid_size(size)) { pr_err("HugeTLB: unsupported hugepagesz=3D%s\n", s); - return 0; + return 1; } =20 h =3D size_to_hstate(size); @@ -4242,7 +4240,7 @@ static int __init hugepagesz_setup(char *s) if (!parsed_default_hugepagesz || h !=3D &default_hstate || default_hstate.max_huge_pages) { pr_warn("HugeTLB: hugepagesz=3D%s specified twice, ignoring\n", s); - return 0; + return 1; } =20 /* @@ -4273,14 +4271,14 @@ static int __init default_hugepagesz_setup(char *s) parsed_valid_hugepagesz =3D false; if (parsed_default_hugepagesz) { pr_err("HugeTLB: default_hugepagesz previously specified, ignoring %s\n"= , s); - return 0; + return 1; } =20 size =3D (unsigned long)memparse(s, NULL); =20 if (!arch_hugetlb_valid_size(size)) { pr_err("HugeTLB: unsupported default_hugepagesz=3D%s\n", s); - return 0; + return 1; } =20 hugetlb_add_hstate(ilog2(size) - PAGE_SHIFT); --=20 2.18.0.huawei.25