From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 947B93EDE54 for ; Mon, 17 Aug 2026 22:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787005580; cv=none; b=Ju3Eq5FkInz6d6CrqO8ETqfHZJpFSRoUZsz0bWxOSkhBBFARZql4+bfohQj7BXVh7AT853XQkElPogXyH9Dmfo/sSHrGF1hyubiwM7agpd1Bc31XqAmQ73jdflcYwuPKXSKaS7iWz89/RWu2nFKtLiJerFYnCllAcS6uQhDH5lI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787005580; c=relaxed/simple; bh=Jk6xDoQBptczChmc0mucvIGCMtKRX+k8N06LXMc3cMw=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=GtQbF1ZI8gqHReaGMoGZKDen0DPS8rB7nMYz461UIJmjBV5mk9ufIknss7PIhbRbYOjJFQgofH8xogvzy7vJziAj5vOXJst/Vh1324W0M+8CFCKSsQFQTmorfp8T3SddKoU0olLMqnv8Oaa+FUtSF0kl0ZbMunwsewtEKobrQYU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=h7gneX+8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="h7gneX+8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FDE61F0156A; Mon, 17 Aug 2026 22:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1787005566; bh=1b7jKWdEZGMoFyuy609fAfk/mYE8kL7oO5E00u5yre8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=h7gneX+844xS7D9EO+tsMQ7wp6/YghmaCMnHl894psOygzK3Mj/axlnr34fk66c0+ 5tZ6gmDpB+oO20VFntrD0gNXzjrn9GF3bx+oLVctjc3kS2xjTLlROXE0k/Dzjr060E 22xjgVprrQhGA7WygH4Cp5plfcOcb0oPP0mLVaeM= Date: Mon, 17 Aug 2026 15:26:05 -0700 From: Andrew Morton To: Foxie Flakey Cc: rppt@kernel.org, peterx@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] userfaultfd: reset err to be 0 when move_pages_ptes succeeded Message-Id: <20260817152605.5d2bee3fbf1a2bace4c0eff1@linux-foundation.org> In-Reply-To: <9c936a9f-ed27-e510-872f-5b3b8c680975@gmail.com> References: <9c936a9f-ed27-e510-872f-5b3b8c680975@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Sat, 15 Aug 2026 17:42:12 +0700 (WIB) Foxie Flakey wrote: > > An fix for edge case can occur if move_pages_ptes return -EAGAIN, later > when checked and it is EAGAIN, outer loop would retry again on same page > and succeeded but the err isn't reset so the outer loop would think need > to retry again so it goes back again and move pages again. On third attempt > move_pages_ptes will fail because it already moved and returns an error > that is not EAGAIN when outer loop checks again it sees non EAGAIN so it > dont retry and break out of loop. When loop is terminated it did not update > the "moved" variable from successful 2nd iteration. > > That behaviour manifested into this at userspace > > Source: [ .. unmapped .. ][ .. mapped ..] > Destination: [ .. mapped .. ][ .. unmapped ..] > ^ ^ > \ Kernel moved this far in actuality > What is reported to userspace on struct > uffdio_move's move field > > When the previous behaviour is > Source: [ .. unmapped .. ][ .. mapped ..] > Destination: [ .. mapped .. ][ .. unmapped ..] > ^ > Reported to user space via uffdio_move's > move field Thanks. The text is a bit hard to follow. I asked Gemini to redo it and perhaps you prefer that? https://share.gemini.google/cOWn3pQadvVw > Fixes: 50944692052b ("userfaultfd: opportunistic TLB-flush batching for present pages in MOVE") > Signed-off-by: Foxie Flakey Yes, the pseudonym is problematic - it is contrary to our written rules. But I'm a sucker for fixes, sigh. Perhaps if someone else were to send me your patch with their signoff also, the rules would be less offended. > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -2069,10 +2069,12 @@ static ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start, > ret = move_pages_ptes(mm, dst_pmd, src_pmd, > dst_vma, src_vma, dst_addr, > src_addr, src_end - src_addr, mode); > - if (ret < 0) > + if (ret < 0) { > err = ret; > - else > + } else { > + err = 0; > step_size = ret; > + } > } > > cond_resched(); Maintainers, when reviewing this please let me know whether you think it should be backported. Sashiko did what it usually does when we make it look at uffd: https://sashiko.dev/#/patchset/9c936a9f-ed27-e510-872f-5b3b8c680975@gmail.com