From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF8D63A5E9D for ; Thu, 9 Apr 2026 11:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775733622; cv=none; b=ujlJSsoVI0HNfKA5U5O6fhYq5QDkEkjNKOkid9eU4pb5/d0CwyyIYu8Vgx4YjSiZjVFQiCPJR+kcmudypbMiqTCsBRmM2CDAMIFXpb1pM6FRwwi2yIzcKHB4WAd1MlTd+QJmfCjLvk/HHlPOxENc6LF5GRCYRigVr/lFR1rJVv4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775733622; c=relaxed/simple; bh=/o2Kzq4IdBBIeCMTS+ThAJwQJ3UP87vmStNfXO+BE+A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WdFSJCrd75eqNBUDGEb0LF423vJaHZlMtyehyzLU2HJD2cM22g5qna+yw6xP4Xi5PuYxbSSuXCE5G4tuzczqBU2e/ii2iySiTrVjXeTQDOlpyFcajLKQ9LM0+adUXTTNpKCiPBh6yZLf3ZBQY0pIR9nhFaD214RlPZNytFKxSzs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IWgByLzq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IWgByLzq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40755C19424; Thu, 9 Apr 2026 11:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775733621; bh=/o2Kzq4IdBBIeCMTS+ThAJwQJ3UP87vmStNfXO+BE+A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IWgByLzqdhdkhrcG2Xyw13/qx7xftZQnzpDqm3VXJGen68ZDTYJSCxuK0JhaFNyTX 41fmJuKHAOrF/0t3MxHNPi2G+ntpxdPsuzOGFjQ+n3H0AtnI4N4Gtw0t6FVZvn6xRI 1yLtLjsnd3DHzWYgu/s8MF/F+pKug+dZiz3/MnoUCQwqnJeeg1p4YapTgpWexN57Ra qFX8fLNo01+pDPaJa7b8IzBrvVfYUL6mGjYaWPL8RvVop19eZIa+7lro05C8GVPJj7 e9kxgBfRyiNOPjWnKFf2dAQEO9VvhN2vhZUkoJTdBPOhPj1DhbJE2sIS4QAgN+GelV 9TWWMYfi8llhw== Date: Thu, 9 Apr 2026 14:20:15 +0300 From: Mike Rapoport To: Peter Xu Cc: David CARLIER , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka Subject: Re: [PATCH v4] mm/userfaultfd: detect VMA replacement after copy retry in mfill_copy_folio_retry() Message-ID: References: <20260331134158.622084-1-devnexen@gmail.com> <20260331200148.cc0c95deaf070579a68af041@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Apr 02, 2026 at 09:29:56AM -0400, Peter Xu wrote: > Hi, Mike, > > On Thu, Apr 02, 2026 at 07:02:40AM +0300, Mike Rapoport wrote: > > On Wed, Apr 01, 2026 at 03:22:03PM -0400, Peter Xu wrote: > > > > > > The other thing is I just noticed the err code was changed to -EINVAL for > > > snapshot changed cases, sorry I didn't follow previously as closely on the > > > discussion. I think it should be -EAGAIN. It's because the userapp can't > > > resolve -EINVAL failures and app will crash. In a VMA change use case, we > > > should return -EAGAIN to imply the app to retry, rather than crashing. > > > > No. The return value should express that the VMA is invalid. -EINVAL could > > work, but looking now at the manual -ENOENT would be even better: > > > > ENOENT (since Linux 4.11) > > The faulting process has changed its virtual memory layout > > simultaneously with an outstanding UFFDIO_COPY operation. > > The VMA changed, but it doesn't mean the UFFDIO_COPY becomes illegal, am I > right? I don't think that "munmap + mmap + userfault_register" during an outstanding UFFDIO_COPY to the same range is, hmm, the smartest thing to do, and I think aborting the outstanding UFFDIO_COPY in such case is better than allowing it to continue. > For example, I wonder if it's possible someone runs soft-dirty concurrently > with userfaultfd, we shouldn't fail the userapp if there's a concurrent > thread collecting dirty information, which IIUC can cause VMA flag changes, > and should be benign, and I think there can be other things causing the > interruption too. Right, we shouldn't fail if some of the VMA flags changed, but we are talking about of complete change of the mapping, with potentially completely different backing store. > Thanks, > -- > Peter Xu -- Sincerely yours, Mike.