From: Zhenguo Yao yaozhenguo1@gmail.com
mainline inclusion from mainline-v5.16-rc5 commit 4178158ef8cadeb0ee86639749ce2b33ad75f770 category: bugfix bugzilla: 186043 CVE: NA
--------------------------------
Preallocation of gigantic pages can't work bacause of commit b5389086ad7b ("hugetlbfs: extend the definition of hugepages parameter to support node allocation"). When nid is NUMA_NO_NODE(-1), alloc_bootmem_huge_page will always return without doing allocation. Fix this by adding more check.
Link: https://lkml.kernel.org/r/20211129133803.15653-1-yaozhenguo1@gmail.com Fixes: b5389086ad7b ("hugetlbfs: extend the definition of hugepages parameter to support node allocation") Signed-off-by: Zhenguo Yao yaozhenguo1@gmail.com Reviewed-by: Mike Kravetz mike.kravetz@oracle.com Tested-by: Maxim Levitsky mlevitsk@redhat.com Reviewed-by: Muchun Song songmuchun@bytedance.com Reviewed-by: Baolin Wang baolin.wang@linux.alibaba.com Signed-off-by: Andrew Morton akpm@linux-foundation.org Signed-off-by: Linus Torvalds torvalds@linux-foundation.org Signed-off-by: Liu Shixin liushixin2@huawei.com Reviewed-by: Kefeng Wangwangkefeng.wang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8286a6f8cb050..f7e41390f3d8b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2249,7 +2249,7 @@ int __alloc_bootmem_huge_page(struct hstate *h, int nid) struct huge_bootmem_page *m = NULL; /* initialize for clang */ int nr_nodes, node;
- if (nid >= nr_online_nodes) + if (nid != NUMA_NO_NODE && nid >= nr_online_nodes) return 0; /* do node specific alloc */ if (nid != NUMA_NO_NODE) {