Re: [PATCH RFC] mm: Fix kernel BUG when userfaultfd_move encounters swapcache

From: Matthew Wilcox
Date: Wed Feb 19 2025 - 15:58:43 EST


On Thu, Feb 20, 2025 at 09:37:50AM +1300, Barry Song wrote:
> > How complex would that be? Is it a matter of adding
> > folio_maybe_dma_pinned() checks, doing folio_move_anon_rmap() and
> > folio->index = linear_page_index like in move_present_pte() or
> > something more?
>
> My main concern is still with large folios that require a split_folio()
> during move_pages(), as the entire folio shares the same index and
> anon_vma. However, userfaultfd_move() moves pages individually,
> making a split necessary.
>
> However, in split_huge_page_to_list_to_order(), there is a:
>
> if (folio_test_writeback(folio))
> return -EBUSY;
>
> This is likely true for swapcache, right?

I don't see why? When they get moved to the swap cache, yes, they're
immediately written back, but after being swapped back in, they stay in
the swap cache, so they don't have to be moved back to the swap cache.
Right?