From: Josef Bacik migrate_vma_collect_pmd() looks up the folio of migrate->fault_page once, when it is entered, at which point the folio is locked. The fault folio is assumed not to change after this, however if migrate_vma_split_folio() splits a PTE-mapped large folio which contains the fault page, the fault page ends up in a different folio. Resolve the issue by looking up fault_folio again after each restart of the walk. Fixes: 022a12deda53 ("mm/migrate_device: handle partially mapped folios during collection") Cc: Signed-off-by: Josef Bacik [ ljs: pared down commit message ] Signed-off-by: Lorenzo Stoakes (ARM) --- mm/migrate_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index ae795fdf36f4..45e571dbfb4c 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -233,11 +233,14 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, struct mm_struct *mm = vma->vm_mm; unsigned long addr = start, unmapped = 0; spinlock_t *ptl; - struct folio *fault_folio = migrate->fault_page ? - page_folio(migrate->fault_page) : NULL; + struct folio *fault_folio; pte_t *ptep; again: + /* The fault page is in another folio once its folio has been split */ + fault_folio = migrate->fault_page ? + page_folio(migrate->fault_page) : NULL; + /* [start, addr) is collected if we get here after splitting a folio */ if (pmd_trans_huge(*pmdp) || !pmd_present(*pmdp)) { int ret = migrate_vma_collect_huge_pmd(pmdp, addr, end, walk, fault_folio); -- 2.56.0