Skip to contentSkip to conversation

mm/userfaultfd: reject DAX mappings

PATCH In review David Hildenbrand (Arm) 3 participants 3 messages Nov 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/userfaultfd: reject DAX mappings

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.

---
 mm/userfaultfd.c | 3 +++
 1 file changed, 3 insertions(+)
mm/userfaultfd.c +3 -0
index 169f681f9849b..6656233d5dcc7 100644
@@ -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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · 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.

Quoted 8 lines

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

Signature · 1 line
~Gregory
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to David Hildenbrand (Arm)
Quoted 15 lines · 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.

Quoted 8 lines

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

Quoted 31 lines
---
 mm/userfaultfd.c | 3 +++
 1 file changed, 3 insertions(+)
mm/userfaultfd.c +3 -1
index 169f681f9849b..6656233d5dcc7 100644
@@ -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

Signature · 2 lines
Sincerely yours,
Mike.