]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/migrate_device: do not access pgmap for non zone device pages
authorBalbir Singh <balbirs@nvidia.com>
Wed, 19 Feb 2025 23:13:37 +0000 (10:13 +1100)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 28 Feb 2025 01:00:13 +0000 (17:00 -0800)
page_pgmap() is referenced before checking if the page is a zone device
page and this triggers the warning in page_pgmap().  Refactor the code to
use the helper function after relevant checks.

Link: https://lkml.kernel.org/r/20250219231337.364133-1-balbirs@nvidia.com
Signed-off-by: Balbir Singh <balbirs@nvidia.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/migrate_device.c

index 6771893d46014b467390f34abef4b9dc0278e525..e0bf771edb6f132bff34a0ea229fb2788f8a5b4b 100644 (file)
@@ -153,14 +153,17 @@ again:
                                goto next;
                        }
                        page = vm_normal_page(migrate->vma, addr, pte);
-                       pgmap = page_pgmap(page);
                        if (page && !is_zone_device_page(page) &&
                            !(migrate->flags & MIGRATE_VMA_SELECT_SYSTEM))
                                goto next;
-                       else if (page && is_device_coherent_page(page) &&
-                           (!(migrate->flags & MIGRATE_VMA_SELECT_DEVICE_COHERENT) ||
-                            pgmap->owner != migrate->pgmap_owner))
-                               goto next;
+                       else if (page && is_device_coherent_page(page)) {
+                               pgmap = page_pgmap(page);
+
+                               if (!(migrate->flags &
+                                       MIGRATE_VMA_SELECT_DEVICE_COHERENT) ||
+                                       pgmap->owner != migrate->pgmap_owner)
+                                       goto next;
+                       }
                        mpfn = migrate_pfn(pfn) | MIGRATE_PFN_MIGRATE;
                        mpfn |= pte_write(pte) ? MIGRATE_PFN_WRITE : 0;
                }