hulk inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/I8YWPT CVE: NA
--------------------------------
Use page_belong_to_dynamic_hugetlb() helper to check whether a page is from dynamic hugetlb pool.
No functional change.
Signed-off-by: Liu Shixin liushixin2@huawei.com --- include/linux/hugetlb.h | 5 +++++ mm/hugetlb.c | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 868aea82db2d..869371c3da05 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -745,6 +745,7 @@ void move_pages_from_smpool_to_hpool(struct dhugetlb_pool *hpool, struct small_page_pool *smpool); void dhugetlb_reserve_hugepages(struct dhugetlb_pool *hpool, unsigned long count, bool gigantic); +bool page_belong_to_dynamic_hugetlb(struct page *page); #else #define enable_dhugetlb 0 #define dhugetlb_enabled 0 @@ -760,6 +761,10 @@ static inline struct dhugetlb_pool *get_dhugetlb_pool_from_dhugetlb_pagelist( return NULL; } static inline void dhugetlb_pool_put(struct dhugetlb_pool *hpool) { return; } +static inline bool page_belong_to_dynamic_hugetlb(struct page *page) +{ + return false; +} #endif /* CONFIG_DYNAMIC_HUGETLB */
static inline spinlock_t *huge_pte_lock(struct hstate *h, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 79d5d2cab271..04caf77c51d7 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1762,7 +1762,6 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed, int dissolve_free_huge_page(struct page *page) { int rc = -EBUSY; - struct dhugetlb_pool *hpool;
retry: /* Not to disrupt normal path by vainly holding hugetlb_lock */ @@ -1770,11 +1769,8 @@ int dissolve_free_huge_page(struct page *page) return 0;
/* Skip dissolve hugepage for dynamic hugetlb */ - hpool = get_dhugetlb_pool_from_dhugetlb_pagelist(page); - if (hpool) { - dhugetlb_pool_put(hpool); + if (page_belong_to_dynamic_hugetlb(page)) return -EBUSY; - }
spin_lock(&hugetlb_lock); if (!PageHuge(page)) { @@ -4210,6 +4206,16 @@ static int dhugetlb_acct_memory(struct hstate *h, long delta,
return ret; } + +bool page_belong_to_dynamic_hugetlb(struct page *page) +{ + struct dhugetlb_pool *hpool; + + hpool = get_dhugetlb_pool_from_dhugetlb_pagelist(page); + dhugetlb_pool_put(hpool); + + return !!hpool; +} #else static int dhugetlb_acct_memory(struct hstate *h, long delta, struct dhugetlb_pool *hpool)