Device-to-device migration may require DRM pagemap IOVA allocations,
which are allowed to acquire dma-resv locks. To support this, pin the BO
before initiating the migration, preventing immediate eviction and
allowing dma-resv locks to be taken safely during the migration process.

Signed-off-by: Matthew Brost <[email protected]>
---
 drivers/gpu/drm/xe/xe_svm.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
index eb8d8fe6ff75..c2a6bb367e0a 100644
--- a/drivers/gpu/drm/xe/xe_svm.c
+++ b/drivers/gpu/drm/xe/xe_svm.c
@@ -1077,15 +1077,26 @@ static int xe_drm_pagemap_populate_mm(struct 
drm_pagemap *dpagemap,
                        block->private = vr;
 
                xe_bo_get(bo);
+               /* Guard against eviction */
+               ttm_bo_pin(&bo->ttm);
 
                /* Ensure the device has a pm ref while there are device pages 
active. */
                xe_pm_runtime_get_noresume(xe);
-               /* Consumes the devmem allocation ref. */
-               err = drm_pagemap_migrate_to_devmem(&bo->devmem_allocation, mm,
-                                                   start, end, &mdetails);
                xe_bo_unlock(bo);
-               xe_bo_put(bo);
+
        }
+
+       /* Consumes the devmem allocation ref. */
+       err = drm_pagemap_migrate_to_devmem(&bo->devmem_allocation, mm,
+                                           start, end, &mdetails);
+
+       xe_bo_lock(bo, false);
+       ttm_bo_unpin(&bo->ttm);
+       ttm_bo_move_to_lru_tail_unlocked(&bo->ttm);
+       xe_bo_unlock(bo);
+
+       xe_bo_put(bo);
+
        xe_pm_runtime_put(xe);
        drm_dev_exit(idx);
 
-- 
2.34.1

Reply via email to