From: Liu Shixin liushixin2@huawei.com
hulk inclusion category: feature bugzilla: 46904, https://gitee.com/openeuler/kernel/issues/I6BDME CVE: NA
--------------------------------
If hugepage_init() is called before hugetlb_init(), dhugetlb_enabled has not been initialized, we should use enable_dhugetlb instead.
Signed-off-by: Liu Shixin liushixin2@huawei.com Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com Signed-off-by: Yongqiang Liu liuyongqiang13@huawei.com --- include/linux/hugetlb.h | 4 +++- mm/huge_memory.c | 4 ++-- mm/hugetlb.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index a26cbc4398a4..d44eea25c0d6 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -668,6 +668,7 @@ static inline void set_huge_swap_pte_at(struct mm_struct *mm, unsigned long addr /* We don't need to try 5 times, or we can't migrate the pages. */ #define HPOOL_RECLAIM_RETRIES 5
+extern bool enable_dhugetlb; extern struct static_key_false dhugetlb_enabled_key; #define dhugetlb_enabled (static_branch_unlikely(&dhugetlb_enabled_key))
@@ -744,7 +745,8 @@ void move_pages_from_smpool_to_hpool(struct dhugetlb_pool *hpool, void dhugetlb_reserve_hugepages(struct dhugetlb_pool *hpool, unsigned long count, bool gigantic); #else -#define dhugetlb_enabled 0 +#define enable_dhugetlb 0 +#define dhugetlb_enabled 0 struct dhugetlb_pool {}; static inline struct dhugetlb_pool *get_dhugetlb_pool_from_task( struct task_struct *tsk) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 484ffdbf5f45..8b7086cfd1ed 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -404,9 +404,9 @@ static int __init hugepage_init(void) * use transparent hugepage in addition. * (May result negative optimization) */ - if (dhugetlb_enabled) { + if (enable_dhugetlb) { transparent_hugepage_flags = 0; - pr_info("transparent hugepage is disabled due to confilct with dynamic hugetlb\n"); + pr_info("transparent hugepage is disabled due to conflict with dynamic hugetlb\n"); return -EINVAL; }
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 625882b7cd97..c61c3d65eafc 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3299,7 +3299,7 @@ static void hugetlb_register_all_nodes(void) { } #endif
#ifdef CONFIG_DYNAMIC_HUGETLB -static bool enable_dhugetlb; +bool enable_dhugetlb; DEFINE_STATIC_KEY_FALSE(dhugetlb_enabled_key); DEFINE_RWLOCK(dhugetlb_pagelist_rwlock); struct dhugetlb_pagelist *dhugetlb_pagelist_t;