Skip to content

Commit 90e09ea

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: revert "rework reserved VMID handling" v2
This reverts commit e44a0fe. Initially we used VMID reservation to enforce isolation between processes. That has now been replaced by proper fence handling. Both OpenGL, RADV and ROCm developers requested a way to reserve a VMID for SPM, so restore that approach by reverting back to only allowing a single process to use the reserved VMID. Only compile tested for now. v2: use -ENOENT instead of -EINVAL if VMID is not available Signed-off-by: Christian König <christian.koenig@amd.com> Acked-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 66f3883 commit 90e09ea

4 files changed

Lines changed: 50 additions & 41 deletions

File tree

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

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,12 @@ static int amdgpu_vmid_grab_reserved(struct amdgpu_vm *vm,
275275
{
276276
struct amdgpu_device *adev = ring->adev;
277277
unsigned vmhub = ring->vm_hub;
278-
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
279278
uint64_t fence_context = adev->fence_context + ring->idx;
280279
bool needs_flush = vm->use_cpu_for_update;
281280
uint64_t updates = amdgpu_vm_tlb_seq(vm);
282281
int r;
283282

284-
*id = id_mgr->reserved;
283+
*id = vm->reserved_vmid[vmhub];
285284
if ((*id)->owner != vm->immediate.fence_context ||
286285
!amdgpu_vmid_compatible(*id, job) ||
287286
(*id)->flushed_updates < updates ||
@@ -474,40 +473,61 @@ bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub)
474473
return vm->reserved_vmid[vmhub];
475474
}
476475

477-
int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,
476+
/*
477+
* amdgpu_vmid_alloc_reserved - reserve a specific VMID for this vm
478+
* @adev: amdgpu device structure
479+
* @vm: the VM to reserve an ID for
480+
* @vmhub: the VMHUB which should be used
481+
*
482+
* Mostly used to have a reserved VMID for debugging and SPM.
483+
*
484+
* Returns: 0 for success, -ENOENT if an ID is already reserved.
485+
*/
486+
int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
478487
unsigned vmhub)
479488
{
480489
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
490+
struct amdgpu_vmid *id;
491+
int r = 0;
481492

482493
mutex_lock(&id_mgr->lock);
483-
484-
++id_mgr->reserved_use_count;
485-
if (!id_mgr->reserved) {
486-
struct amdgpu_vmid *id;
487-
488-
id = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vmid,
489-
list);
490-
/* Remove from normal round robin handling */
491-
list_del_init(&id->list);
492-
id_mgr->reserved = id;
494+
if (vm->reserved_vmid[vmhub])
495+
goto unlock;
496+
if (id_mgr->reserved_vmid) {
497+
r = -ENOENT;
498+
goto unlock;
493499
}
494-
500+
/* Remove from normal round robin handling */
501+
id = list_first_entry(&id_mgr->ids_lru, struct amdgpu_vmid, list);
502+
list_del_init(&id->list);
503+
vm->reserved_vmid[vmhub] = id;
504+
id_mgr->reserved_vmid = true;
495505
mutex_unlock(&id_mgr->lock);
506+
496507
return 0;
508+
unlock:
509+
mutex_unlock(&id_mgr->lock);
510+
return r;
497511
}
498512

499-
void amdgpu_vmid_free_reserved(struct amdgpu_device *adev,
513+
/*
514+
* amdgpu_vmid_free_reserved - free up a reserved VMID again
515+
* @adev: amdgpu device structure
516+
* @vm: the VM with the reserved ID
517+
* @vmhub: the VMHUB which should be used
518+
*/
519+
void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
500520
unsigned vmhub)
501521
{
502522
struct amdgpu_vmid_mgr *id_mgr = &adev->vm_manager.id_mgr[vmhub];
503523

504524
mutex_lock(&id_mgr->lock);
505-
if (!--id_mgr->reserved_use_count) {
506-
/* give the reserved ID back to normal round robin */
507-
list_add(&id_mgr->reserved->list, &id_mgr->ids_lru);
508-
id_mgr->reserved = NULL;
525+
if (vm->reserved_vmid[vmhub]) {
526+
list_add(&vm->reserved_vmid[vmhub]->list,
527+
&id_mgr->ids_lru);
528+
vm->reserved_vmid[vmhub] = NULL;
529+
id_mgr->reserved_vmid = false;
509530
}
510-
511531
mutex_unlock(&id_mgr->lock);
512532
}
513533

@@ -574,7 +594,6 @@ void amdgpu_vmid_mgr_init(struct amdgpu_device *adev)
574594

575595
mutex_init(&id_mgr->lock);
576596
INIT_LIST_HEAD(&id_mgr->ids_lru);
577-
id_mgr->reserved_use_count = 0;
578597

579598
/* for GC <10, SDMA uses MMHUB so use first_kfd_vmid for both GC and MM */
580599
if (amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(10, 0, 0))

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ struct amdgpu_vmid_mgr {
6767
unsigned num_ids;
6868
struct list_head ids_lru;
6969
struct amdgpu_vmid ids[AMDGPU_NUM_VMID];
70-
struct amdgpu_vmid *reserved;
71-
unsigned int reserved_use_count;
70+
bool reserved_vmid;
7271
};
7372

7473
int amdgpu_pasid_alloc(unsigned int bits);
@@ -79,10 +78,10 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv,
7978
bool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev,
8079
struct amdgpu_vmid *id);
8180
bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub);
82-
int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev,
83-
unsigned vmhub);
84-
void amdgpu_vmid_free_reserved(struct amdgpu_device *adev,
85-
unsigned vmhub);
81+
int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
82+
unsigned vmhub);
83+
void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, struct amdgpu_vm *vm,
84+
unsigned vmhub);
8685
int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
8786
struct amdgpu_job *job, struct dma_fence **fence);
8887
void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub,

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,10 +2790,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm)
27902790
dma_fence_put(vm->last_update);
27912791

27922792
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
2793-
if (vm->reserved_vmid[i]) {
2794-
amdgpu_vmid_free_reserved(adev, i);
2795-
vm->reserved_vmid[i] = false;
2796-
}
2793+
amdgpu_vmid_free_reserved(adev, vm, i);
27972794
}
27982795

27992796
ttm_lru_bulk_move_fini(&adev->mman.bdev, &vm->lru_bulk_move);
@@ -2889,6 +2886,7 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
28892886
union drm_amdgpu_vm *args = data;
28902887
struct amdgpu_device *adev = drm_to_adev(dev);
28912888
struct amdgpu_fpriv *fpriv = filp->driver_priv;
2889+
struct amdgpu_vm *vm = &fpriv->vm;
28922890

28932891
/* No valid flags defined yet */
28942892
if (args->in.flags)
@@ -2897,17 +2895,10 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
28972895
switch (args->in.op) {
28982896
case AMDGPU_VM_OP_RESERVE_VMID:
28992897
/* We only have requirement to reserve vmid from gfxhub */
2900-
if (!fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)]) {
2901-
amdgpu_vmid_alloc_reserved(adev, AMDGPU_GFXHUB(0));
2902-
fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)] = true;
2903-
}
2904-
2898+
amdgpu_vmid_alloc_reserved(adev, vm, AMDGPU_GFXHUB(0));
29052899
break;
29062900
case AMDGPU_VM_OP_UNRESERVE_VMID:
2907-
if (fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)]) {
2908-
amdgpu_vmid_free_reserved(adev, AMDGPU_GFXHUB(0));
2909-
fpriv->vm.reserved_vmid[AMDGPU_GFXHUB(0)] = false;
2910-
}
2901+
amdgpu_vmid_free_reserved(adev, vm, AMDGPU_GFXHUB(0));
29112902
break;
29122903
default:
29132904
return -EINVAL;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ struct amdgpu_vm {
415415
struct dma_fence *last_unlocked;
416416

417417
unsigned int pasid;
418-
bool reserved_vmid[AMDGPU_MAX_VMHUBS];
418+
struct amdgpu_vmid *reserved_vmid[AMDGPU_MAX_VMHUBS];
419419

420420
/* Flag to indicate if VM tables are updated by CPU or GPU (SDMA) */
421421
bool use_cpu_for_update;

0 commit comments

Comments
 (0)