Skip to content

Commit 5a104cb

Browse files
fxkamdalexdeucher
authored andcommitted
drm/amdkfd: Improve amdgpu_vm_handle_moved
Let amdgpu_vm_handle_moved update all BO VA mappings of BOs reserved by the caller. This will be useful for handling extra BO VA mappings in KFD VMs that are managed through the render node API. v2: rebase against drm_exec changes (Alex) Signed-off-by: Felix Kuehling <[email protected]> Reviewed-by: Christian König <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 6740ec9 commit 5a104cb

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,11 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
11161116
return r;
11171117
}
11181118

1119+
/* FIXME: In theory this loop shouldn't be needed any more when
1120+
* amdgpu_vm_handle_moved handles all moved BOs that are reserved
1121+
* with p->ticket. But removing it caused test regressions, so I'm
1122+
* leaving it here for now.
1123+
*/
11191124
amdgpu_bo_list_for_each_entry(e, p->bo_list) {
11201125
bo_va = e->bo_va;
11211126
if (bo_va == NULL)
@@ -1130,7 +1135,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
11301135
return r;
11311136
}
11321137

1133-
r = amdgpu_vm_handle_moved(adev, vm);
1138+
r = amdgpu_vm_handle_moved(adev, vm, &p->exec.ticket);
11341139
if (r)
11351140
return r;
11361141

drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ amdgpu_dma_buf_move_notify(struct dma_buf_attachment *attach)
409409
if (!r)
410410
r = amdgpu_vm_clear_freed(adev, vm, NULL);
411411
if (!r)
412-
r = amdgpu_vm_handle_moved(adev, vm);
412+
r = amdgpu_vm_handle_moved(adev, vm, ticket);
413413

414414
if (r && r != -EBUSY)
415415
DRM_ERROR("Failed to invalidate VM page tables (%d))\n",

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,7 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
13731373
*
13741374
* @adev: amdgpu_device pointer
13751375
* @vm: requested vm
1376+
* @ticket: optional reservation ticket used to reserve the VM
13761377
*
13771378
* Make sure all BOs which are moved are updated in the PTs.
13781379
*
@@ -1382,11 +1383,12 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
13821383
* PTs have to be reserved!
13831384
*/
13841385
int amdgpu_vm_handle_moved(struct amdgpu_device *adev,
1385-
struct amdgpu_vm *vm)
1386+
struct amdgpu_vm *vm,
1387+
struct ww_acquire_ctx *ticket)
13861388
{
13871389
struct amdgpu_bo_va *bo_va;
13881390
struct dma_resv *resv;
1389-
bool clear;
1391+
bool clear, unlock;
13901392
int r;
13911393

13921394
spin_lock(&vm->status_lock);
@@ -1409,17 +1411,24 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev,
14091411
spin_unlock(&vm->status_lock);
14101412

14111413
/* Try to reserve the BO to avoid clearing its ptes */
1412-
if (!adev->debug_vm && dma_resv_trylock(resv))
1414+
if (!adev->debug_vm && dma_resv_trylock(resv)) {
14131415
clear = false;
1416+
unlock = true;
1417+
/* The caller is already holding the reservation lock */
1418+
} else if (ticket && dma_resv_locking_ctx(resv) == ticket) {
1419+
clear = false;
1420+
unlock = false;
14141421
/* Somebody else is using the BO right now */
1415-
else
1422+
} else {
14161423
clear = true;
1424+
unlock = false;
1425+
}
14171426

14181427
r = amdgpu_vm_bo_update(adev, bo_va, clear);
14191428
if (r)
14201429
return r;
14211430

1422-
if (!clear)
1431+
if (unlock)
14231432
dma_resv_unlock(resv);
14241433
spin_lock(&vm->status_lock);
14251434
}

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,8 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
443443
struct amdgpu_vm *vm,
444444
struct dma_fence **fence);
445445
int amdgpu_vm_handle_moved(struct amdgpu_device *adev,
446-
struct amdgpu_vm *vm);
446+
struct amdgpu_vm *vm,
447+
struct ww_acquire_ctx *ticket);
447448
void amdgpu_vm_bo_base_init(struct amdgpu_vm_bo_base *base,
448449
struct amdgpu_vm *vm, struct amdgpu_bo *bo);
449450
int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,

0 commit comments

Comments
 (0)