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 3FE842F83B5 for ; Sun, 16 Aug 2026 09:15:29 +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=1786871730; cv=none; b=THE3LK7F4glqO803E4WCLwXFCbfqOBHVn1TPaf7bzg+udKMhrHkF0Oab9RASK5TmztD2YTfYOw2jjTPTP8GTHZUXKX7HRgp+klYHMcQ0FF5yaNpT8rKAnhLPXIcwR/XbRf5LYSE+5losST3eDvgz/KSkXjhwQ8CG2FkhH2GCDMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786871730; c=relaxed/simple; bh=y3eK29y4NKXQ+W0Y1YHuypeGMbWPeLQP9SFJwHH6EdI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Vt3PHY8ZYgmgJyfomYwHMj2m6Ss5JqNi1H0AnxGA8ZkiVpyCXiJ1fsyERCxykp+qwJOZch0T2mKHmCWKvueA67QQN1K1/FZBX1QfLrRYoQEoqMesRDBdl4Ea5RliuKq5b99leqMDVpdvs4IlRJY2KsiBJn4gRLPGtcbIrKkCDdM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lVgxsH+k; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lVgxsH+k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9134F1F000E9; Sun, 16 Aug 2026 09:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786871728; bh=2VGe88VAgYCJFGRjViK7Ut9gr8nKRTBvPXPBjJG3Wcc=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=lVgxsH+k0osth/xM2LJKAeiCBWztelADf/krHPlTt8D3crtjONIb/b4yVelO1OK49 EDxFptWQ05JYmd2xZIy9oC5cPLpuK1A6bzYylLM86CN5qI7kIyHeSt5tBGP78PAGcG psDXjlVZZfLrZwPh+b3crqrr7/p/bvs4pRanOMcBbEYa89Ag6AVB5KM5+iFzyPTekX xK3Fe+jjPQXrAvE2YwhMG2uL89F9f5PuIpibEmsLEn3GEoTNAiMzDZO20kYWVZnqgN V5fPacuNF+444XAaIf+WC5qAjSypuUdzQFZHyExvFI2shLenc1iuy+MhloA9g3JG1h bRJE5xUgCMGDQ== Date: Sun, 16 Aug 2026 12:15:22 +0300 From: Mike Rapoport To: Foxie Flakey , Suren Baghdasaryan Cc: akpm@linux-foundation.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: References: <9c936a9f-ed27-e510-872f-5b3b8c680975@gmail.com> 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: <9c936a9f-ed27-e510-872f-5b3b8c680975@gmail.com> (adding Suren) On Sat, Aug 15, 2026 at 05:42:12PM +0700, 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 > > Fixes: 50944692052b ("userfaultfd: opportunistic TLB-flush batching for present pages in MOVE") > Signed-off-by: Foxie Flakey Is Foxie Flakey your real name? Signed-off-by should be using a known identity (sorry, no anonymous contributions.) > --- > mm/userfaultfd.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index c3adedaaf7d5..595e7e232f90 100644 > --- 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(); > > base-commit: 62cc90241548d5570ee68e01aaba6506964e9811 > -- > 2.55.0 > -- Sincerely yours, Mike.