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=1796384789; b=JE3n/FdHXWAxReQfGOd+diY1k4PJy+9IkwuGdyht4M0IOzzusI5w14DTi22V6E0dyfYk SWYgVW0uTM2qcwh/ev0V5Sr06I+wIT598QiXHzkHd3nLpACPPFpRimdscgfu4WWo45+S6 /fD/IXRC7kA0ruhqIR2LYBH/+LAryIl75eeV9yLhRlyPbVuppbjIi4tRK7oH5CTRzyboH PIuXRa/lV7GLOJXM9J5ZqFpXXhlBJXacwmNBQnqNlNNQ3DhAJ26qPz/sCavB/8d4jlGj6 V1yUXYSFQJzj+wWdXvpNagDG2tiqibmQ9HjF2lTQIWogIw+Trnc/08l+MU3cxMfwZ/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384789; 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=E/EXVuei6ie1Qz+XS4w8FKyGFOCfPJhy2ffplkRnozo=; b=bt3QPbwM0vLpo0EBYJ0cnfxnm3O7Qq62sg1TjcI/vX/RjtXs3GPeUGg3pFF6ITbsiCa3 IQ5/QnjlK2DQpz/K9TjWwSyR0/iFWdh2iKWq6FWstXWxZvYRf+gHEH2IDlVm2zIQN2uKq ASGR46bTylwGI8r6F0EMROG0fq56TdeJnevHK9J66mGiKK3VIA9DdIL4dTY4orOE43hTa 4X6B2+ZCzz+R/ScBSD7Fj+Qem4O1hUpyct/okOSiXPdFoFi92nNnYzdPUq49p7rKxn4MW oUn6nt7ajZKxzx0zvLW1a1q8/8Y5dDy9w+t/s+UE7DLcqgihdtstdLc9hvbIc5FSUPw== 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=tIcyOqyH; 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 2C806606A322; Fri, 4 Dec 2026 11:46:29 +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=tIcyOqyH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D4D01F000C2; Fri, 4 Dec 2026 11:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384789; bh=E/EXVuei6ie1Qz+XS4w8FKyGFOCfPJhy2ffplkRnozo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tIcyOqyHBa84WssYeU8hMxtMz7A2/7XfgcjvRgK0OxB/vwa4gawFOjgdgOpuwPP0b 9aQjKuBkqkwgUHPEZIGtUyZdCcwOqBq4aPJVUVSz2SbMYA0gbDoKf+Sb0ayMc3/d5Y au19eTTMkBmwSlbe74HTFuD0EeOhOvayjR0L+s0U= 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.6 0295/1167] mm/userfaultfd: wake all waiters on unregister Date: Fri, 4 Dec 2026 18:55:22 +0900 Message-ID: <20261204100709.718976789@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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: Replaced the unregister wake's ctx argument with vma->vm_userfaultfd_ctx.ctx, the VMA's own context, and the file path is fs/ instead of mm/. ] 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 ba138f968526f..460eb3017b23c 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1659,6 +1659,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)); @@ -1679,18 +1681,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); /* Reset ptes for the whole vma range if wr-protected */ if (userfaultfd_wp(vma)) -- 2.53.0