From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796387431; b=4HkWJgAG2xEivUNaPFF9BjmzDQC4Yl5jL0Nyf1jFRsScyHZs1SYX93j23KGKwyqCkTCc 7H1xPZ8pxYXwAdlfL0aDSyLVe+VMxTBvi0RMxokUCn/OgYBHevxN89mOKs1RRG56+2Ayl IcQhqQqHkYwcvyqRhR243zJLSVAZLinLmGnMiHPP2vPjt6CqBaEghyimWQOfo8JQTY944 aNTjN4K3u+XhGGDasIXCbnENVmcgfw8TI91AuIv1F9wa0zSfN6IrDXX0+ntmSrGa8GzfJ pvI9kzqOzqZFyVGbOrLOuUsHvz37aSuj9YkJOVMAXfWS4+/t8nCxeF2oD9tXUxebkXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387431; 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=byxj1QL6qQVXaZ0PkR5dGd7kF8DkSFDcbbdMoDNaMp0=; b=NxbQxIoQQoNJXq7c+eAqBj1Z59Ceyv1e9rEw2+PEhKJvLlzf91sK6644kE+oOvPcppYa 90ylrxak0xHMNSD3AwwBUXxhuCmhBCGGC0le9/MPT8sqzD++vk44HsRhKjkNco5hQUrLt DpR7Ls5zNjPTjlyEQGmWiJarGt8WgImW3JVve8HPzzttskKtzKhN3Dee2LDGQZo5G+MZZ y4shxqryIOlnGdGRtfQAFiFNIm4oA4mFVI79kTnvSJXgNZIap0eD6xzYATtZiBTIxgYz/ J3dLuOUjZNye/riAwxTzUdLY/a4JghYQnL6UCdTeW08cA9Y/Gj4YoWu7RW+QfjnnyJQ== 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=FkLBNYe+; 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 52EB2606A32C; Fri, 4 Dec 2026 12:30:31 +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=FkLBNYe+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id C57061F000C2; Fri, 4 Dec 2026 12:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387431; bh=byxj1QL6qQVXaZ0PkR5dGd7kF8DkSFDcbbdMoDNaMp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FkLBNYe+nBLFXd8RT52xoIfP/zliTqEoQmWD2S67aLVXWz9YAcJdnMxipmbdgNhXs k8ITH52K2XJD2Qd1MLdAnFSUoowlVD+wNKnNRmTj7bktKSjZYTLZ1tRvpwR9MHeiLG ZBUghIDhj8ShX/+bHdKk0zgKfFrfHayOCcRQF+Ls= 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.1 0241/1059] mm/userfaultfd: wake all waiters on unregister Date: Fri, 4 Dec 2026 18:56:12 +0900 Message-ID: <20261204100650.516180922@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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: Dropped the userfaultfd_missing() guard in fs/userfaultfd.c (the function isn't in mm/userfaultfd.c here), and kept wake_userfault(vma->vm_userfaultfd_ctx.ctx, &range) instead of upstream's ctx. ] 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 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