From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9FF8D313E01 for ; Thu, 2 Apr 2026 13:30:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775136603; cv=none; b=t6DOCLB3QJxHKupip5pmybo90d30yVb9qjXU5elvT7dodVfxThu4OXG+N0uPp3WKN7DDu1MLWOjEbb1RxZmcXCRl8QT5M2P5/vFeACFu+tL04sjAyBa0wI8UDDFvZaFQxBDOtWU2hofR3EQrZkoTGt2yrkI3xMd/UZ9W4Ec+dGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775136603; c=relaxed/simple; bh=7PPqw0mpoF7hzbxywN2ZS5S5Splc0MSnYlxakXuPGD0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=S7GSZpGu189Ayxi+qVEukJWjg3rZBnAvVFnRQR2+QKyXvpbfq8VHDeQAjjQ2HpT7Wmuzdu+NO0AYbHEnA5KwzpIdDk7afmEqwk8/xR7b2M43WBwkCJ78cX8/hneoz+UdY5JjREtWtzXPHDgp3hSYZlXzZy6T+zrbxdaLdwLb1Zc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=W69XV4mE; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=cuG+e5xH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W69XV4mE"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="cuG+e5xH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775136601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oab+9bmugFMLkp4c4nxmqbTKnHGTJUk1xqQPbFv513o=; b=W69XV4mES+ILYyjs2HPueiXJWSaRhbSBjm/OhwMdmzyjB/cqA81ojBdO2K5YFs9qzv5rKj GbcrL9sTcpGaVYwWICbiCiKho2KA0cTxxhQxkfiHlkIj4whymGQp9lAdvWSLD7tGsw4uAS 2hClXU/JW2u5HWfRPeDUaNPHq4myIe4= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-ySfB9UcDPYm4UCR-41CSOw-1; Thu, 02 Apr 2026 09:30:00 -0400 X-MC-Unique: ySfB9UcDPYm4UCR-41CSOw-1 X-Mimecast-MFC-AGG-ID: ySfB9UcDPYm4UCR-41CSOw_1775136600 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cfbfac0e05so231643485a.1 for ; Thu, 02 Apr 2026 06:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775136600; x=1775741400; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=oab+9bmugFMLkp4c4nxmqbTKnHGTJUk1xqQPbFv513o=; b=cuG+e5xHNZtVNolJ6IS4NL9W0IjyFskhkndKAmNSrrm50DhW5PR/vvvOq/EpKJ2VkE d63TjzMBQIV5nz88rfoT7bUcWx6B4e78zdpjzs7i8bj96DYLYruOiqv+JOe10sEweMiw qYT6OAHxlu3lCBy8Cbv6YlwtPqbTjfhKE/plR/5y+vNUCGIdqcdzQWN1b8nNGzpeika1 Z7vaCOumU7dgxYW0QzIjXxvR4WUmefDfhEMxMB9FAd/mfJw1YsDVX4if6McJjaKx0MAu R/cYHZZH4fNyIwiLR0s34YoUjtbSJgEpSgPdJx4UzSOTpK9c5YbbzzPDH5GBDzAkpdEo LpiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775136600; x=1775741400; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oab+9bmugFMLkp4c4nxmqbTKnHGTJUk1xqQPbFv513o=; b=sEz6WCRkeGV8fuF3eox0ZH/f7CmyLC9IXdyqylpGJp1rxxlW4pWT6ONxYnmgPMws+q +ZEHE1liyw77+lLr6jm1n4Kd+n2iDadcKEEPY6EG0sUSn/gDqgQofGMPH57J9VhZa+Vs jqIJG/3FdDYzWEZDrGUKZW/m3d+ESD4ukyNcta2HkjPSEvdK4/DYr6fRrTjwsBRM5955 KaVINGCL1Cm/zeAqUbF+T982bRpOVKjUdIrw/gtsuoO/yl98Nxgf0ERW49dl0sbabyjo Yl52omKz9WHqiFw86Lqmj5kcw2B15se9N85YJevh7ZTfZ1V+F3lH3fMI1SB4XOUgbI3z mT0Q== X-Forwarded-Encrypted: i=1; AJvYcCUuEMrGnbUiym4184n38XBIzh10/SoVShfzGadpdvpGK6sDQOUzA8rVumqbmCAoAJ06n05hiD9CTlLLqQY=@vger.kernel.org X-Gm-Message-State: AOJu0YxCtm4IDYc9KjQwGLIS0yArSDkO0bx0hagJuAKTuV7ffZg6J5Gu YSq/RuN2VGPoQd+2TWQw/qGOm0VNqxqMIuTOfQF/aI15dIa6Tq51zGJy0YD4rE1p7iKQV7Z/CLi uKfWhcIS6RM3Cs9YsaJUEC3GyhHo7cmbcbykXtUZjCh5ZmcXscq4roBMv3mtnKqbMhQ== X-Gm-Gg: ATEYQzyI0yMKYwSQhL1V4X4lEv7zkCuJfuqPXfweNOnag2hvEP3upw1ElB8/Sfn5IrR gagaaNZ9BY1+ODnYHTY2u6x8xEtg6gM96fcXrwDKXjaBlAqtaXm+D82IaeRVGsdIgiOidb/SPhR zznI9G5q3t1/IccXiwOmqIMjStIS6m+tLrH3vvwRzEnUCWPXiVFxSFrp9zwe7edd7Z0DU2lSUp/ b0MRybHKiacaW+GdJUAm11bHaD1zUWAD+MQz/U7Zz+gUwKaIsul6F3RxxtbSP4fiCvtH1Uxs0hm CyWaaA5b2Cb9iGAZO35qADpSH3omCADP4rdaUbwfI9GmlbPRtGW5EBQQYc8bC+rC6bd0TtQZaVT cRgiuuzI0i3+/OwZPGSveOO+anhtcBUXg++oyAu1kyXMz7g== X-Received: by 2002:a05:620a:2947:b0:8d0:907:a318 with SMTP id af79cd13be357-8d30321dad9mr264192985a.27.1775136599625; Thu, 02 Apr 2026 06:29:59 -0700 (PDT) X-Received: by 2002:a05:620a:2947:b0:8d0:907:a318 with SMTP id af79cd13be357-8d30321dad9mr264187485a.27.1775136598937; Thu, 02 Apr 2026 06:29:58 -0700 (PDT) Received: from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d2a5c5fe8esm217774385a.16.2026.04.02.06.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 06:29:58 -0700 (PDT) Date: Thu, 2 Apr 2026 09:29:56 -0400 From: Peter Xu To: Mike Rapoport 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=utf-8 Content-Disposition: inline In-Reply-To: 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? 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. -EAGAIN essentially requested the user to retry. If the VMA is not legal to be operated anymore, it will fail later. However we should allow legal users to pass. Thanks, -- Peter Xu