From 5398eff0450832aea68f91b796e3a2c873c60129 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 6 Aug 2022 15:54:57 +0530 Subject: [PATCH] Fix `KProcess::MutexUnlock` PI CAS The PI CAS in `MutexUnlock` ends up loading `basePriority` rather than `priority` which could lead to an infinite CAS loop when `basePriority` doesn't equal to `priority` and the `highestPriorityThread`'s priority is lower than `basePriority`. --- app/src/main/cpp/skyline/kernel/types/KProcess.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp index 211796db..c76569a4 100644 --- a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp @@ -177,11 +177,10 @@ namespace skyline::kernel::type { if (!waiters.empty()) { // If there are threads still waiting on us then try to inherit their priority auto highestPriorityThread{waiters.front()}; - i8 newPriority, basePriority; + i8 newPriority, currentPriority{state.thread->priority.load()}; do { - basePriority = state.thread->basePriority.load(); - newPriority = std::min(basePriority, highestPriorityThread->priority.load()); - } while (basePriority != newPriority && !state.thread->priority.compare_exchange_strong(basePriority, newPriority)); + newPriority = std::min(currentPriority, highestPriorityThread->priority.load()); + } while (currentPriority != newPriority && !state.thread->priority.compare_exchange_strong(currentPriority, newPriority)); state.scheduler->UpdatePriority(state.thread); } else { i8 priority, basePriority;