drm/amdgpu: make the reserved SPM VMID per-partition
Subsystems (3)
cover drm/amdgpu: make the reserved SPM VMID per-partition
The reserved (SPM) VMID handling was designed on single-XCC hardware, where one GFXHUB is all there is. On multi-XCC parts with partitioning every XCC has an own GFXHUB and every partition is exposed as an own render node, and the current code is incoherent in three ways at once:
1. AMDGPU_VM_OP_RESERVE_VMID records the reservation on AMDGPU_GFXHUB(0) only. The VMID grab path checks vm->reserved_vmid[ring->vm_hub], and the rings of XCC i use AMDGPU_GFXHUB(i) - so for any job running on XCC 1..n the reservation silently does nothing. A debugger relying on a stable VMID gets one on exactly one XCC of the partition it runs on, or none at all.
2. The physical programming goes the other way: the setup_vm_pt_regs gfxhub callback broadcasts the SPM VMID's page table base to every XCC of the device, including XCCs of partitions the caller cannot even submit to.
3. The exclusion is device-global: because every reservation contends for hub 0's id_mgr, one partition's render node blocks every other partition from reserving, which breaks the isolation the render nodes are supposed to provide.
None of this is visible on single-XCC hardware, where "hub 0", "all hubs" and "the caller's hubs" happen to be the same thing. gfx 9.4.3 partition modes are where the three diverge.
This series makes the per-hub infrastructure, which already exists in the data structures (vm->reserved_vmid[] and id_mgr[] are per-vmhub arrays), real end to end:
Patch 1 exposes the XCC-masked setup_vm_pt_regs variant, which gfxhub v1.2 and v12.1 already implement internally, as a gfxhub callback.
Patch 2 makes the hub argument of the binding path mean what it says:amdgpu_gmc_bind_vmid() programs and flushes only the given hub, amdgpu_vmid_free_spm() unbinds the hub it frees, amdgpu_vm_spm_update() binds every hub the VM holds the reservation on, and the ioctl reserves on every GFXHUB instance. This fixes 1. and 2. while keeping the device-wide scope.
Patch 3 then derives the hub set from the caller's partition (fpriv->xcp_id), fixing 3.: each partition reserves, binds and conflicts only on its own XCCs. Unreserve keeps operating on every hub, freeing whatever the VM actually holds.
A note on the record granularity: the reservation could instead be recorded on the partition's first GFXHUB only and treated as a pure ownership token, closest to the original single-hub design. But the record plays three roles at once: the ownership token, the set of hubs whose page table base has to be bound (each XCC translates through its own hub, so the binding must cover every XCC of the partition either way), and the per-hub check of the VMID grab and CS paths (vm->reserved_vmid[ring->vm_hub]). Recording on every hub of the partition keeps the three consistent by construction, lets amdgpu_vm_spm_update() derive the binding set from the existing structures without a new field, and gives jobs on every XCC of the partition the same reserved-VMID semantics instead of only on the first one. The VMID number itself is the same everywhere either way:
it is always adev->vm_manager.spm_vmid.
No UAPI change. On devices without partitioning, or on the whole-device node, the mask degenerates to every XCC and nothing changes; on single-XCC parts the series is a no-op.
Compile-tested on amd-staging-drm-next with CONFIG_DRM_AMDGPU=m (amdgpu_vm.o, amdgpu_ids.o, amdgpu_gmc.o, gfxhub_v1_2.o, gfxhub_v12_1.o build warning-free); checkpatch clean.
James Zhu (3):
drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub
callback
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 + 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 | 50 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 + drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 + 7 files changed, 96 insertions(+), 15 deletions(-)
Signature · 1 line
2.34.1
RFC PATCH 1/3 drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback
On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the setup_vm_pt_regs gfxhub callback programs a VMID's page table base on every XCC. Callers which bind a VMID on a single VMHUB, like the SPM VMID binding, have no way to reach one GFXHUB through the callback interface.
gfxhub v1.2 and v12.1 already implement an XCC-masked variant internally. Expose it as a new setup_vm_pt_regs_xcc callback. GFXHUBs of IPs with a single XCC don't implement it, for them the existing callback already is per-hub.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 + drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 + 3 files changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h +2 -0
@@ -28,6 +28,8 @@ struct amdgpu_gfxhub_funcs {u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);void (*setup_vm_pt_regs)(struct amdgpu_device *adev,uint32_t vmid,uint64_t page_table_base); +void (*setup_vm_pt_regs_xcc)(struct amdgpu_device *adev,uint32_t vmid, +uint64_t page_table_base,uint32_t xcc_mask);int (*gart_enable)(struct amdgpu_device *adev);void (*gart_disable)(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +1 -0
@@ -809,6 +809,7 @@ const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = { .get_fb_location = gfxhub_v12_1_get_fb_location, .get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset, .setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs, + .setup_vm_pt_regs_xcc = gfxhub_v12_1_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v12_1_gart_enable, .gart_disable = gfxhub_v12_1_gart_disable, .set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +1 -0
@@ -634,6 +634,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = { .get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset, .setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs, + .setup_vm_pt_regs_xcc = gfxhub_v1_2_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v1_2_gart_enable, .gart_disable = gfxhub_v1_2_gart_disable, .set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
Signature · 1 line
2.34.1
Christian König
maintainerRe: [RFC PATCH 1/3] drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback
Quoted 24 lines · James Zhu
On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the
setup_vm_pt_regsgfxhub callback programs a VMID's page table base on every XCC. Callers which bind a VMID on a single VMHUB, like the SPM VMID binding, have no way to reach one GFXHUB through the callback interface.gfxhub v1.2 and v12.1 already implement an XCC-masked variant internally. Expose it as a new
setup_vm_pt_regs_xcccallback. GFXHUBs of IPs with a single XCC don't implement it, for them the existing callback already is per-hub.Signed-off-by James Zhu <[email protected]>Assisted-by Claude:claude-fable-5--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 + drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 + 3 files changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h struct amdgpu_gfxhub_funcs { · line 32
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h +2
-0@@ -28,6 +28,8 @@ struct amdgpu_gfxhub_funcs {u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);void (*setup_vm_pt_regs)(struct amdgpu_device *adev,uint32_t vmid,uint64_t page_table_base); +void (*setup_vm_pt_regs_xcc)(struct amdgpu_device *adev,uint32_t vmid, +uint64_t page_table_base,uint32_t xcc_mask);
Don't add a new callback, extend the setup_vm_pt_regs with the xcc_mask instead.
Regards,
Christian.
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h +0
-0int (*gart_enable)(struct amdgpu_device *adev);void (*gart_disable)(struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +1
-0@@ -809,6 +809,7 @@ const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = { .get_fb_location = gfxhub_v12_1_get_fb_location, .get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset, .setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs, + .setup_vm_pt_regs_xcc = gfxhub_v12_1_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v12_1_gart_enable, .gart_disable = gfxhub_v12_1_gart_disable, .set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +1
-0@@ -634,6 +634,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = { .get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset, .setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs, + .setup_vm_pt_regs_xcc = gfxhub_v1_2_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v1_2_gart_enable, .gart_disable = gfxhub_v1_2_gart_disable, .set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
RFC PATCH 2/3 drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
In reply to James ZhuThe 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.
--- 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4 -0
@@ -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);
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +48 -1
60 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +4 -0
@@ -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,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +26 -14
@@ -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 ; }
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm/amdgpu: physical xcc_mask used as logical index in amdgpu_vm_spm_update() - [High] drm/amdgpu…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] drm/amdgpu: physical xcc_mask used as logical index in amdgpu_vm_spm_update()
- [High] drm/amdgpu: amdgpu_vm_fini() only checks GFXHUB(0) before waiting on jobs
- [Medium] drm/amdgpu: unlocked allocation and unsafe rollback in amdgpu_vmid_alloc_spm_gfxhubs()
--
commit 0df4e49e9ba90dc0c43a497872e17c100a8d4894
Author: James Zhu <[email protected]>
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
This commit updates SPM VMID reservation, binding, and unbinding to operate per GFXHUB instance across XCCs rather than only on AMDGPU_GFXHUB(0).
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +0
-0
[ ... ]
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +5
-0+int amdgpu_vmid_alloc_spm_gfxhubs (struct amdgpu_device *adev, +struct amdgpu_vm *vm,uint32_t xcc_mask) +{ +int i, r; +
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c void amdgpu_vmid_free_spm(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 686
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +10
-0+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 ; +}
[Severity: Medium]
If amdgpu_vmid_alloc_spm() fails on a later hub, can rolling back with amdgpu_vmid_free_spm_gfxhubs(adev, vm, xcc_mask) unbind an active SPM VMID to 0 while GPU jobs are still using it?
amdgpu_vmid_alloc_spm() returns 0 when vm->reserved_vmid[vmhub] is already set, and AMDGPU_VM_OP_RESERVE_VMID calls amdgpu_vmid_alloc_spm_gfxhubs() before reserving vm->root.bo. If vm already held a reservation on an earlier hub, or a concurrent job submission grabs a newly published vm->reserved_vmid[AMDGPU_GFXHUB(i)] before a subsequent hub fails with -ENOENT, the rollback frees and unbinds those earlier hubs to 0 without waiting via dma_resv_wait_timeout().
Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8
-11@@ -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)];
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c uint64_t amdgpu_vm_generation(struct amdgpu_device *adev, struct amdgpu_vm *vm) · line 622
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-0+ +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); + } }
[Severity: High]
Can iterating over adev->gfx.xcc_mask here and in amdgpu_vm_ioctl() index adev->reg_offset[GC_HWIP] out of bounds when lower-numbered physical XCCs are harvested?
adev->gfx.xcc_mask is a bitmask of physical XCC instances, whereas AMDGPU_GFXHUB(i), adev->vmhub[], ring->vm_hub, and setup_vm_pt_regs_xcc() all use contiguous logical XCC indices 0 .. NUM_XCC(adev->gfx.xcc_mask) - 1 and translate them via GET_INST(GC, i):
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c:gfxhub_v1_2_xcc_setup_vm_pt_regs() {
for_each_inst(i, xcc_mask) {
hub = &adev->vmhub[AMDGPU_GFXHUB(i)];
WREG32_SOC15_OFFSET(GC, GET_INST(GC, i),
regVM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
hub->ctx_addr_distance * vmid,
lower_32_bits(page_table_base));
...
}When a lower physical XCC is harvested, amdgpu_populate_ip_map() sets adev->ip_map.dev_inst[GC_HWIP][i] to -1 for i >= NUM_XCC(adev->gfx.xcc_mask). Passing a physical bit position i >= NUM_XCC(adev->gfx.xcc_mask) through amdgpu_gmc_bind_vmid() causes GET_INST(GC, i) to return 0xffffffff, reading adev->reg_offset[GC_HWIP][0xffffffff] out of bounds and flushing an uninitialized adev->vmhub[AMDGPU_GFXHUB(i)], while skipping the logical GFXHUBs at the harvested bit positions. Using GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0) avoids mixing physical and logical XCC masks.
[ ... ]
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0@@ -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 */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 3052
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2-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 ; }
[Severity: High]
Should amdgpu_vm_fini() also check all GFXHUBs before waiting on root->tbo.base.resv, matching this change in AMDGPU_VM_OP_UNRESERVE_VMID?
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:amdgpu_vm_fini() {
...
/* Wait for the jobs which might still use the reserved VMID */
if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
dma_resv_wait_timeout(root->tbo.base.resv, DMA_RESV_USAGE_READ,
false, MAX_SCHEDULE_TIMEOUT);
...
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
amdgpu_vmid_free_spm(adev, vm, i);
}
...
}If a VM holds an SPM reservation on a non-zero GFXHUB while vm->reserved_vmid[AMDGPU_GFXHUB(0)] is NULL (for example when reserved on a subset of GFXHUBs via amdgpu_vmid_alloc_spm_gfxhubs()), closing the DRM file skips dma_resv_wait_timeout(), frees the root PD in amdgpu_vm_pt_free_root(), and unbinds the SPM VMID to 0 while jobs using that VMID are still running.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Christian König
maintainerRe: [RFC PATCH 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
In reply to James ZhuQuoted 11 lines · James Zhu
The SPM VMID reservation made through
AMDGPU_VM_OP_RESERVE_VMIDis recorded onAMDGPU_GFXHUB(0)only, while gfxhub v1.2'ssetup_vm_pt_regsbroadcasts 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'sid_mgr.
Quoted 9 lines
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, andamdgpu_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 newamdgpu_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.
Don't add paralell infrastructure, instead change the existing one to handle the vmhub.
Regards,
Christian.
Quoted 196 lines
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(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4
-0@@ -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);drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +48
-1@@ -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 * drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +4
-0@@ -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,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +26
-14@@ -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 ; }
RFC PATCH 3/3 drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
In reply to James ZhuOn partitioned devices every partition is exposed as an own render node and fpriv->xcp_id records which partition a drm file belongs to. But AMDGPU_VM_OP_RESERVE_VMID reserves the VMID on every GFXHUB of the
device: a reservation made on one partition's render node blocks every other partition from reserving, and rebinds the VMID's page table base on XCCs the caller can't even submit to.
Derive the GFXHUB set from the caller's partition instead. The reservation then only covers the XCCs of the caller's partition, and each partition can hold the reserved VMID on its own hubs independently, matching the isolation the render nodes promise. Unreserve keeps operating on every hub, freeing whatever the VM actually holds.
Without partitioning, or on the whole-device node, the mask stays adev->gfx.xcc_mask and nothing changes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +12 -2
@@ -3021,11 +3021,21 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : { +uint32_t xcc_mask = adev->gfx.xcc_mask;int r; +/* +* Scope the reservation to the hardware partition behind the +* caller's render node, so other partitions can hold the +* reserved VMID on their own XCCs independently. +*/ +if (adev->xcp_mgr && fpriv->xcp_id !=AMDGPU_XCP_NO_PARTITION ) +amdgpu_xcp_get_inst_details ( + &adev->xcp_mgr->xcp[fpriv->xcp_id], +AMDGPU_XCP_GFX , &xcc_mask); +/* We only have requirement to reserve vmid from gfxhub */ - r =amdgpu_vmid_alloc_spm_gfxhubs (adev, vm, - adev->gfx.xcc_mask); + r =amdgpu_vmid_alloc_spm_gfxhubs (adev, vm, xcc_mask);if (!r && !amdgpu_bo_reserve (vm->root.bo, true)) {amdgpu_vm_spm_update (adev, vm);amdgpu_bo_unreserve (vm->root.bo);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [RFC PATCH 3/3] drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/amdgpu: skipped wait in amdgpu_vm_fini() for partition SPM VMID - [Medium] drm/amdgpu: unchecked…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] drm/amdgpu: skipped wait in amdgpu_vm_fini() for partition SPM VMID
- [Medium] drm/amdgpu: unchecked amdgpu_xcp_get_inst_details() in amdgpu_vm_ioctl()
--
commit a5f43653ba23f302ebd963bef5053a4d46508cd1
Author: James Zhu <[email protected]>
drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
This commit scopes AMDGPU_VM_OP_RESERVE_VMID to the GFXHUB instances of the caller's compute partition when fpriv->xcp_id is set.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-0@@ -3021,11 +3021,21 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : { +uint32_t xcc_mask = adev->gfx.xcc_mask;int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 3035
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-0+/* +* Scope the reservation to the hardware partition behind the +* caller's render node, so other partitions can hold the +* reserved VMID on their own XCCs independently. +*/ +if (adev->xcp_mgr && fpriv->xcp_id !=AMDGPU_XCP_NO_PARTITION ) +amdgpu_xcp_get_inst_details ( + &adev->xcp_mgr->xcp[fpriv->xcp_id], +AMDGPU_XCP_GFX , &xcc_mask);
[Severity: Medium]
Should the return value of amdgpu_xcp_get_inst_details() be checked here?
If a runtime compute partition switch reduces the number of partitions while a DRM file opened on a higher-numbered partition remains open, xcp[fpriv->xcp_id].valid becomes false and amdgpu_xcp_get_inst_details() returns -EINVAL without updating xcc_mask. The reservation then silently falls back to adev->gfx.xcc_mask and reserves the SPM VMID across every GFXHUB on the device.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 3038
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2+/* We only have requirement to reserve vmid from gfxhub */ - r =amdgpu_vmid_alloc_spm_gfxhubs (adev, vm, - adev->gfx.xcc_mask); + r =amdgpu_vmid_alloc_spm_gfxhubs (adev, vm, xcc_mask);
[Severity: High]
When a process on a non-zero partition (fpriv->xcp_id > 0) closes its DRM file without calling AMDGPU_VM_OP_UNRESERVE_VMID, does amdgpu_vm_fini() skip waiting for in-flight jobs before unbinding and freeing the reserved SPM VMID?
For fpriv->xcp_id > 0, xcc_mask only includes that partition's XCCs, so vm->reserved_vmid[AMDGPU_GFXHUB(0)] stays NULL. Unlike AMDGPU_VM_OP_UNRESERVE_VMID, amdgpu_vm_fini() only checks GFXHUB(0) before waiting and then frees the SPM VMID on all hubs:
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:amdgpu_vm_fini() {
...
/* Wait for the jobs which might still use the reserved VMID */
if (vm->reserved_vmid[AMDGPU_GFXHUB(0)])
dma_resv_wait_timeout(root->tbo.base.resv, DMA_RESV_USAGE_READ,
false, MAX_SCHEDULE_TIMEOUT);
...
for (i = 0; i < AMDGPU_MAX_VMHUBS; i++) {
amdgpu_vmid_free_spm(adev, vm, i);
}
...
}amdgpu_vmid_free_spm() then unbinds spm_vmid to address 0 and clears id_mgr->reserved_vmid while GPU jobs on that partition are still running under spm_vmid, causing in-flight work to page-fault and letting another process rebind the VMID concurrently. Checking all GFXHUBs in adev->gfx.xcc_mask in amdgpu_vm_fini(), matching AMDGPU_VM_OP_UNRESERVE_VMID, would avoid this regression.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
v2 cover drm/amdgpu: make the reserved SPM VMID per-partition
In reply to James ZhuThe reserved (SPM) VMID handling was designed on single-XCC hardware, where one GFXHUB is all there is. On multi-XCC parts with partitioning every XCC has an own GFXHUB and every partition is exposed as an own render node, and the current code is incoherent in three ways at once:
1. AMDGPU_VM_OP_RESERVE_VMID records the reservation on AMDGPU_GFXHUB(0) only. The VMID grab path checks vm->reserved_vmid[ring->vm_hub], and the rings of XCC i use AMDGPU_GFXHUB(i) - so for any job running on XCC 1..n the reservation silently does nothing. A debugger relying on a stable VMID gets one on exactly one XCC of the partition it runs on, or none at all.
2. The physical programming goes the other way: the setup_vm_pt_regs gfxhub callback broadcasts the SPM VMID's page table base to every XCC of the device, including XCCs of partitions the caller cannot even submit to.
3. The exclusion is device-global: because every reservation contends for hub 0's id_mgr, one partition's render node blocks every other partition from reserving, which breaks the isolation the render nodes are supposed to provide.
None of this is visible on single-XCC hardware, where "hub 0", "all hubs" and "the caller's hubs" happen to be the same thing. gfx 9.4.3 partition modes are where the three diverge.
This series makes the per-hub infrastructure, which already exists in the data structures (vm->reserved_vmid[] and id_mgr[] are per-vmhub arrays), real end to end:
Patch 1 exposes the XCC-masked setup_vm_pt_regs variant, which gfxhub v1.2 and v12.1 already implement internally, as a gfxhub callback.
Patch 2 makes the hub argument of the binding path mean what it says:amdgpu_gmc_bind_vmid() programs and flushes only the given hub, amdgpu_vmid_free_spm() unbinds the hub it frees, amdgpu_vm_spm_update() binds every hub the VM holds the reservation on, and the ioctl reserves on every GFXHUB instance. This fixes 1. and 2. while keeping the device-wide scope.
Patch 3 then derives the hub set from the caller's partition (fpriv->xcp_id), fixing 3.: each partition reserves, binds and conflicts only on its own XCCs. Unreserve keeps operating on every hub, freeing whatever the VM actually holds.
A note on the record granularity: the reservation could instead be recorded on the partition's first GFXHUB only and treated as a pure ownership token, closest to the original single-hub design. But the record plays three roles at once: the ownership token, the set of hubs whose page table base has to be bound (each XCC translates through its own hub, so the binding must cover every XCC of the partition either way), and the per-hub check of the VMID grab and CS paths (vm->reserved_vmid[ring->vm_hub]). Recording on every hub of the partition keeps the three consistent by construction, lets amdgpu_vm_spm_update() derive the binding set from the existing structures without a new field, and gives jobs on every XCC of the partition the same reserved-VMID semantics instead of only on the first one. The VMID number itself is the same everywhere either way:
it is always adev->vm_manager.spm_vmid.
No UAPI change. On devices without partitioning, or on the whole-device node, the mask degenerates to every XCC and nothing changes; on single-XCC parts the series is a no-op.
Compile-tested on amd-staging-drm-next with CONFIG_DRM_AMDGPU=m; checkpatch clean.
v2: address the Sashiko AI review findings, all of which checked out:
- Iterate the GFXHUBs with a logical XCC mask (GENMASK(NUM_XCC(adev->gfx.xcc_mask) - 1, 0)) instead of the physical adev->gfx.xcc_mask, which can be sparse when an XCC is harvested and would send out-of-range logical indices into GET_INST() (amdgpu_vm_spm_update(), both ioctl ops). The partition path already used the logical xcp inst_mask.
- amdgpu_vm_fini() now checks every VMHUB, not just GFXHUB(0), before waiting for jobs that may still use a reserved VMID; with patch 3 a partition > 0 holds no reservation on hub 0 and the wait was skipped.
- amdgpu_vmid_alloc_spm_gfxhubs() rolls back only the hubs it newly reserved, and waits on the root PD reservation first, honoring amdgpu_vmid_free_spm()'s wait requirement; previously the rollback could free pre-held hubs and unbind a VMID a just-submitted job uses.
- The return of amdgpu_xcp_get_inst_details() is checked; a stale fpriv->xcp_id now fails the ioctl instead of silently reserving the whole device.
James Zhu (3):
drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub
callback
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 68 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 70 ++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 + drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 + 7 files changed, 132 insertions(+), 18 deletions(-)
Signature · 1 line
2.34.1
RFC PATCH v2 1/3 drm/amdgpu: expose the XCC-masked setup_vm_pt_regs as a gfxhub callback
On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the setup_vm_pt_regs gfxhub callback programs a VMID's page table base on every XCC. Callers which bind a VMID on a single VMHUB, like the SPM VMID binding, have no way to reach one GFXHUB through the callback interface.
gfxhub v1.2 and v12.1 already implement an XCC-masked variant internally. Expose it as a new setup_vm_pt_regs_xcc callback. GFXHUBs of IPs with a single XCC don't implement it, for them the existing callback already is per-hub.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 ++ drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 1 + drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 + 3 files changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h +2 -0
@@ -28,6 +28,8 @@ struct amdgpu_gfxhub_funcs {u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);void (*setup_vm_pt_regs)(struct amdgpu_device *adev,uint32_t vmid,uint64_t page_table_base); +void (*setup_vm_pt_regs_xcc)(struct amdgpu_device *adev,uint32_t vmid, +uint64_t page_table_base,uint32_t xcc_mask);int (*gart_enable)(struct amdgpu_device *adev);void (*gart_disable)(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +1 -0
@@ -809,6 +809,7 @@ const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = { .get_fb_location = gfxhub_v12_1_get_fb_location, .get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset, .setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs, + .setup_vm_pt_regs_xcc = gfxhub_v12_1_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v12_1_gart_enable, .gart_disable = gfxhub_v12_1_gart_disable, .set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +1 -0
@@ -634,6 +634,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = { .get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset, .setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs, + .setup_vm_pt_regs_xcc = gfxhub_v1_2_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v1_2_gart_enable, .gart_disable = gfxhub_v1_2_gart_disable, .set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
Signature · 1 line
2.34.1
RFC PATCH v2 2/3 drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
In reply to James ZhuThe 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 4 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 68 ++++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 56 +++++++++++++------- 4 files changed, 114 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4 -0
@@ -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);
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +67 -1
79 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +4 -0
@@ -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,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +39 -17
103 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [RFC PATCH v2 2/3] drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/amdgpu: missing root PD lock in amdgpu_vmid_alloc_spm_gfxhubs() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/amdgpu: missing root PD lock in amdgpu_vmid_alloc_spm_gfxhubs()
--
commit 4216e97db26fd6fc889673c452d2434887bc13af
Author: James Zhu <[email protected]>
drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
This commit reserves, binds, and unbinds the SPM VMID on every GFXHUB instance rather than only on AMDGPU_GFXHUB(0).
Quoted 61 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +47
-1@@ -651,12 +651,78 @@ 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 +* only the hubs this call reserved are released again, after waiting for +* the jobs which might have grabbed the reserved VMID in the meantime; +* hubs @vm already held before the call stay reserved. +*/ +int amdgpu_vmid_alloc_spm_gfxhubs (struct amdgpu_device *adev, +struct amdgpu_vm *vm,uint32_t xcc_mask) +{ +uint32_t allocated =0 ; +int i, r; + +for_each_inst (i, xcc_mask) { +bool held =amdgpu_vmid_uses_reserved (vm,AMDGPU_GFXHUB (i)); + + r =amdgpu_vmid_alloc_spm (adev, vm,AMDGPU_GFXHUB (i)); +if (r) + goto error_free; +if (!held) + allocated |=BIT (i); + } + +return 0 ; + +error_free: +/* +* A job may already have grabbed a freshly reserved VMID, give it +* the wait amdgpu_vmid_free_spm() demands before the rollback +* unbinds the VMID again. +*/ +if (allocated) { +dma_resv_wait_timeout (vm->root.bo->tbo.base.resv, +DMA_RESV_USAGE_READ , false, +MAX_SCHEDULE_TIMEOUT ); +amdgpu_vmid_free_spm_gfxhubs (adev, vm, allocated); + } +return r; +}
[ ... ]
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0
[ ... ]
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1@@ -3015,10 +3028,12 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)switch (args->in.op) {case AMDGPU_VM_OP_RESERVE_VMID : { +/* logical XCCs, the GFXHUB index space; xcc_mask is physical */ +uint32_t gfxhub_mask =GENMASK (NUM_XCC (adev->gfx.xcc_mask) -1 ,0 );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, gfxhub_mask);if (!r && !amdgpu_bo_reserve (vm->root.bo, true)) {amdgpu_vm_spm_update (adev, vm);amdgpu_bo_unreserve (vm->root.bo);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 3042
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0}return r; }
[Severity: Medium]
Can the error rollback in amdgpu_vmid_alloc_spm_gfxhubs() unbind a newly reserved SPM VMID while a concurrent CS job is still using it?
Unlike AMDGPU_VM_OP_UNRESERVE_VMID, AMDGPU_VM_OP_RESERVE_VMID calls amdgpu_vmid_alloc_spm_gfxhubs() without holding the vm->root.bo reservation lock:
CPU0 CPU1amdgpu_vm_ioctl(RESERVE_VMID)
amdgpu_vmid_alloc_spm_gfxhubs()
amdgpu_vmid_alloc_spm(hub 0)
vm->reserved_vmid[hub 0] = id
amdgpu_vmid_alloc_spm(hub 1)
-> -ENOENT
dma_resv_wait_timeout(root)
amdgpu_cs_ioctl()
/* reserves root, adds fence */
amdgpu_job_prepare_job()
amdgpu_vmid_grab()
/* grabs reserved VMID on hub 0 */
amdgpu_vmid_free_spm(hub 0)
amdgpu_gmc_bind_vmid(..., 0) <-- unbinds VMID under active jobBecause vm->root.bo is not reserved across the wait and free, a command submission on the same VM can attach a new fence and grab the reserved VMID on hub 0 after dma_resv_wait_timeout() returns and right before amdgpu_vmid_free_spm() unbinds its page-table-base register to 0, causing GPU page faults for the in-flight job.
Running without vm->root.bo reserved also leaves held = amdgpu_vmid_uses_reserved() unsynchronized: amdgpu_vmid_alloc_spm() returns 0 when vm->reserved_vmid[vmhub] is already set, so two concurrent AMDGPU_VM_OP_RESERVE_VMID calls on the same VM can both observe held == false on hub 0 and set allocated |= BIT(0), causing a failure on a later hub in one thread to free the reservation held by the other. Similarly, concurrent RESERVE_VMID and UNRESERVE_VMID calls can interleave across hubs, and if amdgpu_bo_reserve(vm->root.bo, true) fails after amdgpu_vmid_alloc_spm_gfxhubs() succeeds, amdgpu_vm_spm_update() is skipped while returning 0.
Reserving vm->root.bo in AMDGPU_VM_OP_RESERVE_VMID before calling amdgpu_vmid_alloc_spm_gfxhubs() and holding it across amdgpu_vm_spm_update() (matching AMDGPU_VM_OP_UNRESERVE_VMID) would serialize per-VM reservation state and prevent new CS jobs during rollback.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RFC PATCH v2 3/3 drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
In reply to James ZhuOn partitioned devices every partition is exposed as an own render node and fpriv->xcp_id records which partition a drm file belongs to. But AMDGPU_VM_OP_RESERVE_VMID reserves the VMID on every GFXHUB of the
device: a reservation made on one partition's render node blocks every other partition from reserving, and rebinds the VMID's page table base on XCCs the caller can't even submit to.
Derive the GFXHUB set from the caller's partition instead. The reservation then only covers the XCCs of the caller's partition, and each partition can hold the reserved VMID on its own hubs independently, matching the isolation the render nodes promise. Unreserve keeps operating on every hub, freeing whatever the VM actually holds.
Without partitioning, or on the whole-device node, the mask stays adev->gfx.xcc_mask and nothing changes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -0
@@ -3032,6 +3032,20 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)uint32_t gfxhub_mask =GENMASK (NUM_XCC (adev->gfx.xcc_mask) -1 ,0 );int r; +/* +* Scope the reservation to the hardware partition behind the +* caller's render node, so other partitions can hold the +* reserved VMID on their own XCCs independently. The +* partition's inst_mask is logical like the GFXHUB indices. +*/ +if (adev->xcp_mgr && fpriv->xcp_id !=AMDGPU_XCP_NO_PARTITION ) { + r =amdgpu_xcp_get_inst_details ( + &adev->xcp_mgr->xcp[fpriv->xcp_id], +AMDGPU_XCP_GFX , &gfxhub_mask); +if (r) +return r; + } +/* We only have requirement to reserve vmid from gfxhub */ r =amdgpu_vmid_alloc_spm_gfxhubs (adev, vm, gfxhub_mask);if (!r && !amdgpu_bo_reserve (vm->root.bo, true)) {
Signature · 1 line
2.34.1
v3 cover drm/amdgpu: make the reserved SPM VMID per-partition
In reply to James ZhuThe reserved (SPM) VMID handling was designed on single-XCC hardware, where one GFXHUB is all there is. On multi-XCC parts with partitioning every XCC has an own GFXHUB and every partition is exposed as an own render node, and the current code is incoherent in three ways at once:
1. AMDGPU_VM_OP_RESERVE_VMID records the reservation on AMDGPU_GFXHUB(0) only. The VMID grab path checks vm->reserved_vmid[ring->vm_hub], and the rings of XCC i use AMDGPU_GFXHUB(i) - so for any job running on XCC 1..n the reservation silently does nothing. A debugger relying on a stable VMID gets one on exactly one XCC of the partition it runs on, or none at all.
2. The physical programming goes the other way: the setup_vm_pt_regs gfxhub callback broadcasts the SPM VMID's page table base to every XCC of the device, including XCCs of partitions the caller cannot even submit to.
3. The exclusion is device-global: because every reservation contends for hub 0's id_mgr, one partition's render node blocks every other partition from reserving, which breaks the isolation the render nodes are supposed to provide.
None of this is visible on single-XCC hardware, where "hub 0", "all hubs" and "the caller's hubs" happen to be the same thing. gfx 9.4.3 partition modes are where the three diverge.
This series makes the per-hub infrastructure, which already exists in the data structures (vm->reserved_vmid[] and id_mgr[] are per-vmhub arrays), real end to end:
Patch 1 extends the setup_vm_pt_regs gfxhub callback with the mask of logical XCCs to program and adds amdgpu_gfx_logical_xcc_mask() for deriving that mask (the GFXHUBs are indexed by logical XCC, while adev->gfx.xcc_mask holds physical instances and can be sparse under harvesting); no functional change.
Patch 2 makes the hub argument of the binding path mean what it says:amdgpu_gmc_bind_vmid() programs and flushes only the given hub, and amdgpu_vmid_alloc_spm()/free_spm() take the set of GFXHUBs directly, reserving on every hub the VM's jobs can run on, under the root PD reservation as an asserted lock contract. This fixes 1. and 2. while keeping the device-wide scope.
Patch 3 then derives the hub set from the caller's partition (fpriv->xcp_id), fixing 3.: each partition reserves, binds and conflicts only on its own XCCs. Unreserve keeps operating on every hub, freeing whatever the VM actually holds.
A note on the record granularity: the reservation could instead be recorded on the partition's first GFXHUB only and treated as a pure ownership token, closest to the original single-hub design. But the record plays three roles at once: the ownership token, the set of hubs whose page table base has to be bound (each XCC translates through its own hub, so the binding must cover every XCC of the partition either way), and the per-hub check of the VMID grab and CS paths (vm->reserved_vmid[ring->vm_hub]). Recording on every hub of the partition keeps the three consistent by construction, lets amdgpu_vm_spm_update() derive the binding set from the existing structures without a new field, and gives jobs on every XCC of the partition the same reserved-VMID semantics instead of only on the first one. The VMID number itself is the same everywhere either way:
it is always adev->vm_manager.spm_vmid.
No UAPI change. On devices without partitioning, or on the whole-device node, the mask degenerates to every XCC and nothing changes; on single-XCC parts the series is a no-op.
Compile-tested on amd-staging-drm-next with CONFIG_DRM_AMDGPU=m (the whole amdgpu directory builds warning-free); checkpatch clean.
v3: address Christian's review of the v1 structure and the Sashiko AI review of v2:
- Per Christian: no parallel interfaces. Patch 1 extends the existing setup_vm_pt_regs callback with an xcc_mask argument (all nine implementations and all callers updated; gfxhub v1.2/v12.1 hook up their internal XCC-masked variants directly and lose the broadcast wrappers) instead of adding a setup_vm_pt_regs_xcc callback. Patch 2 changes amdgpu_vmid_alloc_spm()/amdgpu_vmid_free_spm() themselves to take the GFXHUB set instead of adding *_gfxhubs() wrappers.
- Per the Sashiko review of v2 (verified): AMDGPU_VM_OP_RESERVE_VMID takes the root PD reservation before reserving and holds it across amdgpu_vm_spm_update(), matching UNRESERVE; both functions assert the root PD reservation. This serializes the per-VM reservation state against concurrent RESERVE/UNRESERVE, keeps a new CS of the same VM from grabbing a freshly reserved VMID between the rollback's wait and its unbind, and makes a failed root PD reservation an ioctl error. amdgpu_vm_fini() consequently frees the reservation while the root PD is still held.
- Further hardening from self-review: the logical-mask idiom lives in one helper (amdgpu_gfx_logical_xcc_mask(), guarding xcc_mask == 0) instead of eight open-coded copies; UNRESERVE checks the root PD reservation result like RESERVE does; amdgpu_vm_spm_update() skips hubs without a reservation with a lock-free check (reserved_vmid[] only changes under the root PD reservation the caller holds), so the common non-SPM VM takes no id_mgr lock on the userqueue validate path.
v2: address the Sashiko AI review findings of v1, all of which checked out:
- Iterate the GFXHUBs with a logical XCC mask instead of the physical adev->gfx.xcc_mask, which can be sparse when an XCC is harvested and would send out-of-range logical indices into GET_INST(). The partition path already used the logical xcp inst_mask.
- amdgpu_vm_fini() now checks every VMHUB, not just GFXHUB(0), before waiting for jobs that may still use a reserved VMID.
- The reservation rollback releases only the hubs the call newly reserved, after waiting for jobs which might have grabbed the VMID.
- The return of amdgpu_xcp_get_inst_details() is checked; a stale fpriv->xcp_id now fails the ioctl instead of silently reserving the whole device.
James Zhu (3):
drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
.../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 3 +- .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 3 +- .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c | 3 +- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 18 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 102 ++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 101 ++++++++++++----- drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c | 4 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c | 5 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 13 +-- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 12 +-- drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 4 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 4 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c | 4 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c | 4 +- 20 files changed, 211 insertions(+), 90 deletions(-)
Signature · 1 line
2.34.1
RFC PATCH v3 1/3 drm/amdgpu: pass an XCC mask to the setup_vm_pt_regs gfxhub callback
On GFX IPs with multiple XCCs each XCC has an own GFXHUB, but the setup_vm_pt_regs gfxhub callback programs a VMID's page table base on every XCC. Callers which bind a VMID on a single VMHUB, like the SPM VMID binding, have no way to reach one GFXHUB through the callback interface.
Extend the callback with the mask of logical XCCs to program. gfxhub v1.2 and v12.1 already implement an XCC-masked variant internally, hook it up directly and drop their broadcast wrappers; the implementations for IPs with a single XCC ignore the mask. All callers pass the full mask, no functional change.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c | 3 ++- .../drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c | 3 ++- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c | 3 ++- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 18 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 ++- drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c | 13 +------------ drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 12 +----------- drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c | 4 ++-- 17 files changed, 48 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c +2 -1
@@ -708,7 +708,8 @@ static void set_vm_context_page_table_base(struct amdgpu_device *adev, }/* SDMA is on gfxhub as well for Navi1* series */ - adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base, +amdgpu_gfx_logical_xcc_mask (adev)); }/*
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c +2 -1
@@ -626,7 +626,8 @@ static void set_vm_context_page_table_base_v10_3(struct amdgpu_device *adev, uint32_t vmid, uint64_t page_table_base) {/* SDMA is on gfxhub as well for Navi1* series */ - adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base, +amdgpu_gfx_logical_xcc_mask (adev)); } static void program_trap_handler_settings_v10_3(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c +2 -1
@@ -606,7 +606,8 @@ static void set_vm_context_page_table_base_v11(struct amdgpu_device *adev, }/* SDMA is on gfxhub as well for gfx11 adapters */ - adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base, +amdgpu_gfx_logical_xcc_mask (adev)); }/*
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +2 -1
@@ -923,7 +923,8 @@ void kgd_gfx_v9_set_vm_context_page_table_base(struct amdgpu_device *adev, adev->mmhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base); - adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, page_table_base, +amdgpu_gfx_logical_xcc_mask (adev)); }static void lock_spi_csq_mutexes (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +18 -0
@@ -170,6 +170,24 @@ static bool amdgpu_gfx_is_compute_multipipe_capable(struct amdgpu_device *adev)return adev->gfx.mec.num_mec >1 ; } +/** +* amdgpu_gfx_logical_xcc_mask - mask of the logical XCCs +* @adev: amdgpu device pointer +* +* The GFXHUBs, and everything else going through GET_INST(GC, ...), are +* indexed by logical XCC. adev->gfx.xcc_mask holds physical instances +* and can be sparse when an XCC is harvested, so it must not be used to +* iterate the GFXHUBs. +* +* Returns: the contiguous mask of the logical XCCs. +*/ +uint32_t amdgpu_gfx_logical_xcc_mask (struct amdgpu_device *adev) +{ +int num_xcc =NUM_XCC (adev->gfx.xcc_mask); + +return num_xcc ?GENMASK (num_xcc -1 ,0 ) :0 ; +} +bool amdgpu_gfx_is_high_priority_graphics_queue (struct amdgpu_device *adev,struct amdgpu_ring *ring) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +1 -0
@@ -597,6 +597,7 @@ static inline u32 amdgpu_gfx_create_bitmask(u32 bit_width)return (u32)((1ULL << bit_width) -1 ); } +uint32_t amdgpu_gfx_logical_xcc_mask (struct amdgpu_device *adev);void amdgpu_gfx_parse_disable_cu (struct amdgpu_device *adev,unsigned int *mask,unsigned int max_se,unsigned int max_sh);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h +1 -1
@@ -27,7 +27,7 @@ struct amdgpu_gfxhub_funcs {u64 (*get_fb_location)(struct amdgpu_device *adev);u64 (*get_mc_fb_offset)(struct amdgpu_device *adev);void (*setup_vm_pt_regs)(struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base); +uint64_t page_table_base,uint32_t xcc_mask);int (*gart_enable)(struct amdgpu_device *adev);void (*gart_disable)(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +2 -1
@@ -806,7 +806,8 @@ 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 - adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, pd_addr); + adev->gfxhub.funcs->setup_vm_pt_regs (adev, vmid, pd_addr, +amdgpu_gfx_logical_xcc_mask (adev));amdgpu_gmc_flush_gpu_tlb (adev, vmid, vmhub,TLB_FLUSH_LEGACY ); }
drivers/gpu/drm/amd/amdgpu/gfxhub_v11_5_0.c +2 -2
@@ -122,7 +122,7 @@ static u64 gfxhub_v11_5_0_get_mc_fb_offset(struct amdgpu_device *adev) }static void gfxhub_v11_5_0_setup_vm_pt_regs (struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base) +uint64_t page_table_base,uint32_t xcc_mask) {struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB (0 )];
@@ -139,7 +139,7 @@ static void gfxhub_v11_5_0_init_gart_aperture_regs(struct amdgpu_device *adev) {uint64_t pt_base =amdgpu_gmc_pd_addr (adev->gart.bo); -gfxhub_v11_5_0_setup_vm_pt_regs (adev,0 , pt_base); +gfxhub_v11_5_0_setup_vm_pt_regs (adev,0 , pt_base,BIT (0 ));WREG32_SOC15 (GC ,0 , regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32, (u32)(adev->gmc.gart_start >>12 ));
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_0.c +3 -2
@@ -125,7 +125,8 @@ static u64 gfxhub_v12_0_get_mc_fb_offset(struct amdgpu_device *adev)static void gfxhub_v12_0_setup_vm_pt_regs (struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base) +uint64_t page_table_base, +uint32_t xcc_mask) {struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB (0 )];
@@ -142,7 +143,7 @@ static void gfxhub_v12_0_init_gart_aperture_regs(struct amdgpu_device *adev) {uint64_t pt_base =amdgpu_gmc_pd_addr (adev->gart.bo); -gfxhub_v12_0_setup_vm_pt_regs (adev,0 , pt_base); +gfxhub_v12_0_setup_vm_pt_regs (adev,0 , pt_base,BIT (0 ));WREG32_SOC15 (GC ,0 , regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32, (u32)(adev->gmc.gart_start >>12 ));
drivers/gpu/drm/amd/amdgpu/gfxhub_v12_1.c +1 -12
@@ -79,17 +79,6 @@ static void gfxhub_v12_1_xcc_setup_vm_pt_regs(struct amdgpu_device *adev, } } -static void gfxhub_v12_1_setup_vm_pt_regs (struct amdgpu_device *adev, -uint32_t vmid, -uint64_t page_table_base) -{ -uint32_t xcc_mask; - - xcc_mask =GENMASK (NUM_XCC (adev->gfx.xcc_mask) -1 ,0 ); -gfxhub_v12_1_xcc_setup_vm_pt_regs (adev, vmid, page_table_base, - xcc_mask); -} -static void gfxhub_v12_1_xcc_init_gart_aperture_regs (struct amdgpu_device *adev,uint32_t xcc_mask) {
@@ -808,7 +797,7 @@ static void gfxhub_v12_1_init(struct amdgpu_device *adev)const struct amdgpu_gfxhub_funcs gfxhub_v12_1_funcs = { .get_fb_location = gfxhub_v12_1_get_fb_location, .get_mc_fb_offset = gfxhub_v12_1_get_mc_fb_offset, - .setup_vm_pt_regs = gfxhub_v12_1_setup_vm_pt_regs, + .setup_vm_pt_regs = gfxhub_v12_1_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v12_1_gart_enable, .gart_disable = gfxhub_v12_1_gart_disable, .set_fault_enable_default = gfxhub_v12_1_set_fault_enable_default,
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c +3 -2
@@ -38,7 +38,8 @@ static u64 gfxhub_v1_0_get_mc_fb_offset(struct amdgpu_device *adev)static void gfxhub_v1_0_setup_vm_pt_regs (struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base) +uint64_t page_table_base, +uint32_t xcc_mask) {struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB (0 )];
@@ -60,7 +61,7 @@ static void gfxhub_v1_0_init_gart_aperture_regs(struct amdgpu_device *adev)else pt_base =amdgpu_gmc_pd_addr (adev->gart.bo); -gfxhub_v1_0_setup_vm_pt_regs (adev,0 , pt_base); +gfxhub_v1_0_setup_vm_pt_regs (adev,0 , pt_base,BIT (0 ));/* If use GART for FB translation, vmid0 page table covers both * vram and system memory (gart)
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +1 -11
@@ -62,16 +62,6 @@ static void gfxhub_v1_2_xcc_setup_vm_pt_regs(struct amdgpu_device *adev, } } -static void gfxhub_v1_2_setup_vm_pt_regs (struct amdgpu_device *adev, -uint32_t vmid, -uint64_t page_table_base) -{ -uint32_t xcc_mask; - - xcc_mask =GENMASK (NUM_XCC (adev->gfx.xcc_mask) -1 ,0 ); -gfxhub_v1_2_xcc_setup_vm_pt_regs (adev, vmid, page_table_base, xcc_mask); -} -static void gfxhub_v1_2_xcc_init_gart_aperture_regs (struct amdgpu_device *adev,uint32_t xcc_mask) {
@@ -633,7 +623,7 @@ static int gfxhub_v1_2_get_xgmi_info(struct amdgpu_device *adev)const struct amdgpu_gfxhub_funcs gfxhub_v1_2_funcs = { .get_mc_fb_offset = gfxhub_v1_2_get_mc_fb_offset, - .setup_vm_pt_regs = gfxhub_v1_2_setup_vm_pt_regs, + .setup_vm_pt_regs = gfxhub_v1_2_xcc_setup_vm_pt_regs, .gart_enable = gfxhub_v1_2_gart_enable, .gart_disable = gfxhub_v1_2_gart_disable, .set_fault_enable_default = gfxhub_v1_2_set_fault_enable_default,
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c +2 -2
@@ -118,7 +118,7 @@ static u64 gfxhub_v2_0_get_mc_fb_offset(struct amdgpu_device *adev) }static void gfxhub_v2_0_setup_vm_pt_regs (struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base) +uint64_t page_table_base,uint32_t xcc_mask) {struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB (0 )];
@@ -135,7 +135,7 @@ static void gfxhub_v2_0_init_gart_aperture_regs(struct amdgpu_device *adev) {uint64_t pt_base =amdgpu_gmc_pd_addr (adev->gart.bo); -gfxhub_v2_0_setup_vm_pt_regs (adev,0 , pt_base); +gfxhub_v2_0_setup_vm_pt_regs (adev,0 , pt_base,BIT (0 ));WREG32_SOC15 (GC ,0 , mmGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32, (u32)(adev->gmc.gart_start >>12 ));
drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c +2 -2
@@ -121,7 +121,7 @@ static u64 gfxhub_v2_1_get_mc_fb_offset(struct amdgpu_device *adev) }static void gfxhub_v2_1_setup_vm_pt_regs (struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base) +uint64_t page_table_base,uint32_t xcc_mask) {struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB (0 )];
@@ -138,7 +138,7 @@ static void gfxhub_v2_1_init_gart_aperture_regs(struct amdgpu_device *adev) {uint64_t pt_base =amdgpu_gmc_pd_addr (adev->gart.bo); -gfxhub_v2_1_setup_vm_pt_regs (adev,0 , pt_base); +gfxhub_v2_1_setup_vm_pt_regs (adev,0 , pt_base,BIT (0 ));WREG32_SOC15 (GC ,0 , mmGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32, (u32)(adev->gmc.gart_start >>12 ));
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0.c +2 -2
@@ -117,7 +117,7 @@ static u64 gfxhub_v3_0_get_mc_fb_offset(struct amdgpu_device *adev) }static void gfxhub_v3_0_setup_vm_pt_regs (struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base) +uint64_t page_table_base,uint32_t xcc_mask) {struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB (0 )];
@@ -134,7 +134,7 @@ static void gfxhub_v3_0_init_gart_aperture_regs(struct amdgpu_device *adev) {uint64_t pt_base =amdgpu_gmc_pd_addr (adev->gart.bo); -gfxhub_v3_0_setup_vm_pt_regs (adev,0 , pt_base); +gfxhub_v3_0_setup_vm_pt_regs (adev,0 , pt_base,BIT (0 ));WREG32_SOC15 (GC ,0 , regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32, (u32)(adev->gmc.gart_start >>12 ));
drivers/gpu/drm/amd/amdgpu/gfxhub_v3_0_3.c +2 -2
@@ -120,7 +120,7 @@ static u64 gfxhub_v3_0_3_get_mc_fb_offset(struct amdgpu_device *adev) }static void gfxhub_v3_0_3_setup_vm_pt_regs (struct amdgpu_device *adev,uint32_t vmid, -uint64_t page_table_base) +uint64_t page_table_base,uint32_t xcc_mask) {struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_GFXHUB (0 )];
@@ -137,7 +137,7 @@ static void gfxhub_v3_0_3_init_gart_aperture_regs(struct amdgpu_device *adev) {uint64_t pt_base =amdgpu_gmc_pd_addr (adev->gart.bo); -gfxhub_v3_0_3_setup_vm_pt_regs (adev,0 , pt_base); +gfxhub_v3_0_3_setup_vm_pt_regs (adev,0 , pt_base,BIT (0 ));WREG32_SOC15 (GC ,0 , regGCVM_CONTEXT0_PAGE_TABLE_START_ADDR_LO32, (u32)(adev->gmc.gart_start >>12 ));
Signature · 1 line
2.34.1
RFC PATCH v3 2/3 drm/amdgpu: reserve and bind the SPM VMID on every GFXHUB instance
In reply to James ZhuThe 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 and flushes only the given hub, and amdgpu_vmid_alloc_spm() and amdgpu_vmid_free_spm() take the set of GFXHUBs directly, reserving the VMID on every hub the VM's jobs can run on. The hub loops use a logical XCC mask (GENMASK(NUM_XCC() - 1, 0)): the GFXHUBs are indexed by logical XCC, while adev->gfx.xcc_mask holds physical instances and can be sparse when an XCC is harvested.
On a partial reservation failure only the hubs the call newly reserved are released again, after waiting for jobs which might have grabbed the VMID in the meantime. Both functions require the root PD reservation as a documented, asserted lock contract; AMDGPU_VM_OP_RESERVE_VMID takes it before reserving, which also serializes the per-VM reservation state against concurrent RESERVE/UNRESERVE calls and makes a failed root PD reservation an ioctl error instead of silently skipping the bind. amdgpu_vm_fini() gives the reservation up while the root PD is still held and checks every hub, not just hub 0, before waiting for jobs. amdgpu_vm_spm_update() binds every GFXHUB on which @vm holds the reservation, so a conflicting reservation shows up on whichever hub two VMs share.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c | 102 +++++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 87 +++++++++++++------- 4 files changed, 150 insertions(+), 48 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +4 -1
@@ -797,6 +797,9 @@ 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 flushed, and for a GFXHUB only @vmhub is programmed; +* the MMHUB callback still programs every AID's MMHUB on IPs with +* more than one. */ void amdgpu_gmc_bind_vmid (struct amdgpu_device *adev,unsigned int vmhub,unsigned int vmid,uint64_t pd_addr)
@@ -807,7 +810,7 @@ void amdgpu_gmc_bind_vmid(struct amdgpu_device *adev, unsigned int vmhub, adev->mmhub.funcs->setup_vm_pt_regs (adev, vmid, pd_addr); else adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, pd_addr, -amdgpu_gfx_logical_xcc_mask (adev )); + BIT(vmhub - AMDGPU_GFXHUB_START));amdgpu_gmc_flush_gpu_tlb (adev, vmid, vmhub,TLB_FLUSH_LEGACY ); }
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c +84 -18
131 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.h +2 -2
@@ -126,9 +126,9 @@ 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_spm (struct amdgpu_device *adev,struct amdgpu_vm *vm, -unsigned vmhub); +uint32_t gfxhub_mask);void amdgpu_vmid_free_spm (struct amdgpu_device *adev,struct amdgpu_vm *vm, -unsigned vmhub); +uint32_t gfxhub_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,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +60 -27
135 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 3/3 drm/amdgpu: scope AMDGPU_VM_OP_RESERVE_VMID to the caller's partition
In reply to James ZhuOn partitioned devices every partition is exposed as an own render node and fpriv->xcp_id records which partition a drm file belongs to. But AMDGPU_VM_OP_RESERVE_VMID reserves the VMID on every GFXHUB of the
device: a reservation made on one partition's render node blocks every other partition from reserving, and rebinds the VMID's page table base on XCCs the caller can't even submit to.
Derive the GFXHUB set from the caller's partition instead. The reservation then only covers the XCCs of the caller's partition, and each partition can hold the reserved VMID on its own hubs independently, matching the isolation the render nodes promise. Unreserve keeps operating on every hub, freeing whatever the VM actually holds.
Without partitioning, or on the whole-device node, the mask stays the full set of XCCs and nothing changes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -0
@@ -3035,6 +3035,20 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)uint32_t gfxhub_mask =amdgpu_gfx_logical_xcc_mask (adev);int r; +/* +* Scope the reservation to the hardware partition behind the +* caller's render node, so other partitions can hold the +* reserved VMID on their own XCCs independently. The +* partition's inst_mask is logical like the GFXHUB indices. +*/ +if (adev->xcp_mgr && fpriv->xcp_id !=AMDGPU_XCP_NO_PARTITION ) { + r =amdgpu_xcp_get_inst_details ( + &adev->xcp_mgr->xcp[fpriv->xcp_id], +AMDGPU_XCP_GFX , &gfxhub_mask); +if (r) +return r; + } +/* * The root PD reservation serializes the per-VM reservation * state and keeps new jobs of this VM from grabbing a freshly
Signature · 1 line
2.34.1