feat(libkernel): robust umutexes and UMTX_OP_ROBUST_LISTS in _umtx_op #19453
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19453"
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 SHOnnay on 2026-11-13T10:52:32Z.
What
Robust umutexes and
_umtx_opUMTX_OP_ROBUST_LISTS(26) no longer throw. They follow FreeBSD stable/11 at5ed7eb0d97ba:sys/kern/kern_umtx.c,sys/sys/umtx.h,sys/sys/_umtx.h,sys/kern/kern_thr.c, andlib/libthr/thread/thr_mutex.cfor the userland side. The kern_umtx.c licence notice is copied verbatim at the top ofSyncOnAddress.cpp, followed by a "Derived from" line.Values
UMUTEX_RB_OWNERDEADisUMUTEX_CONTESTED | 0x10andUMUTEX_RB_NOTRECOVisUMUTEX_CONTESTED | 0x11.EOWNERDEADis 96 andENOTRECOVERABLEis 95.m_rb_lnkis a pointer at offset 16 ofstruct umutex, static-asserted.Locking (lock and trylock, as
do_lock_normal)RB_OWNERDEADowner is taken over by a compare-and-swap toid | CONTESTED; the call returnsEOWNERDEADwith ownership.RB_NOTRECOVowner returnsENOTRECOVERABLE.MUTEX_WAITtreats both values as free, andMUTEX_WAKEhandles both asdo_wake_umutexdoes.Unlocking (as
umtx_unlock_val)RB_OWNERDEAD.UMUTEX_NONCONSISTENTleavesRB_NOTRECOV. A condition-variable wait goes through the same path.Operation 26 (as
__umtx_op_robust_lists): a size above 24 givesEINVALand a failed copy givesEFAULT. The three list heads are kept per thread.Thread exit
ThreadLifecycle::ReleaseRobustUmutexesports the robust part ofumtx_thread_cleanup(umtx_cleanup_rb_listandumtx_handle_rb).GuestCopyIn.EINVAL, as on FreeBSD.finishThreadinPthread/src/Thread.cppafter the key destructors and before joiners are released, assys_thr_exitrunsumtx_thread_exitbefore waking the thread state.finishThreadcovers both a normal return andscePthreadExit.Still throwing: robust umutexes that are also priority-inherit or priority-protect. Lists registered by the main thread or by adopted host threads are not released at exit. Both are in the narrowed debt entry.
Related: #19450 adds
MUTEX_WAKE2, which throws forUMUTEX_ROBUST. FreeBSD treats a robust mutex as a normal one there, so whichever of the two merges second should drop that throw.Tested
macOS 27 on Apple M1. libkernel does not build on macOS, so the registered
guest_umtx_optest was not run; a Linux or Windows run is needed.Harness. A temporary harness, not committed, built the unchanged
SyncOnAddress.cppandTimedWait.cppwith the extendedGuestUmtxOp.cppand minimal stand-ins. Its stand-inscePthreadCreateruns the entry on astd::threadand then callsReleaseRobustUmutexes, so the one-linefinishThreadhook itself was not exercised.asmload replaced bymemcpyin a copy)not implemented: _umtx_op operation 26, exit 134TSan reports one race, in the existing
ConditionWaitReleasesTheMutexAndWakes: a plain read ofhasWaiters.New test cases
scePthreadCreatethread registers robust lists, locks two linked robust mutexes and one held only as inactive, and exits. All three are leftRB_OWNERDEAD.EOWNERDEADwith ownership. ClearingNONCONSISTENTand unlocking frees the mutex.NONCONSISTENTset givesRB_NOTRECOV. After that, lock and trylock returnENOTRECOVERABLE, and wait and wake return 0.MUTEX_LOCKgetsEOWNERDEADwhen the owner exits.MUTEX_WAKEreleases a waiter on anRB_OWNERDEADmutex.Mutation check: 9 of 10 hand mutations failed the harness, by abort or hang:
RB_OWNERDEADtakeoverNONCONSISTENTignoredRB_NOTRECOVnot checkedThe tenth, dropping a contested-bit guard in wake, was equivalent, so I removed that guard.
Overlap. No open PR implements robust support.
UMTX_OP_MEASURED_NOOP, and the_umtx_opdebt line needs a hand merge.Not verified:
finishThreadhook pathChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code