Merge tag 'mm-stable-2024-03-13-20-04' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / mm / userfaultfd.c
index a0331ba..712160c 100644 (file)
@@ -1017,9 +1017,6 @@ static int move_present_pte(struct mm_struct *mm,
                goto out;
        }
 
-       folio_move_anon_rmap(src_folio, dst_vma);
-       WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
-
        orig_src_pte = ptep_clear_flush(src_vma, src_addr, src_pte);
        /* Folio got pinned from under us. Put it back and fail the move. */
        if (folio_maybe_dma_pinned(src_folio)) {
@@ -1028,6 +1025,9 @@ static int move_present_pte(struct mm_struct *mm,
                goto out;
        }
 
+       folio_move_anon_rmap(src_folio, dst_vma);
+       WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
+
        orig_dst_pte = mk_pte(&src_folio->page, dst_vma->vm_page_prot);
        /* Follow mremap() behavior and treat the entry dirty after the move */
        orig_dst_pte = pte_mkwrite(pte_mkdirty(orig_dst_pte), dst_vma);