From: Alex Sierra <alex.sie...@amd.com>

Avoid long term pinning for Coherent device type pages. This could
interfere with their own device memory manager. For now, we are just
returning error for PIN_LONGTERM Coherent device type pages. Eventually,
these type of pages will get migrated to system memory, once the device
migration pages support is added.

Signed-off-by: Alex Sierra <alex.sie...@amd.com>
Acked-by: Felix Kuehling <felix.kuehl...@amd.com>
Reviewed-by: Alistair Poppple <apop...@nvidia.com>
[hch: rebased on previous cleanups, split the two checks]
Signed-off-by: Christoph Hellwig <h...@lst.de>
---
 mm/gup.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/mm/gup.c b/mm/gup.c
index 37d6c24ca71225..39b23ad39a7bde 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1881,6 +1881,19 @@ static long check_and_migrate_movable_pages(unsigned 
long nr_pages,
                        continue;
                prev_head = head;
 
+               /*
+                * Device private pages will get faulted in during gup so it
+                * shouldn't be possible to see one here.
+                */
+               if (WARN_ON_ONCE(is_device_private_page(head))) {
+                       ret = -EFAULT;
+                       goto unpin_pages;
+               }
+               if (is_device_coherent_page(head)) {
+                       ret = -EFAULT;
+                       goto unpin_pages;
+               }
+
                if (is_pinnable_page(head))
                        continue;
 
@@ -1925,7 +1938,7 @@ static long check_and_migrate_movable_pages(unsigned long 
nr_pages,
                        put_page(pages[i]);
        }
 
-       if (!list_empty(&movable_page_list)) {
+       if (!ret && !list_empty(&movable_page_list)) {
                struct migration_target_control mtc = {
                        .nid = NUMA_NO_NODE,
                        .gfp_mask = GFP_USER | __GFP_NOWARN,
-- 
2.30.2


Reply via email to