Skip to content

Commit f162895

Browse files
authored
rocr-runtime: fix segfault when queue allocation fails (#2850)
* rocm-runtime: fix crash in QueueCreate due to trying to free non allocated scratch if (scratch.main_queue_base != nullptr) before calling ReleaseQueueMainScratch because ReleaseQueueMainScratch is only valid if main_queue_base is set and the scope guard can fire for an error allocating the queue. * rocm-runtime: log for errors in QueueCreate
1 parent 8d84709 commit f162895

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,11 +1798,16 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u
17981798
scratch.main_queue_base = nullptr;
17991799
scratch.main_queue_process_offset = 0;
18001800

1801-
MAKE_NAMED_SCOPE_GUARD(scratchGuard, [&]() { ReleaseQueueMainScratch(scratch); });
1801+
MAKE_NAMED_SCOPE_GUARD(scratchGuard, [&]() {
1802+
if (scratch.main_queue_base != nullptr) ReleaseQueueMainScratch(scratch);
1803+
});
18021804

18031805
if (scratch.main_size != 0) {
18041806
AcquireQueueMainScratch(scratch);
18051807
if (scratch.main_queue_base == nullptr) {
1808+
LogPrint(HSA_AMD_LOG_FLAG_INFO,
1809+
"Failed to allocate scratch memory for queue, size=%zu, node=%u",
1810+
scratch.main_size, node_id());
18061811
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
18071812
}
18081813
}
@@ -1831,7 +1836,11 @@ hsa_status_t GpuAgent::QueueCreate(size_t size, hsa_queue_type32_t queue_type, u
18311836
node_id()));
18321837
}
18331838

1834-
if (!shared_queue) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
1839+
if (!shared_queue) {
1840+
LogPrint(HSA_AMD_LOG_FLAG_INFO,
1841+
"Failed to allocate shared queue descriptor memory, node=%u", node_id());
1842+
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
1843+
}
18351844

18361845
auto aql_queue = new AqlQueue(shared_queue, this, size, node_id(), scratch, event_callback, data,
18371846
flags);

0 commit comments

Comments
 (0)