Skip to content

Commit 9a5cc85

Browse files
apopple-nvidiatorvalds
authored andcommitted
mm/memory.c: allow different return codes for copy_nonpresent_pte()
Currently if copy_nonpresent_pte() returns a non-zero value it is assumed to be a swap entry which requires further processing outside the loop in copy_pte_range() after dropping locks. This prevents other values being returned to signal conditions such as failure which a subsequent change requires. Instead make copy_nonpresent_pte() return an error code if further processing is required and read the value for the swap entry in the main loop under the ptl. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Alistair Popple <[email protected]> Reviewed-by: Peter Xu <[email protected]> Cc: Ben Skeggs <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: John Hubbard <[email protected]> Cc: "Matthew Wilcox (Oracle)" <[email protected]> Cc: Ralph Campbell <[email protected]> Cc: Shakeel Butt <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6b49bf6 commit 9a5cc85

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

mm/memory.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
717717

718718
if (likely(!non_swap_entry(entry))) {
719719
if (swap_duplicate(entry) < 0)
720-
return entry.val;
720+
return -EIO;
721721

722722
/* make sure dst_mm is on swapoff's mmlist. */
723723
if (unlikely(list_empty(&dst_mm->mmlist))) {
@@ -973,12 +973,14 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,
973973
continue;
974974
}
975975
if (unlikely(!pte_present(*src_pte))) {
976-
entry.val = copy_nonpresent_pte(dst_mm, src_mm,
977-
dst_pte, src_pte,
978-
dst_vma, src_vma,
979-
addr, rss);
980-
if (entry.val)
976+
ret = copy_nonpresent_pte(dst_mm, src_mm,
977+
dst_pte, src_pte,
978+
dst_vma, src_vma,
979+
addr, rss);
980+
if (ret == -EIO) {
981+
entry = pte_to_swp_entry(*src_pte);
981982
break;
983+
}
982984
progress += 8;
983985
continue;
984986
}
@@ -1011,20 +1013,24 @@ copy_pte_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,
10111013
pte_unmap_unlock(orig_dst_pte, dst_ptl);
10121014
cond_resched();
10131015

1014-
if (entry.val) {
1016+
if (ret == -EIO) {
1017+
VM_WARN_ON_ONCE(!entry.val);
10151018
if (add_swap_count_continuation(entry, GFP_KERNEL) < 0) {
10161019
ret = -ENOMEM;
10171020
goto out;
10181021
}
10191022
entry.val = 0;
1020-
} else if (ret) {
1021-
WARN_ON_ONCE(ret != -EAGAIN);
1023+
} else if (ret == -EAGAIN) {
10221024
prealloc = page_copy_prealloc(src_mm, src_vma, addr);
10231025
if (!prealloc)
10241026
return -ENOMEM;
1025-
/* We've captured and resolved the error. Reset, try again. */
1026-
ret = 0;
1027+
} else if (ret) {
1028+
VM_WARN_ON_ONCE(1);
10271029
}
1030+
1031+
/* We've captured and resolved the error. Reset, try again. */
1032+
ret = 0;
1033+
10281034
if (addr != end)
10291035
goto again;
10301036
out:

0 commit comments

Comments
 (0)