* [PATCH] drm/amdgpu: Report SPM VMID root BO reservation failure
@ 2026-12-02 11:30 Srinivasan Shanmugam
2026-12-02 11:30 ` [PATCH] drm/amdgpu: Check errors before releasing the SPM VMID Srinivasan Shanmugam
0 siblings, 1 reply; 3+ messages in thread
From: Srinivasan Shanmugam @ 2026-12-02 11:30 UTC (permalink / raw)
To: Christian König, Alex Deucher
Cc: amd-gfx, Srinivasan Shanmugam, Sunil Khatri
The reserve ioctl can report success even when it fails to lock the root
page table. The SPM VMID is then reserved without being bound to the
process's page tables.
Lock the root BO first and return the error if locking fails. Reserve
and bind the SPM VMID while that lock is held.
Fixes: ba56c52af8fd ("drm/amdgpu: bind the SPM VMID's page table to the reserving VM")
Cc: Sunil Khatri <sunil.khatri@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 19177ff37ac8..8eb5f28bca7d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -3051,11 +3051,15 @@ 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_bo_reserve(vm->root.bo, true);
+ if (r)
+ return r;
+
r = amdgpu_vmid_alloc_spm(adev, vm, AMDGPU_GFXHUB(0));
- if (!r && !amdgpu_bo_reserve(vm->root.bo, true)) {
+ if (!r)
amdgpu_vm_spm_update(adev, vm);
- amdgpu_bo_unreserve(vm->root.bo);
- }
+
+ amdgpu_bo_unreserve(vm->root.bo);
return r;
}
case AMDGPU_VM_OP_UNRESERVE_VMID: {
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH] drm/amdgpu: Check errors before releasing the SPM VMID
2026-12-02 11:30 [PATCH] drm/amdgpu: Report SPM VMID root BO reservation failure Srinivasan Shanmugam
@ 2026-12-02 11:30 ` Srinivasan Shanmugam
2026-12-02 11:40 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Srinivasan Shanmugam @ 2026-12-02 11:30 UTC (permalink / raw)
To: Christian König, Alex Deucher
Cc: amd-gfx, Srinivasan Shanmugam, Jesse Zhang
The unreserve ioctl ignores failures when locking the root BO or waiting
for outstanding work. It can then release the SPM VMID without the
synchronization that this path requires.
Return the error and leave the VMID reserved so the caller can retry.
Fixes: 8c84a904ee51f ("drm/amdgpu: don't wait for the SPM VMID's jobs under the VMID manager lock")
Cc: Jesse Zhang <Jesse.Zhang@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 8eb5f28bca7d..000ac36062e4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -3064,13 +3064,24 @@ 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;
+ long wait;
+ int r;
+
+ r = amdgpu_bo_reserve(root, true);
+ if (r)
+ return r;
- amdgpu_bo_reserve(root, true);
/* 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);
+ if (vm->reserved_vmid[AMDGPU_GFXHUB(0)]) {
+ wait = dma_resv_wait_timeout(root->tbo.base.resv,
+ DMA_RESV_USAGE_READ, false,
+ MAX_SCHEDULE_TIMEOUT);
+ if (wait <= 0) {
+ amdgpu_bo_unreserve(root);
+ return wait < 0 ? (int)wait : -ETIME;
+ }
+ }
+
amdgpu_vmid_free_spm(adev, vm, AMDGPU_GFXHUB(0));
amdgpu_bo_unreserve(root);
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] drm/amdgpu: Check errors before releasing the SPM VMID
2026-12-02 11:30 ` [PATCH] drm/amdgpu: Check errors before releasing the SPM VMID Srinivasan Shanmugam
@ 2026-12-02 11:40 ` sashiko-bot
0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-02 11:40 UTC (permalink / raw)
To: Srinivasan Shanmugam; +Cc: amd-gfx
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdgpu: dead error checks on uninterruptible waits in
amdgpu_vm_ioctl()
--
commit 1c20d0b2a4030e6c94419ccf8d5459e64734db54
Author: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
drm/amdgpu: Check errors before releasing the SPM VMID
This commit checks the return values of amdgpu_bo_reserve() and
dma_resv_wait_timeout() in the AMDGPU_VM_OP_UNRESERVE_VMID path of
amdgpu_vm_ioctl() before releasing the SPM VMID.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 94b1cfe05e3e0..8031d3072bcdf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -3027,13 +3027,24 @@ 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;
> + long wait;
> + int r;
> +
> + r = amdgpu_bo_reserve(root, true);
> + if (r)
> + return r;
>
> - amdgpu_bo_reserve(root, true);
> /* 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);
> + if (vm->reserved_vmid[AMDGPU_GFXHUB(0)]) {
> + wait = dma_resv_wait_timeout(root->tbo.base.resv,
> + DMA_RESV_USAGE_READ, false,
> + MAX_SCHEDULE_TIMEOUT);
> + if (wait <= 0) {
> + amdgpu_bo_unreserve(root);
> + return wait < 0 ? (int)wait : -ETIME;
> + }
> + }
[Severity: Medium]
Can either of these error checks ever trigger while both calls use
uninterruptible waits?
amdgpu_bo_reserve(root, true) passes no_intr = true to
ttm_bo_reserve(&bo->tbo, !no_intr, false, NULL), which calls
dma_resv_lock() with no ticket and always returns 0. Likewise,
dma_resv_wait_timeout(..., false, MAX_SCHEDULE_TIMEOUT) sleeps
uninterruptibly with no timeout and always returns MAX_SCHEDULE_TIMEOUT.
If this ioctl should abort on a signal so userspace can retry,
amdgpu_bo_reserve(root, false) and dma_resv_wait_timeout(..., true,
MAX_SCHEDULE_TIMEOUT) would be needed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202113037.1806655-2-srinivasan.shanmugam@amd.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 11:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 11:30 [PATCH] drm/amdgpu: Report SPM VMID root BO reservation failure Srinivasan Shanmugam
2026-12-02 11:30 ` [PATCH] drm/amdgpu: Check errors before releasing the SPM VMID Srinivasan Shanmugam
2026-12-02 11:40 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.