mm/migration: return errno when isolate_huge_page failed
authorMiaohe Lin <linmiaohe@huawei.com>
Mon, 30 May 2022 11:30:15 +0000 (19:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Feb 2023 18:17:56 +0000 (19:17 +0100)
[ Upstream commit 7ce82f4c3f3ead13a9d9498768e3b1a79975c4d8 ]

We might fail to isolate huge page due to e.g.  the page is under
migration which cleared HPageMigratable.  We should return errno in this
case rather than always return 1 which could confuse the user, i.e.  the
caller might think all of the memory is migrated while the hugetlb page is
left behind.  We make the prototype of isolate_huge_page consistent with
isolate_lru_page as suggested by Huang Ying and rename isolate_huge_page
to isolate_hugetlb as suggested by Muchun to improve the readability.

Link: https://lkml.kernel.org/r/20220530113016.16663-4-linmiaohe@huawei.com
Fixes: e8db67eb0ded ("mm: migrate: move_pages() supports thp migration")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Suggested-by: Huang Ying <ying.huang@intel.com>
Reported-by: kernel test robot <lkp@intel.com> (build error)
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Xu <peterx@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 73bdf65ea748 ("migrate: hugetlb: check for hugetlb shared PMD in node migration")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/hugetlb.h
mm/gup.c
mm/hugetlb.c
mm/memory-failure.c
mm/memory_hotplug.c
mm/mempolicy.c
mm/migrate.c

index cac25ad9d643f3bcc78db4e9dd4c963c6e16af10..f98d747f983b949a7a5f182c74f4274d685bdf85 100644 (file)
@@ -166,7 +166,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
                                                vm_flags_t vm_flags);
 long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
                                                long freed);
-bool isolate_huge_page(struct page *page, struct list_head *list);
+int isolate_hugetlb(struct page *page, struct list_head *list);
 int get_hwpoison_huge_page(struct page *page, bool *hugetlb);
 int get_huge_page_for_hwpoison(unsigned long pfn, int flags);
 void putback_active_hugepage(struct page *page);
@@ -354,9 +354,9 @@ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
        return NULL;
 }
 
-static inline bool isolate_huge_page(struct page *page, struct list_head *list)
+static inline int isolate_hugetlb(struct page *page, struct list_head *list)
 {
-       return false;
+       return -EBUSY;
 }
 
 static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb)
index 2370565a81dc30bcfba067db26e6e8b4727731f9..0a1839b325747b72aa78f223da1c7d2571a3fb45 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1877,7 +1877,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
                 */
                if (!is_pinnable_page(head)) {
                        if (PageHuge(head)) {
-                               if (!isolate_huge_page(head, &movable_page_list))
+                               if (isolate_hugetlb(head, &movable_page_list))
                                        isolation_error_count++;
                        } else {
                                if (!PageLRU(head) && drain_allow) {
index 8599f16d4aa4fd167e98146dbec414da5e27e092..2f5c1b2456ef2b6e18811c7bfad869f4889b8ba0 100644 (file)
@@ -2656,8 +2656,7 @@ retry:
                 * Fail with -EBUSY if not possible.
                 */
                spin_unlock_irq(&hugetlb_lock);
-               if (!isolate_huge_page(old_page, list))
-                       ret = -EBUSY;
+               ret = isolate_hugetlb(old_page, list);
                spin_lock_irq(&hugetlb_lock);
                goto free_new;
        } else if (!HPageFreed(old_page)) {
@@ -2733,7 +2732,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list)
        if (hstate_is_gigantic(h))
                return -ENOMEM;
 
-       if (page_count(head) && isolate_huge_page(head, list))
+       if (page_count(head) && !isolate_hugetlb(head, list))
                ret = 0;
        else if (!page_count(head))
                ret = alloc_and_dissolve_huge_page(h, head, list);
@@ -6277,15 +6276,15 @@ follow_huge_pgd(struct mm_struct *mm, unsigned long address, pgd_t *pgd, int fla
        return pte_page(*(pte_t *)pgd) + ((address & ~PGDIR_MASK) >> PAGE_SHIFT);
 }
 
-bool isolate_huge_page(struct page *page, struct list_head *list)
+int isolate_hugetlb(struct page *page, struct list_head *list)
 {
-       bool ret = true;
+       int ret = 0;
 
        spin_lock_irq(&hugetlb_lock);
        if (!PageHeadHuge(page) ||
            !HPageMigratable(page) ||
            !get_page_unless_zero(page)) {
-               ret = false;
+               ret = -EBUSY;
                goto unlock;
        }
        ClearHPageMigratable(page);
index 2ad0f45800916d48574c3e3d06b40779442827ea..9f9dd968fbe3cc765878ecbb5dcea9273844867a 100644 (file)
@@ -2106,7 +2106,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)
        bool lru = PageLRU(page);
 
        if (PageHuge(page)) {
-               isolated = isolate_huge_page(page, pagelist);
+               isolated = !isolate_hugetlb(page, pagelist);
        } else {
                if (lru)
                        isolated = !isolate_lru_page(page);
index 9fd0be32a281e238cb17061690435777f40fe3d9..81f2a97c886c9e5fb8323b62d9c6046a391fbe92 100644 (file)
@@ -1704,7 +1704,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
 
                if (PageHuge(page)) {
                        pfn = page_to_pfn(head) + compound_nr(head) - 1;
-                       isolate_huge_page(head, &source);
+                       isolate_hugetlb(head, &source);
                        continue;
                } else if (PageTransHuge(page))
                        pfn = page_to_pfn(head) + thp_nr_pages(page) - 1;
index 4472be6f123dbb3261466383779fe05eeb9e80e4..8687781b41c964e2e636a1ce830376e28338b6f1 100644 (file)
@@ -604,7 +604,7 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask,
        /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */
        if (flags & (MPOL_MF_MOVE_ALL) ||
            (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) {
-               if (!isolate_huge_page(page, qp->pagelist) &&
+               if (isolate_hugetlb(page, qp->pagelist) &&
                        (flags & MPOL_MF_STRICT))
                        /*
                         * Failed to isolate page but allow migrating pages
index 7da052c6cf1eafc072364886d79c0df48483fb80..dd50b1cc089e08e752c94a8d496dd09dda070722 100644 (file)
@@ -134,7 +134,7 @@ static void putback_movable_page(struct page *page)
  *
  * This function shall be used whenever the isolated pageset has been
  * built from lru, balloon, hugetlbfs page. See isolate_migratepages_range()
- * and isolate_huge_page().
+ * and isolate_hugetlb().
  */
 void putback_movable_pages(struct list_head *l)
 {
@@ -1722,8 +1722,9 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 
        if (PageHuge(page)) {
                if (PageHead(page)) {
-                       isolate_huge_page(page, pagelist);
-                       err = 1;
+                       err = isolate_hugetlb(page, pagelist);
+                       if (!err)
+                               err = 1;
                }
        } else {
                struct page *head;