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 48F30606A31A for ; Tue, 27 Oct 2026 08:43:34 +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=lhxHFJG+; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=WzfqTN9d 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=dHr232roZz4zxvNcr7fz7EZ96bBQfhBelI7N1e6dtIg=; b=lhxHFJG+BubFs1sDd75wmVKPFV Hku3AgMd1o57Wj0KM6OHw4LqtHot9Om6YkLuhEKy1e4L+8fSSRTPOY2VeniaVB2qXSQcia0W4Jx7m f6o98uPUq7EAuBoP8v/1EFOhntzlAYiVGmQCtBYjL/1+VhsjQOIr8E1s9fnqlltB/0lY//Bvj+gZ1 /0cDaueNIEfZ1lUjo+GsDBnFE8oP7q/U9a14AwdlzRxo27uMZtEORnCqt9TR8qmLoVw5+hIMCsHHD EoR5YEjCiczVeCU5URY6TzUE+p/ufyjss0hJ55iP3ZidXMqfSjY/MeQIP0gK+OSaOnxsdmt9MLHiK dh7O4bNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLcmL-000000044Ho-3kQY; Tue, 27 Oct 2026 08:43:33 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLcmL-000000044HX-0V2Z for kexec@lists.infradead.org; Tue, 27 Oct 2026 08:43:33 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 36E81601FE; Tue, 27 Oct 2026 08:43:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9500B1F01829; Tue, 27 Oct 2026 08:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793090611; bh=dHr232roZz4zxvNcr7fz7EZ96bBQfhBelI7N1e6dtIg=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=WzfqTN9dybqeLWoA8oUAZ1tXSG8xyenSoildQDFUPskrIwuh0Om8GmkGOBhQ5FsqX 3B6I40g9wmGk8NCIIhxhAbDqi/ZMQNeLz88bXgkLZL9wp3hp24AVldencxxNOmO56E 4Dk/LyzP9i6+CjPNOmovIvMvgBMfOCP5ftzi7ttPrA1HXuEw+YPYQEt8JuPCPhU9Qh FTU2I/BXKFE66SYqvBcFQdHZeCq08jT60hhxAZK8vNRyQ92PVr8LzDAXu2OR6KFYh4 ggHTOX/ZZnJQfYnUIldz4DBR8skhm8PsS7DC9s4XnGtCHDusD1BrLy77dRYwXUQQzN YEpV0CA1ETDaQ== Date: Tue, 27 Oct 2026 08:43:14 +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, stable@vger.kernel.org, Josef Bacik Subject: Re: [PATCH 23/46] mm/userfaultfd: write-lock the VMA before waking waiters when unregistering Message-ID: References: <20261027-fixes_core-v1-0-6f74bec9a5bb@kernel.org> <20261027-fixes_core-v1-23-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-23-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:43AM +0100, David Hildenbrand (Arm) wrote: > userfaultfd_unregister() wakes pending missing faults before clearing the > VMA's userfaultfd registration. With per-VMA fault locking, holding > mmap_lock for write does not prevent another fault from queuing after > the wakeup but before userfaultfd_clear_vma() write-locks the VMA. That > waiter can then remain asleep indefinitely. Oof. I guess userfaultfd_clear_vma() only implicitly takes the VMA write lock via vma_modify_flags_uffd(). > > Call vma_start_write() before waking waiters. Existing fault handlers > queue themselves before dropping the VMA read lock, and new readers are > excluded until mmap_write_unlock(). Clearly an oversight from the VMA locks work. I guess was always a Herculean task to catch every single point at which there is an implicit assumption that mmap write lock ~ readers (esp. faults) excluded. > > Fixes: 29a22b9e08d7 ("mm: handle userfaults under VMA lock") > Cc: stable@vger.kernel.org > Reported-by: Josef Bacik > Signed-off-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) > --- > mm/userfaultfd.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index 669f71d485d02..7e30b5ff17be1 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -3991,6 +3991,9 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, > start = vma->vm_start; > vma_end = min(end, vma->vm_end); > > + /* Prevent new userfaults from being queued after the wakeup. */ > + vma_start_write(vma); > + > if (userfaultfd_missing(vma)) { > /* > * Wake any concurrent pending userfault while > > -- > 2.43.0 > -- Cheers, Lorenzo