Merge tag 'scsi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb...
[deliverable/linux.git] / mm / memory.c
index 5d2ef1217d0c6f8747f3efc448a8cc65b27c2867..494526ae024a3173fc200d47e36087f6252852c2 100644 (file)
@@ -720,7 +720,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
                print_symbol(KERN_ALERT "vma->vm_file->f_op->mmap: %s\n",
                                (unsigned long)vma->vm_file->f_op->mmap);
        dump_stack();
-       add_taint(TAINT_BAD_PAGE);
+       add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
 }
 
 static inline bool is_cow_mapping(vm_flags_t flags)
@@ -1548,8 +1548,24 @@ split_fallthrough:
        ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
 
        pte = *ptep;
-       if (!pte_present(pte))
-               goto no_page;
+       if (!pte_present(pte)) {
+               swp_entry_t entry;
+               /*
+                * KSM's break_ksm() relies upon recognizing a ksm page
+                * even while it is being migrated, so for that case we
+                * need migration_entry_wait().
+                */
+               if (likely(!(flags & FOLL_MIGRATION)))
+                       goto no_page;
+               if (pte_none(pte) || pte_file(pte))
+                       goto no_page;
+               entry = pte_to_swp_entry(pte);
+               if (!is_migration_entry(entry))
+                       goto no_page;
+               pte_unmap_unlock(ptep, ptl);
+               migration_entry_wait(mm, pmd, address);
+               goto split_fallthrough;
+       }
        if ((flags & FOLL_NUMA) && pte_numa(pte))
                goto no_page;
        if ((flags & FOLL_WRITE) && !pte_write(pte))
@@ -2938,7 +2954,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
                unsigned int flags, pte_t orig_pte)
 {
        spinlock_t *ptl;
-       struct page *page, *swapcache = NULL;
+       struct page *page, *swapcache;
        swp_entry_t entry;
        pte_t pte;
        int locked;
@@ -2989,9 +3005,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
                 */
                ret = VM_FAULT_HWPOISON;
                delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
+               swapcache = page;
                goto out_release;
        }
 
+       swapcache = page;
        locked = lock_page_or_retry(page, mm, flags);
 
        delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
@@ -3009,16 +3027,12 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
        if (unlikely(!PageSwapCache(page) || page_private(page) != entry.val))
                goto out_page;
 
-       swapcache = page;
        page = ksm_might_need_to_copy(page, vma, address);
        if (unlikely(!page)) {
                ret = VM_FAULT_OOM;
                page = swapcache;
-               swapcache = NULL;
                goto out_page;
        }
-       if (page == swapcache)
-               swapcache = NULL;
 
        if (mem_cgroup_try_charge_swapin(mm, page, GFP_KERNEL, &ptr)) {
                ret = VM_FAULT_OOM;
@@ -3062,10 +3076,10 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
        }
        flush_icache_page(vma, page);
        set_pte_at(mm, address, page_table, pte);
-       if (swapcache) /* ksm created a completely new copy */
-               page_add_new_anon_rmap(page, vma, address);
-       else
+       if (page == swapcache)
                do_page_add_anon_rmap(page, vma, address, exclusive);
+       else /* ksm created a completely new copy */
+               page_add_new_anon_rmap(page, vma, address);
        /* It's better to call commit-charge after rmap is established */
        mem_cgroup_commit_charge_swapin(page, ptr);
 
@@ -3073,7 +3087,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
        if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
                try_to_free_swap(page);
        unlock_page(page);
-       if (swapcache) {
+       if (page != swapcache) {
                /*
                 * Hold the lock to avoid the swap entry to be reused
                 * until we take the PT lock for the pte_same() check
@@ -3106,7 +3120,7 @@ out_page:
        unlock_page(page);
 out_release:
        page_cache_release(page);
-       if (swapcache) {
+       if (page != swapcache) {
                unlock_page(swapcache);
                page_cache_release(swapcache);
        }
This page took 0.041471 seconds and 5 git commands to generate.