Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/userfaultfd: reject DAX mappings
@ 2026-11-18 10:03 David Hildenbrand (Arm)
  2026-11-18 14:12 ` Gregory Price (Meta)
  2026-11-18 14:58 ` Mike Rapoport
  0 siblings, 2 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-18 10:03 UTC (permalink / raw)
  To: Andrew Morton, Mike Rapoport, Peter Xu, Muhammad Usama Anjum
  Cc: linux-mm, linux-kernel, Chris Mason, Jingyi Sun,
	David Hildenbrand (Arm)

UFFD_FEATURE_WP_ASYNC made DAX mappings eligible for userfaultfd
write-protection, but the DAX fault paths have never fully supported it.

DAX faults use vmf_insert_mixed() and vmf_insert_mixed_mkwrite(), which
treats any non-empty PTE, including uffd-wp markers, as an existing mapping.
A read fault on an uffd-wp marker therefore returns VM_FAULT_NOPAGE without
replacing the marker, causing the fault to repeat indefinitely.

PAGEMAP_SCAN can also write-protect a DAX PMD, but the huge DAX write-fault
path can make it writable without clearing its uffd-wp bit, breaking async
write tracking.

Device DAX mappings requiring huge-page alignment and cannot serve PTE
faults after UFFDIO_WRITEPROTECT has split their huge mappings.

So let's just disallow DAX mappings in vma_can_userfault() entirely,
making UFFDIO_REGISTER fail with EINVAL.

Fixes: d61ea1cb0095 ("userfaultfd: UFFD_FEATURE_WP_ASYNC")
Reported-by: Chris Mason <mason@kernel.org>
Reported-by: Jingyi Sun <1045704958@qq.com>
Closes: https://lore.kernel.org/all/tencent_1874C71D4177A1624528043E008DB1A5EF05@qq.com
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 mm/userfaultfd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 169f681f9849b..6656233d5dcc7 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -2131,6 +2131,9 @@ static bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
 	/* Only mm-backed memory can have its faults handled by userspace. */
 	if (!vma_is_mm_backed(vma))
 		return false;
+	/* DAX fault handlers do not support uffd-wp. */
+	if (vma_is_dax(vma))
+		return false;
 	/* Core mm may discard droppable memory at any time. */
 	if (vma_test_single_mask(vma, VMA_DROPPABLE))
 		return false;

---

base-commit: fa4ad798f6f681031775266044ba1b0cf3c670bd

change-id: 20261118-dax_uffd-0fb2c6d1c087

--

Cheers,

David



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/userfaultfd: reject DAX mappings
  2026-11-18 10:03 [PATCH] mm/userfaultfd: reject DAX mappings David Hildenbrand (Arm)
@ 2026-11-18 14:12 ` Gregory Price (Meta)
  2026-11-18 14:58 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Gregory Price (Meta) @ 2026-11-18 14:12 UTC (permalink / raw)
  To: David Hildenbrand (Arm)
  Cc: Andrew Morton, Mike Rapoport, Peter Xu, Muhammad Usama Anjum,
	linux-mm, linux-kernel, Chris Mason, Jingyi Sun

On 2026-11-18 11:03 +0100, David Hildenbrand (Arm) wrote:
> UFFD_FEATURE_WP_ASYNC made DAX mappings eligible for userfaultfd
> write-protection, but the DAX fault paths have never fully supported it.
> 
> DAX faults use vmf_insert_mixed() and vmf_insert_mixed_mkwrite(), which
> treats any non-empty PTE, including uffd-wp markers, as an existing mapping.
> A read fault on an uffd-wp marker therefore returns VM_FAULT_NOPAGE without
> replacing the marker, causing the fault to repeat indefinitely.
> 
> PAGEMAP_SCAN can also write-protect a DAX PMD, but the huge DAX write-fault
> path can make it writable without clearing its uffd-wp bit, breaking async
> write tracking.
> 
> Device DAX mappings requiring huge-page alignment and cannot serve PTE
> faults after UFFDIO_WRITEPROTECT has split their huge mappings.
> 
> So let's just disallow DAX mappings in vma_can_userfault() entirely,
> making UFFDIO_REGISTER fail with EINVAL.
> 
> Fixes: d61ea1cb0095 ("userfaultfd: UFFD_FEATURE_WP_ASYNC")
> Reported-by: Chris Mason <mason@kernel.org>
> Reported-by: Jingyi Sun <1045704958@qq.com>
> Closes: https://lore.kernel.org/all/tencent_1874C71D4177A1624528043E008DB1A5EF05@qq.com
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>

Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>

-- 
~Gregory



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/userfaultfd: reject DAX mappings
  2026-11-18 10:03 [PATCH] mm/userfaultfd: reject DAX mappings David Hildenbrand (Arm)
  2026-11-18 14:12 ` Gregory Price (Meta)
@ 2026-11-18 14:58 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2026-11-18 14:58 UTC (permalink / raw)
  To: David Hildenbrand (Arm)
  Cc: Andrew Morton, Peter Xu, Muhammad Usama Anjum, linux-mm,
	linux-kernel, Chris Mason, Jingyi Sun

On Wed, Nov 18, 2026 at 11:03:00AM +0100, David Hildenbrand (Arm) wrote:
> UFFD_FEATURE_WP_ASYNC made DAX mappings eligible for userfaultfd
> write-protection, but the DAX fault paths have never fully supported it.
> 
> DAX faults use vmf_insert_mixed() and vmf_insert_mixed_mkwrite(), which
> treats any non-empty PTE, including uffd-wp markers, as an existing mapping.
> A read fault on an uffd-wp marker therefore returns VM_FAULT_NOPAGE without
> replacing the marker, causing the fault to repeat indefinitely.
> 
> PAGEMAP_SCAN can also write-protect a DAX PMD, but the huge DAX write-fault
> path can make it writable without clearing its uffd-wp bit, breaking async
> write tracking.
> 
> Device DAX mappings requiring huge-page alignment and cannot serve PTE
> faults after UFFDIO_WRITEPROTECT has split their huge mappings.
> 
> So let's just disallow DAX mappings in vma_can_userfault() entirely,
> making UFFDIO_REGISTER fail with EINVAL.
> 
> Fixes: d61ea1cb0095 ("userfaultfd: UFFD_FEATURE_WP_ASYNC")
> Reported-by: Chris Mason <mason@kernel.org>
> Reported-by: Jingyi Sun <1045704958@qq.com>
> Closes: https://lore.kernel.org/all/tencent_1874C71D4177A1624528043E008DB1A5EF05@qq.com
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>

Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> ---
>  mm/userfaultfd.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index 169f681f9849b..6656233d5dcc7 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -2131,6 +2131,9 @@ static bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
>  	/* Only mm-backed memory can have its faults handled by userspace. */
>  	if (!vma_is_mm_backed(vma))
>  		return false;
> +	/* DAX fault handlers do not support uffd-wp. */
> +	if (vma_is_dax(vma))
> +		return false;
>  	/* Core mm may discard droppable memory at any time. */
>  	if (vma_test_single_mask(vma, VMA_DROPPABLE))
>  		return false;
> 
> ---
> 
> base-commit: fa4ad798f6f681031775266044ba1b0cf3c670bd
> 
> change-id: 20261118-dax_uffd-0fb2c6d1c087
> 
> --
> 
> Cheers,
> 
> David
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 10:03 [PATCH] mm/userfaultfd: reject DAX mappings David Hildenbrand (Arm)
2026-11-18 14:12 ` Gregory Price (Meta)
2026-11-18 14:58 ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox