* [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
@ 2026-11-18 4:28 Tal Zussman
2026-11-18 4:28 ` [PATCH v3 1/9] userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings Tal Zussman
` (12 more replies)
0 siblings, 13 replies; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Tal Zussman,
Breno Leitao, Thomas Hellström, Lyude Paul,
Danilo Krummrich, Felix Kuehling, Jason Gunthorpe,
Leon Romanovsky, dri-devel, intel-xe, nouveau, amd-gfx
This is a first batch of userfaultfd fixes, with more to come.
These were found by a mix of regular old LLM review and by having an LLM
write a TLA+ model of uffd interactions with PTE bits and other state
and seeing what issues fell out.
Most of these fix places where mm code loses uffd-wp or RWP protection
while moving or migrating an entry. Userspace then either misses writes
and accesses, or gets pages reported that nobody touched.
There is also a hang in UFFDIO_MOVE, and UFFDIO_ZEROPAGE modifying a
file through a private mapping.
Patches 1-2: UFFDIO_ZEROPAGE and UFFDIO_MOVE fixes, cc stable
Patch 3: PAGEMAP_SCAN write-protect vs. writable migration
entries, cc stable
Patch 4: warn on a writable migration entry with the uffd bit set
Patch 5: PAGEMAP_SCAN write-protect vs. device-private THPs
Patch 6: UFFDIO_MOVE of the huge zero page from an RWP source
Patch 7: mremap() losing uffd state when a move fails halfway
Patch 8: migrate_vma losing uffd state of a zero page
Patch 9: hugetlb alignment checks in UFFDIO_REGISTER and
UFFDIO_UNREGISTER
A few of the fixes change what userspace sees:
- UFFDIO_ZEROPAGE on a private file mapping no longer fails with
-EEXIST where the file already has a page, on an mm that cannot use
the zero page (patch 1)
- UFFDIO_MOVE returns -EEXIST for any huge destination PMD, not only
for a present THP (patch 2)
- UFFDIO_UNREGISTER with a misaligned hugetlb end fails before
unregistering anything, also if that hugetlb VMA is not registered
(patch 9)
- UFFDIO_REGISTER and UFFDIO_UNREGISTER accept a misaligned start that
lies in a gap before the first hugetlb VMA of the range (patch 9)
- UFFDIO_REGISTER returns -EINVAL rather than -EPERM for a misaligned
end in a hugetlb VMA without VM_MAYWRITE (patch 9)
Patch 6 has little user impact on its own. It is included because,
together with patch 7, it allows removing clear_uffd_wp_pmd().
Patch 7 adds spurious write faults on shmem and hugetlb after mremap():
when dropping uffd protection there, change_protection() makes writable
pages that were never protected read-only. UFFDIO_UNREGISTER and
UFFDIO_WRITEPROTECT already behave this way and lead to the same
spurious faults. This will be fixed in change_protection() in a separate
series.
Based on mm-new.
---
Changes in v3:
- Collect tags (Thanks David!)
- Patch 1: use vma_is_cow_mapping(), per David
- Patch 4: warn on a writable migration entry with the uffd bit set, and
make the PMD path match the PTE path, per David.
- Patch 4: Drop the Fixes: tag and the review tags due to changes
- Patch 8: add helpers and read the PMD once with pmdp_get(), per
David
- Patch 9: move the hugetlb alignment checks into a helper and use it in
both ioctls, per David
- Link to v2: https://patch.msgid.link/20261116-uffd-state-fixes-v2-0-4397a0196479@columbia.edu
Changes in v2:
- Collect tags (Thanks Kiryl, Lorenzo, Gregory, Alistair!)
- Patch 2: say "softleaf entry" in the commit message, per Lorenzo
- Patch 3: add softleaf_is_writable() and softleaf_mkreadable() to
leafops.h and rename the helpers to say softleaf, per Lorenzo
- Patch 3: add Reported-by and Closes for Breno's report, and cc stable
- Patch 4: explain in the commit message how PAGEMAP_SCAN set the uffd
bit on writable migration entries, per Lorenzo
- Patch 5: use pmd_is_valid_softleaf() rather than open-coding it, per
Lorenzo
- Patch 7: say "write faults" rather than "minor faults" in the commit
message, per Kiryl
- Patch 7: trim the commit message, per Lorenzo and Gregory
- Patch 8: trim the commit message, per Gregory
- Patch 8: Cc the GPU driver maintainers and lists, per Gregory and
Alistair
- Patch 9: use IS_ALIGNED() and a local variable for the VMA's ctx, and
shorten the comment, per Lorenzo
- Drop the three guard region patches, per Lorenzo
- Link to v1: https://patch.msgid.link/20261111-uffd-state-fixes-v1-0-00713d368976@columbia.edu
---
Tal Zussman (9):
userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings
userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD
fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect
mm/migrate: warn on a writable migration entry with the uffd bit set
fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
mm/huge_memory: build the moved huge zero PMD from the destination VMA
mm/mremap: resolve uffd state when the context is dropped, not during the move
mm/migrate_device: do not migrate a uffd-protected zero page
mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan
fs/proc/task_mmu.c | 42 ++++++++++++++--
include/linux/leafops.h | 51 +++++++++++++++++++
include/linux/userfaultfd_k.h | 24 +++++++++
mm/huge_memory.c | 38 +++-----------
mm/hugetlb.c | 27 +---------
mm/migrate.c | 7 ++-
mm/migrate_device.c | 34 ++++++++++---
mm/mremap.c | 46 +----------------
mm/userfaultfd.c | 112 ++++++++++++++++--------------------------
9 files changed, 195 insertions(+), 186 deletions(-)
---
base-commit: 25fee5b1762b8799dd8b72c2f6d666eb01680cc7
change-id: 20261106-uffd-state-fixes-d2111e2abd48
Best regards,
--
Tal Zussman <tz2294@columbia.edu>
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 1/9] userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 14:31 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 2/9] userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD Tal Zussman
` (11 subsequent siblings)
12 siblings, 1 reply; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Tal Zussman
If the mm cannot map the shared zero page, UFFDIO_ZEROPAGE falls back to
mfill_atomic_pte_zeroed_folio(), which allocates a zeroed folio and
installs it through vma_uffd_ops(), no matter what kind of mapping it
is. An s390 KVM guest with storage keys or protected virtualization is
such an mm.
For a MAP_PRIVATE shmem mapping, that adds the zeroed folio to the page
cache of the file. That is wrong: a private mapping must never modify
the file it maps, and the file might even be mapped from a read-only fd.
The ioctl can also fail where it should succeed. A missing fault is only
delivered for a hole in the file, but UFFDIO_ZEROPAGE can be called on
an address that did not fault, or can race with a write to the file. If
the file has a page at that offset by then, inserting the zeroed folio
fails and the ioctl returns -EEXIST although nothing is mapped at the
destination address.
What we want is what UFFDIO_ZEROPAGE does on a private mapping when the
shared zero page can be used, and what UFFDIO_COPY does: only check that
nothing is mapped at the destination address, map zeroed memory there,
and leave the page cache alone. The zeroed folio path did that before it
was moved to vm_uffd_ops.
To fix it, pick the ops in the common folio path, as
mfill_atomic_pte_copy() did for UFFDIO_COPY: anon_uffd_ops for a private
mapping, the ops of the VMA otherwise. That makes
mfill_atomic_pte_copy() and mfill_atomic_pte_zeroed_folio() redundant,
so remove them and rename __mfill_atomic_pte() to
mfill_atomic_pte_folio().
While at it, use vma_is_cow_mapping() to check for a private mapping.
UFFDIO_ZEROPAGE no longer modifies the file, and only fails with -EEXIST
if something is already mapped at the destination address.
Fixes: f74991b4e383 ("shmem, userfaultfd: implement shmem uffd operations using vm_uffd_ops")
Cc: stable@vger.kernel.org
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/userfaultfd.c | 46 ++++++++++++++++------------------------------
1 file changed, 16 insertions(+), 30 deletions(-)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index d65184d9a480..e787e9a3ea29 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -531,15 +531,27 @@ static int mfill_copy_folio_retry(struct mfill_state *mfill_state,
return 0;
}
-static int __mfill_atomic_pte(struct mfill_state *state,
- const struct vm_uffd_ops *ops)
+static int mfill_atomic_pte_folio(struct mfill_state *state)
{
+ const struct vm_uffd_ops *ops = vma_uffd_ops(state->vma);
unsigned long dst_addr = state->dst_addr;
unsigned long src_addr = state->src_addr;
uffd_flags_t flags = state->flags;
struct folio *folio;
int ret;
+ /*
+ * The normal page fault path for a MAP_PRIVATE mapping in a
+ * file-backed VMA will invoke the fault, fill the hole in the file and
+ * COW it right away. The result generates plain anonymous memory.
+ * So when we are asked to fill a hole in a MAP_PRIVATE mapping, we'll
+ * generate anonymous memory directly without actually filling the
+ * hole. For the MAP_PRIVATE case the robustness check only happens in
+ * the pagetable (to verify it's still none) and not in the page cache.
+ */
+ if (vma_is_cow_mapping(state->vma))
+ ops = &anon_uffd_ops;
+
if (!ops) {
VM_WARN_ONCE(1, "UFFDIO_COPY for unsupported VMA");
return -EOPNOTSUPP;
@@ -597,32 +609,6 @@ static int __mfill_atomic_pte(struct mfill_state *state,
return ret;
}
-static int mfill_atomic_pte_copy(struct mfill_state *state)
-{
- const struct vm_uffd_ops *ops = vma_uffd_ops(state->vma);
-
- /*
- * The normal page fault path for a MAP_PRIVATE mapping in a
- * file-backed VMA will invoke the fault, fill the hole in the file and
- * COW it right away. The result generates plain anonymous memory.
- * So when we are asked to fill a hole in a MAP_PRIVATE mapping, we'll
- * generate anonymous memory directly without actually filling the
- * hole. For the MAP_PRIVATE case the robustness check only happens in
- * the pagetable (to verify it's still none) and not in the page cache.
- */
- if (!(state->vma->vm_flags & VM_SHARED))
- ops = &anon_uffd_ops;
-
- return __mfill_atomic_pte(state, ops);
-}
-
-static int mfill_atomic_pte_zeroed_folio(struct mfill_state *state)
-{
- const struct vm_uffd_ops *ops = vma_uffd_ops(state->vma);
-
- return __mfill_atomic_pte(state, ops);
-}
-
static int mfill_atomic_pte_zeropage(struct mfill_state *state)
{
struct vm_area_struct *dst_vma = state->vma;
@@ -634,7 +620,7 @@ static int mfill_atomic_pte_zeropage(struct mfill_state *state)
if (mm_forbids_zeropage(dst_vma->vm_mm) ||
(dst_vma->vm_flags & VM_SHARED))
- return mfill_atomic_pte_zeroed_folio(state);
+ return mfill_atomic_pte_folio(state);
_dst_pte = pte_mkspecial(pfn_pte(zero_pfn(dst_addr),
dst_vma->vm_page_prot));
@@ -927,7 +913,7 @@ static __always_inline ssize_t mfill_atomic_pte(struct mfill_state *state)
if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON))
return mfill_atomic_pte_poison(state);
if (uffd_flags_mode_is(flags, MFILL_ATOMIC_COPY))
- return mfill_atomic_pte_copy(state);
+ return mfill_atomic_pte_folio(state);
if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE))
return mfill_atomic_pte_zeropage(state);
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 2/9] userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
2026-11-18 4:28 ` [PATCH v3 1/9] userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 14:33 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 3/9] fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect Tal Zussman
` (10 subsequent siblings)
12 siblings, 1 reply; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Tal Zussman
move_pages() refuses to move into a destination PMD that already maps a
THP, but checks for that with pmd_trans_huge(), which is only true for a
present THP. A device-private THP or a THP under migration is a PMD
softleaf entry and is not refused.
The destination PMD is then treated as if it pointed to a PTE table. It
is not empty, so pte_alloc() leaves it alone, and move_pages_ptes()
fails to map a PTE table from it and returns -EAGAIN. move_pages()
retries on -EAGAIN, with both VMA read locks held. If the source is a
THP, it is split first for nothing.
For a THP under migration, the loop ends once the migration finishes.
A device-private THP can remain in device memory indefinitely, so the
caller of UFFDIO_MOVE hangs until it receives a fatal signal, and
anything in the mm that needs to write-lock one of the VMAs blocks along
with it. This requires a driver that migrates THPs to device memory.
To fix it, check the destination with pmd_is_huge(), which is true for
a present THP and for a PMD softleaf entry. UFFDIO_MOVE now fails with
-EEXIST in these cases, as it already does for a present THP.
Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
Cc: stable@vger.kernel.org
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/userfaultfd.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index e787e9a3ea29..0435ceafe750 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -2021,12 +2021,13 @@ static ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
dst_pmdval = pmdp_get_lockless(dst_pmd);
/*
- * If the dst_pmd is mapped as THP don't override it and just
- * be strict. If dst_pmd changes into TPH after this check, the
- * move_pages_huge_pmd() will detect the change and retry
- * while move_pages_pte() will detect the change and fail.
+ * If the dst_pmd is a huge leaf, present or not, don't
+ * override it and just be strict. If dst_pmd changes into a
+ * leaf after this check, move_pages_huge_pmd() will detect the
+ * change and retry while move_pages_ptes() will fail to map
+ * the PTE table and the next iteration will see the leaf.
*/
- if (unlikely(pmd_trans_huge(dst_pmdval))) {
+ if (unlikely(pmd_is_huge(dst_pmdval))) {
err = -EEXIST;
break;
}
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 3/9] fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
2026-11-18 4:28 ` [PATCH v3 1/9] userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings Tal Zussman
2026-11-18 4:28 ` [PATCH v3 2/9] userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 14:36 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set Tal Zussman
` (9 subsequent siblings)
12 siblings, 1 reply; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Breno Leitao, stable, Tal Zussman
PAGEMAP_SCAN with PM_SCAN_WP_MATCHING write-protects pages in a VMA
registered for async uffd-wp, and sets the uffd bit on non-present
entries as they are. An entry with the uffd bit set must not be
writable, so that the page is write-protected once it is mapped again.
change_protection() therefore downgrades writable migration and
device-private entries to readable ones first, but PAGEMAP_SCAN does
not.
For a writable migration entry at the PTE level,
remove_migration_pte() restores a writable PTE without the uffd bit. So
if a page is under migration while PAGEMAP_SCAN write-protects it, the
write protection is lost. A user tracking writes with async uffd-wp
sees the page reported as written on the next scan although nothing
wrote to it.
With CONFIG_PAGE_TABLE_CHECK, setting the uffd bit on a writable
non-present PTE or PMD also triggers a warning.
To fix it, downgrade writable migration and device-private entries
before setting the uffd bit, as change_protection() does, at the PTE,
PMD, and hugetlb levels.
Add softleaf_is_writable() and softleaf_mkreadable() to leafops.h for
the downgrade. The open-coded copies in change_protection() can be
converted to them separately.
Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
Reported-by: Breno Leitao <leitao@debian.org>
Closes: https://lore.kernel.org/all/avNEgmvYdoukt6MS@gmail.com/
Cc: stable@vger.kernel.org
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
fs/proc/task_mmu.c | 40 +++++++++++++++++++++++++++++++++++---
include/linux/leafops.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 3 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 22361607020d..0127bf9c3f77 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -2395,6 +2395,25 @@ static unsigned long pagemap_page_category(struct pagemap_scan_private *p,
return categories;
}
+/*
+ * An armed entry must not come back writable, so downgrade a writable
+ * migration or device-private entry before giving it the bit, as
+ * change_softleaf_pte() does.
+ */
+static pte_t set_uffd_wp_softleaf_pte(pte_t pte)
+{
+ softleaf_t entry = softleaf_from_pte(pte);
+ pte_t newpte;
+
+ if (!softleaf_is_writable(entry))
+ return pte_swp_mkuffd(pte);
+
+ newpte = softleaf_to_pte(softleaf_mkreadable(entry));
+ if (pte_swp_soft_dirty(pte))
+ newpte = pte_swp_mksoft_dirty(newpte);
+ return pte_swp_mkuffd(newpte);
+}
+
static void make_uffd_wp_pte(struct vm_area_struct *vma,
unsigned long addr, pte_t *pte, pte_t ptent)
{
@@ -2408,7 +2427,7 @@ static void make_uffd_wp_pte(struct vm_area_struct *vma,
set_pte_at(vma->vm_mm, addr, pte,
make_pte_marker(PTE_MARKER_UFFD_WP));
} else {
- ptent = pte_swp_mkuffd(ptent);
+ ptent = set_uffd_wp_softleaf_pte(ptent);
set_pte_at(vma->vm_mm, addr, pte, ptent);
}
}
@@ -2467,6 +2486,21 @@ static unsigned long pagemap_thp_category(struct pagemap_scan_private *p,
return categories;
}
+/* Same as set_uffd_wp_softleaf_pte(), for a PMD. */
+static pmd_t set_uffd_wp_softleaf_pmd(pmd_t pmd)
+{
+ softleaf_t entry = softleaf_from_pmd(pmd);
+ pmd_t newpmd;
+
+ if (!softleaf_is_writable(entry))
+ return pmd_swp_mkuffd(pmd);
+
+ newpmd = softleaf_to_pmd(softleaf_mkreadable(entry));
+ if (pmd_swp_soft_dirty(pmd))
+ newpmd = pmd_swp_mksoft_dirty(newpmd);
+ return pmd_swp_mkuffd(newpmd);
+}
+
static void make_uffd_wp_pmd(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmdp)
{
@@ -2477,7 +2511,7 @@ static void make_uffd_wp_pmd(struct vm_area_struct *vma,
pmd = pmd_mkuffd(old);
set_pmd_at(vma->vm_mm, addr, pmdp, pmd);
} else if (pmd_is_migration_entry(pmd)) {
- pmd = pmd_swp_mkuffd(pmd);
+ pmd = set_uffd_wp_softleaf_pmd(pmd);
set_pmd_at(vma->vm_mm, addr, pmdp, pmd);
}
}
@@ -2547,7 +2581,7 @@ static void make_uffd_wp_huge_pte(struct vm_area_struct *vma,
if (softleaf_is_migration(entry)) {
set_huge_pte_at(vma->vm_mm, addr, ptep,
- pte_swp_mkuffd(ptent), psize);
+ set_uffd_wp_softleaf_pte(ptent), psize);
} else {
pte_t old_pte, new_pte;
diff --git a/include/linux/leafops.h b/include/linux/leafops.h
index 4c1476ae3234..4c016fc28690 100644
--- a/include/linux/leafops.h
+++ b/include/linux/leafops.h
@@ -434,6 +434,57 @@ static inline struct folio *softleaf_to_folio(softleaf_t entry)
return folio;
}
+/**
+ * softleaf_is_writable() - Is this leaf entry writable?
+ * @entry: Leaf entry.
+ *
+ * Returns: true for a writable migration or device private entry.
+ */
+static inline bool softleaf_is_writable(softleaf_t entry)
+{
+ return softleaf_is_migration_write(entry) ||
+ softleaf_is_device_private_write(entry);
+}
+
+/**
+ * softleaf_migration_mkreadable() - Downgrade a writable migration entry to a
+ * readable one.
+ * @entry: Leaf entry, softleaf_is_migration_write(@entry) must return true.
+ *
+ * Returns: A readable migration entry for the same PFN, which is exclusive if
+ * the folio is anonymous.
+ */
+static inline softleaf_t softleaf_migration_mkreadable(softleaf_t entry)
+{
+ const pgoff_t offset = swp_offset(entry);
+
+ VM_WARN_ON_ONCE(!softleaf_is_migration_write(entry));
+
+ /* A writable anon migration entry implies AnonExclusive. */
+ if (folio_test_anon(softleaf_to_folio(entry)))
+ return make_readable_exclusive_migration_entry(offset);
+ return make_readable_migration_entry(offset);
+}
+
+/**
+ * softleaf_mkreadable() - Downgrade a writable leaf entry to a readable one.
+ * @entry: Leaf entry.
+ *
+ * Returns: A readable entry if @entry is a writable migration or device
+ * private entry, otherwise @entry unchanged.
+ */
+static inline softleaf_t softleaf_mkreadable(softleaf_t entry)
+{
+ switch (softleaf_type(entry)) {
+ case SOFTLEAF_DEVICE_PRIVATE_WRITE:
+ return make_readable_device_private_entry(swp_offset(entry));
+ case SOFTLEAF_MIGRATION_WRITE:
+ return softleaf_migration_mkreadable(entry);
+ default:
+ return entry;
+ }
+}
+
/**
* softleaf_is_poison_marker() - Is this leaf entry a poison marker?
* @entry: Leaf entry.
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (2 preceding siblings ...)
2026-11-18 4:28 ` [PATCH v3 3/9] fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 9:39 ` David Hildenbrand (Arm)
2026-11-18 14:37 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN Tal Zussman
` (8 subsequent siblings)
12 siblings, 2 replies; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Tal Zussman
A writable migration entry must not have the uffd bit set. Every path
that sets the bit on a migration entry makes the entry read-only first.
PAGEMAP_SCAN was the one path that did not, and it now does as well.
remove_migration_pte() restores such an entry writable and drops the
uffd bit, while remove_migration_pmd() sets the bit and write-protects
the PMD.
Warn in both paths on a writable entry with the uffd bit set. Also make
the PMD path only set the uffd bit for a read-only entry, like the PTE
path, so that the two behave the same, as this should never happen.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/huge_memory.c | 7 +++++--
mm/migrate.c | 7 +++++--
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0d589be136d2..4a4e187ae3b1 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -5225,10 +5225,13 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct folio *folio
if (pmd_swp_soft_dirty(*pvmw->pmd))
pmde = pmd_mksoft_dirty(pmde);
- if (softleaf_is_migration_write(entry))
+ if (softleaf_is_migration_write(entry)) {
+ /* Setting the uffd bit must make the entry read-only. */
+ VM_WARN_ON_ONCE(pmd_swp_uffd(*pvmw->pmd));
pmde = pmd_mkwrite(pmde, vma);
- if (pmd_swp_uffd(*pvmw->pmd))
+ } else if (pmd_swp_uffd(*pvmw->pmd)) {
pmde = pmd_mkuffd(pmde);
+ }
/* See do_swap_page(): restore PAGE_NONE for RWP */
if (pmd_swp_uffd(*pvmw->pmd) && userfaultfd_rwp(vma))
diff --git a/mm/migrate.c b/mm/migrate.c
index 28a8d7734735..c5b0f57343ab 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -397,10 +397,13 @@ static bool remove_migration_pte(struct folio *folio,
else
pte = pte_clear_soft_dirty(pte);
- if (softleaf_is_migration_write(entry))
+ if (softleaf_is_migration_write(entry)) {
+ /* Setting the uffd bit must make the entry read-only. */
+ VM_WARN_ON_ONCE(pte_swp_uffd(old_pte));
pte = pte_mkwrite(pte, vma);
- else if (pte_swp_uffd(old_pte))
+ } else if (pte_swp_uffd(old_pte)) {
pte = pte_mkuffd(pte);
+ }
/* See do_swap_page(): restore PAGE_NONE for RWP */
if (pte_swp_uffd(old_pte) && userfaultfd_rwp(vma))
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (3 preceding siblings ...)
2026-11-18 4:28 ` [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 14:38 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA Tal Zussman
` (7 subsequent siblings)
12 siblings, 1 reply; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Tal Zussman
PAGEMAP_SCAN with PM_SCAN_WP_MATCHING write-protects a huge PMD through
make_uffd_wp_pmd(), which handles a present THP and a migration entry
but does nothing for a device-private THP. The PMD never gets the uffd
bit.
pagemap_thp_category() reports a non-present PMD without the uffd bit as
written. A user tracking writes with async uffd-wp therefore sees every
page of a device-private THP as written on every scan, whether it was
written to or not. This requires a driver that migrates THPs to device
memory.
A device-private PMD must be write-protected like any other huge PMD. To
fix it, pass any valid PMD softleaf entry to set_uffd_wp_softleaf_pmd(),
not only a migration entry. It downgrades a writable entry and sets the
uffd bit. When the THP migrates back, set_pmd_migration_entry() carries
the uffd bit over to the migration entry, so the write protection is
kept.
Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
fs/proc/task_mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 0127bf9c3f77..15cb65c3ab94 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -2510,7 +2510,7 @@ static void make_uffd_wp_pmd(struct vm_area_struct *vma,
old = pmdp_invalidate_ad(vma, addr, pmdp);
pmd = pmd_mkuffd(old);
set_pmd_at(vma->vm_mm, addr, pmdp, pmd);
- } else if (pmd_is_migration_entry(pmd)) {
+ } else if (pmd_is_valid_softleaf(pmd)) {
pmd = set_uffd_wp_softleaf_pmd(pmd);
set_pmd_at(vma->vm_mm, addr, pmdp, pmd);
}
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (4 preceding siblings ...)
2026-11-18 4:28 ` [PATCH v3 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 14:41 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 7/9] mm/mremap: resolve uffd state when the context is dropped, not during the move Tal Zussman
` (6 subsequent siblings)
12 siblings, 1 reply; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Tal Zussman
move_pages_huge_pmd() builds the destination PMD for the huge zero page
by copying the source PMD and clearing its uffd bit, so the destination
keeps the protection of the source.
A source VMA registered for RWP can map the huge zero page with a
PAGE_NONE PMD, and UFFDIO_MOVE does not check how the source is
registered. The destination then gets a PAGE_NONE PMD without the uffd
bit, although nothing asked for that in the destination VMA.
The next access fixes it up through the NUMA hinting fault path. Until
then, the first access to the destination takes a spurious fault and GUP
has to take the fault path. The impact on userspace is small.
The moved entry must have the protection of the destination VMA. To fix
it, build the entry from the vm_page_prot of the destination VMA, as
move_zeropage_pte() does for the small zero page, and keep marking it
soft-dirty. A destination VMA registered for RWP still gets its PMD
re-armed afterwards.
Fixes: 763f43865fc4 ("mm: preserve RWP marker across PTE rewrites")
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/huge_memory.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 4a4e187ae3b1..bb7fe695a615 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2981,9 +2981,9 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm
/* Follow mremap() behavior and treat the entry dirty after the move */
_dst_pmd = pmd_mkwrite(pmd_mkdirty(_dst_pmd), dst_vma);
} else {
- src_pmdval = pmdp_huge_clear_flush(src_vma, src_addr, src_pmd);
- _dst_pmd = move_soft_dirty_pmd(src_pmdval);
- _dst_pmd = clear_uffd_wp_pmd(_dst_pmd);
+ pmdp_huge_clear_flush(src_vma, src_addr, src_pmd);
+ _dst_pmd = folio_mk_pmd(huge_zero_folio, dst_vma->vm_page_prot);
+ _dst_pmd = move_soft_dirty_pmd(pmd_mkspecial(_dst_pmd));
}
/* Re-arm RWP on the moved PMD if dst_vma is RWP-registered. */
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 7/9] mm/mremap: resolve uffd state when the context is dropped, not during the move
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (5 preceding siblings ...)
2026-11-18 4:28 ` [PATCH v3 6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 14:45 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page Tal Zussman
` (5 subsequent siblings)
12 siblings, 1 reply; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Tal Zussman
Without UFFD_FEATURE_EVENT_REMAP, the new VMA of an mremap() is not
registered with userfaultfd, so the uffd state of its entries is cleared
while they are moved. If the move fails halfway, the entries are moved
back into the old VMA, which is still registered, without their uffd
state. Writes and accesses to them are then no longer reported.
To fix it, leave the entries alone during the move and clear the uffd
state of the new VMA in mremap_userfaultfd_prep(), right before dropping
the context, like unregistering does. This walks the page tables of the
new VMA a second time.
This is done with userfaultfd_clear_ptes(), which also makes the PTEs
writable again where that is safe. That removes a spurious write fault
per protected page on private anonymous memory, but adds spurious write
faults on shmem and hugetlb, as change_protection() makes writable pages
that were never protected read-only. UFFDIO_UNREGISTER and
UFFDIO_WRITEPROTECT already behave this way. This will be fixed in
change_protection() separately.
The entries no longer need per-entry handling during the move, so drop
uffd_supports_page_table_move() and clear_uffd_wp_pmd(). Whole page
tables of these VMAs can be moved again.
Fixes: 0cef0bb836e3 ("mm: clear uffd-wp PTE/PMD state on mremap()")
Fixes: 763f43865fc4 ("mm: preserve RWP marker across PTE rewrites")
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Tested-by: Gregory Price (Meta) <gourry@gourry.net>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/huge_memory.c | 25 -------------------------
mm/hugetlb.c | 27 +--------------------------
mm/mremap.c | 46 +---------------------------------------------
mm/userfaultfd.c | 1 +
4 files changed, 3 insertions(+), 96 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index bb7fe695a615..13050a5c0c0f 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2616,18 +2616,6 @@ static pmd_t move_soft_dirty_pmd(pmd_t pmd)
return pmd;
}
-static pmd_t clear_uffd_wp_pmd(pmd_t pmd)
-{
- if (pmd_none(pmd))
- return pmd;
- if (pmd_present(pmd))
- pmd = pmd_clear_uffd(pmd);
- else
- pmd = pmd_swp_clear_uffd(pmd);
-
- return pmd;
-}
-
bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
unsigned long new_addr, pmd_t *old_pmd, pmd_t *new_pmd)
{
@@ -2663,19 +2651,6 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
pgtable_trans_huge_deposit(mm, new_pmd, pgtable);
}
pmd = move_soft_dirty_pmd(pmd);
- if (vma_has_uffd_without_event_remap(vma)) {
- /*
- * See __copy_present_ptes(): normalise the RWP marker
- * so the destination starts accessible instead of
- * taking a numa-hinting fault on first access. Only the
- * marker (protnone + uffd) needs it; leave other present
- * PMDs in the VMA untouched.
- */
- if (pmd_present(pmd) && userfaultfd_rwp(vma) &&
- pmd_uffd(pmd))
- pmd = pmd_modify(pmd, vma->vm_page_prot);
- pmd = clear_uffd_wp_pmd(pmd);
- }
set_pmd_at(mm, new_addr, new_pmd, pmd);
if (force_flush)
flush_pmd_tlb_range(vma, old_addr, old_addr + PMD_SIZE);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 3b7b94012c01..c3d4fdd56647 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5245,7 +5245,6 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
unsigned long new_addr, pte_t *src_pte, pte_t *dst_pte,
unsigned long sz)
{
- bool need_clear_uffd_wp = vma_has_uffd_without_event_remap(vma);
struct hstate *h = hstate_vma(vma);
struct mm_struct *mm = vma->vm_mm;
spinlock_t *src_ptl, *dst_ptl;
@@ -5256,31 +5255,7 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr,
double_pt_lock(dst_ptl, src_ptl);
pte = huge_ptep_get_and_clear(mm, old_addr, src_pte, sz);
-
- if (need_clear_uffd_wp && pte_is_uffd_wp_marker(pte)) {
- huge_pte_clear(mm, new_addr, dst_pte, sz);
- } else {
- if (need_clear_uffd_wp) {
- if (pte_present(pte)) {
- /*
- * See __copy_present_ptes(): normalise the RWP
- * marker so the destination starts accessible
- * instead of taking a numa-hinting fault on
- * first access. Only the marker (protnone + uffd)
- * needs it; leave other present PTEs untouched.
- */
- if (userfaultfd_rwp(vma) && huge_pte_uffd(pte)) {
- pte = huge_pte_modify(pte, vma->vm_page_prot);
- pte = arch_make_huge_pte(pte, huge_page_shift(h),
- vma->vm_flags);
- }
- pte = huge_pte_clear_uffd(pte);
- } else {
- pte = pte_swp_clear_uffd(pte);
- }
- }
- set_huge_pte_at(mm, new_addr, dst_pte, pte, sz);
- }
+ set_huge_pte_at(mm, new_addr, dst_pte, pte, sz);
double_pt_unlock(dst_ptl, src_ptl);
}
diff --git a/mm/mremap.c b/mm/mremap.c
index fff0465f5e06..4564416a6994 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -198,7 +198,6 @@ static int move_ptes(struct pagetable_move_control *pmc,
unsigned long extent, pmd_t *old_pmd, pmd_t *new_pmd)
{
struct vm_area_struct *vma = pmc->old;
- bool need_clear_uffd_wp = vma_has_uffd_without_event_remap(vma);
struct mm_struct *mm = vma->vm_mm;
pte_t *old_ptep, *new_ptep;
pte_t old_pte, pte;
@@ -290,27 +289,7 @@ static int move_ptes(struct pagetable_move_control *pmc,
pte = get_and_clear_ptes(mm, old_addr, old_ptep, nr_ptes);
pte = move_pte(pte, old_addr, new_addr);
pte = move_soft_dirty_pte(pte);
-
- if (need_clear_uffd_wp && pte_is_uffd_wp_marker(pte))
- pte_clear(mm, new_addr, new_ptep);
- else {
- if (need_clear_uffd_wp) {
- if (pte_present(pte)) {
- /*
- * See __copy_present_ptes(): normalise
- * RWP PTEs so the destination starts
- * accessible instead of taking a
- * numa-hinting fault on first access.
- */
- if (userfaultfd_rwp(vma) && pte_uffd(pte))
- pte = pte_modify(pte, vma->vm_page_prot);
- pte = pte_clear_uffd(pte);
- } else {
- pte = pte_swp_clear_uffd(pte);
- }
- }
- set_ptes(mm, new_addr, new_ptep, pte, nr_ptes);
- }
+ set_ptes(mm, new_addr, new_ptep, pte, nr_ptes);
}
lazy_mmu_mode_disable();
@@ -334,25 +313,6 @@ static inline bool arch_supports_page_table_move(void)
}
#endif
-static inline bool uffd_supports_page_table_move(struct pagetable_move_control *pmc)
-{
- /*
- * If we are moving a VMA that has uffd-wp registered but with
- * remap events disabled (new VMA will not be registered with uffd), we
- * need to ensure that the uffd-wp state is cleared from all pgtables.
- * This means recursing into lower page tables in move_page_tables().
- *
- * We might get called with VMAs reversed when recovering from a
- * failed page table move. In that case, the
- * "old"-but-actually-"originally new" VMA during recovery will not have
- * a uffd context. Recursing into lower page tables during the original
- * move but not during the recovery move will cause trouble, because we
- * run into already-existing page tables. So check both VMAs.
- */
- return !vma_has_uffd_without_event_remap(pmc->old) &&
- !vma_has_uffd_without_event_remap(pmc->new);
-}
-
#ifdef CONFIG_HAVE_MOVE_PMD
static bool move_normal_pmd(struct pagetable_move_control *pmc,
pmd_t *old_pmd, pmd_t *new_pmd)
@@ -365,8 +325,6 @@ static bool move_normal_pmd(struct pagetable_move_control *pmc,
if (!arch_supports_page_table_move())
return false;
- if (!uffd_supports_page_table_move(pmc))
- return false;
/*
* The destination pmd shouldn't be established, free_pgtables()
* should have released it.
@@ -434,8 +392,6 @@ static bool move_normal_pud(struct pagetable_move_control *pmc,
if (!arch_supports_page_table_move())
return false;
- if (!uffd_supports_page_table_move(pmc))
- return false;
/*
* The destination pud shouldn't be established, free_pgtables()
* should have released it.
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 0435ceafe750..ada841a9cb2a 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -3161,6 +3161,7 @@ void mremap_userfaultfd_prep(struct vm_area_struct *vma,
up_write(&ctx->map_changing_lock);
} else {
/* Drop uffd context if remap feature not enabled */
+ userfaultfd_clear_ptes(vma, vma->vm_start, vma->vm_end);
userfaultfd_reset_ctx(vma);
}
}
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (6 preceding siblings ...)
2026-11-18 4:28 ` [PATCH v3 7/9] mm/mremap: resolve uffd state when the context is dropped, not during the move Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 9:40 ` David Hildenbrand (Arm)
2026-11-18 14:52 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan Tal Zussman
` (4 subsequent siblings)
12 siblings, 2 replies; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Thomas Hellström,
Lyude Paul, Danilo Krummrich, Felix Kuehling, Jason Gunthorpe,
Leon Romanovsky, dri-devel, intel-xe, nouveau, amd-gfx,
Tal Zussman
Device migration replaces a PTE that maps the zero page with a new PTE
that is built only from the VMA flags, so its userfaultfd WP or RWP
protection is lost. The same applies to the huge zero PMD. Writes and
accesses to the page are then no longer reported to userfaultfd.
To fix it, do not migrate a uffd-protected zero page. Skip it during
collection, and check again under the page table lock before inserting,
as another thread can protect the page after it was collected.
The alternative would be to carry the uffd state over to the new entry,
but a uffd-protected zero page in a range that a driver migrates should
be rare.
While at it, read the PMD once with pmdp_get() in
migrate_vma_collect_huge_pmd().
Fixes: 292924b26024 ("userfaultfd: wp: apply _PAGE_UFFD_WP bit")
Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Felix Kuehling <Felix.Kuehling@amd.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
include/linux/userfaultfd_k.h | 24 ++++++++++++++++++++++++
mm/migrate_device.c | 34 ++++++++++++++++++++++++++--------
2 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
index 5768a3902c7c..54850cdabf5e 100644
--- a/include/linux/userfaultfd_k.h
+++ b/include/linux/userfaultfd_k.h
@@ -246,6 +246,18 @@ static inline bool userfaultfd_huge_pmd_rwp(struct vm_area_struct *vma,
return userfaultfd_rwp(vma) && pmd_uffd(pmd);
}
+static inline bool userfaultfd_pte_protected(struct vm_area_struct *vma,
+ pte_t pte)
+{
+ return userfaultfd_protected(vma) && pte_uffd(pte);
+}
+
+static inline bool userfaultfd_huge_pmd_protected(struct vm_area_struct *vma,
+ pmd_t pmd)
+{
+ return userfaultfd_protected(vma) && pmd_uffd(pmd);
+}
+
static inline bool userfaultfd_armed(struct vm_area_struct *vma)
{
return vma_test_any_mask(vma, __VMA_UFFD_FLAGS);
@@ -390,6 +402,18 @@ static inline bool userfaultfd_huge_pmd_rwp(struct vm_area_struct *vma,
return false;
}
+static inline bool userfaultfd_pte_protected(struct vm_area_struct *vma,
+ pte_t pte)
+{
+ return false;
+}
+
+static inline bool userfaultfd_huge_pmd_protected(struct vm_area_struct *vma,
+ pmd_t pmd)
+{
+ return false;
+}
+
static inline bool userfaultfd_armed(struct vm_area_struct *vma)
{
return false;
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 9e19fadfa65c..60985e9bec8b 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -142,30 +142,38 @@ static int migrate_vma_collect_huge_pmd(pmd_t *pmdp, unsigned long start,
struct folio *folio;
struct migrate_vma *migrate = walk->private;
spinlock_t *ptl;
+ pmd_t pmd;
int ret;
unsigned long write = 0;
ptl = pmd_lock(mm, pmdp);
- if (pmd_none(*pmdp)) {
+ pmd = pmdp_get(pmdp);
+ if (pmd_none(pmd)) {
spin_unlock(ptl);
return migrate_vma_collect_hole(start, end, -1, walk);
}
- if (pmd_trans_huge(*pmdp)) {
+ if (pmd_trans_huge(pmd)) {
if (!(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) {
spin_unlock(ptl);
return migrate_vma_collect_skip(start, end, walk);
}
- folio = pmd_folio(*pmdp);
+ folio = pmd_folio(pmd);
if (is_huge_zero_folio(folio)) {
spin_unlock(ptl);
+ /*
+ * Nothing carries the uffd state of the zero page
+ * over, so skip it if its uffd bit is set.
+ */
+ if (userfaultfd_huge_pmd_protected(walk->vma, pmd))
+ return migrate_vma_collect_skip(start, end, walk);
return migrate_vma_collect_hole(start, end, -1, walk);
}
- if (pmd_write(*pmdp))
+ if (pmd_write(pmd))
write = MIGRATE_PFN_WRITE;
- } else if (!pmd_present(*pmdp)) {
- const softleaf_t entry = softleaf_from_pmd(*pmdp);
+ } else if (!pmd_present(pmd)) {
+ const softleaf_t entry = softleaf_from_pmd(pmd);
if (!softleaf_is_device_private(entry) ||
!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_PRIVATE)) {
@@ -337,6 +345,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
pfn = pte_pfn(pte);
if (is_zero_pfn(pfn) &&
(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM)) {
+ /* See migrate_vma_collect_huge_pmd(). */
+ if (userfaultfd_pte_protected(vma, pte))
+ goto next;
mpfn = MIGRATE_PFN_MIGRATE;
migrate->cpages++;
goto next;
@@ -871,10 +882,14 @@ static int migrate_vma_insert_huge_pmd_page(struct migrate_vma *migrate,
if (userfaultfd_missing(vma))
goto unlock_abort;
- if (is_huge_zero_pmd(*pmdp))
+ if (is_huge_zero_pmd(*pmdp)) {
+ /* The uffd bit can have been set since the collection. */
+ if (userfaultfd_huge_pmd_protected(vma, *pmdp))
+ goto unlock_abort;
flush = true;
- else if (!pmd_none(*pmdp))
+ } else if (!pmd_none(*pmdp)) {
goto unlock_abort;
+ }
add_mm_counter(vma->vm_mm, MM_ANONPAGES, HPAGE_PMD_NR);
folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE);
@@ -1074,6 +1089,9 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate,
if (!is_zero_pfn(pfn))
goto unlock_abort;
+ /* The uffd bit can have been set since the collection. */
+ if (userfaultfd_pte_protected(vma, orig_pte))
+ goto unlock_abort;
flush = true;
} else if (!pte_none(orig_pte))
goto unlock_abort;
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (7 preceding siblings ...)
2026-11-18 4:28 ` [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page Tal Zussman
@ 2026-11-18 4:28 ` Tal Zussman
2026-11-18 9:38 ` David Hildenbrand (Arm)
2026-11-18 14:55 ` Mike Rapoport
2026-11-18 9:41 ` [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) David Hildenbrand (Arm)
` (3 subsequent siblings)
12 siblings, 2 replies; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 4:28 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Tal Zussman
UFFDIO_REGISTER and UFFDIO_UNREGISTER both scan the VMAs of the range
before changing anything. For a hugetlb VMA, userfaultfd_register()
rejects a range whose start or end is not huge page aligned there.
However, userfaultfd_unregister() only checks the start.
An unaligned end only fails later, when vma_modify_flags_uffd() cannot
split the VMA there. At that point, userfaultfd_clear_vma() already
cleared the WP or RWP protection. The ioctl returns -EINVAL and the VMA
stays registered, but accesses to its pages are no longer reported. This
requires a caller passing a misaligned range.
To fix it, move the alignment checks into vma_uffd_range_aligned() and
call it for every VMA in the pre-scan of both ioctls. UFFDIO_UNREGISTER
still returns -EINVAL for such a range, but no longer unregisters the
VMAs before the misaligned one first.
Checking every VMA the same way also changes the following:
- UFFDIO_UNREGISTER now returns -EINVAL if the end is not huge page
aligned in a hugetlb VMA that is not registered. It used to skip that
VMA and succeed.
- Both ioctls now accept a start that is not huge page aligned if it is
not inside any VMA and the first VMA of the range is a hugetlb one.
They used to return -EINVAL, although such a range covers that VMA
from its start, which is always huge page aligned.
- UFFDIO_REGISTER now returns -EINVAL rather than -EPERM if the end is
not huge page aligned in a hugetlb VMA without VM_MAYWRITE.
Fixes: cab350afcbc9 ("userfaultfd: hugetlbfs: allow registration of ranges containing huge pages")
Fixes: f369b07c8614 ("mm/uffd: reset write protection when unregister with wp-mode")
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/userfaultfd.c | 54 ++++++++++++++++++------------------------------------
1 file changed, 18 insertions(+), 36 deletions(-)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index ada841a9cb2a..b80bcc1e03d0 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -3692,6 +3692,20 @@ static __always_inline int validate_range(struct mm_struct *mm,
return validate_unaligned_range(mm, start, len);
}
+static bool vma_uffd_range_aligned(struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ unsigned long size;
+
+ if (!vma_is_hugetlb(vma))
+ return true;
+
+ /* A hugetlb VMA can only be split at a huge page boundary. */
+ size = huge_page_size(hstate_vma(vma));
+ return IS_ALIGNED(max(start, vma->vm_start), size) &&
+ IS_ALIGNED(min(end, vma->vm_end), size);
+}
+
static int userfaultfd_register(struct userfaultfd_ctx *ctx,
unsigned long arg)
{
@@ -3770,17 +3784,6 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
if (!vma)
goto out_unlock;
- /*
- * If the first vma contains huge pages, make sure start address
- * is aligned to huge page size.
- */
- if (vma_is_hugetlb(vma)) {
- unsigned long vma_hpagesize = vma_kernel_pagesize(vma);
-
- if (start & (vma_hpagesize - 1))
- goto out_unlock;
- }
-
/*
* Search for not compatible vmas.
*/
@@ -3797,6 +3800,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
ret = -EINVAL;
if (!vma_can_userfault(cur, vm_flags, wp_async))
goto out_unlock;
+ if (!vma_uffd_range_aligned(cur, start, end))
+ goto out_unlock;
/*
* RWP uses protnone as an access-tracking marker. PROT_NONE
@@ -3820,20 +3825,6 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
ret = -EPERM;
if (unlikely(!(cur->vm_flags & VM_MAYWRITE)))
goto out_unlock;
-
- /*
- * If this vma contains ending address, and huge pages
- * check alignment.
- */
- if (vma_is_hugetlb(cur) && end <= cur->vm_end &&
- end > cur->vm_start) {
- unsigned long vma_hpagesize = vma_kernel_pagesize(cur);
-
- ret = -EINVAL;
-
- if (end & (vma_hpagesize - 1))
- goto out_unlock;
- }
if ((vm_flags & VM_UFFD_WP) && !(cur->vm_flags & VM_MAYWRITE))
goto out_unlock;
@@ -3943,17 +3934,6 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
if (!vma)
goto out_unlock;
- /*
- * If the first vma contains huge pages, make sure start address
- * is aligned to huge page size.
- */
- if (vma_is_hugetlb(vma)) {
- unsigned long vma_hpagesize = vma_kernel_pagesize(vma);
-
- if (start & (vma_hpagesize - 1))
- goto out_unlock;
- }
-
/*
* Search for not compatible vmas.
*/
@@ -3982,6 +3962,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
*/
if (!vma_can_userfault(cur, cur->vm_flags, wp_async))
goto out_unlock;
+ if (!vma_uffd_range_aligned(cur, start, end))
+ goto out_unlock;
found = true;
} for_each_vma_range(vmi, cur, end);
--
2.39.5
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan
2026-11-18 4:28 ` [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan Tal Zussman
@ 2026-11-18 9:38 ` David Hildenbrand (Arm)
2026-11-18 14:55 ` Mike Rapoport
1 sibling, 0 replies; 29+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-18 9:38 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Mike Rapoport, Peter Xu,
James Houghton, Andrea Arcangeli, Suren Baghdasaryan,
Balbir Singh, Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka,
Jann Horn, Pedro Falcato, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel
On 11/18/26 05:28, Tal Zussman wrote:
> UFFDIO_REGISTER and UFFDIO_UNREGISTER both scan the VMAs of the range
> before changing anything. For a hugetlb VMA, userfaultfd_register()
> rejects a range whose start or end is not huge page aligned there.
> However, userfaultfd_unregister() only checks the start.
>
> An unaligned end only fails later, when vma_modify_flags_uffd() cannot
> split the VMA there. At that point, userfaultfd_clear_vma() already
> cleared the WP or RWP protection. The ioctl returns -EINVAL and the VMA
> stays registered, but accesses to its pages are no longer reported. This
> requires a caller passing a misaligned range.
>
> To fix it, move the alignment checks into vma_uffd_range_aligned() and
> call it for every VMA in the pre-scan of both ioctls. UFFDIO_UNREGISTER
> still returns -EINVAL for such a range, but no longer unregisters the
> VMAs before the misaligned one first.
>
> Checking every VMA the same way also changes the following:
>
> - UFFDIO_UNREGISTER now returns -EINVAL if the end is not huge page
> aligned in a hugetlb VMA that is not registered. It used to skip that
> VMA and succeed.
>
> - Both ioctls now accept a start that is not huge page aligned if it is
> not inside any VMA and the first VMA of the range is a hugetlb one.
> They used to return -EINVAL, although such a range covers that VMA
> from its start, which is always huge page aligned.
>
> - UFFDIO_REGISTER now returns -EINVAL rather than -EPERM if the end is
> not huge page aligned in a hugetlb VMA without VM_MAYWRITE.
>
> Fixes: cab350afcbc9 ("userfaultfd: hugetlbfs: allow registration of ranges containing huge pages")
> Fixes: f369b07c8614 ("mm/uffd: reset write protection when unregister with wp-mode")
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
Thanks!
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set
2026-11-18 4:28 ` [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set Tal Zussman
@ 2026-11-18 9:39 ` David Hildenbrand (Arm)
2026-11-18 14:37 ` Mike Rapoport
1 sibling, 0 replies; 29+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-18 9:39 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Mike Rapoport, Peter Xu,
James Houghton, Andrea Arcangeli, Suren Baghdasaryan,
Balbir Singh, Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka,
Jann Horn, Pedro Falcato, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel
On 11/18/26 05:28, Tal Zussman wrote:
> A writable migration entry must not have the uffd bit set. Every path
> that sets the bit on a migration entry makes the entry read-only first.
> PAGEMAP_SCAN was the one path that did not, and it now does as well.
>
> remove_migration_pte() restores such an entry writable and drops the
> uffd bit, while remove_migration_pmd() sets the bit and write-protects
> the PMD.
>
> Warn in both paths on a writable entry with the uffd bit set. Also make
> the PMD path only set the uffd bit for a read-only entry, like the PTE
> path, so that the two behave the same, as this should never happen.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page
2026-11-18 4:28 ` [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page Tal Zussman
@ 2026-11-18 9:40 ` David Hildenbrand (Arm)
2026-11-18 14:52 ` Mike Rapoport
1 sibling, 0 replies; 29+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-18 9:40 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Mike Rapoport, Peter Xu,
James Houghton, Andrea Arcangeli, Suren Baghdasaryan,
Balbir Singh, Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka,
Jann Horn, Pedro Falcato, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, Thomas Hellström,
Lyude Paul, Danilo Krummrich, Felix Kuehling, Jason Gunthorpe,
Leon Romanovsky, dri-devel, intel-xe, nouveau, amd-gfx
On 11/18/26 05:28, Tal Zussman wrote:
> Device migration replaces a PTE that maps the zero page with a new PTE
> that is built only from the VMA flags, so its userfaultfd WP or RWP
> protection is lost. The same applies to the huge zero PMD. Writes and
> accesses to the page are then no longer reported to userfaultfd.
>
> To fix it, do not migrate a uffd-protected zero page. Skip it during
> collection, and check again under the page table lock before inserting,
> as another thread can protect the page after it was collected.
>
> The alternative would be to carry the uffd state over to the new entry,
> but a uffd-protected zero page in a range that a driver migrates should
> be rare.
>
> While at it, read the PMD once with pmdp_get() in
> migrate_vma_collect_huge_pmd().
>
> Fixes: 292924b26024 ("userfaultfd: wp: apply _PAGE_UFFD_WP bit")
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: dri-devel@lists.freedesktop.org
> Cc: intel-xe@lists.freedesktop.org
> Cc: nouveau@lists.freedesktop.org
> Cc: amd-gfx@lists.freedesktop.org
> Reviewed-by: Alistair Popple <apopple@nvidia.com>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (8 preceding siblings ...)
2026-11-18 4:28 ` [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan Tal Zussman
@ 2026-11-18 9:41 ` David Hildenbrand (Arm)
2026-11-18 15:26 ` Tal Zussman
2026-11-18 15:19 ` (subset) " David Hildenbrand
` (2 subsequent siblings)
12 siblings, 1 reply; 29+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-18 9:41 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Mike Rapoport, Peter Xu,
James Houghton, Andrea Arcangeli, Suren Baghdasaryan,
Balbir Singh, Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka,
Jann Horn, Pedro Falcato, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Breno Leitao,
Thomas Hellström, Lyude Paul, Danilo Krummrich,
Felix Kuehling, Jason Gunthorpe, Leon Romanovsky, dri-devel,
intel-xe, nouveau, amd-gfx
On 11/18/26 05:28, Tal Zussman wrote:
> This is a first batch of userfaultfd fixes, with more to come.
>
> These were found by a mix of regular old LLM review and by having an LLM
> write a TLA+ model of uffd interactions with PTE bits and other state
> and seeing what issues fell out.
>
> Most of these fix places where mm code loses uffd-wp or RWP protection
> while moving or migrating an entry. Userspace then either misses writes
> and accesses, or gets pages reported that nobody touched.
> There is also a hang in UFFDIO_MOVE, and UFFDIO_ZEROPAGE modifying a
> file through a private mapping.
>
> Patches 1-2: UFFDIO_ZEROPAGE and UFFDIO_MOVE fixes, cc stable
> Patch 3: PAGEMAP_SCAN write-protect vs. writable migration
> entries, cc stable
> Patch 4: warn on a writable migration entry with the uffd bit set
> Patch 5: PAGEMAP_SCAN write-protect vs. device-private THPs
> Patch 6: UFFDIO_MOVE of the huge zero page from an RWP source
> Patch 7: mremap() losing uffd state when a move fails halfway
> Patch 8: migrate_vma losing uffd state of a zero page
> Patch 9: hugetlb alignment checks in UFFDIO_REGISTER and
> UFFDIO_UNREGISTER
>
> A few of the fixes change what userspace sees:
>
> - UFFDIO_ZEROPAGE on a private file mapping no longer fails with
> -EEXIST where the file already has a page, on an mm that cannot use
> the zero page (patch 1)
> - UFFDIO_MOVE returns -EEXIST for any huge destination PMD, not only
> for a present THP (patch 2)
> - UFFDIO_UNREGISTER with a misaligned hugetlb end fails before
> unregistering anything, also if that hugetlb VMA is not registered
> (patch 9)
> - UFFDIO_REGISTER and UFFDIO_UNREGISTER accept a misaligned start that
> lies in a gap before the first hugetlb VMA of the range (patch 9)
> - UFFDIO_REGISTER returns -EINVAL rather than -EPERM for a misaligned
> end in a hugetlb VMA without VM_MAYWRITE (patch 9)
>
> Patch 6 has little user impact on its own. It is included because,
> together with patch 7, it allows removing clear_uffd_wp_pmd().
>
> Patch 7 adds spurious write faults on shmem and hugetlb after mremap():
> when dropping uffd protection there, change_protection() makes writable
> pages that were never protected read-only. UFFDIO_UNREGISTER and
> UFFDIO_WRITEPROTECT already behave this way and lead to the same
> spurious faults. This will be fixed in change_protection() in a separate
> series.
>
> Based on mm-new.
>
> ---
> Changes in v3:
> - Collect tags (Thanks David!)
> - Patch 1: use vma_is_cow_mapping(), per David
> - Patch 4: warn on a writable migration entry with the uffd bit set, and
> make the PMD path match the PTE path, per David.
> - Patch 4: Drop the Fixes: tag and the review tags due to changes
> - Patch 8: add helpers and read the PMD once with pmdp_get(), per
> David
> - Patch 9: move the hugetlb alignment checks into a helper and use it in
> both ioctls, per David
> - Link to v2: https://patch.msgid.link/20261116-uffd-state-fixes-v2-0-4397a0196479@columbia.edu
>
> Changes in v2:
> - Collect tags (Thanks Kiryl, Lorenzo, Gregory, Alistair!)
> - Patch 2: say "softleaf entry" in the commit message, per Lorenzo
> - Patch 3: add softleaf_is_writable() and softleaf_mkreadable() to
> leafops.h and rename the helpers to say softleaf, per Lorenzo
> - Patch 3: add Reported-by and Closes for Breno's report, and cc stable
> - Patch 4: explain in the commit message how PAGEMAP_SCAN set the uffd
> bit on writable migration entries, per Lorenzo
> - Patch 5: use pmd_is_valid_softleaf() rather than open-coding it, per
> Lorenzo
> - Patch 7: say "write faults" rather than "minor faults" in the commit
> message, per Kiryl
> - Patch 7: trim the commit message, per Lorenzo and Gregory
> - Patch 8: trim the commit message, per Gregory
> - Patch 8: Cc the GPU driver maintainers and lists, per Gregory and
> Alistair
> - Patch 9: use IS_ALIGNED() and a local variable for the VMA's ctx, and
> shorten the comment, per Lorenzo
> - Drop the three guard region patches, per Lorenzo
> - Link to v1: https://patch.msgid.link/20261111-uffd-state-fixes-v1-0-00713d368976@columbia.edu
>
> ---
So, I would be picking up ...
> Tal Zussman (9):
> userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings
> userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD
> fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect
> mm/migrate: warn on a writable migration entry with the uffd bit set
This
> fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
> mm/huge_memory: build the moved huge zero PMD from the destination VMA
This
> mm/mremap: resolve uffd state when the context is dropped, not during the move
> mm/migrate_device: do not migrate a uffd-protected zero page
This
> mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan
After waiting a bit longer for more review. Andrew can take the rest.
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 1/9] userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings
2026-11-18 4:28 ` [PATCH v3 1/9] userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings Tal Zussman
@ 2026-11-18 14:31 ` Mike Rapoport
0 siblings, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:31 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel, stable
On Tue, Nov 17, 2026 at 11:28:41PM -0500, Tal Zussman wrote:
> If the mm cannot map the shared zero page, UFFDIO_ZEROPAGE falls back to
> mfill_atomic_pte_zeroed_folio(), which allocates a zeroed folio and
> installs it through vma_uffd_ops(), no matter what kind of mapping it
> is. An s390 KVM guest with storage keys or protected virtualization is
> such an mm.
>
> For a MAP_PRIVATE shmem mapping, that adds the zeroed folio to the page
> cache of the file. That is wrong: a private mapping must never modify
> the file it maps, and the file might even be mapped from a read-only fd.
>
> The ioctl can also fail where it should succeed. A missing fault is only
> delivered for a hole in the file, but UFFDIO_ZEROPAGE can be called on
> an address that did not fault, or can race with a write to the file. If
> the file has a page at that offset by then, inserting the zeroed folio
> fails and the ioctl returns -EEXIST although nothing is mapped at the
> destination address.
>
> What we want is what UFFDIO_ZEROPAGE does on a private mapping when the
> shared zero page can be used, and what UFFDIO_COPY does: only check that
> nothing is mapped at the destination address, map zeroed memory there,
> and leave the page cache alone. The zeroed folio path did that before it
> was moved to vm_uffd_ops.
>
> To fix it, pick the ops in the common folio path, as
> mfill_atomic_pte_copy() did for UFFDIO_COPY: anon_uffd_ops for a private
> mapping, the ops of the VMA otherwise. That makes
> mfill_atomic_pte_copy() and mfill_atomic_pte_zeroed_folio() redundant,
> so remove them and rename __mfill_atomic_pte() to
> mfill_atomic_pte_folio().
>
> While at it, use vma_is_cow_mapping() to check for a private mapping.
>
> UFFDIO_ZEROPAGE no longer modifies the file, and only fails with -EEXIST
> if something is already mapped at the destination address.
>
> Fixes: f74991b4e383 ("shmem, userfaultfd: implement shmem uffd operations using vm_uffd_ops")
> Cc: stable@vger.kernel.org
> Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> mm/userfaultfd.c | 46 ++++++++++++++++------------------------------
> 1 file changed, 16 insertions(+), 30 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 2/9] userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD
2026-11-18 4:28 ` [PATCH v3 2/9] userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD Tal Zussman
@ 2026-11-18 14:33 ` Mike Rapoport
0 siblings, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:33 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel, stable
On Tue, Nov 17, 2026 at 11:28:42PM -0500, Tal Zussman wrote:
> move_pages() refuses to move into a destination PMD that already maps a
> THP, but checks for that with pmd_trans_huge(), which is only true for a
> present THP. A device-private THP or a THP under migration is a PMD
> softleaf entry and is not refused.
>
> The destination PMD is then treated as if it pointed to a PTE table. It
> is not empty, so pte_alloc() leaves it alone, and move_pages_ptes()
> fails to map a PTE table from it and returns -EAGAIN. move_pages()
> retries on -EAGAIN, with both VMA read locks held. If the source is a
> THP, it is split first for nothing.
>
> For a THP under migration, the loop ends once the migration finishes.
> A device-private THP can remain in device memory indefinitely, so the
> caller of UFFDIO_MOVE hangs until it receives a fatal signal, and
> anything in the mm that needs to write-lock one of the VMAs blocks along
> with it. This requires a driver that migrates THPs to device memory.
>
> To fix it, check the destination with pmd_is_huge(), which is true for
> a present THP and for a PMD softleaf entry. UFFDIO_MOVE now fails with
> -EEXIST in these cases, as it already does for a present THP.
>
> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Cc: stable@vger.kernel.org
> Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> Tested-by: Gregory Price (Meta) <gourry@gourry.net>
> Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> mm/userfaultfd.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 3/9] fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect
2026-11-18 4:28 ` [PATCH v3 3/9] fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect Tal Zussman
@ 2026-11-18 14:36 ` Mike Rapoport
0 siblings, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:36 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel, Breno Leitao, stable
On Tue, Nov 17, 2026 at 11:28:43PM -0500, Tal Zussman wrote:
> PAGEMAP_SCAN with PM_SCAN_WP_MATCHING write-protects pages in a VMA
> registered for async uffd-wp, and sets the uffd bit on non-present
> entries as they are. An entry with the uffd bit set must not be
> writable, so that the page is write-protected once it is mapped again.
> change_protection() therefore downgrades writable migration and
> device-private entries to readable ones first, but PAGEMAP_SCAN does
> not.
>
> For a writable migration entry at the PTE level,
> remove_migration_pte() restores a writable PTE without the uffd bit. So
> if a page is under migration while PAGEMAP_SCAN write-protects it, the
> write protection is lost. A user tracking writes with async uffd-wp
> sees the page reported as written on the next scan although nothing
> wrote to it.
>
> With CONFIG_PAGE_TABLE_CHECK, setting the uffd bit on a writable
> non-present PTE or PMD also triggers a warning.
>
> To fix it, downgrade writable migration and device-private entries
> before setting the uffd bit, as change_protection() does, at the PTE,
> PMD, and hugetlb levels.
>
> Add softleaf_is_writable() and softleaf_mkreadable() to leafops.h for
> the downgrade. The open-coded copies in change_protection() can be
> converted to them separately.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Reported-by: Breno Leitao <leitao@debian.org>
> Closes: https://lore.kernel.org/all/avNEgmvYdoukt6MS@gmail.com/
> Cc: stable@vger.kernel.org
> Tested-by: Gregory Price (Meta) <gourry@gourry.net>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> fs/proc/task_mmu.c | 40 +++++++++++++++++++++++++++++++++++---
> include/linux/leafops.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 88 insertions(+), 3 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set
2026-11-18 4:28 ` [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set Tal Zussman
2026-11-18 9:39 ` David Hildenbrand (Arm)
@ 2026-11-18 14:37 ` Mike Rapoport
1 sibling, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:37 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel
On Tue, Nov 17, 2026 at 11:28:44PM -0500, Tal Zussman wrote:
> A writable migration entry must not have the uffd bit set. Every path
> that sets the bit on a migration entry makes the entry read-only first.
> PAGEMAP_SCAN was the one path that did not, and it now does as well.
>
> remove_migration_pte() restores such an entry writable and drops the
> uffd bit, while remove_migration_pmd() sets the bit and write-protects
> the PMD.
>
> Warn in both paths on a writable entry with the uffd bit set. Also make
> the PMD path only set the uffd bit for a read-only entry, like the PTE
> path, so that the two behave the same, as this should never happen.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> mm/huge_memory.c | 7 +++++--
> mm/migrate.c | 7 +++++--
> 2 files changed, 10 insertions(+), 4 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
2026-11-18 4:28 ` [PATCH v3 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN Tal Zussman
@ 2026-11-18 14:38 ` Mike Rapoport
0 siblings, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:38 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel
On Tue, Nov 17, 2026 at 11:28:45PM -0500, Tal Zussman wrote:
> PAGEMAP_SCAN with PM_SCAN_WP_MATCHING write-protects a huge PMD through
> make_uffd_wp_pmd(), which handles a present THP and a migration entry
> but does nothing for a device-private THP. The PMD never gets the uffd
> bit.
>
> pagemap_thp_category() reports a non-present PMD without the uffd bit as
> written. A user tracking writes with async uffd-wp therefore sees every
> page of a device-private THP as written on every scan, whether it was
> written to or not. This requires a driver that migrates THPs to device
> memory.
>
> A device-private PMD must be write-protected like any other huge PMD. To
> fix it, pass any valid PMD softleaf entry to set_uffd_wp_softleaf_pmd(),
> not only a migration entry. It downgrades a writable entry and sets the
> uffd bit. When the THP migrates back, set_pmd_migration_entry() carries
> the uffd bit over to the migration entry, so the write protection is
> kept.
>
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Tested-by: Gregory Price (Meta) <gourry@gourry.net>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> fs/proc/task_mmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA
2026-11-18 4:28 ` [PATCH v3 6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA Tal Zussman
@ 2026-11-18 14:41 ` Mike Rapoport
0 siblings, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:41 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel
On Tue, Nov 17, 2026 at 11:28:46PM -0500, Tal Zussman wrote:
> move_pages_huge_pmd() builds the destination PMD for the huge zero page
> by copying the source PMD and clearing its uffd bit, so the destination
> keeps the protection of the source.
>
> A source VMA registered for RWP can map the huge zero page with a
> PAGE_NONE PMD, and UFFDIO_MOVE does not check how the source is
> registered. The destination then gets a PAGE_NONE PMD without the uffd
> bit, although nothing asked for that in the destination VMA.
>
> The next access fixes it up through the NUMA hinting fault path. Until
> then, the first access to the destination takes a spurious fault and GUP
> has to take the fault path. The impact on userspace is small.
>
> The moved entry must have the protection of the destination VMA. To fix
> it, build the entry from the vm_page_prot of the destination VMA, as
> move_zeropage_pte() does for the small zero page, and keep marking it
> soft-dirty. A destination VMA registered for RWP still gets its PMD
> re-armed afterwards.
>
> Fixes: 763f43865fc4 ("mm: preserve RWP marker across PTE rewrites")
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Tested-by: Gregory Price (Meta) <gourry@gourry.net>
> Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> mm/huge_memory.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 7/9] mm/mremap: resolve uffd state when the context is dropped, not during the move
2026-11-18 4:28 ` [PATCH v3 7/9] mm/mremap: resolve uffd state when the context is dropped, not during the move Tal Zussman
@ 2026-11-18 14:45 ` Mike Rapoport
0 siblings, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:45 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel
On Tue, Nov 17, 2026 at 11:28:47PM -0500, Tal Zussman wrote:
> Without UFFD_FEATURE_EVENT_REMAP, the new VMA of an mremap() is not
> registered with userfaultfd, so the uffd state of its entries is cleared
> while they are moved. If the move fails halfway, the entries are moved
> back into the old VMA, which is still registered, without their uffd
> state. Writes and accesses to them are then no longer reported.
>
> To fix it, leave the entries alone during the move and clear the uffd
> state of the new VMA in mremap_userfaultfd_prep(), right before dropping
> the context, like unregistering does. This walks the page tables of the
> new VMA a second time.
>
> This is done with userfaultfd_clear_ptes(), which also makes the PTEs
> writable again where that is safe. That removes a spurious write fault
> per protected page on private anonymous memory, but adds spurious write
> faults on shmem and hugetlb, as change_protection() makes writable pages
> that were never protected read-only. UFFDIO_UNREGISTER and
> UFFDIO_WRITEPROTECT already behave this way. This will be fixed in
> change_protection() separately.
>
> The entries no longer need per-entry handling during the move, so drop
> uffd_supports_page_table_move() and clear_uffd_wp_pmd(). Whole page
> tables of these VMAs can be moved again.
>
> Fixes: 0cef0bb836e3 ("mm: clear uffd-wp PTE/PMD state on mremap()")
> Fixes: 763f43865fc4 ("mm: preserve RWP marker across PTE rewrites")
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> Tested-by: Gregory Price (Meta) <gourry@gourry.net>
> Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> mm/huge_memory.c | 25 -------------------------
> mm/hugetlb.c | 27 +--------------------------
> mm/mremap.c | 46 +---------------------------------------------
> mm/userfaultfd.c | 1 +
> 4 files changed, 3 insertions(+), 96 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page
2026-11-18 4:28 ` [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page Tal Zussman
2026-11-18 9:40 ` David Hildenbrand (Arm)
@ 2026-11-18 14:52 ` Mike Rapoport
1 sibling, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:52 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel, Thomas Hellström, Lyude Paul,
Danilo Krummrich, Felix Kuehling, Jason Gunthorpe,
Leon Romanovsky, dri-devel, intel-xe, nouveau, amd-gfx
On Tue, Nov 17, 2026 at 11:28:48PM -0500, Tal Zussman wrote:
> Device migration replaces a PTE that maps the zero page with a new PTE
> that is built only from the VMA flags, so its userfaultfd WP or RWP
> protection is lost. The same applies to the huge zero PMD. Writes and
> accesses to the page are then no longer reported to userfaultfd.
>
> To fix it, do not migrate a uffd-protected zero page. Skip it during
> collection, and check again under the page table lock before inserting,
> as another thread can protect the page after it was collected.
>
> The alternative would be to carry the uffd state over to the new entry,
> but a uffd-protected zero page in a range that a driver migrates should
> be rare.
>
> While at it, read the PMD once with pmdp_get() in
> migrate_vma_collect_huge_pmd().
>
> Fixes: 292924b26024 ("userfaultfd: wp: apply _PAGE_UFFD_WP bit")
> Fixes: a30b48bf1b24 ("mm/migrate_device: implement THP migration of zone device pages")
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Felix Kuehling <Felix.Kuehling@amd.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Leon Romanovsky <leon@kernel.org>
> Cc: dri-devel@lists.freedesktop.org
> Cc: intel-xe@lists.freedesktop.org
> Cc: nouveau@lists.freedesktop.org
> Cc: amd-gfx@lists.freedesktop.org
> Reviewed-by: Alistair Popple <apopple@nvidia.com>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> include/linux/userfaultfd_k.h | 24 ++++++++++++++++++++++++
> mm/migrate_device.c | 34 ++++++++++++++++++++++++++--------
> 2 files changed, 50 insertions(+), 8 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan
2026-11-18 4:28 ` [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan Tal Zussman
2026-11-18 9:38 ` David Hildenbrand (Arm)
@ 2026-11-18 14:55 ` Mike Rapoport
1 sibling, 0 replies; 29+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:55 UTC (permalink / raw)
To: Tal Zussman
Cc: Andrew Morton, Peter Xu, James Houghton, Andrea Arcangeli,
Suren Baghdasaryan, Balbir Singh, Liam R. Howlett,
Lorenzo Stoakes, Vlastimil Babka, Jann Horn, Pedro Falcato,
David Hildenbrand, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, linux-mm, linux-kernel,
linux-fsdevel
On Tue, Nov 17, 2026 at 11:28:49PM -0500, Tal Zussman wrote:
> UFFDIO_REGISTER and UFFDIO_UNREGISTER both scan the VMAs of the range
> before changing anything. For a hugetlb VMA, userfaultfd_register()
> rejects a range whose start or end is not huge page aligned there.
> However, userfaultfd_unregister() only checks the start.
>
> An unaligned end only fails later, when vma_modify_flags_uffd() cannot
> split the VMA there. At that point, userfaultfd_clear_vma() already
> cleared the WP or RWP protection. The ioctl returns -EINVAL and the VMA
> stays registered, but accesses to its pages are no longer reported. This
> requires a caller passing a misaligned range.
>
> To fix it, move the alignment checks into vma_uffd_range_aligned() and
> call it for every VMA in the pre-scan of both ioctls. UFFDIO_UNREGISTER
> still returns -EINVAL for such a range, but no longer unregisters the
> VMAs before the misaligned one first.
>
> Checking every VMA the same way also changes the following:
>
> - UFFDIO_UNREGISTER now returns -EINVAL if the end is not huge page
> aligned in a hugetlb VMA that is not registered. It used to skip that
> VMA and succeed.
>
> - Both ioctls now accept a start that is not huge page aligned if it is
> not inside any VMA and the first VMA of the range is a hugetlb one.
> They used to return -EINVAL, although such a range covers that VMA
> from its start, which is always huge page aligned.
>
> - UFFDIO_REGISTER now returns -EINVAL rather than -EPERM if the end is
> not huge page aligned in a hugetlb VMA without VM_MAYWRITE.
>
> Fixes: cab350afcbc9 ("userfaultfd: hugetlbfs: allow registration of ranges containing huge pages")
> Fixes: f369b07c8614 ("mm/uffd: reset write protection when unregister with wp-mode")
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> mm/userfaultfd.c | 54 ++++++++++++++++++------------------------------------
> 1 file changed, 18 insertions(+), 36 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: (subset) [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (9 preceding siblings ...)
2026-11-18 9:41 ` [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) David Hildenbrand (Arm)
@ 2026-11-18 15:19 ` David Hildenbrand
2026-11-18 15:20 ` David Hildenbrand
2026-11-18 15:21 ` David Hildenbrand
12 siblings, 0 replies; 29+ messages in thread
From: David Hildenbrand @ 2026-11-18 15:19 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, Tal Zussman
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Breno Leitao,
Thomas Hellström, Lyude Paul, Danilo Krummrich,
Felix Kuehling, Jason Gunthorpe, Leon Romanovsky, dri-devel,
intel-xe, nouveau, amd-gfx
On Tue, 17 Nov 2026 23:28:40 -0500, Tal Zussman wrote:
> This is a first batch of userfaultfd fixes, with more to come.
>
> These were found by a mix of regular old LLM review and by having an LLM
> write a TLA+ model of uffd interactions with PTE bits and other state
> and seeing what issues fell out.
>
> Most of these fix places where mm code loses uffd-wp or RWP protection
> while moving or migrating an entry. Userspace then either misses writes
> and accesses, or gets pages reported that nobody touched.
> There is also a hang in UFFDIO_MOVE, and UFFDIO_ZEROPAGE modifying a
> file through a private mapping.
>
> [...]
Applied, thanks!
tree: mm/core.git
branch: migrate-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.
[4/9] mm/migrate: warn on a writable migration entry with the uffd bit set
https://git.kernel.org/mm/core/c/ec53fccd
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: (subset) [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (10 preceding siblings ...)
2026-11-18 15:19 ` (subset) " David Hildenbrand
@ 2026-11-18 15:20 ` David Hildenbrand
2026-11-18 15:37 ` David Hildenbrand (Arm)
2026-11-18 15:21 ` David Hildenbrand
12 siblings, 1 reply; 29+ messages in thread
From: David Hildenbrand @ 2026-11-18 15:20 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, Tal Zussman
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Breno Leitao,
Thomas Hellström, Lyude Paul, Danilo Krummrich,
Felix Kuehling, Jason Gunthorpe, Leon Romanovsky, dri-devel,
intel-xe, nouveau, amd-gfx
On Tue, 17 Nov 2026 23:28:40 -0500, Tal Zussman wrote:
> This is a first batch of userfaultfd fixes, with more to come.
>
> These were found by a mix of regular old LLM review and by having an LLM
> write a TLA+ model of uffd interactions with PTE bits and other state
> and seeing what issues fell out.
>
> Most of these fix places where mm code loses uffd-wp or RWP protection
> while moving or migrating an entry. Userspace then either misses writes
> and accesses, or gets pages reported that nobody touched.
> There is also a hang in UFFDIO_MOVE, and UFFDIO_ZEROPAGE modifying a
> file through a private mapping.
>
> [...]
Applied, thanks!
tree: mm/core.git
branch: thp-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.
[6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA
https://git.kernel.org/mm/core/c/ec36bf72
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: (subset) [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
` (11 preceding siblings ...)
2026-11-18 15:20 ` David Hildenbrand
@ 2026-11-18 15:21 ` David Hildenbrand
12 siblings, 0 replies; 29+ messages in thread
From: David Hildenbrand @ 2026-11-18 15:21 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, David Hildenbrand, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, Tal Zussman
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Breno Leitao,
Thomas Hellström, Lyude Paul, Danilo Krummrich,
Felix Kuehling, Jason Gunthorpe, Leon Romanovsky, dri-devel,
intel-xe, nouveau, amd-gfx
On Tue, 17 Nov 2026 23:28:40 -0500, Tal Zussman wrote:
> This is a first batch of userfaultfd fixes, with more to come.
>
> These were found by a mix of regular old LLM review and by having an LLM
> write a TLA+ model of uffd interactions with PTE bits and other state
> and seeing what issues fell out.
>
> Most of these fix places where mm code loses uffd-wp or RWP protection
> while moving or migrating an entry. Userspace then either misses writes
> and accesses, or gets pages reported that nobody touched.
> There is also a hang in UFFDIO_MOVE, and UFFDIO_ZEROPAGE modifying a
> file through a private mapping.
>
> [...]
Applied, thanks!
tree: mm/core.git
branch: migrate-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.
[8/9] mm/migrate_device: do not migrate a uffd-protected zero page
https://git.kernel.org/mm/core/c/a37a6cf0
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
2026-11-18 9:41 ` [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) David Hildenbrand (Arm)
@ 2026-11-18 15:26 ` Tal Zussman
2026-11-18 15:37 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 29+ messages in thread
From: Tal Zussman @ 2026-11-18 15:26 UTC (permalink / raw)
To: David Hildenbrand (Arm),
Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Breno Leitao,
Thomas Hellström, Lyude Paul, Danilo Krummrich,
Felix Kuehling, Jason Gunthorpe, Leon Romanovsky, dri-devel,
intel-xe, nouveau, amd-gfx
On 11/18/26 4:41 AM, David Hildenbrand (Arm) wrote:
> On 11/18/26 05:28, Tal Zussman wrote:
...
>> Patch 6 has little user impact on its own. It is included because,
>> together with patch 7, it allows removing clear_uffd_wp_pmd().
>>
...>
> So, I would be picking up ...
>
>> Tal Zussman (9):
>> userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings
>> userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD
>> fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect
>> mm/migrate: warn on a writable migration entry with the uffd bit set
>
> This
>
>> fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
>> mm/huge_memory: build the moved huge zero PMD from the destination VMA
>
> This
>
So my one concern is that (as per above), the mremap patch removes
clear_uffd_wp_pmd() after the huge_memory patch removes the other user.
Splitting them may break compilation. I would've left clear_uffd_wp_pmd()
alone but then it throws a nice ugly unused code warning :\
>> mm/mremap: resolve uffd state when the context is dropped, not during the move
>> mm/migrate_device: do not migrate a uffd-protected zero page
>
> This
>
>> mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan
>
>
> After waiting a bit longer for more review. Andrew can take the rest.
>
>
> --
> Cheers,
>
> David
>
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
2026-11-18 15:26 ` Tal Zussman
@ 2026-11-18 15:37 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 29+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-18 15:37 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Mike Rapoport, Peter Xu,
James Houghton, Andrea Arcangeli, Suren Baghdasaryan,
Balbir Singh, Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka,
Jann Horn, Pedro Falcato, Michal Hocko,
Michał Mirosław, Andrei Vagin, Muhammad Usama Anjum,
Stephen Rothwell, Arnd Bergmann, Zi Yan, Matthew Brost,
Joshua Hahn, Byungchul Park, Gregory Price, Ying Huang,
Alistair Popple, Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain,
Barry Song, Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Breno Leitao,
Thomas Hellström, Lyude Paul, Danilo Krummrich,
Felix Kuehling, Jason Gunthorpe, Leon Romanovsky, dri-devel,
intel-xe, nouveau, amd-gfx
On 11/18/26 16:26, Tal Zussman wrote:
> On 11/18/26 4:41 AM, David Hildenbrand (Arm) wrote:
>> On 11/18/26 05:28, Tal Zussman wrote:
> ...
>
>>> Patch 6 has little user impact on its own. It is included because,
>>> together with patch 7, it allows removing clear_uffd_wp_pmd().
>>>
>
> ...>
>> So, I would be picking up ...
>>
>>> Tal Zussman (9):
>>> userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings
>>> userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD
>>> fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect
>>> mm/migrate: warn on a writable migration entry with the uffd bit set
>>
>> This
>>
>>> fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN
>>> mm/huge_memory: build the moved huge zero PMD from the destination VMA
>>
>> This
>>
>
> So my one concern is that (as per above), the mremap patch removes
> clear_uffd_wp_pmd() after the huge_memory patch removes the other user.
> Splitting them may break compilation. I would've left clear_uffd_wp_pmd()
> alone but then it throws a nice ugly unused code warning :\
Ah, so it's best Andrew picks that up as well then?
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: (subset) [PATCH v3 0/9] userfaultfd: assorted fixes (part 1)
2026-11-18 15:20 ` David Hildenbrand
@ 2026-11-18 15:37 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 29+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-18 15:37 UTC (permalink / raw)
To: Andrew Morton, Mike Rapoport, Peter Xu, James Houghton,
Andrea Arcangeli, Suren Baghdasaryan, Balbir Singh,
Liam R. Howlett, Lorenzo Stoakes, Vlastimil Babka, Jann Horn,
Pedro Falcato, Michal Hocko, Michał Mirosław,
Andrei Vagin, Muhammad Usama Anjum, Stephen Rothwell,
Arnd Bergmann, Zi Yan, Matthew Brost, Joshua Hahn,
Byungchul Park, Gregory Price, Ying Huang, Alistair Popple,
Baolin Wang, Nico Pache, Ryan Roberts, Dev Jain, Barry Song,
Lance Yang, Usama Arif, Kiryl Shutsemau, Muchun Song,
Oscar Salvador, Mikołaj Lenczewski, Tal Zussman
Cc: linux-mm, linux-kernel, linux-fsdevel, stable, Breno Leitao,
Thomas Hellström, Lyude Paul, Danilo Krummrich,
Felix Kuehling, Jason Gunthorpe, Leon Romanovsky, dri-devel,
intel-xe, nouveau, amd-gfx
On 11/18/26 16:20, David Hildenbrand wrote:
> On Tue, 17 Nov 2026 23:28:40 -0500, Tal Zussman wrote:
>> This is a first batch of userfaultfd fixes, with more to come.
>>
>> These were found by a mix of regular old LLM review and by having an LLM
>> write a TLA+ model of uffd interactions with PTE bits and other state
>> and seeing what issues fell out.
>>
>> Most of these fix places where mm code loses uffd-wp or RWP protection
>> while moving or migrating an entry. Userspace then either misses writes
>> and accesses, or gets pages reported that nobody touched.
>> There is also a hang in UFFDIO_MOVE, and UFFDIO_ZEROPAGE modifying a
>> file through a private mapping.
>>
>> [...]
>
> Applied, thanks!
>
> tree: mm/core.git
> branch: thp-7.5.misc
>
> Applied patches will appear soon in mm-next, followed by linux-next.
>
> Please report any outstanding bugs that were missed during review, so we
> can either drop the patch series or decide how to fix it up.
>
> It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
> though the patches have already been applied. If possible, patch trailers
> will be updated.
>
> Note that commit hashes shown below are subject to change due to rebase,
> trailer updates or similar. Further, this is not a guarantee that the
> patches will go upstream. If in doubt, please check the listed branch.
>
> [6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA
> https://git.kernel.org/mm/core/c/ec36bf72
Aaaaaand undone. :)
--
Cheers,
David
^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2026-11-18 15:38 UTC | newest]
Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 4:28 [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) Tal Zussman
2026-11-18 4:28 ` [PATCH v3 1/9] userfaultfd: use anonymous memory for UFFDIO_ZEROPAGE on private file mappings Tal Zussman
2026-11-18 14:31 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 2/9] userfaultfd: refuse UFFDIO_MOVE into a non-present huge destination PMD Tal Zussman
2026-11-18 14:33 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 3/9] fs/proc/task_mmu: downgrade writable migration entries in PAGEMAP_SCAN write-protect Tal Zussman
2026-11-18 14:36 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 4/9] mm/migrate: warn on a writable migration entry with the uffd bit set Tal Zussman
2026-11-18 9:39 ` David Hildenbrand (Arm)
2026-11-18 14:37 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 5/9] fs/proc/task_mmu: write-protect device-private THPs in PAGEMAP_SCAN Tal Zussman
2026-11-18 14:38 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 6/9] mm/huge_memory: build the moved huge zero PMD from the destination VMA Tal Zussman
2026-11-18 14:41 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 7/9] mm/mremap: resolve uffd state when the context is dropped, not during the move Tal Zussman
2026-11-18 14:45 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 8/9] mm/migrate_device: do not migrate a uffd-protected zero page Tal Zussman
2026-11-18 9:40 ` David Hildenbrand (Arm)
2026-11-18 14:52 ` Mike Rapoport
2026-11-18 4:28 ` [PATCH v3 9/9] mm/userfaultfd: check the hugetlb alignment of every VMA in the pre-scan Tal Zussman
2026-11-18 9:38 ` David Hildenbrand (Arm)
2026-11-18 14:55 ` Mike Rapoport
2026-11-18 9:41 ` [PATCH v3 0/9] userfaultfd: assorted fixes (part 1) David Hildenbrand (Arm)
2026-11-18 15:26 ` Tal Zussman
2026-11-18 15:37 ` David Hildenbrand (Arm)
2026-11-18 15:19 ` (subset) " David Hildenbrand
2026-11-18 15:20 ` David Hildenbrand
2026-11-18 15:37 ` David Hildenbrand (Arm)
2026-11-18 15:21 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®