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=1796195544; b=LQg/qPivl7JgiHPSu9GfweStV18SVeMBCuUKiK4G5a37S08b2jwj+j8x3um6e3hGARKv blfe9F2W4MKxEMNr7Eo8HveSx4ugWNG+txmiGSNCfa7lG9Fkca1VkufMRVJ6qrg27U9gX RCWca+El2xaOgRZd6DsLPG+vQgqh4LSbUnhsINOeREkvmwNKGbk4IQFgPO3VA3r20VVbK Ipdetgf52JrwAaZx6rdcu8fEr4O65LYLYp+UIadkVaXU2baf5Ug6P81DNJcgWXhRB2S/s U7Nh5RlcLPcFxBlh7C3de3x5bTYfxu9391b8cABv4Twp86+0agf35eJFxdafOXDUNdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796195544; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=xElCjEwuGJho9BUBaDYueq2PoJGB2Qt7s4cENvLE24g=; b=w9sHGKJ9D9/2xs65zyG+K8okF3Ph0ONo8RZNAJSQAV+t/MEq6czzIgwY+9v4rWHA1c89 GfTEeW6C4qJnYRbLJHMq/C4E+FHvxTZLiQDmk5uxxWCh1twoweY0kirkO9Yws0wZVnoQQ wqkh4jaQgmZTR1i5ti4Gxr62lIjRsXtfmjFkUbPceuAr7UvPLdQVBl0hAEaYOenKGpuOJ bayeG9019NIqe3PYRMtV7WQbVJNceanVni8ZbQctP+louaxsZq/Tl/NtyDKZ+Ozj9E4rs tt3TRCT2By3n4RHCV5MicMlFpigYxXtb4WRXuOcd8u8kuDlsyN2XyWEEfEC7MgMhtEA== 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=nz95g0U5; 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 B357D606A31A; Wed, 2 Dec 2026 07:12:24 +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=nz95g0U5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DD011F00896; Wed, 2 Dec 2026 07:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796195544; bh=xElCjEwuGJho9BUBaDYueq2PoJGB2Qt7s4cENvLE24g=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=nz95g0U5iwFvD04hFNVpX/Xojy8s50nz6M9x3HHobXjXE37fGEuLrszdjT35EOwba NlVJIBKCKclMNbZT/pfPih3FLZ0Ybj9iSp5tv2Xv9pYAiPru8HXaGdtsDfIuJt6X94 1Biuud16Y7AWIsRgxmZSYnJvONp+SRj7F1TPfLVs3NAeK3fRJ67ktdCbpYHXXlOmFb hUQn0TyK67pTWTuDkQMAAdby6j8gaWcY8BFi2Q2/HChUv66HmmIztKVNJwVvQrstmQ I1nBoZZn96uc4nSGkrU23rc3GHXxnqdqsn0vynj1AookWvM9AKjE8PchVJqsaDFRYa N+WfRYW003cMQ== Date: Wed, 2 Dec 2026 09:12:16 +0200 From: Mike Rapoport To: "Lorenzo Stoakes (ARM)" Cc: Andrew Morton , "Liam R. Howlett" , David Hildenbrand , Jann Horn , Noah Weinberger , Pedro Falcato , Peter Xu , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org Subject: Re: [PATCH] mm/vma: undo userfaultfd unmap preparation when unmapping fails Message-ID: References: <20261101-uffd-unmap-abort-v1-1-1588d7a7c61a@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Dec 01, 2026 at 02:56:49PM +0000, Lorenzo Stoakes (ARM) wrote: > On Sun, Nov 01, 2026 at 10:24:02AM +0200, Mike Rapoport (Microsoft) wrote: > > vms_gather_munmap_vmas() collects VMAs to unmap and calls > > userfaultfd_unmap_prep() for each of these VMAs. This takes a reference > > to the userfaultfd context, raises ctx->mmap_changing and queues an > > UFFD_EVENT_UNMAP on the caller's list. > > > > If gathering fails half way, e.g. because one of the VMAs is sealed, or > > the operation fails after the VMAs were gathered, the original mappings > > stay intact but the queued events remain on the list. > > > > Depending on the caller they are either delivered although nothing was > > unmapped (munmap(), mremap(), mmap(MAP_FIXED)), or silently dropped > > (brk()). In the latter case the userfaultfd context and the mm_struct it > > pins are leaked and mmap_changing is never lowered, so UFFDIO_COPY, > > UFFDIO_ZEROPAGE and all other ioctls that check mmap_changing fail with > > -EAGAIN forever. > > > > With mseal() this is trivially triggered by an unprivileged process. > > Great... :) > > > > > Collect the events in do_vmi_align_munmap() on a local list and splice > > it to the caller's list only when the unmap completes, because mremap() > > may already have events for earlier unmaps on that list. > > > > Drop the pending events with a new userfaultfd_unmap_abort() helper when > > do_vmi_align_munmap() or __mmap_setup() fail. > > > > Fixes: 65ac132027a88 ("userfaultfd: fix regression in userfaultfd_unmap_prep()") > > Reported-by: Noah Weinberger > > Cc: stable@vger.kernel.org > > Signed-off-by: Mike Rapoport (Microsoft) > > Ahem. I see this got merged already without any input from VMA people :) > > The AI slop wave is making the workload nearly unmanageable, so it's easy > to miss stuff, you are welcome to nag though. > > This gets fixed next cycle when the VMA tree becomes independent, but let's > try to avoid this for the remainder of the cycle please! > > I wonder if we could have avoided propagating this terrible linked list > stuff here. But ah well, too late. Believe me, I tried :) > Maybe not possible for a backport but would have been good to explore at > least! Maybe with vm_uffd_state in VMA, but that's a long shot. > -- > Cheers, Lorenzo -- Sincerely yours, Mike.