From: Foxie Flakey <foxieflakey@gmail.com>
To: linux-newbie@vger.kernel.org
Subject: [PATCH] userfaultfd: reset err when move_pages_ptes succeeded
Date: Sat, 15 Aug 2026 19:34:54 +0700 (WIB) [thread overview]
Message-ID: <db93293b-2e02-7ca9-2f92-f52447d2849c@gmail.com> (raw)
When UFFDIO_MOVE moves non huge pages and temporarily fails, then the outer
loop retries again and succeeded but in that path "err" isn't reset to 0.
Later, when checked for EAGAIN error, the loop mistakenly retries moving
same page again which will fail because its already moved.
When the UFFDIO_MOVE returned, this is what userspace observed.
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 <foxieflakey@gmail.com>
Assisted-by: ChatGPT:GPT-5.6-Luna
---
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
next reply other threads:[~2026-08-15 12:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 12:34 Foxie Flakey [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-08-15 14:11 [PATCH] userfaultfd: reset err when move_pages_ptes succeeded Foxie Flakey
2026-08-15 14:13 Foxie Flakey
2026-08-15 15:50 ` Ali Nasrolahi
2026-08-15 16:05 ` Foxie Flakey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=db93293b-2e02-7ca9-2f92-f52447d2849c@gmail.com \
--to=foxieflakey@gmail.com \
--cc=linux-newbie@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.