The patch titled Subject: mm: mlock: avoid folio_within_range() on KSM pages has been added to the -mm mm-unstable branch. Its filename is mm-mlock-avoid-folio_within_range-on-ksm-pages.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-mlock-avoid-folio_within_range-on-ksm-pages.patch This patch will later appear in the mm-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: Hugh Dickins <hughd@xxxxxxxxxx> Subject: mm: mlock: avoid folio_within_range() on KSM pages Date: Mon, 23 Oct 2023 23:38:41 -0700 (PDT) Since commit dc68badcede4 ("mm: mlock: update mlock_pte_range to handle large folio") I've just occasionally seen VM_WARN_ON_FOLIO(folio_test_ksm) warnings from folio_within_range(), in a splurge after testing with KSM hyperactive. folio_referenced_one()'s use of folio_within_vma() is safe because it checks folio_test_large() first; but allow_mlock_munlock() needs to do the same to avoid those warnings (or check !folio_test_ksm() itself? or move either check into folio_within_range()? hard to tell without more examples of its use). Link: https://lkml.kernel.org/r/23852f6a-5bfa-1ffd-30db-30c5560ad426@xxxxxxxxxx Fixes: dc68badcede4 ("mm: mlock: update mlock_pte_range to handle large folio") Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx> Reviewed-by: Yin Fengwei <fengwei.yin@xxxxxxxxx> Cc: Lorenzo Stoakes <lstoakes@xxxxxxxxx> Cc: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> Cc: Stefan Roesch <shr@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/mlock.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/mlock.c~mm-mlock-avoid-folio_within_range-on-ksm-pages +++ a/mm/mlock.c @@ -346,6 +346,10 @@ static inline bool allow_mlock_munlock(s if (!(vma->vm_flags & VM_LOCKED)) return true; + /* folio_within_range() cannot take KSM, but any small folio is OK */ + if (!folio_test_large(folio)) + return true; + /* folio not in range [start, end), skip mlock */ if (!folio_within_range(folio, vma, start, end)) return false; _ Patches currently in -mm which might be from hughd@xxxxxxxxxx are hugetlbfs-drop-shared-numa-mempolicy-pretence.patch kernfs-drop-shared-numa-mempolicy-hooks.patch mempolicy-fix-migrate_pages2-syscall-return-nr_failed.patch mempolicy-trivia-delete-those-ancient-pr_debugs.patch mempolicy-trivia-slightly-more-consistent-naming.patch mempolicy-trivia-use-pgoff_t-in-shared-mempolicy-tree.patch mempolicy-mpol_shared_policy_init-without-pseudo-vma.patch mempolicy-remove-confusing-mpol_mf_lazy-dead-code.patch mm-add-page_rmappable_folio-wrapper.patch mempolicy-alloc_pages_mpol-for-numa-policy-without-vma.patch mempolicy-mmap_lock-is-not-needed-while-migrating-folios.patch mempolicy-migration-attempt-to-match-interleave-nodes.patch ext4-add-__gfp_nowarn-to-gfp_nowait-in-readahead.patch mm-mlock-avoid-folio_within_range-on-ksm-pages.patch