Skip to content

Commit e28647b

Browse files
committed
drm/xe: share bo dma-resv with backup object
We end up needing to grab both locks together anyway and keep them held until we complete the copy or add the fence. Plus the backup_obj is short lived and tied to the parent object, so seems reasonable to share the same dma-resv. This will simplify the locking here, and in follow up patches. v2: - Hold reference to the parent bo to be sure the shared dma-resv can't go out of scope too soon. (Thomas) Signed-off-by: Matthew Auld <matthew.auld@intel.com> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com> Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com> Link: https://lore.kernel.org/r/20250416150913.434369-7-matthew.auld@intel.com
1 parent c6a4d46 commit e28647b

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,13 +1120,15 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
11201120
if (bo->flags & XE_BO_FLAG_PINNED_NORESTORE)
11211121
goto out_unlock_bo;
11221122

1123-
backup = xe_bo_create_locked(xe, NULL, NULL, bo->size, ttm_bo_type_kernel,
1124-
XE_BO_FLAG_SYSTEM | XE_BO_FLAG_NEEDS_CPU_ACCESS |
1125-
XE_BO_FLAG_PINNED);
1123+
backup = ___xe_bo_create_locked(xe, NULL, NULL, bo->ttm.base.resv, NULL, bo->size,
1124+
DRM_XE_GEM_CPU_CACHING_WB, ttm_bo_type_kernel,
1125+
XE_BO_FLAG_SYSTEM | XE_BO_FLAG_NEEDS_CPU_ACCESS |
1126+
XE_BO_FLAG_PINNED);
11261127
if (IS_ERR(backup)) {
11271128
ret = PTR_ERR(backup);
11281129
goto out_unlock_bo;
11291130
}
1131+
backup->parent_obj = xe_bo_get(bo); /* Released by bo_destroy */
11301132

11311133
if (xe_bo_is_user(bo) || (bo->flags & XE_BO_FLAG_PINNED_LATE_RESTORE)) {
11321134
struct xe_migrate *migrate;
@@ -1177,7 +1179,6 @@ int xe_bo_evict_pinned(struct xe_bo *bo)
11771179

11781180
out_backup:
11791181
xe_bo_vunmap(backup);
1180-
xe_bo_unlock(backup);
11811182
if (ret)
11821183
xe_bo_put(backup);
11831184
out_unlock_bo:
@@ -1212,17 +1213,12 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
12121213
if (!backup)
12131214
return 0;
12141215

1215-
xe_bo_lock(backup, false);
1216+
xe_bo_lock(bo, false);
12161217

12171218
ret = ttm_bo_validate(&backup->ttm, &backup->placement, &ctx);
12181219
if (ret)
12191220
goto out_backup;
12201221

1221-
if (WARN_ON(!dma_resv_trylock(bo->ttm.base.resv))) {
1222-
ret = -EBUSY;
1223-
goto out_backup;
1224-
}
1225-
12261222
if (xe_bo_is_user(bo) || (bo->flags & XE_BO_FLAG_PINNED_LATE_RESTORE)) {
12271223
struct xe_migrate *migrate;
12281224
struct dma_fence *fence;
@@ -1271,15 +1267,14 @@ int xe_bo_restore_pinned(struct xe_bo *bo)
12711267

12721268
bo->backup_obj = NULL;
12731269

1274-
out_unlock_bo:
1275-
if (unmap)
1276-
xe_bo_vunmap(bo);
1277-
xe_bo_unlock(bo);
12781270
out_backup:
12791271
xe_bo_vunmap(backup);
1280-
xe_bo_unlock(backup);
12811272
if (!bo->backup_obj)
12821273
xe_bo_put(backup);
1274+
out_unlock_bo:
1275+
if (unmap)
1276+
xe_bo_vunmap(bo);
1277+
xe_bo_unlock(bo);
12831278
return ret;
12841279
}
12851280

@@ -1532,6 +1527,9 @@ static void xe_ttm_bo_destroy(struct ttm_buffer_object *ttm_bo)
15321527
if (bo->vm && xe_bo_is_user(bo))
15331528
xe_vm_put(bo->vm);
15341529

1530+
if (bo->parent_obj)
1531+
xe_bo_put(bo->parent_obj);
1532+
15351533
mutex_lock(&xe->mem_access.vram_userfault.lock);
15361534
if (!list_empty(&bo->vram_userfault_link))
15371535
list_del(&bo->vram_userfault_link);

drivers/gpu/drm/xe/xe_bo_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ struct xe_bo {
3030
struct ttm_buffer_object ttm;
3131
/** @backup_obj: The backup object when pinned and suspended (vram only) */
3232
struct xe_bo *backup_obj;
33+
/** @parent_obj: Ref to parent bo if this a backup_obj */
34+
struct xe_bo *parent_obj;
3335
/** @size: Size of this buffer object */
3436
size_t size;
3537
/** @flags: flags for this buffer object */

0 commit comments

Comments
 (0)