From b995ea06e84d0d7260c40d18c803a3116f9aeca2 Mon Sep 17 00:00:00 2001 From: Joseph Greathouse Date: Fri, 19 Aug 2022 23:09:34 -0500 Subject: [PATCH] SWDEV-330307 - Avoid releasing command before last use The fix for SWDEV-329789 moved down the last use of the a command object pointer in order to prevent a race condition. However, the previous patch did not move down the release of that command. By releasing the command early, another thread could get a command with the same pointer. That second thread could later submit work to the queue using that new command. The first thread could then perform a comparison against the queue's last command using its own now-stale pointer. This could eventually allow the second thread to skip synchornizing on the queue. This would result in host synchronizations completing before their device work was actually complete. Change-Id: I292b7b369743251ceafe453a4c5cae14a6d01046 [ROCm/clr commit: 6b956f76273ebb2892d596e19dc6ca3324c862b1] --- projects/clr/rocclr/platform/commandqueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/rocclr/platform/commandqueue.cpp b/projects/clr/rocclr/platform/commandqueue.cpp index c865bccdd4..070b239cf3 100644 --- a/projects/clr/rocclr/platform/commandqueue.cpp +++ b/projects/clr/rocclr/platform/commandqueue.cpp @@ -136,7 +136,6 @@ void HostQueue::finish() { ClPrint(LOG_DEBUG, LOG_CMD, "HW Event not ready, awaiting completion instead"); command->awaitCompletion(); } - command->release(); if (IS_HIP) { ScopedLock sl(vdev()->execution()); ScopedLock l(lastCmdLock_); @@ -146,6 +145,7 @@ void HostQueue::finish() { lastEnqueueCommand_ = nullptr; } } + command->release(); ClPrint(LOG_DEBUG, LOG_CMD, "All commands finished"); }