Skip to contentSkip to conversation

mm: migration: fix the FOLL_GET failure on following huge page

PATCH In review Haiyue Wang 11 participants 62 messages Aug 12, 2022 – Aug 26, 2022

Subsystems (7)
Memory management s390 HugeTLB THP +3 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: migration: fix the FOLL_GET failure on following huge page

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
Signature · 1 line
2.37.1
maintainer
#1 lore raw
Quoted 2 lines · On Fri, 12 Aug 2022 16:49:21 +0800 Haiyue Wang <[email protected]> wrote:

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

Which ones need fixing?

What are the user-visible runtime effects of this bug?

Is a -stable backport warranted?

Quoted 5 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

#2 lore raw
Quoted 8 lines

-----Original Message-----
From: Andrew Morton <[email protected]>
Sent: Sunday, August 14, 2022 07:29
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v1] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 6 lines
Quoted 2 lines · On Fri, 12 Aug 2022 16:49:21 +0800 Haiyue Wang <[email protected]> wrote:

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

Which ones need fixing?

1. 'follow_huge_pud' arch/s390/mm/hugetlbpage.c

2. 'follow_huge_addr' arch/ia64/mm/hugetlbpage.c

3. 'follow_huge_pgd' mm/hugetlb.c

And I found that only 'pud' and 'pmd' need to check 'is_vm_hugetlb_page' like:
pud_huge(*pud) && is_vm_hugetlb_page(vma)
pmd_huge(pmdval) && is_vm_hugetlb_page(vma)

So I'm not sure whether my patch can cover 2 & 3 for other huge page use cases except by hugetlbfs.

Quoted 3 lines

What are the user-visible runtime effects of this bug?

In my test, the '__NR_move_pages' system call will return '-2' for 1GB huge page memory map when dump the page node information. [Test on linux-5.19 stable]

Quoted 1 line

Is a -stable backport warranted?

Yes.

Since the mainline has introduced the new patch:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3218f8712d6bb

The backported needs to rebase like for 5.19:

- if (page && !is_zone_device_page(page)) {
+ if (page) {

Quoted 6 lines
Quoted 6 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

#3 lore raw
Quoted 23 lines

-----Original Message-----
From: Wang, Haiyue
Sent: Sunday, August 14, 2022 14:20
To: Andrew Morton <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH v1] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 13 lines

-----Original Message-----
From: Andrew Morton <[email protected]>
Sent: Sunday, August 14, 2022 07:29
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v1] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 2 lines · On Fri, 12 Aug 2022 16:49:21 +0800 Haiyue Wang <[email protected]> wrote:

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

Quoted 8 lines
Quoted 1 line

Is a -stable backport warranted?

Yes.

Since the mainline has introduced the new patch:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3218f8712d6bb

Looks like 'is_zone_device_page' will cause 'FOLL_GET' page reference count issue, which should call 'put_page' before call branch jump.

try_grab_page -->

		if (flags & FOLL_GET)
			folio_ref_inc(folio);

Or I misunderstood the 'is_zone_device_page' ? ;-)

Quoted 7 lines

The backported needs to rebase like for 5.19:

(quoted diff) +1 -1
-		if (page && !is_zone_device_page(page)) {
+		if (page) {
Quoted 3 lines
Quoted 3 lines
#4 lore raw

v2 cover fix follow_page related issues

In reply to Haiyue Wang

v2: Add the Non-LRU pages fix with two patches, so that
'mm: migration: fix the FOLL_GET' can be applied directly on linux-5.19 stable branch.

Haiyue Wang (3):
mm: revert handling Non-LRU pages returned by follow_page
mm: migration: fix the FOLL_GET failure on following huge page
mm: handling Non-LRU pages returned by follow_page

 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 16 +++++++++++++---
 mm/migrate.c     | 20 +++++++++++++++-----
 3 files changed, 30 insertions(+), 10 deletions(-)
Signature · 1 line
2.37.2
#5 lore raw

PATCH v2 1/3 mm: revert handling Non-LRU pages returned by follow_page

The commit
3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages") doesn't handle the follow_page with flag FOLL_GET correctly, this will do get_page on page, it shouldn't just return directly without put_page.

So revert the related fix to prepare for clean patch to handle Non-LRU pages returned by follow_page.

---
 mm/huge_memory.c | 2 +-
 mm/ksm.c         | 6 +++---
 mm/migrate.c     | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
mm/huge_memory.c +1 -1
index 8a7c1b344abe..2ee6d38a1426 100644
@@ -2963,7 +2963,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
 		if (!is_transparent_hugepage(page))
mm/ksm.c +3 -3
index 42ab153335a2..fe3e0a39f73a 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,7 +560,7 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
@@ -2308,7 +2308,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
mm/migrate.c +2 -2
index 6a1597c92261..3d5f0262ab60 100644
@@ -1672,7 +1672,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
 	err = 0;
@@ -1863,7 +1863,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
+		if (page) {
 			err = page_to_nid(page);
 			put_page(page);
 		} else {
Signature · 1 line
2.37.2
#6 lore raw

Re: [PATCH v2 1/3] mm: revert handling Non-LRU pages returned by follow_page

Quoted 7 lines · Haiyue Wang

The commit
3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages") doesn't handle the follow_page with flag FOLL_GET correctly, this will do get_page on page, it shouldn't just return directly without put_page.

So revert the related fix to prepare for clean patch to handle Non-LRU pages returned by follow_page.

What? Why?

Just fix it.

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

RE: [PATCH v2 1/3] mm: revert handling Non-LRU pages returned by follow_page

Quoted 14 lines

-----Original Message-----
From: David Hildenbrand <[email protected]>
Sent: Monday, August 15, 2022 00:31
To: Wang, Haiyue <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 1/3] mm: revert handling Non-LRU pages returned by follow_page

Quoted 5 lines · Haiyue Wang

The commit
3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages") doesn't handle the follow_page with flag FOLL_GET correctly, this will do get_page on page, it shouldn't just return directly without put_page.

Quoted 5 lines
Quoted 2 lines

So revert the related fix to prepare for clean patch to handle Non-LRU pages returned by follow_page.

What? Why?

Just as the cover letter said, for applying the PATCH 2/3 can be applied on Linux-5.19 branch directly. I will drop this kind of fix, and fix the issue directly in v3.

Quoted 6 lines

Just fix it.

--
Thanks,

David / dhildenb

#8 lore raw

PATCH v2 2/3 mm: migration: fix the FOLL_GET failure on following huge page

In reply to Haiyue Wang

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 3d5f0262ab60..5d304de3950b 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
Signature · 1 line
2.37.2
#9 lore raw

PATCH v2 3/3 mm: handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang

Add the missed put_page handling for handling Non-LRU pages returned by follow_page with FOLL_GET flag set.

This is the second patch for fixing the commit
3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

---
 mm/huge_memory.c |  2 +-
 mm/ksm.c         | 10 ++++++++++
 mm/migrate.c     |  6 +++++-
 3 files changed, 16 insertions(+), 2 deletions(-)
mm/huge_memory.c +1 -1
index 2ee6d38a1426..b2ba17c3dcd7 100644
@@ -2966,7 +2966,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +10 -0
index fe3e0a39f73a..1360bb52ada6 100644
@@ -477,6 +477,10 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
 		if (IS_ERR_OR_NULL(page))
 			break;
+		if (is_zone_device_page(page)) {
+			put_page(page);
+			break;
+		}
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
 					      FAULT_FLAG_WRITE | FAULT_FLAG_REMOTE,
@@ -562,10 +566,13 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 	page = follow_page(vma, addr, FOLL_GET);
 	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2313,6 +2320,8 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2336,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +5 -1
index 5d304de3950b..fee12cd2f294 100644
@@ -1675,6 +1675,9 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1869,7 +1872,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 			goto set_status;
 
 		if (page) {
-			err = page_to_nid(page);
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
Signature · 1 line
2.37.2
#10 lore raw

Re: [PATCH v2 3/3] mm: handling Non-LRU pages returned by follow_page

Quoted 31 lines · Haiyue Wang

Add the missed put_page handling for handling Non-LRU pages returned by follow_page with FOLL_GET flag set.

This is the second patch for fixing the commit
3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

---
 mm/huge_memory.c |  2 +-
 mm/ksm.c         | 10 ++++++++++
 mm/migrate.c     |  6 +++++-
 3 files changed, 16 insertions(+), 2 deletions(-)
mm/huge_memory.c +1 -1
index 2ee6d38a1426..b2ba17c3dcd7 100644
@@ -2966,7 +2966,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +0 -0
index fe3e0a39f73a..1360bb52ada6 100644

mm/ksm.c static int break_ksm(struct vm_area_struct *vma, unsigned long addr) · line 483

Quoted 7 lines
mm/ksm.c +4 -0
@@ -477,6 +477,10 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
 		if (IS_ERR_OR_NULL(page))
 			break;
+		if (is_zone_device_page(page)) {
+			put_page(page);
+			break;
+		}

I think we can drop this check completely. While working on patches that touch this code I realized that this check is completely useless. device pages are never PageKsm pages and there is no need to special-case here.

If a zone device page could be PageKsm, then we wouldn't handle it here correctly and not break ksm.

So just drop it.

Signature · 3 lines
Thanks,

David / dhildenb
#11 lore raw

RE: [PATCH v2 3/3] mm: handling Non-LRU pages returned by follow_page

Quoted 39 lines

-----Original Message-----
From: David Hildenbrand <[email protected]>
Sent: Monday, August 15, 2022 00:34
To: Wang, Haiyue <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 3/3] mm: handling Non-LRU pages returned by follow_page

Quoted 18 lines · Haiyue Wang

Add the missed put_page handling for handling Non-LRU pages returned by follow_page with FOLL_GET flag set.

This is the second patch for fixing the commit
3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

---
 mm/huge_memory.c |  2 +-
 mm/ksm.c         | 10 ++++++++++
 mm/migrate.c     |  6 +++++-
 3 files changed, 16 insertions(+), 2 deletions(-)
mm/ksm.c +0 -0
index fe3e0a39f73a..1360bb52ada6 100644

mm/ksm.c static int break_ksm(struct vm_area_struct *vma, unsigned long addr) · line 483

Quoted 7 lines
mm/ksm.c +4 -0
@@ -477,6 +477,10 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
 		if (IS_ERR_OR_NULL(page))
 			break;
+		if (is_zone_device_page(page)) {
+			put_page(page);
+			break;
+		}

I think we can drop this check completely. While working on patches that touch this code I realized that this check is completely useless. device pages are never PageKsm pages and there is no need to special-case here.

Quoted 5 lines

If a zone device page could be PageKsm, then we wouldn't handle it here correctly and not break ksm.

So just drop it.

Fixed in v3.

Quoted 6 lines

--
Thanks,

David / dhildenb

#12 lore raw

v3 cover fix follow_page related issues

In reply to Haiyue Wang

v3: Merge the fix for handling Non-LRU pages into one patch.
Drop the break_ksm zone device page check.

v2: Add the Non-LRU pages fix with two patches, so that
'mm: migration: fix the FOLL_GET' can be applied directly on linux-5.19 stable branch.

Haiyue Wang (2):
mm: migration: fix the FOLL_GET failure on following huge page
mm: fix the handling Non-LRU pages returned by follow_page

 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 20 +++++++++++++++-----
 3 files changed, 26 insertions(+), 10 deletions(-)
Signature · 1 line
2.37.2
#13 lore raw

PATCH v3 1/2 mm: migration: fix the FOLL_GET failure on following huge page

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
Signature · 1 line
2.37.2
#14 lore raw
Quoted 1 line · Haiyue Wang

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages

move_pages() is a syscall, so you can just call it move_pages(), or move_pages() syscall.

Quoted 1 line

will fail to get the page node information for huge page.

                                                 ~~~~~~~~~

some huge pages?

Quoted 1 line

This is an temporary solution to mitigate the racing fix.

Why is it "racing fix"? This isn't a race condition fix.

Best Regards,
Huang, Ying

Quoted 5 lines

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")

[snip]

#15 lore raw
Quoted 8 lines

-----Original Message-----
From: Huang, Ying <[email protected]>
Sent: Monday, August 15, 2022 09:59
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 6 lines
Quoted 1 line · Haiyue Wang

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages

move_pages() is a syscall, so you can just call it move_pages(), or move_pages() syscall.

The application meets the issue, use the bellow function:
syscall (__NR_move_pages, 0, n_pages, ptr, 0, status, 0)

So I used it directly in the commit. "move_pages() syscall" is better. Will update latter.

Quoted 4 lines
Quoted 2 lines

will fail to get the page node information for huge page.

                                                 ~~~~~~~~~

some huge pages?

OK.

Quoted 4 lines
Quoted 2 lines

This is an temporary solution to mitigate the racing fix.

Why is it "racing fix"? This isn't a race condition fix.

The 'Fixes' commit is about race condition fix.

How about " his is an temporary solution to mitigate the side effect Of the race condition fix"

Quoted 11 lines

Best Regards,
Huang, Ying

Quoted 5 lines

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")

[snip]

#16 lore raw
Quoted 21 lines

-----Original Message-----
From: Wang, Haiyue
Sent: Monday, August 15, 2022 10:11
To: Huang, Ying <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v3 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 13 lines

-----Original Message-----
From: Huang, Ying <[email protected]>
Sent: Monday, August 15, 2022 09:59
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Haiyue Wang <[email protected]> writes:

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

This is an temporary solution to mitigate the racing fix.

Why is it "racing fix"? This isn't a race condition fix.

The 'Fixes' commit is about race condition fix.

How about " his is an temporary solution to mitigate the side effect Of the race condition fix"

Try to add more words to make things clean:

"This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set."

Quoted 12 lines
Quoted 12 lines

Best Regards,
Huang, Ying

Quoted 5 lines

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")

[snip]

#17 lore raw
Quoted 27 lines · Haiyue
Quoted 27 lines

-----Original Message-----
From: Wang, Haiyue
Sent: Monday, August 15, 2022 10:11
To: Huang, Ying <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v3 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 8 lines

-----Original Message-----
From: Huang, Ying <[email protected]>
Sent: Monday, August 15, 2022 09:59
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 8 lines
Quoted 1 line · Haiyue Wang

This is an temporary solution to mitigate the racing fix.

Why is it "racing fix"? This isn't a race condition fix.

The 'Fixes' commit is about race condition fix.

Quoted 7 lines
Quoted 2 lines

How about " his is an temporary solution to mitigate the side effect Of the race condition fix"

Try to add more words to make things clean:

"This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set."

Looks good to me. Thanks!

Best Regards,
Huang, Ying

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Best Regards,
Huang, Ying

Quoted 5 lines

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")

[snip]

#18 lore raw

PATCH v3 2/2 mm: fix the handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang

The page returned by follow_page with 'FOLL_GET' has get_page called, so it needs to call put_page for handling the reference count correctly.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm.

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +7 -3
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
Signature · 1 line
2.37.2
#19 lore raw

Re: [PATCH v3 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 1 line · Haiyue Wang

The page returned by follow_page with 'FOLL_GET' has get_page called, so

Better to add "()" after function name to improve the readability, for example, "follow_page()".

Quoted 6 lines

it needs to call put_page for handling the reference count correctly.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm.

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

In your patch description, I cannot find how the above commit is related to the bug you fixed. Add some words about that?

Best Regards,
Huang, Ying

Quoted 107 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +7 -3
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
#20 lore raw

RE: [PATCH v3 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 9 lines

-----Original Message-----
From: Huang, Ying <[email protected]>
Sent: Monday, August 15, 2022 09:40
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Felix Kuehling <[email protected]>; Alistair Popple <[email protected]>
Subject: Re: [PATCH v3 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 6 lines
Quoted 1 line · Haiyue Wang

The page returned by follow_page with 'FOLL_GET' has get_page called, so

Better to add "()" after function name to improve the readability, for example, "follow_page()".

Got it, didn't notice this. ;-)

Quoted 10 lines
Quoted 7 lines

it needs to call put_page for handling the reference count correctly.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm.

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

In your patch description, I cannot find how the above commit is related to the bug you fixed. Add some words about that?

The first commit session, but maybe not very clear, will try to add more words In v4.

Quoted 11 lines

Best Regards,
Huang, Ying

Quoted 7 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
#21 lore raw

v4 cover fix follow_page related issues

In reply to Haiyue Wang

v4: add '()' for the function for readability.
add more words about the Non-LRU pages fix in commit message.

v3: Merge the fix for handling Non-LRU pages into one patch.
Drop the break_ksm zone device page check.

v2: Add the Non-LRU pages fix with two patches, so that
'mm: migration: fix the FOLL_GET' can be applied directly on linux-5.19 stable branch.

Haiyue Wang (2):
mm: migration: fix the FOLL_GET failure on following huge page
mm: fix the handling Non-LRU pages returned by follow_page

 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 20 +++++++++++++++-----
 3 files changed, 26 insertions(+), 10 deletions(-)
Signature · 1 line
2.37.2
#22 lore raw

PATCH v4 1/2 mm: migration: fix the FOLL_GET failure on following huge page

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
Signature · 1 line
2.37.2
#23 lore raw
Quoted 2 lines · AEST Haiyue Wang

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

I think you should be explicit in the commit message about which functions do not support FOLL_GET as it's not obvious what support needs to be added before this fix can be reverted.

Thanks.

- Alistair

Quoted 6 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing

with memory offline")

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm,

Quoted 10 lines
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +0 -0
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, 

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm,

Quoted 8 lines
mm/migrate.c +1 -0
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, 

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm,

Quoted 14 lines
mm/migrate.c +5 -1
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, 

unsigned long nr_pages,

Quoted 10 lines
mm/migrate.c +2 -1
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
 
#24 lore raw
Quoted 9 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 12:29
To: [email protected]; [email protected]; Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Wang, Haiyue <[email protected]>
Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 7 lines
Quoted 2 lines · AEST Haiyue Wang

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

I think you should be explicit in the commit message about which functions do not support FOLL_GET as it's not obvious what support needs to be added before this fix can be reverted.

Yes, make sense, will add them in new patch.

Quoted 60 lines

Thanks.

- Alistair

Quoted 6 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing

with memory offline")

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm,

Quoted 10 lines
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +0 -0
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm,

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm,

Quoted 8 lines
mm/migrate.c +1 -0
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm,

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm,

Quoted 14 lines
mm/migrate.c +5 -1
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm,

unsigned long nr_pages,

Quoted 10 lines
mm/migrate.c +2 -1
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
 
#25 lore raw
Quoted 4 lines · Haiyue
Quoted 4 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 12:29
To: [email protected]; [email protected]; Wang, Haiyue

<[email protected]>

Quoted 1 line
Quoted 1 line

Huang, Ying

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected]; [email protected]; Wang,

Quoted 2 lines
Quoted 2 lines

Haiyue <[email protected]>
Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on

following huge page

Quoted 6 lines
Quoted 6 lines · AEST Haiyue Wang
Quoted 2 lines

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

I think you should be explicit in the commit message about which functions

do

Quoted 1 line
Quoted 1 line

not support FOLL_GET as it's not obvious what support needs to be added

before

Quoted 3 lines
Quoted 1 line

this fix can be reverted.

Yes, make sense, will add them in new patch.

Actually while you're at it I think it would be good to include a description of the impact of this failure in the commit message. Ie. You're answer to:

Quoted 1 line

What are the user-visible runtime effects of this bug?

As it documents what should be tested if this fix does actually ever get reverted.

Quoted 11 lines
Quoted 11 lines

Thanks.

- Alistair

Quoted 6 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array

racing

Quoted 11 lines
Quoted 11 lines

with memory offline")

mm/migrate.c static void do_pages_stat_array(struct mm_struct

Quoted 10 lines
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +0 -0
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct 

*mm,

Quoted 9 lines
Quoted 9 lines

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct

Quoted 8 lines
mm/migrate.c +1 -0
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct 

*mm,

Quoted 12 lines
Quoted 12 lines

unsigned long nr_pages,

Quoted 11 lines
mm/migrate.c +5 -1
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
Quoted 3 lines
Quoted 3 lines

mm/migrate.c static void do_pages_stat_array(struct mm_struct

Quoted 3 lines
mm/migrate.c +0 -0
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct 

*mm,

Quoted 16 lines
Quoted 14 lines

unsigned long nr_pages,

Quoted 10 lines
mm/migrate.c +2 -1
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
 
#26 lore raw
Quoted 34 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 13:17
To: [email protected]; [email protected]; Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 4 lines · Haiyue
Quoted 4 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 12:29
To: [email protected]; [email protected]; Wang, Haiyue

<[email protected]>

Quoted 1 line
Quoted 1 line

Huang, Ying

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected]; [email protected]; Wang,

Quoted 2 lines
Quoted 2 lines

Haiyue <[email protected]>
Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on

following huge page

Quoted 6 lines
Quoted 6 lines · AEST Haiyue Wang
Quoted 2 lines

Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page.

I think you should be explicit in the commit message about which functions

do

Quoted 1 line
Quoted 1 line

not support FOLL_GET as it's not obvious what support needs to be added

before

Quoted 3 lines
Quoted 1 line

this fix can be reverted.

Yes, make sense, will add them in new patch.

Quoted 7 lines

Actually while you're at it I think it would be good to include a description of the impact of this failure in the commit message. Ie. You're answer to:

Quoted 1 line

What are the user-visible runtime effects of this bug?

As it documents what should be tested if this fix does actually ever get reverted.

An short example *.c code to capture the bug in commit message ?

Quoted 70 lines
Quoted 4 lines
Quoted 4 lines

Thanks.

Quoted 8 lines
Quoted 8 lines

- Alistair

Quoted 6 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array

racing

Quoted 11 lines
Quoted 11 lines

with memory offline")

mm/migrate.c static void do_pages_stat_array(struct mm_struct

Quoted 10 lines
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +0 -0
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct

*mm,

Quoted 9 lines
Quoted 9 lines

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct

Quoted 8 lines
mm/migrate.c +1 -0
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct

*mm,

Quoted 12 lines
Quoted 12 lines

unsigned long nr_pages,

Quoted 11 lines
mm/migrate.c +5 -1
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
Quoted 3 lines
Quoted 3 lines

mm/migrate.c static void do_pages_stat_array(struct mm_struct

Quoted 3 lines
mm/migrate.c +0 -0
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct

*mm,

Quoted 16 lines
Quoted 14 lines

unsigned long nr_pages,

Quoted 10 lines
mm/migrate.c +2 -1
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
 
#27 lore raw
Quoted 4 lines · Haiyue
Quoted 4 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 13:17
To: [email protected]; [email protected]; Wang, Haiyue

<[email protected]>

Quoted 1 line
Quoted 1 line

Huang, Ying

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected]; [email protected]

Quoted 1 line
Quoted 1 line

Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on

following huge page

Quoted 9 lines
Quoted 9 lines · Haiyue
Quoted 4 lines
Quoted 4 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 12:29
To: [email protected]; [email protected]; Wang, Haiyue

<[email protected]>

Quoted 1 line
Quoted 1 line

Huang, Ying

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected]; [email protected]; Wang,

Quoted 2 lines
Quoted 2 lines

Haiyue <[email protected]>
Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on

following huge page

Quoted 3 lines
Quoted 3 lines · AEST Haiyue Wang
Quoted 1 line

Not all huge page APIs support FOLL_GET option, so the

__NR_move_pages

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

will fail to get the page node information for huge page.

I think you should be explicit in the commit message about which

functions

Quoted 2 lines
Quoted 2 lines

do

Quoted 1 line
Quoted 1 line

not support FOLL_GET as it's not obvious what support needs to be

added

Quoted 6 lines
Quoted 6 lines

before

Quoted 3 lines
Quoted 1 line

this fix can be reverted.

Yes, make sense, will add them in new patch.

Actually while you're at it I think it would be good to include a

description

Quoted 8 lines
Quoted 6 lines

of the impact of this failure in the commit message. Ie. You're answer to:

Quoted 1 line

What are the user-visible runtime effects of this bug?

As it documents what should be tested if this fix does actually ever get reverted.

An short example *.c code to capture the bug in commit message ?

That's probably overkill. Just being a bit more explicit about the circumstances in which sys_move_pages() actually fails would be good. Eg. something like this:

"Without this sys_move_pages() will return -ENOENT for 1GB huge page memory map when dumping the page node information for nodes != NULL"

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Thanks.

- Alistair

Quoted 3 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can

be

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible

do_pages_stat_array

Quoted 7 lines
Quoted 7 lines

racing

Quoted 6 lines
Quoted 6 lines

with memory offline")

Quoted 5 lines
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

mm/migrate.c static void do_pages_stat_array(struct

Quoted 5 lines
mm/migrate.c +0 -0
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct 

mm_struct

Quoted 10 lines
Quoted 10 lines

*mm,

Quoted 9 lines
Quoted 9 lines

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct

Quoted 8 lines
mm/migrate.c +1 -0
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct 

mm_struct

Quoted 6 lines
Quoted 6 lines

*mm,

Quoted 5 lines
Quoted 5 lines

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,

Quoted 4 lines
mm/migrate.c +1 -0
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' 

*/

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

mm/migrate.c static void do_pages_stat_array(struct

Quoted 10 lines
mm/migrate.c +4 -1
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct 

mm_struct

Quoted 22 lines
Quoted 20 lines

*mm,

Quoted 16 lines
Quoted 14 lines

unsigned long nr_pages,

Quoted 10 lines
mm/migrate.c +2 -1
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
 
#28 lore raw
Quoted 59 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 13:35
To: [email protected]; [email protected]; Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 4 lines · Haiyue
Quoted 4 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 13:17
To: [email protected]; [email protected]; Wang, Haiyue

<[email protected]>

Quoted 1 line
Quoted 1 line

Huang, Ying

Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected]; [email protected]

Quoted 1 line
Quoted 1 line

Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on

following huge page

Quoted 9 lines
Quoted 9 lines · Haiyue
Quoted 4 lines
Quoted 4 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Monday, August 15, 2022 12:29
To: [email protected]; [email protected]; Wang, Haiyue

<[email protected]>

Quoted 1 line
Quoted 1 line

Huang, Ying

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line

<[email protected]>; [email protected];

[email protected]; [email protected]; Wang,

Quoted 2 lines
Quoted 2 lines

Haiyue <[email protected]>
Subject: Re: [PATCH v4 1/2] mm: migration: fix the FOLL_GET failure on

following huge page

Quoted 3 lines
Quoted 3 lines · AEST Haiyue Wang
Quoted 1 line

Not all huge page APIs support FOLL_GET option, so the

__NR_move_pages

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

will fail to get the page node information for huge page.

I think you should be explicit in the commit message about which

functions

Quoted 2 lines
Quoted 2 lines

do

Quoted 1 line
Quoted 1 line

not support FOLL_GET as it's not obvious what support needs to be

added

Quoted 6 lines
Quoted 6 lines

before

Quoted 3 lines
Quoted 1 line

this fix can be reverted.

Yes, make sense, will add them in new patch.

Actually while you're at it I think it would be good to include a

description

Quoted 7 lines
Quoted 6 lines

of the impact of this failure in the commit message. Ie. You're answer to:

Quoted 1 line

What are the user-visible runtime effects of this bug?

As it documents what should be tested if this fix does actually ever get reverted.

Quoted 8 lines
Quoted 1 line

An short example *.c code to capture the bug in commit message ?

That's probably overkill. Just being a bit more explicit about the circumstances in which sys_move_pages() actually fails would be good. Eg. something like this:

"Without this sys_move_pages() will return -ENOENT for 1GB huge page memory map when dumping the page node information for nodes != NULL"

OK, understood, will try to add more information about the error. ;-)

Quoted 82 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Thanks.

- Alistair

Quoted 3 lines

This is an temporary solution to mitigate the racing fix.

After supporting follow huge page by FOLL_GET is done, this fix can

be

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible

do_pages_stat_array

Quoted 7 lines
Quoted 7 lines

racing

Quoted 6 lines
Quoted 6 lines

with memory offline")

Quoted 5 lines
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

mm/migrate.c static void do_pages_stat_array(struct

Quoted 5 lines
mm/migrate.c +0 -0
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct

mm_struct

Quoted 10 lines
Quoted 10 lines

*mm,

Quoted 9 lines
Quoted 9 lines

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct

Quoted 8 lines
mm/migrate.c +1 -0
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct

mm_struct

Quoted 6 lines
Quoted 6 lines

*mm,

Quoted 5 lines
Quoted 5 lines

unsigned long nr_pages,

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,

Quoted 4 lines
mm/migrate.c +1 -0
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET'

*/

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

mm/migrate.c static void do_pages_stat_array(struct

Quoted 10 lines
mm/migrate.c +4 -1
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct

mm_struct

Quoted 22 lines
Quoted 20 lines

*mm,

Quoted 16 lines
Quoted 14 lines

unsigned long nr_pages,

Quoted 10 lines
mm/migrate.c +2 -1
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
 
#29 lore raw

PATCH v4 2/2 mm: fix the handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +7 -3
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
Signature · 1 line
2.37.2
#30 lore raw

v5 cover fix follow_page related issues

In reply to Haiyue Wang

v5: reword the commit message for FOLL_GET with more information.

v4: add '()' for the function for readability.
add more words about the Non-LRU pages fix in commit message.

v3: Merge the fix for handling Non-LRU pages into one patch.
Drop the break_ksm zone device page check.

v2: Add the Non-LRU pages fix with two patches, so that
'mm: migration: fix the FOLL_GET' can be applied directly on linux-5.19 stable branch.

Haiyue Wang (2):
mm: migration: fix the FOLL_GET failure on following huge page
mm: fix the handling Non-LRU pages returned by follow_page

 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 20 +++++++++++++++-----
 3 files changed, 26 insertions(+), 10 deletions(-)
Signature · 1 line
2.37.2
#31 lore raw

PATCH v5 1/2 mm: migration: fix the FOLL_GET failure on following huge page

Not all huge page APIs support FOLL_GET option, so move_pages() syscall will fail to get the page node information for some huge pages.

Like x86 on linux 5.19 with 1GB huge page API follow_huge_pud(), it will return NULL page for FOLL_GET when calling move_pages() syscall with the NULL 'nodes' parameter, the 'status' parameter has '-2' error in array.

Note: follow_huge_pud() now supports FOLL_GET in linux 6.0.

      Link: https://lore.kernel.org/all/[email protected]

But these huge page APIs don't support FOLL_GET:
1. follow_huge_pud() in arch/s390/mm/hugetlbpage.c
2. follow_huge_addr() in arch/ia64/mm/hugetlbpage.c It will cause WARN_ON_ONCE for FOLL_GET.
3. follow_huge_pgd() in mm/hugetlb.c

This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set for huge pages.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
Signature · 1 line
2.37.2
Reviewed-by on v5 1/2
#32 lore raw
Quoted 16 lines · Haiyue Wang

Not all huge page APIs support FOLL_GET option, so move_pages() syscall will fail to get the page node information for some huge pages.

Like x86 on linux 5.19 with 1GB huge page API follow_huge_pud(), it will return NULL page for FOLL_GET when calling move_pages() syscall with the NULL 'nodes' parameter, the 'status' parameter has '-2' error in array.

Note: follow_huge_pud() now supports FOLL_GET in linux 6.0.

      Link: https://lore.kernel.org/all/[email protected]

But these huge page APIs don't support FOLL_GET:
1. follow_huge_pud() in arch/s390/mm/hugetlbpage.c
2. follow_huge_addr() in arch/ia64/mm/hugetlbpage.c It will cause WARN_ON_ONCE for FOLL_GET.
3. follow_huge_pgd() in mm/hugetlb.c

Quoted 8 lines

This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set for huge pages.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")

LGTM, Thanks!

Quoted 40 lines
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
#33 lore raw

PATCH v5 2/2 mm: fix the handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +7 -3
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
Signature · 1 line
2.37.2
Reviewed-by on v5 2/2
#34 lore raw

Re: [PATCH v5 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 10 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

LGTM, Thanks!

Quoted 106 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +7 -3
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
Reviewed-by on v5 2/2
#35 lore raw

Re: [PATCH v5 2/2] mm: fix the handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang

Am 2022-08-15 um 03:02 schrieb Haiyue Wang:

Quoted 10 lines

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

Thank you for catching this. The patch is

Quoted 106 lines
---
  mm/huge_memory.c |  4 ++--
  mm/ksm.c         | 12 +++++++++---
  mm/migrate.c     | 10 +++++++---
  3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
  		/* FOLL_DUMP to ignore special (like zero) pages */
  		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
  			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
  			goto next;
 
  		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
  		cond_resched();
  		page = follow_page(vma, addr,
  				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
  			break;
  		if (PageKsm(page))
  			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
  		goto out;
 
  	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
  		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
  	if (PageAnon(page)) {
  		flush_anon_page(vma, page, addr);
  		flush_dcache_page(page);
  	} else {
+out_putpage:
  		put_page(page);
  out:
  		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
  			if (ksm_test_exit(mm))
  				break;
  			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
  				ksm_scan.address += PAGE_SIZE;
  				cond_resched();
  				continue;
  			}
+			if (is_zone_device_page(*page))
+				goto next_page;
  			if (PageAnon(*page)) {
  				flush_anon_page(vma, *page, ksm_scan.address);
  				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
  				mmap_read_unlock(mm);
  				return rmap_item;
  			}
+next_page:
  			put_page(*page);
  			ksm_scan.address += PAGE_SIZE;
  			cond_resched();
mm/migrate.c +7 -3
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
  		goto out;
 
  	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
  		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
  	err = 0;
  	if (page_to_nid(page) == node)
  		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
  		if (IS_ERR(page))
  			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;
  			if (foll_flags & FOLL_GET)
  				put_page(page);
  		} else {
#36 lore raw

Re: [PATCH v5 2/2] mm: fix the handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang
Quoted 47 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +1 -1
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,

mm/ksm.c static struct page *get_mergeable_page(struct rmap_item *rmap_item) · line 565

Quoted 7 lines
mm/ksm.c +2 -1
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))

Same as for break_ksm() I think we should be able to drop the is_zone_device_page() check here because scan_get_next_rmap_item() already filters out zone device pages.

Quoted 51 lines
mm/ksm.c +6 -1
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +4 -1
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, · line 1876

Quoted 8 lines
mm/migrate.c +3 -2
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;

Can we remove the multiple layers of conditionals here? Something like this is cleaner and easier to understand IMHO:

- if (page && !is_zone_device_page(page)) {
- err = page_to_nid(page);
- if (foll_flags & FOLL_GET)
- put_page(page);
- } else {

+               if (!page) {
                        err = -ENOENT;
+                       goto set_status;
                }

+
+ if (is_zone_device_page(page))
+ err = -ENOENT;
+ else
+ err = page_to_nid_page(page);
+
+ if (foll_flags & FOLL_GET)
+ put_page(page);

Thanks.

- Alistair

Quoted 3 lines
mm/migrate.c +0 -0
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
#37 lore raw

RE: [PATCH v5 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 61 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Tuesday, August 16, 2022 08:01
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Felix Kuehling <[email protected]>
Subject: Re: [PATCH v5 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 49 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +1 -1
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
Quoted 10 lines

mm/ksm.c static struct page *get_mergeable_page(struct rmap_item *rmap_item) · line 565

Quoted 5 lines
mm/ksm.c +2 -1
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))

Same as for break_ksm() I think we should be able to drop the is_zone_device_page() check here because scan_get_next_rmap_item() already filters out zone device pages.

The 'page' for scan_get_next_rmap_item() is from 'vma' which is NOT MERGEABLE:

	for (; vma; vma = vma->vm_next) {
		if (!(vma->vm_flags & VM_MERGEABLE))
			continue;

The 'page' for get_mergeable_page() is from 'vma' which is MERGEABLE by 'find_mergeable_vma()'

So they may be different, and the unstable_tree_search_insert() shows the logical:

'page' vs 'tree_page':

		tree_page = get_mergeable_page(tree_rmap_item);
		if (!tree_page)
			return NULL;

		/*
		 * Don't substitute a ksm page for a forked page.
		 */
		if (page == tree_page) {
			put_page(tree_page);
			return NULL;
		}

		ret = memcmp_pages(page, tree_page);
Quoted 54 lines
Quoted 54 lines
mm/ksm.c +6 -1
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +4 -1
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
Quoted 8 lines

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, · line 1876

Quoted 5 lines
mm/migrate.c +3 -2
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;

Can we remove the multiple layers of conditionals here? Something like this is cleaner and easier to understand IMHO:

OK, I will try it in new patch.

Quoted 26 lines
(quoted diff) +10 -5
-               if (page && !is_zone_device_page(page)) {
-                       err = page_to_nid(page);
-                       if (foll_flags & FOLL_GET)
-                               put_page(page);
-               } else {
+               if (!page) {
                        err = -ENOENT;
+                       goto set_status;
                }
+
+               if (is_zone_device_page(page))
+                       err = -ENOENT;
+               else
+                       err = page_to_nid_page(page);
+
+               if (foll_flags & FOLL_GET)
+                       put_page(page);

Thanks.

- Alistair

Quoted 3 lines
mm/migrate.c +0 -0
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
#38 lore raw

Re: [PATCH v5 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 72 lines · Haiyue
Quoted 61 lines

-----Original Message-----
From: Alistair Popple <[email protected]>
Sent: Tuesday, August 16, 2022 08:01
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Felix Kuehling <[email protected]>
Subject: Re: [PATCH v5 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 49 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 10 +++++++---
 3 files changed, 18 insertions(+), 8 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +1 -1
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
Quoted 10 lines

mm/ksm.c static struct page *get_mergeable_page(struct rmap_item *rmap_item) · line 565

Quoted 5 lines
mm/ksm.c +2 -1
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))

Same as for break_ksm() I think we should be able to drop the is_zone_device_page() check here because scan_get_next_rmap_item() already filters out zone device pages.

Quoted 6 lines

The 'page' for scan_get_next_rmap_item() is from 'vma' which is NOT MERGEABLE:

	for (; vma; vma = vma->vm_next) {
		if (!(vma->vm_flags & VM_MERGEABLE))
			continue;

The 'page' for get_mergeable_page() is from 'vma' which is MERGEABLE by 'find_mergeable_vma()'

Oh, ok. I'm actually not too familiar with KSM but I think I follow so if you think we need to keep the check by all means do so.

Quoted 82 lines

So they may be different, and the unstable_tree_search_insert() shows the logical:

'page' vs 'tree_page':

		tree_page = get_mergeable_page(tree_rmap_item);
		if (!tree_page)
			return NULL;

		/*
		 * Don't substitute a ksm page for a forked page.
		 */
		if (page == tree_page) {
			put_page(tree_page);
			return NULL;
		}

		ret = memcmp_pages(page, tree_page);
Quoted 54 lines
Quoted 54 lines
mm/ksm.c +6 -1
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +4 -1
index 581dfaad9257..fee12cd2f294 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,8 +1871,9 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
Quoted 8 lines

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, · line 1876

Quoted 5 lines
mm/migrate.c +3 -2
-		if (page && !is_zone_device_page(page)) {
-			err = page_to_nid(page);
+		if (page) {
+			err = !is_zone_device_page(page) ? page_to_nid(page)
+							 : -ENOENT;

Can we remove the multiple layers of conditionals here? Something like this is cleaner and easier to understand IMHO:

Quoted 1 line

OK, I will try it in new patch.

Thanks.

Quoted 26 lines
Quoted 26 lines
(quoted diff) +10 -5
-               if (page && !is_zone_device_page(page)) {
-                       err = page_to_nid(page);
-                       if (foll_flags & FOLL_GET)
-                               put_page(page);
-               } else {
+               if (!page) {
                        err = -ENOENT;
+                       goto set_status;
                }
+
+               if (is_zone_device_page(page))
+                       err = -ENOENT;
+               else
+                       err = page_to_nid_page(page);
+
+               if (foll_flags & FOLL_GET)
+                       put_page(page);

Thanks.

- Alistair

Quoted 3 lines
mm/migrate.c +0 -0
 			if (foll_flags & FOLL_GET)
 				put_page(page);
 		} else {
#39 lore raw

v6 cover fix follow_page related issues

In reply to Haiyue Wang

v6: Simplify the multiple layers of conditionals for if {}

- if (page) {
- err = !is_zone_device_page(page) ? page_to_nid(page)
- : -ENOENT;
- if (foll_flags & FOLL_GET)
- put_page(page);
- } else {
- err = -ENOENT;

-               }
+               err = -ENOENT;
+               if (!page)

+ goto set_status;
+
+ if (!is_zone_device_page(page))
+ err = page_to_nid(page);
+
+ if (foll_flags & FOLL_GET)
+ put_page(page);

v5: reword the commit message for FOLL_GET with more information.

v4: add '()' for the function for readability.
add more words about the Non-LRU pages fix in commit message.

v3: Merge the fix for handling Non-LRU pages into one patch.
Drop the break_ksm zone device page check.

v2: Add the Non-LRU pages fix with two patches, so that
'mm: migration: fix the FOLL_GET' can be applied directly on linux-5.19 stable branch.

Haiyue Wang (2):
mm: migration: fix the FOLL_GET failure on following huge page
mm: fix the handling Non-LRU pages returned by follow_page

 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 23 +++++++++++++++++------
 3 files changed, 28 insertions(+), 11 deletions(-)
Signature · 1 line
2.37.2
#40 lore raw

PATCH v6 1/2 mm: migration: fix the FOLL_GET failure on following huge page

Not all huge page APIs support FOLL_GET option, so move_pages() syscall will fail to get the page node information for some huge pages.

Like x86 on linux 5.19 with 1GB huge page API follow_huge_pud(), it will return NULL page for FOLL_GET when calling move_pages() syscall with the NULL 'nodes' parameter, the 'status' parameter has '-2' error in array.

Note: follow_huge_pud() now supports FOLL_GET in linux 6.0.

      Link: https://lore.kernel.org/all/[email protected]

But these huge page APIs don't support FOLL_GET:
1. follow_huge_pud() in arch/s390/mm/hugetlbpage.c
2. follow_huge_addr() in arch/ia64/mm/hugetlbpage.c It will cause WARN_ON_ONCE for FOLL_GET.
3. follow_huge_pgd() in mm/hugetlb.c

This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set for huge pages.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")
---
 mm/migrate.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}
Signature · 1 line
2.37.2
reviewer Reviewed-by on v6 1/2
#41 lore raw
Quoted 19 lines · Haiyue Wang

Not all huge page APIs support FOLL_GET option, so move_pages() syscall will fail to get the page node information for some huge pages.

Like x86 on linux 5.19 with 1GB huge page API follow_huge_pud(), it will return NULL page for FOLL_GET when calling move_pages() syscall with the NULL 'nodes' parameter, the 'status' parameter has '-2' error in array.

Note: follow_huge_pud() now supports FOLL_GET in linux 6.0.

       Link: https://lore.kernel.org/all/[email protected]

But these huge page APIs don't support FOLL_GET:
1. follow_huge_pud() in arch/s390/mm/hugetlbpage.c
2. follow_huge_addr() in arch/ia64/mm/hugetlbpage.c It will cause WARN_ON_ONCE for FOLL_GET.
3. follow_huge_pgd() in mm/hugetlb.c

This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set for huge pages.

Quoted 7 lines

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")

---

Looks good to me.

Quoted 39 lines
  mm/migrate.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
mm/migrate.c +8 -2
index 6a1597c92261..581dfaad9257 100644
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
  	for (i = 0; i < nr_pages; i++) {
  		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
  		struct vm_area_struct *vma;
  		struct page *page;
  		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
  		if (!vma)
  			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
  		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
  		err = PTR_ERR(page);
  		if (IS_ERR(page))
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
  		if (page && !is_zone_device_page(page)) {
  			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
  		} else {
  			err = -ENOENT;
  		}
maintainer
#42 lore raw
In reply to Haiyue Wang
Quoted 7 lines · On Tue, 16 Aug 2022 10:21:00 +0800 Haiyue Wang <[email protected]> wrote:

Not all huge page APIs support FOLL_GET option, so move_pages() syscall will fail to get the page node information for some huge pages.

Like x86 on linux 5.19 with 1GB huge page API follow_huge_pud(), it will return NULL page for FOLL_GET when calling move_pages() syscall with the NULL 'nodes' parameter, the 'status' parameter has '-2' error in array.

Quoted 5 lines

Note: follow_huge_pud() now supports FOLL_GET in linux 6.0.

      Link: https://lore.kernel.org/all/[email protected]

But these huge page APIs don't support FOLL_GET:
1. follow_huge_pud() in arch/s390/mm/hugetlbpage.c

Let's tell the s390 maintainers.

Quoted 2 lines

2. follow_huge_addr() in arch/ia64/mm/hugetlbpage.c It will cause WARN_ON_ONCE for FOLL_GET.

ia64 doesn't have maintainers :( Can we come up with something local to arch/ia64 for this?

Quoted 1 line

3. follow_huge_pgd() in mm/hugetlb.c

Hi, Mike.

Quoted 33 lines

This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set for huge pages.

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

...

mm/migrate.c +6 -1
@@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 	for (i = 0; i < nr_pages; i++) {
 		unsigned long addr = (unsigned long)(*pages);
+		unsigned int foll_flags = FOLL_DUMP;
 		struct vm_area_struct *vma;
 		struct page *page;
 		int err = -EFAULT;
@@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (!vma)
 			goto set_status;
 
+		/* Not all huge page follow APIs support 'FOLL_GET' */
+		if (!is_vm_hugetlb_page(vma))
+			foll_flags |= FOLL_GET;
+
 		/* FOLL_DUMP to ignore special (like zero) pages */
-		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
+		page = follow_page(vma, addr, foll_flags);
 
 		err = PTR_ERR(page);
 		if (IS_ERR(page))

mm/migrate.c static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, · line 1877

Quoted 9 lines
mm/migrate.c +2 -1
@@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 
 		if (page && !is_zone_device_page(page)) {
 			err = page_to_nid(page);
-			put_page(page);
+			if (foll_flags & FOLL_GET)
+				put_page(page);
 		} else {
 			err = -ENOENT;
 		}

I would be better to fix this for real at those three client code sites?

#43 lore raw
Quoted 27 lines

-----Original Message-----
From: Andrew Morton <[email protected]>
Sent: Wednesday, August 17, 2022 08:59
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Heiko Carstens <[email protected]>; Vasily Gorbik <[email protected]>; Alexander Gordeev <[email protected]>; Christian Borntraeger <[email protected]>; Sven Schnelle <[email protected]>; Mike Kravetz <[email protected]>
Subject: Re: [PATCH v6 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 7 lines · On Tue, 16 Aug 2022 10:21:00 +0800 Haiyue Wang <[email protected]> wrote:

Not all huge page APIs support FOLL_GET option, so move_pages() syscall will fail to get the page node information for some huge pages.

Like x86 on linux 5.19 with 1GB huge page API follow_huge_pud(), it will return NULL page for FOLL_GET when calling move_pages() syscall with the NULL 'nodes' parameter, the 'status' parameter has '-2' error in array.

Quoted 5 lines

Note: follow_huge_pud() now supports FOLL_GET in linux 6.0.

      Link: https://lore.kernel.org/all/[email protected]

But these huge page APIs don't support FOLL_GET:
1. follow_huge_pud() in arch/s390/mm/hugetlbpage.c

Quoted 7 lines

Let's tell the s390 maintainers.

Quoted 2 lines

2. follow_huge_addr() in arch/ia64/mm/hugetlbpage.c It will cause WARN_ON_ONCE for FOLL_GET.

ia64 doesn't have maintainers :( Can we come up with something local to arch/ia64 for this?

The 'follow_huge_addr' itself just has interest on "FOLL_WRITE" struct page *
follow_huge_addr(struct mm_struct *mm, unsigned long address,
int write)

And arch/ia64 defines this function 17 years ago ...

But I found that "WARN_ON_ONCE for FOLL_GET" was introduced on 2005-10-29 by commit:

[PATCH] mm: follow_page with inner ptlock

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=deceb6cd17e6dfafe4c4f81b1b4153bc41b2cb70

- page = follow_huge_addr(mm, address, write);
- if (! IS_ERR(page))
- return page;
+ page = follow_huge_addr(mm, address, flags & FOLL_WRITE);
+ if (!IS_ERR(page)) {
+ BUG_ON(flags & FOLL_GET);
+ goto out;
+ }

Quoted 10 lines
Quoted 2 lines

3. follow_huge_pgd() in mm/hugetlb.c

Hi, Mike.

Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Then 5.19 will break for a while to wait for the final BIG patch ?

maintainer
#44 lore raw
Quoted 5 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

#45 lore raw
Quoted 18 lines

-----Original Message-----
From: Andrew Morton <[email protected]>
Sent: Wednesday, August 17, 2022 13:43
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Heiko Carstens <[email protected]>; Vasily Gorbik <[email protected]>; Alexander Gordeev <[email protected]>; Christian Borntraeger <[email protected]>; Sven Schnelle <[email protected]>; Mike Kravetz <[email protected]>
Subject: Re: [PATCH v6 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 7 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for

Got it, make sense. ;-)

Quoted 1 line

backporting. I don't think they'll be terribly intrusive or risky?

#46 lore raw
In reply to Andrew Morton
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 8 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

I will start on adding follow_huge_pgd() support. Although, I may need some help with verification from the powerpc folks, as that is the only architecture which supports hugetlb pages at that level.

mpe any suggestions?

When Naoya recently modified follow_huge_pud, it ended up looking very much like follow_huge_pmd (as it should). I expect follow_huge_pgd will be similar. In the end we may want to factor out the common code. However, for a backport it would be better to just modify follow_huge_pgd and do the cleanup/condensing common code later.

Signature · 1 line
Mike Kravetz
#47 lore raw
Quoted 16 lines · Mike Kravetz
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 8 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

Quoted 5 lines

I will start on adding follow_huge_pgd() support. Although, I may need some help with verification from the powerpc folks, as that is the only architecture which supports hugetlb pages at that level.

mpe any suggestions?

From 4925a98a6857dbb5a23bd97063ded2648863e65e Mon Sep 17 00:00:00 2001
From: Mike Kravetz <[email protected]>
Date: Wed, 17 Aug 2022 14:32:10 -0700
Subject: [PATCH] hugetlb: make follow_huge_pgd support FOLL_GET

The existing version of follow_huge_pgd was very primitive and only provided limited functionality. Specifically, it did not support FOLL_GET. Update follow_huge_pgd with modifications similar to those made for follow_huge_pud in commit 3a194f3f8ad0 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry").

Note, common code should be factored out of follow_huge_p*d routines. This will be done in future modifications.

---
 mm/hugetlb.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
mm/hugetlb.c +30 -2
index ea1c7bfa1cc3..6f32d2bd1ca9 100644
@@ -7055,10 +7055,38 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
 struct page * __weak
 follow_huge_pgd(struct mm_struct *mm, unsigned long address, pgd_t *pgd, int flags)
 {
-	if (flags & (FOLL_GET | FOLL_PIN))
+	struct page *page = NULL;
+	spinlock_t *ptl;
+	pte_t pte;
+
+	if (WARN_ON_ONCE(flags & FOLL_PIN))
 		return NULL;
 
-	return pte_page(*(pte_t *)pgd) + ((address & ~PGDIR_MASK) >> PAGE_SHIFT);
+retry:
+	ptl = huge_pte_lock(hstate_sizelog(PGDIR_SHIFT), mm, (pte_t *)pgd);
+	if (!pgd_huge(*pgd))
+		goto out;
+	pte = huge_ptep_get((pte_t *)pgd);
+	if (pte_present(pte)) {
+		page = pgd_page(*pgd) + ((address & ~PGDIR_MASK) >> PAGE_SHIFT);
+		if (WARN_ON_ONCE(!try_grab_page(page, flags))) {
+			page = NULL;
+			goto out;
+		}
+	} else {
+		if (is_hugetlb_entry_migration(pte)) {
+			spin_unlock(ptl);
+			__migration_entry_wait(mm, (pte_t *)pgd, ptl);
+			goto retry;
+		}
+		/*
+		 * hwpoisoned entry is treated as no_page_table in
+		 * follow_page_mask().
+		 */
+	}
+out:
+	spin_unlock(ptl);
+	return page;
 }
 
 int isolate_hugetlb(struct page *page, struct list_head *list)
Signature · 1 line
2.37.1
#48 lore raw
Quoted 39 lines

-----Original Message-----
From: Mike Kravetz <[email protected]>
Sent: Thursday, August 18, 2022 05:58
To: Andrew Morton <[email protected]>; Michael Ellerman <[email protected]>
Cc: Wang, Haiyue <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Heiko Carstens <[email protected]>; Vasily Gorbik <[email protected]>; Alexander Gordeev <[email protected]>; Christian Borntraeger <[email protected]>; Sven Schnelle <[email protected]>
Subject: Re: [PATCH v6 1/2] mm: migration: fix the FOLL_GET failure on following huge page

Quoted 16 lines · Mike Kravetz
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 8 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

Quoted 5 lines

I will start on adding follow_huge_pgd() support. Although, I may need some help with verification from the powerpc folks, as that is the only architecture which supports hugetlb pages at that level.

mpe any suggestions?

From 4925a98a6857dbb5a23bd97063ded2648863e65e Mon Sep 17 00:00:00 2001
From: Mike Kravetz <[email protected]>
Date: Wed, 17 Aug 2022 14:32:10 -0700
Subject: [PATCH] hugetlb: make follow_huge_pgd support FOLL_GET

Quoted 9 lines

The existing version of follow_huge_pgd was very primitive and only provided limited functionality. Specifically, it did not support FOLL_GET. Update follow_huge_pgd with modifications similar to those made for follow_huge_pud in commit 3a194f3f8ad0 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry").

Note, common code should be factored out of follow_huge_p*d routines. This will be done in future modifications.

I found "Anshuman Khandual <[email protected]>" submit the similar patch on "Apr 2016 11:07:37 +0530"

[PATCH 03/10] mm/hugetlb: Protect follow_huge_(pud|pgd) functions from race
https://lore.kernel.org/all/[email protected]/

Quoted 52 lines
---
 mm/hugetlb.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
mm/hugetlb.c +30 -3
index ea1c7bfa1cc3..6f32d2bd1ca9 100644
@@ -7055,10 +7055,38 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
 struct page * __weak
 follow_huge_pgd(struct mm_struct *mm, unsigned long address, pgd_t *pgd, int flags)
 {
-	if (flags & (FOLL_GET | FOLL_PIN))
+	struct page *page = NULL;
+	spinlock_t *ptl;
+	pte_t pte;
+
+	if (WARN_ON_ONCE(flags & FOLL_PIN))
 		return NULL;
 
-	return pte_page(*(pte_t *)pgd) + ((address & ~PGDIR_MASK) >> PAGE_SHIFT);
+retry:
+	ptl = huge_pte_lock(hstate_sizelog(PGDIR_SHIFT), mm, (pte_t *)pgd);
+	if (!pgd_huge(*pgd))
+		goto out;
+	pte = huge_ptep_get((pte_t *)pgd);
+	if (pte_present(pte)) {
+		page = pgd_page(*pgd) + ((address & ~PGDIR_MASK) >> PAGE_SHIFT);
+		if (WARN_ON_ONCE(!try_grab_page(page, flags))) {
+			page = NULL;
+			goto out;
+		}
+	} else {
+		if (is_hugetlb_entry_migration(pte)) {
+			spin_unlock(ptl);
+			__migration_entry_wait(mm, (pte_t *)pgd, ptl);
+			goto retry;
+		}
+		/*
+		 * hwpoisoned entry is treated as no_page_table in
+		 * follow_page_mask().
+		 */
+	}
+out:
+	spin_unlock(ptl);
+	return page;
 }
 
 int isolate_hugetlb(struct page *page, struct list_head *list)
--

2.37.1

#49 lore raw
In reply to Mike Kravetz
Quoted 16 lines · Mike Kravetz
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 8 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

Quoted 5 lines

I will start on adding follow_huge_pgd() support. Although, I may need some help with verification from the powerpc folks, as that is the only architecture which supports hugetlb pages at that level.

mpe any suggestions?

I'm happy to test.

I have a system where I can allocate 1GB huge pages.

I'm not sure how to actually test this path though. I hacked up the vm/migration.c test to allocate 1GB hugepages, but I can't see it going through follow_huge_pgd() (using ftrace).

Maybe I hacked it up badly, I'll have a closer look on Monday. But if you have any tips on how to trigger that path let me know :)

cheers

#50 lore raw
Quoted 23 lines · Michael Ellerman
Quoted 16 lines · Mike Kravetz
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 8 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

Quoted 5 lines

I will start on adding follow_huge_pgd() support. Although, I may need some help with verification from the powerpc folks, as that is the only architecture which supports hugetlb pages at that level.

mpe any suggestions?

Quoted 7 lines

I'm happy to test.

I have a system where I can allocate 1GB huge pages.

I'm not sure how to actually test this path though. I hacked up the vm/migration.c test to allocate 1GB hugepages, but I can't see it going through follow_huge_pgd() (using ftrace).

I thing you needed to use 16GB to trigger this code path. Anshuman introduced support for page offline (and migration) at this level in commit 94310cbcaa3c ("mm/madvise: enable (soft|hard) offline of HugeTLB pages at PGD level"). When asked about the use case, he mentioned:

"Yes, its in the context of 16GB pages on POWER8 system where all the
gigantic pages are pre allocated from the platform and passed on to the kernel through the device tree. We dont allocate these gigantic pages on runtime."

Signature · 1 line
Mike Kravetz
Quoted 5 lines

Maybe I hacked it up badly, I'll have a closer look on Monday. But if you have any tips on how to trigger that path let me know :)

cheers

#51 lore raw
Quoted 37 lines · Mike Kravetz
Quoted 23 lines · Michael Ellerman
Quoted 16 lines · Mike Kravetz
Quoted 6 lines · Andrew Morton
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 8 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

Quoted 5 lines

I will start on adding follow_huge_pgd() support. Although, I may need some help with verification from the powerpc folks, as that is the only architecture which supports hugetlb pages at that level.

mpe any suggestions?

Quoted 7 lines

I'm happy to test.

I have a system where I can allocate 1GB huge pages.

I'm not sure how to actually test this path though. I hacked up the vm/migration.c test to allocate 1GB hugepages, but I can't see it going through follow_huge_pgd() (using ftrace).

I thing you needed to use 16GB to trigger this code path. Anshuman introduced support for page offline (and migration) at this level in commit 94310cbcaa3c ("mm/madvise: enable (soft|hard) offline of HugeTLB pages at PGD level"). When asked about the use case, he mentioned:

Quoted 4 lines

"Yes, its in the context of 16GB pages on POWER8 system where all the
gigantic pages are pre allocated from the platform and passed on to the kernel through the device tree. We dont allocate these gigantic pages on runtime."

That was true, but isn't anymore.

I must have been insufficently caffeinated the other day. On our newer machines 1GB is the largest huge page size, but it's obviously way too small to sit at the PGD level. So that was a waste of my time :)

We used to support 16GB at the PGD level, but we reworked the page table geometry a few years ago, and now they sit at the PUD level on machines that support 16GB pages:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ba95b5d0359609b4ec8010f77c40ab3c595a6ac6

Note the author :}

So the good news is we no longer have any configuration where a huge page entry is expected in the PGD. So we can drop our pgd_huge() definitions, and ours are the last non-zero definitions, so it can all go away I think.

I'll send a patch to remove the powerpc pgd_huge() definitions after I've run it through some tests.

cheers

maintainer
#52 lore raw
In reply to Andrew Morton
Quoted 6 lines · On Tue, 16 Aug 2022 22:43:22 -0700 Andrew Morton <[email protected]>…
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 9 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

The private follow_huge_pud() for s390 is just some leftover, and the only reason is / was that the generic version was using pte_page() instead of pud_page(), which would not work for s390. See also commit 97534127012f ("mm/hugetlb: use pmd_page() in follow_huge_pmd()").

Since commit 3a194f3f8ad01 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry") made follow_huge_pud() behave similar to follow_huge_pmd(), in particular also adding pud_page(), we can now switch to the generic version.

Note that we cannot support migration / hwpoison for hugetlb or THP, because of different layout for PTE and PMD/PUD on s390. The generic swp_entry functions all require proper PTEs, which wouldn't work on PMD/PUD entries. In theory, at least for hugetlb, due to the "fake PTE" conversion logic in huge_ptep_get(), we might be able to also fake swp_entries, but the other problem is that we do not have enough free bits in the PMD/PUD, so there probably will never be migration support for huge pages on s390.

Anyway, that should not matter wrt to switching to the generic follow_huge_pud(), because is_hugetlb_entry_migration() should always return false, and no special change to pud_huge() check should be needed like on x86.

maintainer
#53 lore raw
Quoted 38 lines · On Thu, 18 Aug 2022 13:51:49 +0200 Gerald Schaefer…
Quoted 6 lines · On Tue, 16 Aug 2022 22:43:22 -0700 Andrew Morton <[email protected]>…
Quoted 4 lines · Haiyue
Quoted 3 lines
Quoted 1 line

}

I would be better to fix this for real at those three client code sites?

Quoted 9 lines
Quoted 1 line

Then 5.19 will break for a while to wait for the final BIG patch ?

If that's the proposal then your [1/2] should have had a cc:stable and changelog words describing the plan for 6.0.

But before we do that I'd like to see at least a prototype of the final fixes to s390 and hugetlb, so we can assess those as preferable for backporting. I don't think they'll be terribly intrusive or risky?

The private follow_huge_pud() for s390 is just some leftover, and the only reason is / was that the generic version was using pte_page() instead of pud_page(), which would not work for s390. See also commit 97534127012f ("mm/hugetlb: use pmd_page() in follow_huge_pmd()").

Since commit 3a194f3f8ad01 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry") made follow_huge_pud() behave similar to follow_huge_pmd(), in particular also adding pud_page(), we can now switch to the generic version.

Note that we cannot support migration / hwpoison for hugetlb or THP, because of different layout for PTE and PMD/PUD on s390. The generic swp_entry functions all require proper PTEs, which wouldn't work on PMD/PUD entries. In theory, at least for hugetlb, due to the "fake PTE" conversion logic in huge_ptep_get(), we might be able to also fake swp_entries, but the other problem is that we do not have enough free bits in the PMD/PUD, so there probably will never be migration support for huge pages on s390.

Quoted 4 lines

Anyway, that should not matter wrt to switching to the generic follow_huge_pud(), because is_hugetlb_entry_migration() should always return false, and no special change to pud_huge() check should be needed like on x86.

From ce0150cd6f80425c702ccdc4cd8a511c47e99b67 Mon Sep 17 00:00:00 2001
From: Gerald Schaefer <[email protected]>
Date: Thu, 18 Aug 2022 13:19:23 +0200
Subject: [PATCH] s390/hugetlb: switch to generic version of follow_huge_pud()

When pud-sized hugepages were introduced for s390, the generic version of follow_huge_pud() was using pte_page() instead of pud_page(). This would be wrong for s390, see also commit 97534127012f ("mm/hugetlb: use pmd_page() in follow_huge_pmd()"). Therefore, and probably because not all archs were supporting pud_page() at that time, a private version of follow_huge_pud() was added for s390, correctly using pud_page().

Since commit 3a194f3f8ad01 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry"), the generic version of follow_huge_pud() is now also using pud_page(), and in general behaves similar to follow_huge_pmd().

Therefore we can now switch to the generic version and get rid of the s390-specific follow_huge_pud().

---
 arch/s390/mm/hugetlbpage.c | 10 ----------
 1 file changed, 10 deletions(-)
arch/s390/mm/hugetlbpage.c +0 -10
index 10e51ef9c79a..c299a18273ff 100644
@@ -237,16 +237,6 @@ int pud_huge(pud_t pud)
 	return pud_large(pud);
 }
 
-struct page *
-follow_huge_pud(struct mm_struct *mm, unsigned long address,
-		pud_t *pud, int flags)
-{
-	if (flags & FOLL_GET)
-		return NULL;
-
-	return pud_page(*pud) + ((address & ~PUD_MASK) >> PAGE_SHIFT);
-}
-
 bool __init arch_hugetlb_valid_size(unsigned long size)
 {
 	if (MACHINE_HAS_EDAT1 && size == PMD_SIZE)
Signature · 1 line
2.34.1
Reviewed-by on v6 1/2
#54 lore raw
In reply to Haiyue Wang
Quoted 19 lines · Haiyue Wang

Not all huge page APIs support FOLL_GET option, so move_pages() syscall will fail to get the page node information for some huge pages.

Like x86 on linux 5.19 with 1GB huge page API follow_huge_pud(), it will return NULL page for FOLL_GET when calling move_pages() syscall with the NULL 'nodes' parameter, the 'status' parameter has '-2' error in array.

Note: follow_huge_pud() now supports FOLL_GET in linux 6.0.

      Link: https://lore.kernel.org/all/[email protected]

But these huge page APIs don't support FOLL_GET:
1. follow_huge_pud() in arch/s390/mm/hugetlbpage.c
2. follow_huge_addr() in arch/ia64/mm/hugetlbpage.c It will cause WARN_ON_ONCE for FOLL_GET.
3. follow_huge_pgd() in mm/hugetlb.c

This is an temporary solution to mitigate the side effect of the race condition fix by calling follow_page() with FOLL_GET set for huge pages.

Quoted 6 lines

After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely.

Fixes 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline")

LGTM. Many thanks for fixing this.

Thanks,
Miaohe Lin

#55 lore raw

PATCH v6 2/2 mm: fix the handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 19 ++++++++++++-------
 3 files changed, 23 insertions(+), 12 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +12 -7
index 581dfaad9257..44e05ce41d49 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,13 +1871,15 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
+		err = -ENOENT;
+		if (!page)
+			goto set_status;
+
+		if (!is_zone_device_page(page))
 			err = page_to_nid(page);
-			if (foll_flags & FOLL_GET)
-				put_page(page);
-		} else {
-			err = -ENOENT;
-		}
+
+		if (foll_flags & FOLL_GET)
+			put_page(page);
 set_status:
 		*status = err;
 
Signature · 1 line
2.37.2
reviewer Reviewed-by on v6 2/2
#56 lore raw

Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Looks good, thanks.

Quoted 127 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 19 ++++++++++++-------
 3 files changed, 23 insertions(+), 12 deletions(-)
mm/huge_memory.c +2 -2
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))
 			goto next;
 
 		total++;
mm/ksm.c +9 -3
index 42ab153335a2..e26f57fc1f0e 100644
@@ -475,7 +475,7 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr)
 		cond_resched();
 		page = follow_page(vma, addr,
 				FOLL_GET | FOLL_MIGRATION | FOLL_REMOTE);
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			break;
 		if (PageKsm(page))
 			ret = handle_mm_fault(vma, addr,
@@ -560,12 +560,15 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
 		goto out;
 
 	page = follow_page(vma, addr, FOLL_GET);
-	if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+	if (IS_ERR_OR_NULL(page))
 		goto out;
+	if (is_zone_device_page(page))
+		goto out_putpage;
 	if (PageAnon(page)) {
 		flush_anon_page(vma, page, addr);
 		flush_dcache_page(page);
 	} else {
+out_putpage:
 		put_page(page);
 out:
 		page = NULL;
@@ -2308,11 +2311,13 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 			if (ksm_test_exit(mm))
 				break;
 			*page = follow_page(vma, ksm_scan.address, FOLL_GET);
-			if (IS_ERR_OR_NULL(*page) || is_zone_device_page(*page)) {
+			if (IS_ERR_OR_NULL(*page)) {
 				ksm_scan.address += PAGE_SIZE;
 				cond_resched();
 				continue;
 			}
+			if (is_zone_device_page(*page))
+				goto next_page;
 			if (PageAnon(*page)) {
 				flush_anon_page(vma, *page, ksm_scan.address);
 				flush_dcache_page(*page);
@@ -2327,6 +2332,7 @@ static struct rmap_item *scan_get_next_rmap_item(struct page **page)
 				mmap_read_unlock(mm);
 				return rmap_item;
 			}
+next_page:
 			put_page(*page);
 			ksm_scan.address += PAGE_SIZE;
 			cond_resched();
mm/migrate.c +12 -7
index 581dfaad9257..44e05ce41d49 100644
@@ -1672,9 +1672,12 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
 		goto out;
 
 	err = -ENOENT;
-	if (!page || is_zone_device_page(page))
+	if (!page)
 		goto out;
 
+	if (is_zone_device_page(page))
+		goto out_putpage;
+
 	err = 0;
 	if (page_to_nid(page) == node)
 		goto out_putpage;
@@ -1868,13 +1871,15 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
 		if (IS_ERR(page))
 			goto set_status;
 
-		if (page && !is_zone_device_page(page)) {
+		err = -ENOENT;
+		if (!page)
+			goto set_status;
+
+		if (!is_zone_device_page(page))
 			err = page_to_nid(page);
-			if (foll_flags & FOLL_GET)
-				put_page(page);
-		} else {
-			err = -ENOENT;
-		}
+
+		if (foll_flags & FOLL_GET)
+			put_page(page);
 set_status:
 		*status = err;
Reviewed-by on v6 2/2
#57 lore raw

Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

In reply to Haiyue Wang
Quoted 5 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

Quoted 7 lines

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

Thanks for your fixing. LGTM with one nit below. But I have no strong opinion on it. So with or without fixing below nit:

Quoted 11 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 19 ++++++++++++-------
 3 files changed, 23 insertions(+), 12 deletions(-)
mm/huge_memory.c +0 -0
index 8a7c1b344abe..b2ba17c3dcd7 100644

mm/huge_memory.c static int split_huge_pages_pid(int pid, unsigned long vaddr_start, · line 2969

Quoted 9 lines
mm/huge_memory.c +2 -2
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))

!is_transparent_hugepage should already do the work here? IIRC, zone_device_page can't be a transhuge page anyway. And only transparent_hugepage is cared here.

Thanks,
Miaohe Lin

#58 lore raw

Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 37 lines · Miaohe Lin
Quoted 5 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

Quoted 7 lines

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

Thanks for your fixing. LGTM with one nit below. But I have no strong opinion on it. So with or without fixing below nit:

Quoted 18 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 19 ++++++++++++-------
 3 files changed, 23 insertions(+), 12 deletions(-)
mm/huge_memory.c +1 -1
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
Quoted 5 lines

mm/huge_memory.c static int split_huge_pages_pid(int pid, unsigned long vaddr_start, · line 2969

Quoted 2 lines
mm/huge_memory.c +1 -1
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))

!is_transparent_hugepage should already do the work here? IIRC, zone_device_page can't be a transhuge page anyway. And only transparent_hugepage is cared here.

I agree.

Can we avoid sending a new version of a patch series as reply to another patch series (previous version)?

Signature · 3 lines
Thanks,

David / dhildenb
#59 lore raw

RE: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 48 lines

-----Original Message-----
From: David Hildenbrand <[email protected]>
Sent: Tuesday, August 23, 2022 18:07
To: Miaohe Lin <[email protected]>; Wang, Haiyue <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Felix Kuehling <[email protected]>
Subject: Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 37 lines · Miaohe Lin
Quoted 5 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

Quoted 7 lines

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

Thanks for your fixing. LGTM with one nit below. But I have no strong opinion on it. So with or without fixing below nit:

Quoted 18 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 19 ++++++++++++-------
 3 files changed, 23 insertions(+), 12 deletions(-)
mm/huge_memory.c +1 -1
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
Quoted 7 lines
Quoted 5 lines

mm/huge_memory.c static int split_huge_pages_pid(int pid, unsigned long vaddr_start, · line 2969

Quoted 2 lines
mm/huge_memory.c +1 -1
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))

!is_transparent_hugepage should already do the work here? IIRC, zone_device_page can't be a transhuge page anyway. And only transparent_hugepage is cared here.

I agree.

OK, will remove it in next version.

Quoted 3 lines

Can we avoid sending a new version of a patch series as reply to another patch series (previous version)?

Don't use '--in-reply-to=' when running 'git send-email' ?

Quoted 8 lines

--
Thanks,

David / dhildenb

#60 lore raw

Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 56 lines · Haiyue
Quoted 48 lines

-----Original Message-----
From: David Hildenbrand <[email protected]>
Sent: Tuesday, August 23, 2022 18:07
To: Miaohe Lin <[email protected]>; Wang, Haiyue <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Felix Kuehling <[email protected]>
Subject: Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 37 lines · Miaohe Lin
Quoted 5 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

Quoted 7 lines

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

Thanks for your fixing. LGTM with one nit below. But I have no strong opinion on it. So with or without fixing below nit:

Quoted 18 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 19 ++++++++++++-------
 3 files changed, 23 insertions(+), 12 deletions(-)
mm/huge_memory.c +1 -1
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
Quoted 7 lines
Quoted 5 lines

mm/huge_memory.c static int split_huge_pages_pid(int pid, unsigned long vaddr_start, · line 2969

Quoted 2 lines
mm/huge_memory.c +1 -1
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))

!is_transparent_hugepage should already do the work here? IIRC, zone_device_page can't be a transhuge page anyway. And only transparent_hugepage is cared here.

I agree.

Quoted 7 lines

OK, will remove it in next version.

Quoted 3 lines

Can we avoid sending a new version of a patch series as reply to another patch series (previous version)?

Don't use '--in-reply-to=' when running 'git send-email' ?

Yes. That makes it easier top identify versions of patch series, without having to dig down into an ever-growing thread.

Signature · 3 lines
Thanks,

David / dhildenb
#61 lore raw

RE: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 70 lines

-----Original Message-----
From: David Hildenbrand <[email protected]>
Sent: Tuesday, August 23, 2022 21:28
To: Wang, Haiyue <[email protected]>; Miaohe Lin <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Felix Kuehling <[email protected]>
Subject: Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 59 lines · Haiyue
Quoted 48 lines

-----Original Message-----
From: David Hildenbrand <[email protected]>
Sent: Tuesday, August 23, 2022 18:07
To: Miaohe Lin <[email protected]>; Wang, Haiyue <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Huang, Ying <[email protected]>; [email protected]; [email protected]; [email protected]; Felix Kuehling <[email protected]>
Subject: Re: [PATCH v6 2/2] mm: fix the handling Non-LRU pages returned by follow_page

Quoted 37 lines · Miaohe Lin
Quoted 5 lines · Haiyue Wang

The handling Non-LRU pages returned by follow_page() jumps directly, it doesn't call put_page() to handle the reference count, since 'FOLL_GET' flag for follow_page() has get_page() called. Fix the zone device page check by handling the page reference count correctly before returning.

Quoted 7 lines

And as David reviewed, "device pages are never PageKsm pages". Drop this zone device page check for break_ksm().

Fixes 3218f8712d6b ("mm: handling Non-LRU pages returned by vm_normal_pages")

Thanks for your fixing. LGTM with one nit below. But I have no strong opinion on it. So with or without fixing below nit:

Quoted 18 lines
---
 mm/huge_memory.c |  4 ++--
 mm/ksm.c         | 12 +++++++++---
 mm/migrate.c     | 19 ++++++++++++-------
 3 files changed, 23 insertions(+), 12 deletions(-)
mm/huge_memory.c +1 -1
index 8a7c1b344abe..b2ba17c3dcd7 100644
@@ -2963,10 +2963,10 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start,
 		/* FOLL_DUMP to ignore special (like zero) pages */
 		page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP);
 
-		if (IS_ERR_OR_NULL(page) || is_zone_device_page(page))
+		if (IS_ERR_OR_NULL(page))
 			continue;
 
Quoted 7 lines
Quoted 5 lines

mm/huge_memory.c static int split_huge_pages_pid(int pid, unsigned long vaddr_start, · line 2969

Quoted 2 lines
mm/huge_memory.c +1 -1
-		if (!is_transparent_hugepage(page))
+		if (is_zone_device_page(page) || !is_transparent_hugepage(page))

!is_transparent_hugepage should already do the work here? IIRC, zone_device_page can't be a transhuge page anyway. And only transparent_hugepage is cared here.

I agree.

OK, will remove it in next version.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Can we avoid sending a new version of a patch series as reply to another patch series (previous version)?

Don't use '--in-reply-to=' when running 'git send-email' ?

Yes. That makes it easier top identify versions of patch series, without having to dig down into an ever-growing thread.

Got it, thanks. ;-)

Quoted 5 lines

--
Thanks,

David / dhildenb