]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm/userfaultfd: don't consider uffd-wp bit of writable migration entries
authorDavid Hildenbrand <david@redhat.com>
Wed, 5 Apr 2023 16:02:36 +0000 (18:02 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 5 Apr 2023 23:02:57 +0000 (16:02 -0700)
commite8c7ecb290fe405dedc3f8ccc180092f07624b26
tree8a5300a26730987c2b254d0333b78248edc6d2a4
parent9cf8e4b570b71fd8416dc1dd27d89b037f0a787b
mm/userfaultfd: don't consider uffd-wp bit of writable migration entries

If we end up with a writable migration entry that has the uffd-wp bit set,
we already messed up: the source PTE/PMD was writable, which means we
could have modified the page without notifying uffd first.  Setting the
uffd-wp bit always implies converting migration entries to !writable
migration entries.

Commit 8f34f1eac382 ("mm/userfaultfd: fix uffd-wp special cases for
fork()") documents that "3.  Forget to carry over uffd-wp bit for a write
migration huge pmd entry", but it doesn't really say why that should be
relevant.

So let's remove that code to avoid hiding an eventual underlying issue (in
the future, we might want to warn when creating writable migration entries
that have the uffd-wp bit set -- or even better when turning a PTE
writable that still has the uffd-wp bit set).

This now matches the handling for hugetlb migration entries in
hugetlb_change_protection().

In copy_huge_pmd()/copy_nonpresent_pte()/copy_hugetlb_page_range(), we
still transfer the uffd-bit also for writable migration entries, but
simply because we have unified handling for "writable" and
"readable-exclusive" migration entries, and we care about transferring the
uffd-wp bit for the latter.

Link: https://lkml.kernel.org/r/20230405160236.587705-3-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/huge_memory.c
mm/mprotect.c