Skip to contentSkip to conversation

mm: avoid VM_BUG_ON when try to map an anon large folio to zero page.

PATCH Applied Zi Yan 3 participants 3 messages Oct 23, 2024

Subsystems (3)
lore
Share & tools
lore

Zi Yan

author reviewer
#0 lore raw

PATCH 1/1 mm: avoid VM_BUG_ON when try to map an anon large folio to zero page.

An anonymous large folio can be split into non order-0 folios, try_to_map_unused_to_zeropage() should not VM_BUG_ON compound pages but just return false. This fixes the crash when splitting anonymous large folios to non order-0 folios.

Fixes b1f202060afe ("mm: remap unused subpages to shared zeropage when splitting isolated thp")
---
 mm/migrate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/migrate.c +2 -1
index e950fd62607f..7ffdbe078aa7 100644
@@ -206,7 +206,8 @@ static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw,
 	pte_t newpte;
 	void *addr;
 
-	VM_BUG_ON_PAGE(PageCompound(page), page);
+	if (PageCompound(page))
+		return false;
 	VM_BUG_ON_PAGE(!PageAnon(page), page);
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(pte_present(*pvmw->pte), page);
Signature · 1 line
2.45.2
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Zi Yan

An anonymous large folio can be split into non order-0 folios, try_to_map_unused_to_zeropage() should not VM_BUG_ON compound pages but just return false. This fixes the crash when splitting anonymous large folios to non order-0 folios.

Fixes b1f202060afe ("mm: remap unused subpages to shared zeropage when splitting isolated thp")
---
  mm/migrate.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
mm/migrate.c +0 -0
index e950fd62607f..7ffdbe078aa7 100644

mm/migrate.c static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw, · line 213

Quoted 9 lines
mm/migrate.c +2 -1
@@ -206,7 +206,8 @@ static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw,
  	pte_t newpte;
  	void *addr;
 
-	VM_BUG_ON_PAGE(PageCompound(page), page);
+	if (PageCompound(page))
+		return false;
  	VM_BUG_ON_PAGE(!PageAnon(page), page);
  	VM_BUG_ON_PAGE(!PageLocked(page), page);
  	VM_BUG_ON_PAGE(pte_present(*pvmw->pte), page);

Would read nicer in 2024 when working on folios ;)

Signature · 3 lines
Cheers,

David / dhildenb
Acked-by on v1 1/1
#2 lore raw
In reply to Zi Yan
Quoted 16 lines · Zi Yan

An anonymous large folio can be split into non order-0 folios, try_to_map_unused_to_zeropage() should not VM_BUG_ON compound pages but just return false. This fixes the crash when splitting anonymous large folios to non order-0 folios.

Fixes b1f202060afe ("mm: remap unused subpages to shared zeropage when splitting isolated thp")
---
 mm/migrate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/migrate.c +0 -0
index e950fd62607f..7ffdbe078aa7 100644

mm/migrate.c static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw, · line 213

Quoted 9 lines
mm/migrate.c +2 -1
@@ -206,7 +206,8 @@ static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw,
 	pte_t newpte;
 	void *addr;
 
-	VM_BUG_ON_PAGE(PageCompound(page), page);
+	if (PageCompound(page))
+		return false;
 	VM_BUG_ON_PAGE(!PageAnon(page), page);
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(pte_present(*pvmw->pte), page);

Thanks for fixing it!