fix(libkernel): keep the join reference across the cancel check #21941
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21941"
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 AasishDairelSahayaGrinspan on 2026-11-16T22:36:48Z.
What
JoinThread_nid_no_patchretained the thread, released the registry lock, dropped that reference (reference.Reset()), ranThreadCancel::Check(), then re-locked and re-acquired it. In that unlocked gap a racingscePthreadDetach— legal, because_joiningis not claimed yet — could release the last reference and delete the ended joinable object. The joiner then returnedESRCH, or with heap address reuse retained a new object and joined the wrong thread.The reference taken at admission now spans
RetainJoinedThread, matchingscePthreadCancelandscePthreadDetach, which retain past the unlock; the intermediate reset and re-retain are removed. Only that path changes.For coverage, a one-shot join-window test hook — the same pattern as the existing final-release hook — parks a joiner inside the window between the admission unlock and
RetainJoinedThread, so the test can hold a concurrent detach against the parked joiner deterministically.Tested
Linux (Omarchy 4.0.2), host build
ReleasewithBUILD_TESTING=ON:scePthreadDetachmust not drive the final release. Negative control — with the change reverted (the removed reset and re-retain re-added around the hook) the assertion fails in 3/3 runs, aborting at the invariant, so the test covers this change.taskset -c 0) at 0.08–0.12 s, under the unchanged 20 s timeout.check_conventions.py --base origin/mainpasses;pr_overlap --branchreports no overlap.Checklist
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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T22:38:21Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
607d118545:tools/check_conventions.pypassed.guest_pthread_final_release_race_testsbuilt cleanly.guest_pthread_final_release_race):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T09:41:54Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
abffc39628:tools/check_conventions.pypassed.guest_pthread_final_release_race_testsbuilt cleanly.guest_pthread_final_release_race):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T20:30:45Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional, but CI and the tests were not checked in this run, so no approval is given.
What I ran
abffc3962879f127e6054bc250be7ea424cc482b, basemain.Thread.cpp(join path andRetainJoinedThread) and ofGuestPthreadFinalReleaseRace.cpp(gate helpers and the admission test) through the reader.Results
Findings
Blocking
None.
Non-blocking
core/libs/tests/GuestPthreadFinalReleaseRace.cpp:71:WaitUntilReleasednow returns silently on timeout instead of failing. The admission test still checksresult == SCE_KERNEL_ERROR_ESRCHafterwards, so a stall no longer fails with its own message.core/libs/tests/GuestPthreadFinalReleaseRace.cpp:48:WaitForFinalReleaseno longer requires that the final-release hook was reached.RequireAdmissionRejectsFinalReleasestill calls it and continues, so that test no longer asserts its own precondition. Consider keeping aRequireon the returnedboolin the admission path.core/libs/tests/GuestPthreadFinalReleaseRace.cpp:195: eachRequireJoinDetachInterleavesrun creates 1000 guest threads with 64 KiB stacks, and the test repeats it 60 times. That is a lot of threads per run; a smaller padding count may be enough.Sources
Not verified
JoinThread_nid_no_patch.GuestThreadReferencewas not read.scePthreadCancelandscePthreadDetachretain the same way. Those functions were not read.RequireJoinDetachInterleave. Read, not traced.To get this to a good state
Nothing is required.
Optional: keep a
Requireon the final-release precondition in the admission test, and reduce the padding count if the run time allows.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T22:14:33Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
4883355afe:tools/check_conventions.pypassed.guest_pthread_final_release_race_testsbuilt cleanly.guest_pthread_final_release_race):core/libs/prx/libkernel/Pthread/src/Thread.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T00:26:18Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this review; the points below are optional.
What I ran
Reviewed head
4883355afecd7518f14e983c230d0f938baab246. I read the prepared description, commits, manifest, diff, and both included changed files throughrepo_read.py. I ran no build or tests.Results
Findings
Blocking
None.
Non-blocking
core/libs/tests/GuestPthreadFinalReleaseRace.cpp:276aborts immediately if the test hook is not entered. The preceding wait loop at lines 252–256 has a five-second deadline but does not assert that the worker finished. If that scheduling wait times out, the test can fail later at the ten-second hook wait with less useful diagnostic context. Consider requiringWorkerFinished(thread)before installing the hook.Not verified
files.jsonwas not available through the reader; the manifest identifies both changed files as included, and both were read. No other changed paths were listed in the manifest.To get this to a good state
Nothing is required. Optional: assert that the worker finished before installing the join-window hook.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T01:04:18Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
572b1b1c09:tools/check_conventions.pypassed.guest_pthread_final_release_race_testsbuilt cleanly.guest_pthread_final_release_race):core/libs/prx/libkernel/Pthread/src/Thread.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T01:08:58Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reference remains held across the cancel check and the new deterministic test exercises the detach race.
What I ran
Reviewed head
572b1b1c098de1401758d673bbd51525e41ed56c. I readdescription.md,commits.md,manifest.json,diff.patch,Thread.cpp, andGuestPthreadFinalReleaseRace.cppusingrepo_read.py. I did not run build or test commands.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build/test results and the reported negative control were not independently verified. No files were excluded from the review; both files marked reviewed in the manifest were read.
To get this to a good state
Nothing is required.