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. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > index e1691145da903..8098fbb542c82 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); [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. > + > /* 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. -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
