The SPM VMID reservation made through AMDGPU_VM_OP_RESERVE_VMID is recorded on AMDGPU_GFXHUB(0) only, while gfxhub v1.2's setup_vm_pt_regs broadcasts the page table base to every XCC. On multi-XCC parts the two disagree, in both directions:
- the reservation only takes effect for jobs running on XCC 0, since the VMID grab path checks vm->reserved_vmid[ring->vm_hub] and the rings of XCC i use AMDGPU_GFXHUB(i); - the page table base is physically programmed on all XCCs anyway, and conflicting reservations are only detected on hub 0's id_mgr. Make the hub argument real end to end: amdgpu_gmc_bind_vmid() programs only the given hub, through the XCC-masked gfxhub callback where one exists, and amdgpu_vmid_free_spm() unbinds the hub it frees instead of hub 0. amdgpu_vm_spm_update() binds every GFXHUB on which @vm holds the reservation. The VM ioctl reserves the VMID on every GFXHUB instance through the new amdgpu_vmid_alloc_spm_gfxhubs() helper, so the reservation now takes effect, is bound and is flushed on every XCC the VM's jobs can run on, and a conflicting reservation shows up on whichever hub two VMs share. Signed-off-by: James Zhu <[email protected]> Assisted-by: Claude:claude-fable-5 --- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 49 ++++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 40 +++++++++++++------- 4 files changed, 82 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c index 08d3ff61edcc..704a30ad388a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c @@ -797,6 +797,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid, * * For VMIDs that are bound directly to a VM's page table outside the * normal per-job VM flush path, e.g. a dedicated out-of-pool VMID. + * Only @vmhub is programmed and flushed, other hubs keep their binding. */ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub, unsigned int vmid, uint64_t pd_addr) @@ -805,6 +806,9 @@ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub, if (is_mmhub) adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr); + else if (adev->gfxhub.funcs->setup_vm_pt_regs_xcc) + adev->gfxhub.funcs->setup_vm_pt_regs_xcc(adev, vmid, pd_addr, + BIT(vmhub - AMDGPU_GFXHUB_START)); else adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c index 9c879ac68352..41f3dba530e3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c @@ -651,12 +651,59 @@ void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm, id_mgr->reserved_vmid = false; if (adev->vm_manager.spm_vmid && adev->gfxhub.funcs) - amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), + amdgpu_gmc_bind_vmid(adev, vmhub, adev->vm_manager.spm_vmid, 0); } mutex_unlock(&id_mgr->lock); } +/* + * amdgpu_vmid_alloc_spm_gfxhubs - reserve the SPM VMID on a set of GFXHUBs + * @adev: amdgpu device structure + * @vm: the VM to reserve the ID for + * @xcc_mask: XCC instances on whose GFXHUBs to reserve + * + * Reserve the SPM VMID on the GFXHUB of every XCC in @xcc_mask, so that + * the reservation covers every hub the VM's jobs can run on. + * + * Returns: 0 for success, the first per-hub error otherwise. On an error + * the reservation is released on every hub in @xcc_mask again. + */ +int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev, + struct amdgpu_vm *vm, uint32_t xcc_mask) +{ + int i, r; + + for_each_inst(i, xcc_mask) { + r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(i)); + if (r) { + amdgpu_vmid_free_spm_gfxhubs(adev, vm, xcc_mask); + return r; + } + } + + return 0; +} + +/* + * amdgpu_vmid_free_spm_gfxhubs - undo amdgpu_vmid_alloc_spm_gfxhubs + * @adev: amdgpu device structure + * @vm: the VM with the reserved ID + * @xcc_mask: XCC instances on whose GFXHUBs to free the reservation + * + * Free the SPM VMID on every GFXHUB in @xcc_mask @vm holds it on, hubs + * without a reservation are skipped. The same wait requirement as for + * amdgpu_vmid_free_spm() applies. + */ +void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev, + struct amdgpu_vm *vm, uint32_t xcc_mask) +{ + int i; + + for_each_inst(i, xcc_mask) + amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(i)); +} + /** * amdgpu_vmid_reset - reset VMID to zero * diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h index c134000eecfd..d2b225d0aa38 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h @@ -129,6 +129,10 @@ int amdgpu_vmid_alloc_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm, unsigned vmhub); void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm, unsigned vmhub); +int amdgpu_vmid_alloc_spm_gfxhubs(struct amdgpu_device *adev, + struct amdgpu_vm *vm, uint32_t xcc_mask); +void amdgpu_vmid_free_spm_gfxhubs(struct amdgpu_device *adev, + struct amdgpu_vm *vm, uint32_t xcc_mask); int amdgpu_vmid_grab(struct amdgpu_vm *vm, struct amdgpu_ring *ring, struct amdgpu_job *job, struct dma_fence **fence); void amdgpu_vmid_reset(struct amdgpu_device *adev, unsigned vmhub, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 6b4dc0276e27..bd9aa35933dc 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -589,30 +589,36 @@ uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) * The SPM VMID is fixed (adev->vm_manager.spm_vmid), so its page-table-base * register must track whichever VM currently holds the reservation instead * of being set per-job like a normal VMID. Bind it to @vm's real root PD - * address if @vm holds the reservation; otherwise do nothing, since @vm is - * not the one that could legitimately change the current binding. + * address on every GFXHUB @vm holds the reservation on; hubs reserved by + * other VMs or not reserved at all are left alone, since @vm is not the + * one that could legitimately change their binding. * * @vm's root PD must be locked by the caller. */ void amdgpu_vm_spm_update(struct amdgpu_device *adev, struct amdgpu_vm *vm) { - struct amdgpu_kq_vmid_mgr *id_mgr = - &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(0)]; uint64_t pd_addr; + int i; if (!adev->vm_manager.spm_vmid || !adev->gfxhub.funcs) return; - mutex_lock(&id_mgr->lock); - if (vm->reserved_vmid[AMDGPU_GFXHUB(0)] != - &id_mgr->ids[adev->vm_manager.spm_vmid] || !amdgpu_vm_ready(vm)) { - mutex_unlock(&id_mgr->lock); + if (!amdgpu_vm_ready(vm)) return; - } pd_addr = amdgpu_gmc_pd_addr(vm->root.bo); - amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(0), adev->vm_manager.spm_vmid, pd_addr); - mutex_unlock(&id_mgr->lock); + for_each_inst(i, adev->gfx.xcc_mask) { + struct amdgpu_kq_vmid_mgr *id_mgr = + &adev->vm_manager.id_mgr[AMDGPU_GFXHUB(i)]; + + mutex_lock(&id_mgr->lock); + if (vm->reserved_vmid[AMDGPU_GFXHUB(i)] == + &id_mgr->ids[adev->vm_manager.spm_vmid]) + amdgpu_gmc_bind_vmid(adev, AMDGPU_GFXHUB(i), + adev->vm_manager.spm_vmid, + pd_addr); + mutex_unlock(&id_mgr->lock); + } } /** @@ -3018,7 +3024,8 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) int r; /* We only have requirement to reserve vmid from gfxhub */ - r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0)); + r = amdgpu_vmid_alloc_spm_gfxhubs(adev, vm, + adev->gfx.xcc_mask); if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) { amdgpu_vm_spm_update(adev, vm); amdgpu_bo_unreserve(vm->root.bo); @@ -3027,14 +3034,19 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) } case AMDGPU_VM_OP_UNRESERVE_VMID: { struct amdgpu_bo *root = vm->root.bo; + bool reserved = false; + int i; amdgpu_bo_reserve(root, true); + for_each_inst(i, adev->gfx.xcc_mask) + reserved |= amdgpu_vmid_uses_reserved(vm, + AMDGPU_GFXHUB(i)); /* Wait for the jobs which might still use the reserved VMID */ - if (vm->reserved_vmid[AMDGPU_GFXHUB(0)]) + if (reserved) dma_resv_wait_timeout(root->tbo.base.resv, DMA_RESV_USAGE_READ, false, MAX_SCHEDULE_TIMEOUT); - amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0)); + amdgpu_vmid_free_spm_gfxhubs(adev, vm, adev->gfx.xcc_mask); amdgpu_bo_unreserve(root); break; } -- 2.34.1
