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=1796025228; b=K7uzjX81PAxYScsWYDUjjQWiFCbJ3Ee4eW5SavEPALB224l9Og5iprOVm7kW8iOek7yy 4UBa+Tn704Ga32R3+4ZkYu/JQSFreCW/TrKjvHxfdQ2ccPyK3KT6cIKayolHXhVpkBnEi A508PayBtHBklZuGJsrM/JouHUQqPbZU95gM06SruoI5WJl51e2a6TKaPdqGmsbnYKTK5 bIotmbgANe1h9ZpisK/aXwYxwPDMIhh215iVsczRSFUYTBPGvYr3F+k7a4FEvJNJMR4Q3 PvhnxIbAPYWjT6yRYPF/pibboXaU/b4EqXTqkmJOwHHVeaYwlKjVcQ9sAIYiKY8FuUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796025228; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=XCWGvm0IK8QbqkKqs/rkthKN04BF5J/iSOW9P56DUfU=; b=Q+8CsTg1SQ1FOA6uHUcxK9WqDTG34nUtihUr9RL45dppUwb6xDQCBhc22AoKKRTOIyOx Ro/yDRCvNuKioFFtipV15d01Gmgo+0PvPevu/JTC1Xb1jamqULQ+wv9cAJX58BDdw4ldE sK0f806uEKTY7sH+5QI/lXRnsPX8UN/4gqGuSUZ7Zbx3zRIDm8SqV5mvDcFRuT7EGXgH4 aSkzkGEkU8Z/Q1Xq9JUVbVvhgpFam8gsfKIi6gDsDs2wY4kC6hWaO8/BHMoBMKAac5o2l q9f2OQu+sYWthD7Rw1MGrQCiFod4V9B/NHH7ZJ/yUrMeA/bmyb4UVrnNdI9V0MSHGZg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jplewd8t; 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 6F5F2606A32D for ; Mon, 30 Nov 2026 07:53:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jplewd8t Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0227E1F0089F; Mon, 30 Nov 2026 07:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796025227; bh=XCWGvm0IK8QbqkKqs/rkthKN04BF5J/iSOW9P56DUfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jplewd8t6RldI9gtOouIlfO8QLq8G9y4eUmwMqziWCvXqeIDx4lh66GRpcMnClhs1 orP6To4bps7mKyIMPoNwT6xPLPyPhLLt3HuUy1ws8KqZKvlResm4jXEbk1KAe3M9aF zIz7R/N13dUrKZJh5O5M1nPZ/ncersKMDPdL59VlrDhYvwisbCdqzeab/r+JYQ/xpF YlM6Mgxaoce62VngZP5H6tGvf2YzFgl//zTSmMmpc9IUC2Esl0khUOOdEY5R2d3q3c VF0IEFNM8t0hXJ12zPVIgcalx/Ctbsf9Flk2sHEg0yD4McS5FXpkaktsHGqEF6kV1C yXgTEfkdviSmw== From: Mike Rapoport To: stable@vger.kernel.org Cc: Josef Bacik , "Mike Rapoport (Microsoft)" , "Lorenzo Stoakes (ARM)" , Muhammad Usama Anjum , "David Hildenbrand (Arm)" Subject: [PATCH 6.6.y] mm/userfaultfd: wake all waiters on unregister Date: Mon, 30 Nov 2026 09:53:34 +0200 Message-ID: <20261130075334.246765-4-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261109201332-failed-6.6-3afb19d68cc5@kernel.org> References: <20261109201332-failed-6.6-3afb19d68cc5@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Josef Bacik 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) (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) --- 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