When MES is enabled and amdgpu_amdkfd_alloc_kernel_mem() fails during
the first queue creation for a process, pqm_create_queue() returns
early via 'return retval' without going through the err_create_queue
cleanup label.

This means clear_bit(*qid, pqm->queue_slot_bitmap) is never called,
leaving the reserved QID bit permanently set in queue_slot_bitmap.
Over time this leaks QID slots, potentially exhausting all available
queue slots.

Fix this by replacing 'return retval' with 'goto err_create_queue'
so that clear_bit() is always called on the error path.

Fixes: AILIKFD-813
Reported-by: Deucher, Alexander <[email protected]>
Signed-off-by: Marioukhine, Vladimir <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
index 1234567..abcdefg 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
@@ -378,7 +378,7 @@
                                                     false);
                if (retval) {
                        dev_err(dev->adev->dev, "failed to allocate process 
context bo\n");
-                       return retval;
+                       goto err_create_queue;
                }
                memset(pdd->proc_ctx_cpu_ptr, 0, AMDGPU_MES_PROC_CTX_SIZE);
        }
--
2.34.1
From: Marioukhine, Vladimir <[email protected]>
Date: Wed, 20 May 2026 21:31:49 +0000
Subject: [PATCH] drm/amdkfd: fix QID bit leak in pqm_create_queue()

When MES is enabled and amdgpu_amdkfd_alloc_kernel_mem() fails during
the first queue creation for a process, pqm_create_queue() returns
early via 'return retval' without going through the err_create_queue
cleanup label.

This means clear_bit(*qid, pqm->queue_slot_bitmap) is never called,
leaving the reserved QID bit permanently set in queue_slot_bitmap.
Over time this leaks QID slots, potentially exhausting all available
queue slots.

Fix this by replacing 'return retval' with 'goto err_create_queue'
so that clear_bit() is always called on the error path.

Fixes: AILIKFD-813
Reported-by: Deucher, Alexander <[email protected]>
Signed-off-by: Marioukhine, Vladimir <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
index 1234567..abcdefg 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
@@ -378,7 +378,7 @@
 						     false);
 		if (retval) {
 			dev_err(dev->adev->dev, "failed to allocate process context bo\n");
-			return retval;
+			goto err_create_queue;
 		}
 		memset(pdd->proc_ctx_cpu_ptr, 0, AMDGPU_MES_PROC_CTX_SIZE);
 	}
-- 
2.34.1
=== AILIKFD-813 Patch Test Results ===
Date: Thu May 21 02:29:44 PM EDT 2026
Kernel: 6.17.0
GPU: 03:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] 
Navi 31 [Radeon RX 7900 XT/7900 XTX/7900M] (rev ce)

=== BASELINE (unpatched) ===
[       OK ] KFDQMTest.CreateDestroyCpQueue (34 ms)
[       OK ] KFDQMTest.SubmitNopCpQueue (18 ms)
[       OK ] KFDQMTest.SubmitPacketCpQueue (17 ms)
[       OK ] KFDQMTest.AllCpQueues (82 ms)
[       OK ] KFDQMTest.CreateDestroySdmaQueue (9 ms)
[       OK ] KFDQMTest.SubmitNopSdmaQueue (10 ms)
[       OK ] KFDQMTest.SubmitPacketSdmaQueue (10 ms)
[       OK ] KFDQMTest.AllSdmaQueues (35 ms)
[       OK ] KFDQMTest.AllXgmiSdmaQueues (7 ms)
[       OK ] KFDQMTest.AllQueues (108 ms)
[       OK ] KFDQMTest.SdmaConcurrentCopies (5712 ms)
[       OK ] KFDQMTest.DisableCpQueueByUpdateWithNullAddress (2030 ms)
[       OK ] KFDQMTest.DisableSdmaQueueByUpdateWithNullAddress (2026 ms)
[       OK ] KFDQMTest.DisableCpQueueByUpdateWithZeroPercentage (2045 ms)
[       OK ] KFDQMTest.CreateQueueStressSingleThreaded (15020 ms)
[       OK ] KFDQMTest.OverSubscribeCpQueues (5897 ms)
[  FAILED  ] KFDQMTest.BasicCuMaskingLinear (7780 ms)
[  FAILED  ] KFDQMTest.BasicCuMaskingEven (3100 ms)
[       OK ] KFDQMTest.QueuePriorityOnDifferentPipe (107 ms)
[       OK ] KFDQMTest.QueuePriorityOnSamePipe (209 ms)
[       OK ] KFDQMTest.EmptyDispatch (19 ms)
[       OK ] KFDQMTest.SimpleWriteDispatch (19 ms)
[       OK ] KFDQMTest.MultipleCpQueuesStressDispatch (15162 ms)
[       OK ] KFDQMTest.CpuWriteCoherence (19 ms)
[  FAILED  ] KFDQMTest.CreateAqlCpQueue (15 ms)
[       OK ] KFDQMTest.QueueLatency (25 ms)
[       OK ] KFDQMTest.CpQueueWraparound (26 ms)
[       OK ] KFDQMTest.SdmaQueueWraparound (471 ms)
[       OK ] KFDQMTest.Atomics (37 ms)

=== PATCHED ===
[       OK ] KFDQMTest.CreateDestroyCpQueue (33 ms)
[       OK ] KFDQMTest.SubmitNopCpQueue (22 ms)
[       OK ] KFDQMTest.SubmitPacketCpQueue (16 ms)
[       OK ] KFDQMTest.AllCpQueues (78 ms)
[       OK ] KFDQMTest.CreateDestroySdmaQueue (9 ms)
[       OK ] KFDQMTest.SubmitNopSdmaQueue (10 ms)
[       OK ] KFDQMTest.SubmitPacketSdmaQueue (10 ms)
[       OK ] KFDQMTest.AllSdmaQueues (35 ms)
[       OK ] KFDQMTest.AllXgmiSdmaQueues (6 ms)
[       OK ] KFDQMTest.AllQueues (127 ms)
[       OK ] KFDQMTest.SdmaConcurrentCopies (5646 ms)
[       OK ] KFDQMTest.DisableCpQueueByUpdateWithNullAddress (2021 ms)
[       OK ] KFDQMTest.DisableSdmaQueueByUpdateWithNullAddress (2014 ms)
[       OK ] KFDQMTest.DisableCpQueueByUpdateWithZeroPercentage (2026 ms)
[       OK ] KFDQMTest.CreateQueueStressSingleThreaded (15017 ms)
[       OK ] KFDQMTest.OverSubscribeCpQueues (5831 ms)
[  FAILED  ] KFDQMTest.BasicCuMaskingLinear (8405 ms)
[  FAILED  ] KFDQMTest.BasicCuMaskingEven (3197 ms)
[       OK ] KFDQMTest.QueuePriorityOnDifferentPipe (107 ms)
[       OK ] KFDQMTest.QueuePriorityOnSamePipe (213 ms)
[       OK ] KFDQMTest.EmptyDispatch (18 ms)
[       OK ] KFDQMTest.SimpleWriteDispatch (28 ms)
[       OK ] KFDQMTest.MultipleCpQueuesStressDispatch (15135 ms)
[       OK ] KFDQMTest.CpuWriteCoherence (20 ms)
[  FAILED  ] KFDQMTest.CreateAqlCpQueue (14 ms)
[       OK ] KFDQMTest.QueueLatency (23 ms)
[       OK ] KFDQMTest.CpQueueWraparound (23 ms)
[       OK ] KFDQMTest.SdmaQueueWraparound (474 ms)
[       OK ] KFDQMTest.Atomics (51 ms)

=== SUMMARY ===
Baseline  - PASSED: 26 FAILED: 3
Patched   - PASSED: 26 FAILED: 3
Regressions: NONE

Reply via email to