Re: [PATCH v6 04/13] mm/migrate_device: Add migrate PFN flag to track device private pages

David Hildenbrand (Arm)
2026-03-03T16:58:33Z

On 2/2/26 12:36, Jordan Niethe wrote:
> A future change will remove device private pages from the physical
> address space. This will mean that device private pages no longer have
> normal PFN and must be handled separately.
>
> Prepare for this by adding a MIGRATE_PFN_DEVICE_PRIVATE flag to indicate
> that a migrate pfn contains a PFN for a device private page.
>
> Acked-by: Felix Kuehling <felix.kuehling@amd.com>
> Signed-off-by: Jordan Niethe <jniethe@nvidia.com>
> Signed-off-by: Alistair Popple <apopple@nvidia.com>
>
> ---
> v1:
> - Update for HMM huge page support
> - Update existing drivers to use MIGRATE_PFN_DEVICE
> v2:
> - Include changes to migrate_pfn_from_page()
> - Rename to MIGRATE_PFN_DEVICE_PRIVATE
> - drm/amd: Check adev->gmc.xgmi.connected_to_cpu
> - lib/test_hmm.c: Check chunk->pagemap.type == MEMORY_DEVICE_PRIVATE
>
> v3:
> - Use adev->kfd.pgmap.type == MEMORY_DEVICE_PRIVATE
>
> v4:
> - No change
> ---
> drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 7 ++++++-
> drivers/gpu/drm/nouveau/nouveau_dmem.c | 3 ++-
> drivers/gpu/drm/xe/xe_svm.c | 2 +-
> include/linux/migrate.h | 14 +++++++++-----
> lib/test_hmm.c | 6 +++++-
> 5 files changed, 23 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> index b6075a2808c2..fc9465db6d5e 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c
> @@ -212,7 +212,12 @@ svm_migrate_copy_done(struct amdgpu_device *adev, struct dma_fence *mfence)
> unsigned long
> svm_migrate_addr_to_mpfn(struct amdgpu_device *adev, unsigned long addr)
> {
> - return migrate_pfn((addr + adev->kfd.pgmap.range.start) >> PAGE_SHIFT);
> + unsigned long flags = 0;
> +
> + if (adev->kfd.pgmap.type == MEMORY_DEVICE_PRIVATE)
> + flags |= MIGRATE_PFN_DEVICE_PRIVATE;
> + return migrate_pfn((addr + adev->kfd.pgmap.range.start) >> PAGE_SHIFT) |
> + flags;
> }

Just pack it into a single line (checkpatch should no longer complain),
or alternatively, indent "flags" properly.

Shouldn't migrate_pfn really be called pfn_to_migrate_pfn()?

Also, looks like a "addr_to_migrate_pfn()" might be a reasonable helper,
which might also reduce the line lenght :)

But now I wonder: could't migrate_pfn() detect internally that this is
MIGRATE_PFN_DEVICE_PRIVATE, similar to how migrate_pfn_from_page() does
it? After all, there must be a "struct page/struct folio" there, or am I
wrong?

--
Cheers,

David