From 742c464ec65e79fe4450ed256715306de4a73d0b Mon Sep 17 00:00:00 2001 From: jsg Date: Thu, 12 Sep 2024 23:42:34 +0000 Subject: [PATCH] drm/amdgpu: reject gang submit on reserved VMIDs From Christian Koenig 6922ab2932622dbc638620aae0e2f6b8eb22940c in linux-6.6.y/6.6.51 320debca1ba3a81c87247eac84eff976ead09ee0 in mainline linux --- sys/dev/pci/drm/amd/amdgpu/amdgpu_cs.c | 15 +++++++++++++++ sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.c | 15 ++++++++++++++- sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_cs.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_cs.c index f7bd2ba292e..dca5c07fa3b 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_cs.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_cs.c @@ -1098,6 +1098,21 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p) unsigned int i; int r; + /* + * We can't use gang submit on with reserved VMIDs when the VM changes + * can't be invalidated by more than one engine at the same time. + */ + if (p->gang_size > 1 && !p->adev->vm_manager.concurrent_flush) { + for (i = 0; i < p->gang_size; ++i) { + struct drm_sched_entity *entity = p->entities[i]; + struct drm_gpu_scheduler *sched = entity->rq->sched; + struct amdgpu_ring *ring = to_amdgpu_ring(sched); + + if (amdgpu_vmid_uses_reserved(vm, ring->vm_hub)) + return -EINVAL; + } + } + r = amdgpu_vm_clear_freed(adev, vm, NULL); if (r) return r; diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.c index 5b64d2a379f..27bdf32b0ed 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.c @@ -409,7 +409,7 @@ int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring, if (r || !idle) goto error; - if (vm->reserved_vmid[vmhub] || (enforce_isolation && (vmhub == AMDGPU_GFXHUB(0)))) { + if (amdgpu_vmid_uses_reserved(vm, vmhub)) { r = amdgpu_vmid_grab_reserved(vm, ring, job, &id, fence); if (r || !id) goto error; @@ -459,6 +459,19 @@ error: return r; } +/* + * amdgpu_vmid_uses_reserved - check if a VM will use a reserved VMID + * @vm: the VM to check + * @vmhub: the VMHUB which will be used + * + * Returns: True if the VM will use a reserved VMID. + */ +bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub) +{ + return vm->reserved_vmid[vmhub] || + (enforce_isolation && (vmhub == AMDGPU_GFXHUB(0))); +} + int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, unsigned vmhub) { diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.h b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.h index 1aa1f81b772..3a5b2cc9a0e 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.h +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_ids.h @@ -78,6 +78,7 @@ void amdgpu_pasid_free_delayed(struct dma_resv *resv, bool amdgpu_vmid_had_gpu_reset(struct amdgpu_device *adev, struct amdgpu_vmid *id); +bool amdgpu_vmid_uses_reserved(struct amdgpu_vm *vm, unsigned int vmhub); int amdgpu_vmid_alloc_reserved(struct amdgpu_device *adev, unsigned vmhub); void amdgpu_vmid_free_reserved(struct amdgpu_device *adev, -- 2.20.1