From: Mike Rapoport <rppt@kernel.org>
To: stable@vger.kernel.org
Cc: Josef Bacik <josef@toxicpanda.com>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
"Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
Muhammad Usama Anjum <usama.anjum@arm.com>,
"David Hildenbrand (Arm)" <david@kernel.org>
Subject: [PATCH 6.1.y] mm/userfaultfd: wake all waiters on unregister
Date: Mon, 30 Nov 2026 09:53:33 +0200 [thread overview]
Message-ID: <20261130075334.246765-3-rppt@kernel.org> (raw)
In-Reply-To: <20261109201815-failed-6.1-3afb19d68cc5@kernel.org>
From: Josef Bacik <josef@toxicpanda.com>
UFFDIO_UNREGISTER only wakes pending faults if VM_UFFD_MISSING is set.
Threads waiting on write-protect, minor or RWP faults can therefore remain
asleep after unregistering a range that does not track missing faults.
Wake pending faults regardless of the registration mode so they can retry
without an explicit UFFDIO_WAKE or closing the userfaultfd. This matches
the existing behavior for missing faults, including removing unread fault
messages for the woken waiters.
Fix generated by an LLM and sent by Josef Bacik in private.
Fixes: 63b2d4174c4a ("userfaultfd: wp: add the writeprotect API to userfaultfd ioctl")
Cc: stable@vger.kernel.org
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
[ david: rebase; simplify description ]
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com>
Link: https://patch.msgid.link/20261031-fixes_core-v3-24-d6437171ecc3@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
(cherry picked from commit 3afb19d68cc5e7851fdb1069c8094af97bd80417)
[rppt: applied to fs/userfaultfd.c and kept vma->vm_userfaultfd_ctx.ctx
because a VMA can be unregistered through a different userfaultfd]
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
fs/userfaultfd.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 00690ada9c7b0..3b75d42338846 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1642,6 +1642,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
ret = 0;
do {
+ struct userfaultfd_wake_range range;
+
cond_resched();
BUG_ON(!vma_can_userfault(vma, vma->vm_flags));
@@ -1659,18 +1661,14 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
start = vma->vm_start;
vma_end = min(end, vma->vm_end);
- if (userfaultfd_missing(vma)) {
- /*
- * Wake any concurrent pending userfault while
- * we unregister, so they will not hang
- * permanently and it avoids userland to call
- * UFFDIO_WAKE explicitly.
- */
- struct userfaultfd_wake_range range;
- range.start = start;
- range.len = vma_end - start;
- wake_userfault(vma->vm_userfaultfd_ctx.ctx, &range);
- }
+ /*
+ * Wake any concurrent pending userfault while we unregister,
+ * so they will not hang permanently and it avoids userland to
+ * call UFFDIO_WAKE explicitly.
+ */
+ range.start = start;
+ range.len = vma_end - start;
+ wake_userfault(vma->vm_userfaultfd_ctx.ctx, &range);
/* Reset ptes for the whole vma range if wr-protected */
if (userfaultfd_wp(vma))
--
2.53.0
prev parent reply other threads:[~2026-11-30 7:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 1:18 FAILED: patch "[PATCH] mm/userfaultfd: wake all waiters on unregister" failed to apply to 6.1-stable tree Sasha Levin
2026-11-30 7:53 ` Mike Rapoport [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130075334.246765-3-rppt@kernel.org \
--to=rppt@kernel.org \
--cc=david@kernel.org \
--cc=josef@toxicpanda.com \
--cc=ljs@kernel.org \
--cc=stable@vger.kernel.org \
--cc=usama.anjum@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox