FAILED: patch "[PATCH] mm/userfaultfd: wake waiters when registration modes are removed" failed to apply to 6.1-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 4eee9c389b072e161549d46dcb1ae10b0222717e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 4eee9c389b072e161549d46dcb1ae10b0222717e Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Arm)" <[email protected]>
Date: Sat, 31 Oct 2026 10:39:54 +0100
Subject: [PATCH] mm/userfaultfd: wake waiters when registration modes are
removed
UFFDIO_REGISTER can replace MISSING or MINOR tracking without waking faults that are already queued. For example, switching an anonymous range from MISSING to WP leaves a missing-fault waiter asleep until userspace explicitly wakes it.
When a registration change removes a UFFD mode, wake waiters in the affected interval after updating the VMA. The VMA is write-locked at this point, so no new faults can queue under the old modes and woken threads cannot retry until mmap_write_unlock(). Waiters for retained modes in the same interval may also wake and refault.
The hang reproduces for MISSING-to-WP and MINOR-to-MISSING transitions, with both read and unread fault events.
--- mm/userfaultfd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
mm/userfaultfd.c +20 -0
@@ -2270,6 +2270,9 @@ static struct vm_area_struct *userfaultfd_clear_vma(struct vma_iterator *vmi,return ret; } +static void wake_userfault_range (struct userfaultfd_ctx *ctx, +unsigned long start,unsigned long end); +/* Assumes mmap write lock taken, and mm_struct pinned. */ static int userfaultfd_register_range(struct userfaultfd_ctx *ctx, struct vm_area_struct *vma,
@@ -2287,6 +2290,8 @@ static int userfaultfd_register_range(struct userfaultfd_ctx *ctx, prev = vma;for_each_vma_range (vmi, vma, end) { +const bool any_mode_removed = vma->vm_flags & __VM_UFFD_FLAGS & ~vm_flags; +cond_resched ();VM_WARN_ON_ONCE (!vma_can_userfault (vma, vm_flags, wp_async));
@@ -2332,6 +2337,10 @@ static int userfaultfd_register_range(struct userfaultfd_ctx *ctx,*/ userfaultfd_set_ctx (vma, ctx, vm_flags); +/* Retry faults for removed modes while the VMA is write-locked. */ +if (any_mode_removed) +wake_userfault_range (ctx, start, vma_end); +if (vma_is_hugetlb (vma) &&uffd_disable_huge_pmd_share (vma))hugetlb_unshare_all_pmds (vma);
@@ -3648,6 +3657,17 @@ static __always_inline void wake_userfault(struct userfaultfd_ctx *ctx,__wake_userfault (ctx, range); } +static void wake_userfault_range (struct userfaultfd_ctx *ctx, +unsigned long start,unsigned long end) +{ +struct userfaultfd_wake_range range = { + .start = start, + .len = end - start, + }; + +wake_userfault (ctx, &range); +} + static __always_inline int validate_unaligned_range(struct mm_struct *mm,__u64 start,__u64 len) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 mm/userfaultfd: wake waiters when registration modes are removed
From: "David Hildenbrand (Arm)" <[email protected]>
[ Upstream commit 4eee9c389b072e161549d46dcb1ae10b0222717e ]
UFFDIO_REGISTER can replace MISSING or MINOR tracking without waking faults that are already queued. For example, switching an anonymous range from MISSING to WP leaves a missing-fault waiter asleep until userspace explicitly wakes it.
When a registration change removes a UFFD mode, wake waiters in the affected interval after updating the VMA. The VMA is write-locked at this point, so no new faults can queue under the old modes and woken threads cannot retry until mmap_write_unlock(). Waiters for retained modes in the same interval may also wake and refault.
The hang reproduces for MISSING-to-WP and MINOR-to-MISSING transitions, with both read and unread fault events.
--- fs/userfaultfd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/userfaultfd.c +12 -0
@@ -1450,6 +1450,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, ret =0 ; do { + const bool any_mode_removed = vma->vm_flags & __VM_UFFD_FLAGS & ~vm_flags; + cond_resched(); BUG_ON(!vma_can_userfault(vma, vm_flags));
@@ -1504,6 +1506,16 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,userfaultfd_set_vm_flags (vma, new_flags); vma->vm_userfaultfd_ctx.ctx = ctx; +/* Retry faults for removed modes while the VMA is write-locked. */ +if (any_mode_removed) { +struct userfaultfd_wake_range range = { + .start = start, + .len = vma_end - start, + }; + +wake_userfault (ctx, &range); + } +if (is_vm_hugetlb_page (vma) &&uffd_disable_huge_pmd_share (vma))hugetlb_unshare_all_pmds (vma);
Signature · 1 line
2.53.0