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=1796137015; b=jqdQ06qaiO2OFgrHYFb3a7ZFLyCVt28hBNFO2GfDIFstRgWxnYoh5Wd+rA/z78k2gDKi hWwrj+pbBgde2kcNjlirheLW4oba0876HPKawKmKOBlQ2rkZddg/6rqIYys5bPfXxOLy4 1nhVLGdO2LwLaKcNS7k01xheGLGBZPVCBF73pR3BmY3RlCBeNmDSBS0ujaFkRzBYnw5p+ tgG/JX4OeQfg5/OVb/yh5HdfYrPzGcccoDN5zRviFgAkjn5uEGM4PVOQy0Ki6650fHD2N Cqws3y4VDAh8WpPs7KVkZvYNgVO40TV2nymtLK6e/3eOWRLuK7Nb46a9y/sgDcL8dRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796137015; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=sfnVH6Sbig37aqKOecsHiH6gHyI4uti3OowWjbnqEXk=; b=jSo6IorVPj1cHu6RHtMAgG/1NDfz6muI+L5F+2cJZw/DSxukLuFLXAvcA+BRqqdYToMA cOOkx9fvnk3MBKsp+uQChwVPv6MPtHUuipAuU1N+zOmehoj2AA5ZD7C5rk8D6nTLrnGxe fE/ec2aOW9REgJTjRIvzWnf0mCiz/pfnIYojkr9RNVeJsb1dteNgQlIhCS1Cx4JzYGJ91 cxTQIVvb6ljRTSosWyC+lse/5pWgr884fWn6owcv2VplIfj15ekQ7pzcUP4fz929qN6g4 AZdVAlPLJCJTIlSgRd5Xno/Ndkdrgx8watE0JU/m0gq33FVR1kaniDgsa2jMgGxBMFA== 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=jvDkykDo; 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 D6D49606A320; Tue, 1 Dec 2026 14:56:55 +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=jvDkykDo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 185E91F008A0; Tue, 1 Dec 2026 14:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796137015; bh=sfnVH6Sbig37aqKOecsHiH6gHyI4uti3OowWjbnqEXk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=jvDkykDodCfCssytRSHvcxrEkXMPE3fL1Blke5HRSh1/C2yW7aThlOE5GzGwkOtBI q2lCYFE7ZS2SuOoIKnlFcBmtTal3H7cISN31UOOqr3QGwt1ayYAJo5ss1LOYToOLSM y1uPECfmMD1qALibcoTOJbbi6Zvtf2z1i7jV8H8fGvIwt3LklRe8Eymb3/4yxKrvyD +hwCoTgPt27kUc17UIdQmYfvovkHxQM8/KSkKG9sClte89kMXoq2LTOZBknfgxEpz3 uqtolKglcrV/OY+d1aWy3pGnUFPLKEdlNr+wlW3TbHjWGIygPoB+0GJDgGSP+6bJyR 5pn/kaTfDSkXQ== Date: Tue, 1 Dec 2026 14:56:49 +0000 From: "Lorenzo Stoakes (ARM)" To: "Mike Rapoport (Microsoft)" 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: <20261101-uffd-unmap-abort-v1-1-1588d7a7c61a@kernel.org> 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. Maybe not possible for a backport but would have been good to explore at least! -- Cheers, Lorenzo