mm: move the copy_one_pte() pte_present check into the caller
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 23 Sep 2020 17:04:16 +0000 (10:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 23 Sep 2020 17:04:16 +0000 (10:04 -0700)
This completes the split of the non-present and present pte cases by
moving the check for the source pte being present into the single
caller, which also means that we clearly separate out the very different
return value case for a non-present pte.

The present pte case currently always succeeds.

This is a pure code re-organization with no semantic change: the intent
is to make it much easier to add a new return case to the present pte
case for when we do early COW at page table copy time.

This was split out from the previous commit simply to make it easy to
visually see that there were no semantic changes from this code
re-organization.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/memory.c

index 31a3ab7d9aa379c0fa97990b93a6d0d3c7338507..e315b1f1ef084103196e712b3ba9188d2bff1aa2 100644 (file)
@@ -773,8 +773,8 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
        return 0;
 }
 
-static inline unsigned long
-copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
+static inline void
+copy_present_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
                pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
                unsigned long addr, int *rss)
 {
@@ -782,12 +782,6 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
        pte_t pte = *src_pte;
        struct page *page;
 
-       /* pte contains position in swap or file, so copy. */
-       if (unlikely(!pte_present(pte)))
-               return copy_nonpresent_pte(dst_mm, src_mm,
-                                          dst_pte, src_pte, vma,
-                                          addr, rss);
-
        /*
         * If it's a COW mapping, write protect it both
         * in the parent and the child
@@ -821,7 +815,6 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
        }
 
        set_pte_at(dst_mm, addr, dst_pte, pte);
-       return 0;
 }
 
 static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
@@ -863,10 +856,17 @@ again:
                        progress++;
                        continue;
                }
-               entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
+               if (unlikely(!pte_present(*src_pte))) {
+                       entry.val = copy_nonpresent_pte(dst_mm, src_mm,
+                                                       dst_pte, src_pte,
                                                        vma, addr, rss);
-               if (entry.val)
-                       break;
+                       if (entry.val)
+                               break;
+                       progress += 8;
+                       continue;
+               }
+               copy_present_pte(dst_mm, src_mm, dst_pte, src_pte,
+                                vma, addr, rss);
                progress += 8;
        } while (dst_pte++, src_pte++, addr += PAGE_SIZE, addr != end);