Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795625023; b=NNlI91MDCwJi2joTgxxLoAK2ZNKRDTAl9prUZKHyrTlx8If4g8xe8FzDyUQfv2wuMGyO hBuipn2JiyL7rBMr1KnjIN9Xj9Ql+AALXS3/UKmY38wvk2BjJaG5g63Mqmg8z+syv+fQ+ KgJjibHH4n9JUXuk+8UW5k3Qo8KPwjoDnmuzyYSuXf3Xj3b6bFxSSU1tmBHJ7pgtivfAA Lp5M7xjC+yEKnJxIZG3dFeFxNCx9BiDVic+NnDHoMGnsJgA0y2XXA6gKaNQUaibBspYwK 4J8h9Eapq3QEM8bBhUFuTd4bm5JwGFjmRXjV1gazoBAuFDnRxzcw2gzLbe9M6C14n0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795625023; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=nwsawGvHRvAQqhgYx5CLlM/CfHtlNR3dxZdkDCx3N40=; b=jRTZ9YdreAfalk2c8m7k/2U9wQam/KexQe1ot9CsoGfoLm/YCPnzOoKUTHZm3P0EKjga 6y/lhROIstDWC25t7grm0SQ0Va5gjKWEfQEyY1qEwo8/S4pH4WGhsevOFzk1PEslxml4z A24WpWVpHOk6sXa6RKuzw4n9wPk1b1whWEm0Fn+l84YkOdWNteze4o1xKviQVEdZXlKKT kqbZiOrMV6aEyXfao5AcNsS3j3RfjCl3qGaiNlaYKLY2LCGkmzzxVDSwfhDUnZE8KUL8F XfKGusVYTxR20+Qq0/5yOkC6lBnkF3FgJUTGqPP3/4RwcqyzoEzhYm5995kYx0G+k/A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BUbUUEvf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 098CE606A321; Wed, 25 Nov 2026 16:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BUbUUEvf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 578391F000C4; Wed, 25 Nov 2026 16:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795625022; bh=nwsawGvHRvAQqhgYx5CLlM/CfHtlNR3dxZdkDCx3N40=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BUbUUEvfWzHHdA5eqeZAloi7M0TLTdlfVW+bjUym65Zrx2vcUE8YJwpjbU21fKooa 4b2ivTiL90RZQyDqksBt5sDmQnbMksynHwDgKIw0OKtViTJIOjNV2nkB0J1bkBocCG 9ngoJjOwenYq8+Zz4qtnIxa0PpV3lg2GQBBtAoNg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , "Mike Rapoport (Microsoft)" , "Lorenzo Stoakes (ARM)" , Muhammad Usama Anjum , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 6.12 382/816] mm/userfaultfd: wake all waiters on unregister Date: Wed, 25 Nov 2026 15:32:10 +0100 Message-ID: <20261125143858.047737106@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143849.205329330@linuxfoundation.org> References: <20261125143849.205329330@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit 3afb19d68cc5e7851fdb1069c8094af97bd80417 ] 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 [ david: rebase; simplify description ] Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Lorenzo Stoakes (ARM) Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-24-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) [ sashal: Wake target kept as the VMA's own userfaultfd ctx instead of upstream's ctx argument, since this tree lacks the check that rejects unregistering another ctx's VMA; the file path also differs. ] Signed-off-by: Sasha Levin --- fs/userfaultfd.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index e1b1a5b1a757a..77b295cb39906 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1491,6 +1491,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, ret = 0; for_each_vma_range(vmi, vma, end) { + struct userfaultfd_wake_range range; + cond_resched(); BUG_ON(!vma_can_userfault(vma, vma->vm_flags, wp_async)); @@ -1511,18 +1513,14 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, /* Prevent new userfaults from being queued after the wakeup. */ vma_start_write(vma); - 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); vma = userfaultfd_clear_vma(&vmi, prev, vma, start, vma_end); -- 2.53.0