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=1795622399; b=ZdkX825pCsyrox05DU1RJC3hwBtS5mxiV/OHtAjLIuS9oSlFT19WWEQvoelfXJ2HtIQz Nwd2i0qsFbwPSEeEU88IaPD126/yCk3ZIMuLNHvLiN7cu6qOFnZIlBu+753832PkIdeyl 6I5MnPThEqT4WTUhWUP/CCoY4HPYCUpk2XONhtG3926USvZrPCWFVrFA0pvQ1ZNfwoXt9 fVQcupp2DjLmQkAbS3M7KbcgD2BLWeiQ2Y0CO/2c8oNHS4K0vjObyhKq6U1SV81F9p8U/ jKbp7ShyH3by55bRsDVGmfcvLbfbPxZzSofhPpjSJDd5uo4ciKFPl8ZMnnER2PlAwOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795622399; 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=AEGXU68njbiR0I8odwwFXeoCs0abrIPdpNA0l2xRUiY=; b=Vhd3UfIn7jhAm64QtXZTHadvHn7h3yZPzSTvIrRswHmv2wpoCHh/VLXTeO+/WZrv79r+ FKi+e8Kb9ph0hh5UDmtnp3Eu7QsasyyviPnIv+HMf7VCImCxg9FTMqsdhWvrwyYZ90UZl xkpc3FiRWYkCph4TrbAEADx26gQtezElZz/gfwOFlzP7boFPl5FHgqRndDRp/h5PoHbBk Nt+zGDFpvFLGnUNN00aNjBEkb4MpkUv8s5qSPWuO4WvqXFNpMLCpzwFl0YVAXxvyCqfJc T8sWYNVRF15wNWUzZdWKBEUEOgiWSKFi3qGwHgygcHqyaW8d4IwOOn8Ht5qb5CwmREg== 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=r9gRzchz; 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 85168606A321; Wed, 25 Nov 2026 15:59:59 +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=r9gRzchz Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1DB01F000C6; Wed, 25 Nov 2026 15:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795622399; bh=AEGXU68njbiR0I8odwwFXeoCs0abrIPdpNA0l2xRUiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=r9gRzchzyN1EBiQdbJRbxk80D9fvv3esUFVmgdtzoeEuJknoM1sXCSRrlNFduseP/ w+ykuJGvgcPrPDTUtsa05dV+ftG6jl7nZZTKZMCQZ2926zcNxVI6t0VZBLYA81ZqgO AnreEoBDsUvjBxwq30CQ8EX1yvdttkGni8DEtsMk= 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.18 498/990] mm/userfaultfd: wake all waiters on unregister Date: Wed, 25 Nov 2026 15:31:05 +0100 Message-ID: <20261125143833.761548483@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143822.072087159@linuxfoundation.org> References: <20261125143822.072087159@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.18-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: Applied the change to the in-tree userfaultfd_unregister() in fs/userfaultfd.c, since the mm/ file move isn't present, with identical function body but a different location. ] 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 02ff11cf42bd8..1b33c92bae9e2 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1505,6 +1505,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(); /* VMA not registered with userfaultfd. */ @@ -1522,18 +1524,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(ctx, &range); vma = userfaultfd_clear_vma(&vmi, prev, vma, start, vma_end); -- 2.53.0