fix(libkernel): release every level of a recursive mutex during a cond wait #1480
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1480"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by awake-devel on 2026-10-08T08:54:49Z.
What
A condition wait on a recursive mutex that the waiter has locked more than once deadlocks.
waitUntilinPthread/src/Cond.cppcleared_countand_owner, but the condition variable unlocks the nativestd::recursive_timed_mutexonly once. EveryscePthreadMutexLockon a recursive mutex locks the native mutex again, so after N locks the waiter still holds N-1 levels during the wait. The thread that should take the mutex and signal blocks inscePthreadMutexLock, and the waiter never wakes (an untimed wait hangs; a timed wait times out forever).FreeBSD libthr, which the PS5 libkernel is based on, releases the mutex completely for the wait and restores the recursion count afterwards:
_mutex_cv_unlock/_mutex_cv_detachsavem_count, set it to 0 and unlock, and_mutex_cv_lock/_mutex_cv_attachput it back (thr_mutex.c, thr_cond.ccond_wait_kernel/cond_wait_user).The fix unlocks the remaining N-1 native levels before the wait and locks them again after it. This covers
scePthreadCondWait,scePthreadCondTimedwait,pthread_cond_waitandpthread_cond_timedwait, which all go throughwaitUntil. The FreeBSD behaviour is recorded in TechnicalDebt as unverified on hardware.guest_cond_recursive_mutexlocks a recursive mutex twice and waits with each of the four functions while another thread locks the mutex and signals. After the wake the waiter unlocks twice and a third unlock returnsSCE_KERNEL_ERROR_EPERM.This PR was investigated and written by Claude Code (AI), and posted by me after review.
Tested
Arch Linux, GCC, Release,
-DBUILD_TESTING=ON,APS5_WRITE_WATCH_IMPORTS=watch(Intel UHD 630 + GTX 1050 Ti).guest_cond_recursive_mutex: passes; with only theCond.cppchange reverted it fails (ctest timeout, the signalling thread never gets the mutex).ctest -j4: 424/424 passed, 0 skipped, 0 failed (mainbc1fbe81: 423/423, 0 skipped; the new test is the only difference).VK_LAYER_KHRONOS_validation: 424/424 passed, 0 skipped; 27Validation Errormessages with the same VUIDs and counts asmain(52VUID-vkDestroyDevice-device-05137, 2VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605).tools/check_conventions.py: passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01HeC9bA3n74TzJRYv9AgBE8
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:56:08Z.
Could you rebase onto current main? The full build checks out this branch with main's workflow, and it stops at
tools/check_test_registration.pynot being on the branch yet, so nothing gets compiled. After a rebase it can get a full build and go in.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:45:23Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
7406c975, merged ontomaind70b8998in one build with 38 other PRs that had no Windows run.guest_cond_recursive_mutex. None of them reported skipping a case.No title was run.
🤖 Addressed by Claude Code