Skip to contentSkip to conversation

userfaultfd: reset err when move_pages_ptes succeeded

PATCH Superseded Foxie Flakey 2 participants 3 messages Aug 15

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 userfaultfd: reset err when move_pages_ptes succeeded

There is an edge case when move_pages_ptes fails with EAGAIN and then outer loop attempt to retry and succeeded but "err" isn't reset. This leads to outer loop retry erroneously on same set of pages that was successfully moved. This is fixed by resetting "err" when move_pages_ptes succeeded.

Fixes 50944692052b ("userfaultfd: opportunistic TLB-flush batching for present pages in MOVE")
Assisted-by ChatGPT:GPT-5.6-Luna
---
 mm/userfaultfd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/userfaultfd.c +4 -2
index c3adedaaf7d5..595e7e232f90 100644
@@ -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

Signature · 1 line
2.55.0
#1 lore raw
Quoted 33 lines · Foxie Flakey

There is an edge case when move_pages_ptes fails with EAGAIN and then outer loop attempt to retry and succeeded but "err" isn't reset. This leads to outer loop retry erroneously on same set of pages that was successfully moved. This is fixed by resetting "err" when move_pages_ptes succeeded.

Fixes 50944692052b ("userfaultfd: opportunistic TLB-flush batching for present pages in MOVE")
Assisted-by ChatGPT:GPT-5.6-Luna
---
 mm/userfaultfd.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/userfaultfd.c +4 -2
index c3adedaaf7d5..595e7e232f90 100644
@@ -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();
Quoted 5 lines

base-commit: 62cc90241548d5570ee68e01aaba6506964e9811

Signature · 1 line
2.55.0

Hi,

Use ./scripts/get_maintainer.pl <file> to figure out to which mailing list you should send your patches. Also don't forget to CC the subsytem and the file maintainer. I don't think this is the correct mailing list for your patch :)

Cheers,
Ali

#2 lore raw
Quoted 6 lines · Ali Nasrolahi

Hi,

Use ./scripts/get_maintainer.pl <file> to figure out to which mailing list you should send your patches. Also don't forget to CC the subsytem and the file maintainer. I don't think this is the correct mailing list for your patch :)

Thanks! I already sent it previously but there was few issues pointed by someone on IRC and I was sending here so they can check.

Quoted 3 lines

Cheers,
Ali