[PATCH v3] userfaultfd: reset err to be 0 when move_pages_ptes succeeded
From: Foxie Flakey
Date: Tue Aug 18 2026 - 23:08:41 EST
During move_pages() operation, when move_pages_ptes() returns EAGAIN,
the error code is not cleared even after we processed it. This leads
to a successful retry but then the same pages are retried again due to
the stale error code. This time move fails because pages are already
moved, loop is terminated and move_pages() reports a failure.
Clear the error code once we processes EAGAIN.
Fixes: 50944692052b ("userfaultfd: opportunistic TLB-flush batching for present pages in MOVE")
Assisted-by: ChatGPT:GPT-5.6-Luna
Signed-off-by: Bryan Lim <foxieflakey@xxxxxxxxx>
---
Changes in v3:
- Updated to use proper sign off.
Changes in v2:
- Updated on description to be easier to understood
- Reset err before retrying, instead of fixing right at the move_pages_ptes
branch.
- Added Assisted-by, received an answer few days ago from linux-newbies IRC
that even I just used AI/LLM as "fast path" of git bisect. I still need
to add it following
https://docs.kernel.org/process/coding-assistants.html doc.
---
mm/userfaultfd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index c3adedaaf7d5..ec5d511bd179 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -2085,8 +2085,10 @@ static ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
}
if (err) {
- if (err == -EAGAIN)
+ if (err == -EAGAIN) {
+ err = 0;
continue;
+ }
break;
}
--
2.55.0