fix(libc): open the app0 archive without holding its mutex across path resolution #10100
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10100"
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 xXPBSXx on 2026-10-23T09:01:32Z.
What
Resolve
/app0before taking the archive mutex inOpened()(core/libs/prx/libc/src/AppArchive.cpp) and re-checkopenedunder it, so the archive mutex is never held while the resolver mutex is acquired. Two threads that race on the first opening both resolve the path; the second one seesopenedand returns.Fixes: #10099
Tested
-fsanitize=thread,setarch x86_64 -R), the 16 tests that reported the cycle on main21554447d0: before 16 lock-order-inversion warnings and 16 failing tests; with this change 0 lock-order-inversion warnings and 1 failing test (guest_avplayer, FFmpeg-internal data races, unrelated).-DANYPS5_ENABLE_TSAN=ON, RelWithDebInfo) at this head merged ontomainc3ee5a425: the archive-to-resolver cycle was reported in 16 tests of the non-GPU suite onmainand in 10 of 10 repeated runs ofguest_kernel_sys,guest_filesystemandguest_realpath; with this PR those three tests show 0 reports in 10 runs and nolock-order-inversionreport is left in any of the 16 tests.guest_posix_spawnstill stops on its deliberate SIGBUS, which TSan treats as fatal onmaintoo. The reviewer merged it together with #10810 and #11125 for the run.check_conventions --base upstream/mainpasses;merge-treeagainstupstream/mainand #7447 is clean.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:27:38Z.
Review: APPROVED
I reviewed exact head
88ad0a1440.Opened()now checks the initialized fast path under the archive mutex, releases it before resolving/app0, and rechecks under the mutex before publishing the archive state. That removes the archive→resolver edge without creating a double-initialization race. The cached archive state is process-lifetime, so returning its reference after releasing the lock remains consistent with the existing use pattern.The linked issue’s ThreadSanitizer report shows the inversion across 16 tests on
main; the PR reports zero inversion warnings after the change and 11/11 focused Windows tests. Exact-head conventions, diff-check and current-main merge check pass. I also compared open #8520: it changes archive enumeration code in the same source file but notOpened(), and the two heads merge cleanly. Hosted policy, relinker, ASan, register-context and write-watch checks pass; the full Linux/Windows product jobs are skipped for these paths. My local full-build configure stopped because SDL2’s submodule is uninitialized here and the SDL XRandR support is unavailable, so I did not run a local C++ test. No blocker found.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T23:47:35Z.
Review: APPROVED
Reviewed the full one-file change at
88ad0a1440fee9f6c125164f4e4a650e70ee4ff5against #10099. The initial archive-mutex check is released before/app0resolution, then the state is checked again under the mutex before initialization. This removes the archive-to-resolver lock nesting while keeping initialization serialized when multiple callers race.The applicable hosted checks pass, including conventions and the register-context and relinker matrices. The full Linux and Windows product builds are skipped by the repository's PR workflow; I relied on the Linux ThreadSanitizer and Windows guest-test results reported in the PR description for those checks. I could not run the product tests locally because SDL2 development files are unavailable in this environment.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T05:37:46Z.
Review: COMMENTED
ThreadSanitizer run of head
88ad0a144on bare-metal Linux.Setup: Ubuntu 26.04 x86-64 (i7-8700, not a VM), GCC 15.2,
-DANYPS5_ENABLE_TSAN=ON(the option from #11179), RelWithDebInfo,TSAN_OPTIONS=suppressions=tools/tsan-suppressions.txt:second_deadlock_stack=1. Base:mainc3ee5a425. This head merges onto it cleanly;AppArchive.cppauto-merges around0a64d23bd. I merged it together with #10810 and #11125 for the run. Those two touch other files and other reports.Baseline (
mainc3ee5a425):ctest -E "^agc|gpu|vulkan|video_out"): the archive→resolver cycle from #10099 is reported in 16 tests. Examples:guest_kernel_sys,guest_filesystem,guest_realpath,guest_access,guest_font,guest_dynamic_loaderandguest_posix_spawn.Opened(AppArchive.cpp:38) holds the archive mutex whileResolveDiskPathtakes theDirectories()mutex (General.cpp:803).chdir→AppArchiveRefuseOnly→Openedtakes them in the other order.guest_kernel_sys,guest_filesystemandguest_realpathreported it in 10 of 10 repeated runs (30 of 30).With this PR:
lock-order-inversionreport left in any of the 16 tests. All of them pass, exceptguest_posix_spawn, whose child raises SIGBUS on purpose, which TSan treats as fatal onmaintoo.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.