fix(libc): order read-trap resolution against the GPU mutex #20580
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20580"
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 kali113 on 2026-11-15T10:24:08Z.
What
ImportWatchedon macOS deadlocks when a guest write-watch read trap is resolved on the importing thread (#15742). The async read-trap worker claimed a trap (registered it in_resolving) before its resolver callback acquiredGuestMemory::GpuMutex(). An importer holding that mutex then waited inwaitForResolvingfor the claimed trap, while the worker's callback blocked acquiring the same mutex — a lock-order cycle.Add a
GuestWriteWatchSetReadTrapLock_nid_postfix(acquire, release)hook (mirroringSetReadTrapBypass) and reorder the worker: wait for other resolvers, acquire the GPU mutex, claim the trap, release the mutex, run the callback, then untrap.GpuMutexnever sees a foreign claim, so it resolves the trap itself through the existing bypass; the worker later finds it gone and no-ops.GpuMutexwhile blocked on another resolver.The AGC driver wires the hook to
GpuMutexinLabelTrapsEnabled. The two-argumentGuestWriteWatchResolveReadTrapsLater_nid_postfixABI is unchanged.Fixes #15742
Tested
Apple M5 Pro, macOS 27.3, x86_64 Release under Rosetta, MoltenVK (Vulkan SDK 1.4.363.1),
VK_LAYER_KHRONOS_validationinserted,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1. This is a synthetic Vulkan component fixture, not console or title evidence.agc_driver_import_read_trap(direct),_copyand_locked_copy: 3/3 runs each passed (CTest, 100% of 3), validation layer inserted, 0 VUIDs. The locked-copy case resolves in ~0.2 s with no deadlock.waitForResolvingand the worker blocked onGpuMutex— the cycle this change removes.python tools/check_conventions.py --base origin/mainandpython tools/debt_fold.py --check: passed.git diff --check origin/main...HEAD: clean.queued_indirect_read_ordertimeout and label/pixel execution-test failures on this branch are unrelated to this change (they persist with the lock hook and the import hook removed) and are not claimed fixed. No broad-suite or console-equivalence claim is made.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-15T10:24:17Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T10:38:49Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes show no verified blocking defect, but two changed files were available only for targeted hunk review, so a formal approval is not justified.
What I ran
Reviewed the prepared diff and targeted source ranges at head
6f1729df1ae816dc6aece4ab5ba8d73dc52d8d48usingrepo_read.pytools. No test commands were run; the test results in the PR description are author-reported.Results
Negative control
Not run by this review. The PR description reports a variant without the lock hook deadlocked.
Findings
Blocking
None verified in the inspected changes.
Non-blocking
None.
Sources
Not verified
Full text was read for
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_import_read_trap_tests.cmake,core/libs/prx/libSceAgcDriver/tests/execution/ImportReadTrap.cpp,core/libs/prx/libc/include/GuestWriteWatch.hpp, andcore/libs/prx/libc/src/GuestWriteWatch.cpp. Targeted changed hunks and surrounding context were read forcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppandcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp; their full text was excluded because the files were too large. Tests were not run here. Full application build, complete CTest suite, Windows runtime, and PS5 hardware behavior were not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T22:25:25Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: ensure deferred resolution cannot lose a trap when the fixed resolver-slot pool is exhausted.
What I ran
d8b660500c78eee3611f3f39fe9a3ce2aca53db8and the prepared diff. No commands or tests were run.description.md,commits.md,manifest.json,diff.patch, and the full text ofagc_driver_import_read_trap_tests.cmake,ImportReadTrap.cpp, andGuestWriteWatch.hpp.GuestBufferMemory.cpp,Texture.cpp,GuestWriteWatch.cpp, and the AGC driverCMakeLists.txt.files.jsonwas unavailable; the manifest identifies two changed files excluded for size, and I read their changed sections through the pinned reader.Results
Negative control
Not run during this review; the description reports a regression variant that deadlocks without the lock hook.
Findings
Blocking
core/libs/prx/libc/src/GuestWriteWatch.cpp:1280, deferred resolution stops queuing pages when all 32 slots are occupied, but still returns true.importRunAtthen returnsnullptr, and no work is scheduled for the remaining trapped pages. Those pages can remainPROT_NONEindefinitely and later reads can wait for a resolver that was never queued. This can occur when an import range covers more trapped pages than available slots, or while other resolver work occupies slots. Queue all affected pages reliably (for example, wait for a free slot as the fault path does, or return failure and preserve a synchronous resolution path).Non-blocking
None.
Sources
Not verified
To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T22:30:46Z.
Review: COMMENTED
Actionable comments posted: 2
Architecture findings (2)
Advisory architecture findings (2)
57227c74-41ec-4ec8-a9c3-456e0f1aaaeaReviewing files that changed from the base of the PR and between
1a557321f3andd8b660500c.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_import_read_trap_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/ImportReadTrap.cppcore/libs/prx/libc/include/GuestWriteWatch.hppcore/libs/prx/libc/src/GuestWriteWatch.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T20:42:15Z.
Review: COMMENTED
Actionable comments
Failed.b3127288-8fff-4ab3-aee7-cf847cdb1655Reviewing files that changed from the base of the PR and between
d8b660500cand2a5a07dd6f.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libc/include/GuestWriteWatch.hppcore/libs/prx/libc/src/GuestWriteWatch.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T20:46:28Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
2a5a07dd6fb2f355729d75adbab3c217b4485e62using the pinnedrepo_read.pysource reader and the prepared review artifacts. No tests, builds, or other executable checks were run.Results
Negative control
Not run by me. The description reports that a variant without the lock hook deadlocks in the locked-copy case.
Findings
Blocking
None.
Non-blocking
None.
Sources
GpuMutex: Texture.cpp at the reviewed head.Not verified
No build, test binary, or CTest suite was run. Windows behavior, PS5 hardware behavior, and the full application build remain unverified. I reviewed all six changed paths listed in
manifest.json;files.jsonlists no excluded paths. For the two large changed source files, I read the changed hunks and relevant surrounding functions throughrepo_read.py.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T01:15:12Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The deferred scheduling method can report success after it runs out of resolver slots, leaving remaining trapped pages without queued resolution.
What I ran
Reviewed head
7c57a3c9de527b06c74a85949a585e0488ae0be3using the prepared diff and manifest, and read the changed sections and relevant callers throughrepo_read.py. No tests or builds were run.Results
Findings
Blocking
core/libs/prx/libc/src/GuestWriteWatch.cpp:1344— When there are more trapped runs to schedule than free resolver slots, the loop stops at the first unavailable slot. The method still returnstrueat line 1350, soimportRunAtreturnsnullptras though resolution were queued. The unscheduled runs remain trapped, and this call does not arrange a later retry for them. Ensure every discovered run is either queued or guaranteed to be retried before reporting success.Non-blocking
None.
Not verified
No tests or builds were run. The PR description reports macOS fixture runs, but those results were not independently verified. I read the changed sections and relevant context for all seven changed paths listed in
files.json; I did not read unrelated portions of the large source files.To get this to a good state
Ensure resolver-slot exhaustion cannot leave trapped runs without a queued or guaranteed retry, then rerun the import read-trap regression cases.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:21:31Z.
Review: COMMENTED
The trial merge onto
a1b75b0947was clean. Please reconcile the Linux title with the current platform guards.GuestWriteWatchSetReadTrapLockandGuestWriteWatchResolveReadTrapsLaterimplement their new behavior under__APPLE__, and theImportReadTrapfixture is excluded on other hosts. If this is the macOS change, please name the platform and report the native locked-copy result. If it is meant to fix Linux, the Linux resolver path needs corresponding coverage. I reviewed the source on Linux and have no macOS result.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.