Merge patch series "riscv: Introduce KASLR"
[linux-2.6-block.git] / mm / migrate_device.c
index d5f492356e3efcbd18845b77c4adbf18e26d71a8..8ac1f79f754a290445a9a40c0e71f7e5b5853491 100644 (file)
@@ -624,7 +624,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate,
                }
                entry = mk_pte(page, vma->vm_page_prot);
                if (vma->vm_flags & VM_WRITE)
-                       entry = pte_mkwrite(pte_mkdirty(entry));
+                       entry = pte_mkwrite(pte_mkdirty(entry), vma);
        }
 
        ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl);
@@ -659,7 +659,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate,
 
        if (flush) {
                flush_cache_page(vma, addr, pte_pfn(orig_pte));
-               ptep_clear_flush_notify(vma, addr, ptep);
+               ptep_clear_flush(vma, addr, ptep);
                set_pte_at_notify(mm, addr, ptep, entry);
                update_mmu_cache(vma, addr, ptep);
        } else {
@@ -728,13 +728,22 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 
                if (is_device_private_page(newpage) ||
                    is_device_coherent_page(newpage)) {
-                       /*
-                        * For now only support anonymous memory migrating to
-                        * device private or coherent memory.
-                        */
                        if (mapping) {
-                               src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
-                               continue;
+                               struct folio *folio;
+
+                               folio = page_folio(page);
+
+                               /*
+                                * For now only support anonymous memory migrating to
+                                * device private or coherent memory.
+                                *
+                                * Try to get rid of swap cache if possible.
+                                */
+                               if (!folio_test_anon(folio) ||
+                                   !folio_free_swap(folio)) {
+                                       src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
+                                       continue;
+                               }
                        }
                } else if (is_zone_device_page(newpage)) {
                        /*
@@ -755,13 +764,8 @@ static void __migrate_device_pages(unsigned long *src_pfns,
                        src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
        }
 
-       /*
-        * No need to double call mmu_notifier->invalidate_range() callback as
-        * the above ptep_clear_flush_notify() inside migrate_vma_insert_page()
-        * did already call it.
-        */
        if (notified)
-               mmu_notifier_invalidate_range_only_end(&range);
+               mmu_notifier_invalidate_range_end(&range);
 }
 
 /**