fix(libkernel): let exception delivery interrupt mutex and rwlock waits #2051
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2051"
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 esatturan on 2026-10-09T05:59:49Z.
What
scePthreadMutexLock,scePthreadMutexTimedlockand the rwlock read and write locks, plain and timed, wait in 1 ms slices inside aTimedWait::InterruptibleScope.sceKernelRaiseExceptionnow reaches a thread blocked on a guest mutex or rwlock: the handler runs during the wait, and the wait goes on afterwards, as a FreeBSD thread blocked inpthread_mutex_lockruns a signal handler and keeps waiting.Unity's GC in PPSA29141 stops the world by raising an exception on every thread. A thread blocked on a mutex never ran the handler, and the title deadlocked during level loads.
_umtx_opwas split out in review: #1482 implements it.Tested
Windows 11, i7-13650HX, RTX 4070 Laptop, MinGW-w64 GCC 15.2.
guest_raise_exception: new rounds deliver an exception to a thread blocked in a mutex lock, a timed mutex lock and an rwlock write lock. Onmainthe test blocks at the first round and times out; here it passes.cteston currentmain(c6e3aa76) merged with this branch, the other LEGO Party! PRs and #1482: 547/547 pass. On Windows,main'slibsstep currently fails withduplicate patched export name: LibwuIonIBw: #1714 addedAPS5_EXPORTs forsceVideoOutAddVrrActiveStatusEventandsceVideoOutAddVrrStatusFlagsPrivilege, whose names the NID table already maps. Those two lines were removed locally for the run.--module-dirfor its plugins, and #846 no longer merges with today'smain, so the title was not converted and run again on it.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)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:57Z.
Please split this in two: the interruptible mutex/rwlock waits (the PPSA29141 GC deadlock) in one PR,
_umtx_opin another. #1482 already implements_umtx_op; if PPSA29141 stops at it on main, please give the log line.Imported from boykopovar/AnyPS5. Originally posted by esatturan on 2026-10-09T23:34:51Z.
Split as asked. This PR now holds only the interruptible mutex and rwlock waits, rebased on current
main. The newguest_raise_exceptionrounds block at the first round onmainand time out after 30 s; they pass here._umtx_op: on currentmain, PPSA29141 stops at load withThat is its only unresolved import. With #1482 merged into
mainlocally, it loads, boots Unity and runs on to the stencil clear that #2504 handles. So #1482 covers what PPSA29141 needs, and I dropped my_umtx_opand its test. That also removes the__error_nid_postfixoverlap with #2123.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:17:37Z.
Conflicts with main in
Mutex.cppandRwlock.cpp(from #1562); please rebase.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:49:18Z.
Review: CHANGES_REQUESTED
Thanks for the split. #1562 is merged and already covers part of this, so the PR now conflicts in
Mutex.cppandRwlock.cpp. Please rebase and keep only what main still lacks:Mutex.cpp/Rwlock.cpp: main now polls withTimedWait::SleepNanos(1000000)under#ifdef _WIN32inscePthreadMutexLock,scePthreadRwlockRdlockandscePthreadRwlockWrlock. Drop the duplicate; keep the polling Windows-only, since on LinuxInterruptibleScopeis a no-op and 1 ms polling instead of a blockinglock()only adds latency and CPU.scePthreadMutexTimedlock,scePthreadRwlockTimedrdlock/Timedwrlock) still can't be interrupted on main, make that the PR's only change and say so in the description.guest_raise_exceptionrounds (mutex, timed mutex, rwlock write lock). Please confirm they still block on currentmainand pass with the rebased change.### Testedto say whether the deadlock still reproduces on currentmainwith #1562.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T10:09:40Z.
Additional platform validation on standalone PR head
e86107d3bb0637f93337035c7a699ffc68e4955a:Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja.
Release /
BUILD_TESTING=ON: built the selected test targets; 4 CTest cases, 0 failures, 0 CTest skips.Tests:
guest_kernel_sync,guest_cond_timedwait,guest_cond_recursive_mutex,guest_pthread_rwlock.Reproduce after building the test targets:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_(raise_exception|pthread_rwlock|cond_timedwait|cond_recursive_mutex|kernel_sync|pthread_mutex)$".guest_raise_exception is registered only on Windows at this head; Linux checks cover the portable mutex/rwlock/condition wait behavior, not the Windows exception-delivery rounds
Integration limitation: a local merge against main
948a526c2has source conflicts; these results validate the standalone PR head, not a resolved merge.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:28:28Z.
Review: APPROVED
Rebased onto main and reduced to what #1562 does not cover, since the PR was conflicting and had no push after the review:
InterruptibleScope, the lock/rwlock polling helpers and the 1 ms polling inscePthreadMutexLock/Rdlock/Wrlock(already on main,_WIN32only).TimedWait::AcquireUntil(timed mutex, rwlock rdlock/wrlock): on Windows it now polls in 0.5 ms slices instead of one long blockingtry_lock_for, so a pending exception is delivered during the wait. Linux is unchanged.MutexOperations::Timedlock: Windows-only try_lock +SleepNanosloop up to the deadline.guest_raise_exceptionrounds (mutex, timed mutex, rwlock write lock).Checked: libkernel build and scoped ctest on Linux (
guest_kernel_sync,guest_pthread_rwlock,guest_cond_*pass).guest_raise_exceptionis Windows-only, so it was not run here; @esatturan, if you can run it on Windows with this head it would confirm the rounds still block on main and pass now.