The patch titled Subject: minor cleanup according to Peter Xu has been added to the -mm mm-hotfixes-unstable branch. Its filename is mm-fix-kernel-bug-when-userfaultfd_move-encounters-swapcache-fix.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-fix-kernel-bug-when-userfaultfd_move-encounters-swapcache-fix.patch This patch will later appear in the mm-hotfixes-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Barry Song <v-songbaohua@xxxxxxxx> Subject: minor cleanup according to Peter Xu Date: Wed, 26 Feb 2025 15:22:17 +1300 According to Peter Xu: 1. Unnecessary line move. 2. Can drop this folio check as it just did check "!IS_ERR_OR_NULL(folio)" 3. Not sure if it can do any harm, but maybe still nicer to put swap before locking folio. Link: https://lkml.kernel.org/r/20250226024411.47092-1-21cnbao@xxxxxxxxx Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx> Cc: Peter Xu <peterx@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/userfaultfd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/mm/userfaultfd.c~mm-fix-kernel-bug-when-userfaultfd_move-encounters-swapcache-fix +++ a/mm/userfaultfd.c @@ -1105,8 +1105,8 @@ static int move_swap_pte(struct mm_struc orig_src_pte = ptep_get_and_clear(mm, src_addr, src_pte); set_pte_at(mm, dst_addr, dst_pte, orig_src_pte); - double_pt_unlock(dst_ptl, src_ptl); + return 0; } @@ -1373,7 +1373,7 @@ retry: folio = filemap_get_folio(swap_address_space(entry), swap_cache_index(entry)); if (!IS_ERR_OR_NULL(folio)) { - if (folio && folio_test_large(folio)) { + if (folio_test_large(folio)) { err = -EBUSY; folio_put(folio); goto out; @@ -1384,10 +1384,10 @@ retry: pte_unmap(&orig_src_pte); pte_unmap(&orig_dst_pte); src_pte = dst_pte = NULL; - /* now we can block and wait */ - folio_lock(src_folio); put_swap_device(si); si = NULL; + /* now we can block and wait */ + folio_lock(src_folio); goto retry; } } _ Patches currently in -mm which might be from v-songbaohua@xxxxxxxx are mm-fix-kernel-bug-when-userfaultfd_move-encounters-swapcache.patch mm-fix-kernel-bug-when-userfaultfd_move-encounters-swapcache-fix.patch mm-set-folio-swapbacked-iff-folios-are-dirty-in-try_to_unmap_one.patch mm-support-tlbbatch-flush-for-a-range-of-ptes.patch mm-support-batched-unmap-for-lazyfree-large-folios-during-reclamation.patch mm-avoid-splitting-pmd-for-lazyfree-pmd-mapped-thp-in-try_to_unmap.patch