From b4029887b45ef390430610ae93578fa46ab8a393 Mon Sep 17 00:00:00 2001 From: Dean Galvin Date: Thu, 8 Oct 2026 17:44:31 +1300 Subject: [PATCH] fix(agc): guard the reported wait-timeout set against concurrent queues waitMemory's timeout report keeps a function-local static std::set of the addresses already reported and a static counter. Two queue workers whose waits time out at the same time insert into the set concurrently, which is a data race on a std::set and can corrupt the tree. The set and the counter are now updated under a mutex. --- .../src/Driver/Synchronization/WaitMemory.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp index 72a41535e..9a6ee823d 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp @@ -5,6 +5,8 @@ #include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp" #include "prx/libSceAgcDriver/Execution/include/Pm4.hpp" #include +#include +#include #ifdef _WIN32 #include #endif @@ -287,10 +289,14 @@ void Driver::waitMemory(std::span packet, std::uint32_t que if (!warned && std::chrono::steady_clock::now() - start > std::chrono::milliseconds(waitTimeoutMs())) { warned = true; ++outcomes.timedOut; - static std::set reported; - static std::uint64_t timeouts = 0; - if (++timeouts % 20 == 0) std::fprintf(stderr, "[gpu] %llu GPU waits have timed out\n", static_cast(timeouts)); - if (!reported.insert(packet[2] | (static_cast(packet[3]) << 32u)).second) return; + { + static std::mutex reportedMutex; + static std::set reported; + static std::uint64_t timeouts = 0; + const std::lock_guard lock(reportedMutex); + if (++timeouts % 20 == 0) std::fprintf(stderr, "[gpu] %llu GPU waits have timed out\n", static_cast(timeouts)); + if (!reported.insert(packet[2] | (static_cast(packet[3]) << 32u)).second) return; + } const bool wide = ((packet[0] >> 8u) & 0xffu) == 0x93u; const std::uint64_t reference = wide ? packet[4] | (static_cast(packet[5]) << 32u) : packet[4]; const std::uint64_t mask = wide ? packet[6] | (static_cast(packet[7]) << 32u) : packet[5];