Skip to contentSkip to conversation

mm/page_isolation: fix potential missing call to unset_migratetype_isolate()

PATCH Superseded Miaohe Lin 2 participants 5 messages Sep 4, 2021 – Sep 6, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 mm/page_isolation: fix potential missing call to unset_migratetype_isolate()

In start_isolate_page_range() undo path, pfn_to_online_page() just checks the first pfn in a pageblock while __first_valid_page() will traverse the pageblock until the first online pfn is found. So we may miss the call to unset_migratetype_isolate() in undo path and pages will remain isolated unexpectedly. Fix this by calling undo_isolate_page_range() and this will also help to remove some duplicated codes.

Fixes 2ce13640b3f4 ("mm: __first_valid_page skip over offline pages")
---
 mm/page_isolation.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
mm/page_isolation.c +1 -8
index 471e3a13b541..9bb562d5d194 100644
@@ -202,14 +202,7 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
 	}
 	return 0;
 undo:
-	for (pfn = start_pfn;
-	     pfn < undo_pfn;
-	     pfn += pageblock_nr_pages) {
-		struct page *page = pfn_to_online_page(pfn);
-		if (!page)
-			continue;
-		unset_migratetype_isolate(page, migratetype);
-	}
+	undo_isolate_page_range(start_pfn, undo_pfn, migratetype);
 
 	return -EBUSY;
 }
Signature · 1 line
2.23.0
#1 lore raw
Quoted 8 lines · Miaohe Lin

In start_isolate_page_range() undo path, pfn_to_online_page() just checks the first pfn in a pageblock while __first_valid_page() will traverse the pageblock until the first online pfn is found. So we may miss the call to unset_migratetype_isolate() in undo path and pages will remain isolated unexpectedly. Fix this by calling undo_isolate_page_range() and this will also help to remove some duplicated codes.

Fixes 2ce13640b3f4 ("mm: __first_valid_page skip over offline pages")

While that is true, we shouldn't ever trigger, neither via cma, virtio-mem nor memory offlining, because essentially all operate on MAX_ORDER -1 -aligned ranges without memory holes.

Quoted 13 lines
---
  mm/page_isolation.c | 9 +--------
  1 file changed, 1 insertion(+), 8 deletions(-)
mm/page_isolation.c +0 -0
index 471e3a13b541..9bb562d5d194 100644
@@ -202,14 +202,7 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
  	}
  	return 0;
  undo:

mm/page_isolation.c int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn, · line 206

Quoted 10 lines
mm/page_isolation.c +1 -8
-	for (pfn = start_pfn;
-	     pfn < undo_pfn;
-	     pfn += pageblock_nr_pages) {
-		struct page *page = pfn_to_online_page(pfn);
-		if (!page)
-			continue;
-		unset_migratetype_isolate(page, migratetype);
-	}
+	undo_isolate_page_range(start_pfn, undo_pfn, migratetype);
 

It'd be even cleaner to drop the label completely and call it from the single callsite. We can even avoid undo_pfn ...

if (page && set_migratetype_isolate(page, migratetype, flags)) {
	undo_isolate_page_range(start_pfn, pfn, migratetype);
	return -EBUSY;
}

If pfn == start_pfn, undo_isolate_page_range() will simply do nothing.

Quoted 3 lines
mm/page_isolation.c +0 -0
  	return -EBUSY;
  }
Signature · 3 lines
Thanks,

David / dhildenb
author
#2 lore raw
Quoted 11 lines · David Hildenbrand
Quoted 8 lines · Miaohe Lin

In start_isolate_page_range() undo path, pfn_to_online_page() just checks the first pfn in a pageblock while __first_valid_page() will traverse the pageblock until the first online pfn is found. So we may miss the call to unset_migratetype_isolate() in undo path and pages will remain isolated unexpectedly. Fix this by calling undo_isolate_page_range() and this will also help to remove some duplicated codes.

Fixes 2ce13640b3f4 ("mm: __first_valid_page skip over offline pages")

While that is true, we shouldn't ever trigger, neither via cma, virtio-mem nor memory offlining, because essentially all operate on MAX_ORDER -1 -aligned ranges without memory holes.

I think this should never trigger too. It's a theoretical issue. So is the Fixes tag necessary ?

Quoted 27 lines
Quoted 16 lines

---
  mm/page_isolation.c | 9 +--------

  1 file changed, 1 insertion(+), 8 deletions(-)
mm/page_isolation.c +0 -0
index 471e3a13b541..9bb562d5d194 100644
@@ -202,14 +202,7 @@ int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
       }
       return 0;

  undo:
-    for (pfn = start_pfn;
-         pfn < undo_pfn;

Quoted 8 lines

-         pfn += pageblock_nr_pages) {
-        struct page *page = pfn_to_online_page(pfn); -        if (!page)
-            continue;
-        unset_migratetype_isolate(page, migratetype); -    }
+    undo_isolate_page_range(start_pfn, undo_pfn, migratetype);

It'd be even cleaner to drop the label completely and call it from the single callsite. We can even avoid undo_pfn ...

Quoted 5 lines

if (page && set_migratetype_isolate(page, migratetype, flags)) { undo_isolate_page_range(start_pfn, pfn, migratetype); return -EBUSY;
}

Looks much better. Will do it later. Many thanks. :)

Quoted 6 lines

If pfn == start_pfn, undo_isolate_page_range() will simply do nothing.

Quoted 3 lines

      return -EBUSY;
  }

#3 lore raw
Quoted 9 lines · Miaohe Lin
Quoted 8 lines · David Hildenbrand
Quoted 7 lines · Miaohe Lin

In start_isolate_page_range() undo path, pfn_to_online_page() just checks the first pfn in a pageblock while __first_valid_page() will traverse the pageblock until the first online pfn is found. So we may miss the call to unset_migratetype_isolate() in undo path and pages will remain isolated unexpectedly. Fix this by calling undo_isolate_page_range() and this will also help to remove some duplicated codes.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Fixes 2ce13640b3f4 ("mm: __first_valid_page skip over offline pages")

While that is true, we shouldn't ever trigger, neither via cma, virtio-mem nor memory offlining, because essentially all operate on MAX_ORDER -1 -aligned ranges without memory holes.

I think this should never trigger too. It's a theoretical issue. So is the Fixes tag necessary ?

I think it's one of these "let's add Fixes: but no need for Cc: stable".

BUT in older kernels we could have triggered this via memory offlining eventually ... before c5e79ef561b0 ("mm/memory_hotplug.c: don't allow to online/offline memory blocks with holes") ... so maybe even a Cc: stable?

Signature · 3 lines
Thanks,

David / dhildenb
author
#4 lore raw
Quoted 12 lines · David Hildenbrand
Quoted 11 lines · Miaohe Lin
Quoted 10 lines · David Hildenbrand
Quoted 8 lines · Miaohe Lin

In start_isolate_page_range() undo path, pfn_to_online_page() just checks the first pfn in a pageblock while __first_valid_page() will traverse the pageblock until the first online pfn is found. So we may miss the call to unset_migratetype_isolate() in undo path and pages will remain isolated unexpectedly. Fix this by calling undo_isolate_page_range() and this will also help to remove some duplicated codes.

Fixes 2ce13640b3f4 ("mm: __first_valid_page skip over offline pages")
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

While that is true, we shouldn't ever trigger, neither via cma, virtio-mem nor memory offlining, because essentially all operate on MAX_ORDER -1 -aligned ranges without memory holes.

I think this should never trigger too. It's a theoretical issue. So is the Fixes tag necessary ?

I think it's one of these "let's add Fixes: but no need for Cc: stable".

BUT in older kernels we could have triggered this via memory offlining eventually ... before c5e79ef561b0 ("mm/memory_hotplug.c: don't allow to online/offline memory blocks with holes") ... so maybe even a Cc: stable?

Looks like it could happen in older kernels. Maybe a Cc: stable is necessary. Many thanks.

Quoted 1 line