Skip to content

Commit f857236

Browse files
xzpeterakpm00
authored andcommitted
mm/memory: fix missing pte marker for !page on pte zaps
Commit 0cf18e8 of large folio zap work broke uffd-wp. Now mm's uffd unit test "wp-unpopulated" will trigger this WARN_ON_ONCE(). The WARN_ON_ONCE() asserts that an VMA cannot be registered with userfaultfd-wp if it contains a !normal page, but it's actually possible. One example is an anonymous vma, register with uffd-wp, read anything will install a zero page. Then when zap on it, this should trigger. What's more, removing that WARN_ON_ONCE may not be enough either, because we should also not rely on "whether it's a normal page" to decide whether pte marker is needed. For example, one can register wr-protect over some DAX regions to track writes when UFFD_FEATURE_WP_ASYNC enabled, in which case it can have page==NULL for a devmap but we may want to keep the marker around. Link: https://lkml.kernel.org/r/20240313213107.235067-1-peterx@redhat.com Fixes: 0cf18e8 ("mm/memory: handle !page case in zap_present_pte() separately") Signed-off-by: Peter Xu <peterx@redhat.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Muhammad Usama Anjum <usama.anjum@collabora.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 4cece76 commit f857236

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

mm/memory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,9 @@ static inline int zap_present_ptes(struct mmu_gather *tlb,
15361536
ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm);
15371537
arch_check_zapped_pte(vma, ptent);
15381538
tlb_remove_tlb_entry(tlb, pte, addr);
1539-
VM_WARN_ON_ONCE(userfaultfd_wp(vma));
1539+
if (userfaultfd_pte_wp(vma, ptent))
1540+
zap_install_uffd_wp_if_needed(vma, addr, pte, 1,
1541+
details, ptent);
15401542
ksm_might_unmap_zero_page(mm, ptent);
15411543
return 1;
15421544
}

0 commit comments

Comments
 (0)