From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 680C6606A31B for ; Tue, 27 Oct 2026 08:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=kUiOrK6L; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YgWQ0jUy DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=yYgcjxrZzXoy0psYU0Nq+QxW34HHCYEZSvr+g4Xkf3Q=; b=kUiOrK6LwYazstdIHzUS5SZFYP LqgGIo/MtHDBxhVQYFiN+awWryCkresGPxnOA95EAK9VIX+rgGqn5g4RYDEVH/OTkdLPelxpqJUVY Xjj2SQLFHdIPl+s05dJtW/KE7GSxnAyfyLPyCP+9+2q/7mEVhG3P4vKlAVYrG6/BSOYR2sREgY6x9 yyk9E1GGxr+ufNqwMX7wNOcaTmvN18ChmveAAU+qIETADIYJsPPv1KyYl9tnGJRb/B4Wzz9JEpXJ9 +KYf/7EGpkYHNCC1BBNGa8JiAjiJt58fm6iqurnXkt2eknRvk1riswoZgVqdamZ7rJukV33oupRyn yXHlNCKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLcfv-000000043DP-2PNO; Tue, 27 Oct 2026 08:36:55 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLcfu-000000043Ci-0giQ for kexec@lists.infradead.org; Tue, 27 Oct 2026 08:36:54 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 4B6C6601F9; Tue, 27 Oct 2026 08:36:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0202A1F01825; Tue, 27 Oct 2026 08:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793090213; bh=yYgcjxrZzXoy0psYU0Nq+QxW34HHCYEZSvr+g4Xkf3Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=YgWQ0jUy2R3Rh6tVUq1cYOMph9r06iXsVVDLcV7MttnPuaU1a16q5fg+QaCk7f+Fx FzVMQCYd/p+MkpgpnFyBzCzl+fi3rnW0pIlK1fRrVDOkrsTCamrF3lIKcsPE77OK+Q GIcJKTG5KNfSBGz+lX+edsIgMQTXvFzfUt5kzxtbIx9RH8l3e/D3N5JbaEWymZs/AM k9m2KnjFXcgH69AYMz8pQx4Dw81BFFnZ5uku8faOD0mwALYfuFExgFXDKgj/Ka6VQy tuZal11vRiWnP6mU0vu9Ih1K1GdOoDAAEAdwlWfYaybPxhriIQnfLoHF5xpZXNFlOf U/cWZtqdU5sAQ== Date: Tue, 27 Oct 2026 08:36:36 +0000 From: "Lorenzo Stoakes (ARM)" To: "David Hildenbrand (Arm)" Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kees Cook , Peter Zijlstra , Jann Horn , Pedro Falcato , Hugh Dickins , Pasha Tatashin , Pratyush Yadav , "Matthew Wilcox (Oracle)" , Jan Kara , Zi Yan , Lance Yang , Rik van Riel , Harry Yoo , Alistair Popple , Nico Pache , Ryan Roberts , Dev Jain , Usama Arif , Kiryl Shutsemau , Matthew Brost , John Hubbard , Peter Xu , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Oscar Salvador , Minchan Kim , Muchun Song , Xu Xin , Chengming Zhou , Chris Li , Kemeng Shi , Nhat Pham , Youngjun Park , Gregory Price , Joshua Hahn , Rakie Kim , Ying Huang , Jason Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, Josef Bacik , stable@vger.kernel.org Subject: Re: [PATCH 24/46] mm/userfaultfd: wake all waiters on unregister Message-ID: References: <20261027-fixes_core-v1-0-6f74bec9a5bb@kernel.org> <20261027-fixes_core-v1-24-6f74bec9a5bb@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261027-fixes_core-v1-24-6f74bec9a5bb@kernel.org> X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Tue, Oct 27, 2026 at 12:17:44AM +0100, David Hildenbrand (Arm) wrote: > 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 ] > Signed-off-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) > --- > mm/userfaultfd.c | 22 ++++++++++------------ > 1 file changed, 10 insertions(+), 12 deletions(-) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index 7e30b5ff17be1..2122676c4220f 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -3977,6 +3977,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. */ > @@ -3994,18 +3996,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.43.0 > -- Cheers, Lorenzo