On 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.

Signed-off-by: James Zhu <[email protected]>
Assisted-by: Claude:claude-fable-5
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index bd9aa35933dc..d37af0dbd691 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -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);
-- 
2.34.1

Reply via email to