FAILED: patch "[PATCH] mm/userfaultfd: wake waiters when registration modes are removed" failed to apply to 6.12-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.12-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.12.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.12.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 | 9 ++------- include/linux/userfaultfd_k.h | 8 ++++++++ mm/userfaultfd.c | 12 ++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-)
fs/userfaultfd.c +2 -7
@@ -71,11 +71,6 @@ struct userfaultfd_wait_queue {bool waken; }; -struct userfaultfd_wake_range { -unsigned long start; -unsigned long len; -}; -/* internal indication that UFFD_API ioctl was successfully executed */ #define UFFD_FEATURE_INITIALIZED (1u << 31)
@@ -1185,8 +1180,8 @@ static void __wake_userfault(struct userfaultfd_ctx *ctx,spin_unlock_irq (&ctx->fault_pending_wqh.lock); } -static __always_inline void wake_userfault(struct userfaultfd_ctx *ctx, -struct userfaultfd_wake_range *range) +void wake_userfault (struct userfaultfd_ctx *ctx, +struct userfaultfd_wake_range *range) {unsigned seq;bool need_wakeup;
include/linux/userfaultfd_k.h +8 -0
@@ -82,6 +82,14 @@ struct userfaultfd_ctx {struct mm_struct *mm; }; +struct userfaultfd_wake_range { +unsigned long start; +unsigned long len; +}; + +void wake_userfault (struct userfaultfd_ctx *ctx, +struct userfaultfd_wake_range *range); +extern vm_fault_t handle_userfault (struct vm_fault *vmf,unsigned long reason);/* A combined operation mode + behavior flags. */
mm/userfaultfd.c +12 -0
@@ -1962,6 +1962,8 @@ 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 ();BUG_ON (!vma_can_userfault (vma, vm_flags, wp_async));
@@ -1996,6 +1998,16 @@ 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) { +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