Skip to content

Commit b809ca9

Browse files
Jie1zhangalexdeucher
authored andcommitted
drm/amdgpu: Merge amdgpu_vm_set_pasid into amdgpu_vm_init
As KFD no longer uses a separate PASID, the global amdgpu_vm_set_pasid()function is no longer necessary. Merge its functionality directly intoamdgpu_vm_init() to simplify code flow and eliminate redundant locking. v2: remove superflous check adjust amdgpu_vm_fin and remove amdgpu_vm_set_pasid (Chritian) v3: drop amdgpu_vm_assert_locked (Chritian) Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/4614 Fixes: 59e4405 ("drm/amdgpu: revert to old status lock handling v3") Reviewed-by: Christian König <christian.koenig@amd.com> Suggested-by: Christian König <christian.koenig@amd.com> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 8dbac5c commit b809ca9

File tree

3 files changed

+24
-56
lines changed

3 files changed

+24
-56
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,14 +1421,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
14211421

14221422
amdgpu_debugfs_vm_init(file_priv);
14231423

1424-
r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id);
1424+
r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id, pasid);
14251425
if (r)
14261426
goto error_pasid;
14271427

1428-
r = amdgpu_vm_set_pasid(adev, &fpriv->vm, pasid);
1429-
if (r)
1430-
goto error_vm;
1431-
14321428
fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL);
14331429
if (!fpriv->prt_va) {
14341430
r = -ENOMEM;
@@ -1468,10 +1464,8 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
14681464
amdgpu_vm_fini(adev, &fpriv->vm);
14691465

14701466
error_pasid:
1471-
if (pasid) {
1467+
if (pasid)
14721468
amdgpu_pasid_free(pasid);
1473-
amdgpu_vm_set_pasid(adev, &fpriv->vm, 0);
1474-
}
14751469

14761470
kfree(fpriv);
14771471

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

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -138,48 +138,6 @@ static void amdgpu_vm_assert_locked(struct amdgpu_vm *vm)
138138
dma_resv_assert_held(vm->root.bo->tbo.base.resv);
139139
}
140140

141-
/**
142-
* amdgpu_vm_set_pasid - manage pasid and vm ptr mapping
143-
*
144-
* @adev: amdgpu_device pointer
145-
* @vm: amdgpu_vm pointer
146-
* @pasid: the pasid the VM is using on this GPU
147-
*
148-
* Set the pasid this VM is using on this GPU, can also be used to remove the
149-
* pasid by passing in zero.
150-
*
151-
*/
152-
int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
153-
u32 pasid)
154-
{
155-
int r;
156-
157-
amdgpu_vm_assert_locked(vm);
158-
159-
if (vm->pasid == pasid)
160-
return 0;
161-
162-
if (vm->pasid) {
163-
r = xa_err(xa_erase_irq(&adev->vm_manager.pasids, vm->pasid));
164-
if (r < 0)
165-
return r;
166-
167-
vm->pasid = 0;
168-
}
169-
170-
if (pasid) {
171-
r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm,
172-
GFP_KERNEL));
173-
if (r < 0)
174-
return r;
175-
176-
vm->pasid = pasid;
177-
}
178-
179-
180-
return 0;
181-
}
182-
183141
/**
184142
* amdgpu_vm_bo_evicted - vm_bo is evicted
185143
*
@@ -2554,14 +2512,15 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
25542512
* @adev: amdgpu_device pointer
25552513
* @vm: requested vm
25562514
* @xcp_id: GPU partition selection id
2515+
* @pasid: the pasid the VM is using on this GPU
25572516
*
25582517
* Init @vm fields.
25592518
*
25602519
* Returns:
25612520
* 0 for success, error for failure.
25622521
*/
25632522
int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
2564-
int32_t xcp_id)
2523+
int32_t xcp_id, uint32_t pasid)
25652524
{
25662525
struct amdgpu_bo *root_bo;
25672526
struct amdgpu_bo_vm *root;
@@ -2638,12 +2597,26 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
26382597
if (r)
26392598
dev_dbg(adev->dev, "Failed to create task info for VM\n");
26402599

2600+
/* Store new PASID in XArray (if non-zero) */
2601+
if (pasid != 0) {
2602+
r = xa_err(xa_store_irq(&adev->vm_manager.pasids, pasid, vm, GFP_KERNEL));
2603+
if (r < 0)
2604+
goto error_free_root;
2605+
2606+
vm->pasid = pasid;
2607+
}
2608+
26412609
amdgpu_bo_unreserve(vm->root.bo);
26422610
amdgpu_bo_unref(&root_bo);
26432611

26442612
return 0;
26452613

26462614
error_free_root:
2615+
/* If PASID was partially set, erase it from XArray before failing */
2616+
if (vm->pasid != 0) {
2617+
xa_erase_irq(&adev->vm_manager.pasids, vm->pasid);
2618+
vm->pasid = 0;
2619+
}
26472620
amdgpu_vm_pt_free_root(adev, vm);
26482621
amdgpu_bo_unreserve(vm->root.bo);
26492622
amdgpu_bo_unref(&root_bo);
@@ -2749,7 +2722,11 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
27492722

27502723
root = amdgpu_bo_ref(vm->root.bo);
27512724
amdgpu_bo_reserve(root, true);
2752-
amdgpu_vm_set_pasid(adev, vm, 0);
2725+
/* Remove PASID mapping before destroying VM */
2726+
if (vm->pasid != 0) {
2727+
xa_erase_irq(&adev->vm_manager.pasids, vm->pasid);
2728+
vm->pasid = 0;
2729+
}
27532730
dma_fence_wait(vm->last_unlocked, false);
27542731
dma_fence_put(vm->last_unlocked);
27552732
dma_fence_wait(vm->last_tlb_flush, false);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,8 @@ extern const struct amdgpu_vm_update_funcs amdgpu_vm_sdma_funcs;
503503
void amdgpu_vm_manager_init(struct amdgpu_device *adev);
504504
void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
505505

506-
int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm,
507-
u32 pasid);
508-
509506
long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout);
510-
int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id);
507+
int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id, uint32_t pasid);
511508
int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
512509
void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
513510
int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,

0 commit comments

Comments
 (0)