From 36029ea1a8cd55f78e9746a4e53ce080aef46f11 Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras <38722728+iassiour@users.noreply.github.com> Date: Sun, 23 Nov 2025 08:45:45 +0000 Subject: [PATCH] SWDEV-559166 - Fix race condition in getDemangledName (#1868) --- projects/clr/rocclr/device/rocm/rockernel.hpp | 14 ++++---------- projects/clr/rocclr/platform/command.cpp | 8 +++----- projects/clr/rocclr/platform/command.hpp | 4 ++-- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/projects/clr/rocclr/device/rocm/rockernel.hpp b/projects/clr/rocclr/device/rocm/rockernel.hpp index c88021d060..7f8439ec89 100644 --- a/projects/clr/rocclr/device/rocm/rockernel.hpp +++ b/projects/clr/rocclr/device/rocm/rockernel.hpp @@ -48,20 +48,14 @@ class Kernel : public device::Kernel { //! Pull demangled name, used only for logging const std::string& getDemangledName() { - if (demangled_name_.empty()) { - initDemangledName(); - } + std::call_once(demangle_once_, [this] { + amd::Os::CxaDemangle(name(), &demangled_name_); + }); return demangled_name_; } - private: - void initDemangledName() { - if (demangled_name_.empty()) { - amd::Os::CxaDemangle(name(), &demangled_name_); - } - } - std::string demangled_name_; //!< Cache demangled name + std::once_flag demangle_once_; }; } // namespace amd::roc diff --git a/projects/clr/rocclr/platform/command.cpp b/projects/clr/rocclr/platform/command.cpp index e54755504d..6a268ac77b 100644 --- a/projects/clr/rocclr/platform/command.cpp +++ b/projects/clr/rocclr/platform/command.cpp @@ -66,9 +66,8 @@ Event::~Event() { delete callback; callback = next; } - // Release the notify event - if (notify_event_ != nullptr) { - notify_event_->release(); + if (auto* notifyEvent = notify_event_.load(std::memory_order_acquire)) { + notifyEvent->release(); } // Destroy global HW event if available if ((hw_event_ != nullptr) && (device_ != nullptr)) { @@ -269,11 +268,10 @@ bool Event::notifyCmdQueue(bool cpu_wait) { // If HW event was assigned, then notification can be ignored, since a barrier was issued // @note: Force the marker always in OCL for now, since OCL events require precise // sequence of the status update - ((HwEvent() == nullptr) || !amd::IS_HIP) && !notified_.test_and_set()) { + ((HwEvent() == nullptr) || !amd::IS_HIP) && (notify_event_ == nullptr)) { // Make sure the queue is draining the enqueued commands. amd::Command* command = new amd::Marker(*queue, false, nullWaitList, this, cpu_wait); if (command == NULL) { - notified_.clear(); return false; } command->enqueue(); diff --git a/projects/clr/rocclr/platform/command.hpp b/projects/clr/rocclr/platform/command.hpp index 9969cd7153..e3575b42f7 100644 --- a/projects/clr/rocclr/platform/command.hpp +++ b/projects/clr/rocclr/platform/command.hpp @@ -90,7 +90,7 @@ class Event : public RuntimeObject { std::atomic_flag notified_; //!< Command queue was notified void* hw_event_; //!< HW event ID associated with SW event - Event* notify_event_; //!< Notify event, which should contain HW signal + std::atomic notify_event_; //!< Notify event, which should contain HW signal const Device* device_; //!< Device, this event associated with std::atomic event_entry_scope_; //!< Command entry scope @@ -219,7 +219,7 @@ class Event : public RuntimeObject { void* HwEvent() const { return hw_event_; } //! Returns notify even associated with the current command - Event* NotifyEvent() const {ScopedLock l(notify_lock_); return notify_event_; } + Event* NotifyEvent() const { return notify_event_; } //! Get entry scope of the event int32_t getCommandEntryScope() const {