fix(libc): resolve read traps before an unmap takes them under the allocations lock #28465
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28465"
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 oneandonlydean on 2026-11-30T20:41:36Z.
What
On Windows a direct-memory release can deadlock against any driver thread that takes a guest allocations lease under the GPU mutex (#28461, two stacks at the PPSA01317 garage transition):
VulkanDevice::StoreIdleResultsand many other sites take a lease while they hold the mutex.GuestAllocationsRequireUnpinnedalready states the rule and releases the registry lock while it waits for GPU work.Mutationholds the registry lock for its whole life, and its apply step runsGuestArenaReset, whose trap fence opens a host write over the range. If a read trap is set there, the fence resolves it on the spot: the driver's resolver stores the pending image and takes the GPU mutex (StorageTexture::AccessKeptByCpu), inside the registry lock.The fix resolves the traps in the step that is allowed to drop the registry lock.
GuestAllocationsRequireUnpinned, which every unmap and protection change calls first, now opens the host write over the range (widened to its resident runs, as the fence does) before the pin scan:GuestWriteWatchBeginUntrappedAccess), and the registry lock is never released;GuestWriteWatchBeginHostWrite, so the resolver is free to take the GPU mutex, and retaken before the pin scan, which already expects other mutations to have run meanwhile.The window stays open until the mutation ends, and a read trap cannot be set over an open host write, so the fence inside the lock finds nothing left to resolve. Linux and macOS are unchanged: their reset has no fence.
Two things for the reviewer: a caller of
RequireUnpinnedcan now see the registry lock released when a trap sits on its range, where before that happened only for a pinned range; and the range is refused to new read traps for the length of the mutation.Tested
unmaplockofwindows_read_trap_tests: one thread holds the lock the read-trap resolver needs and then asks for an allocations lease, while the main thread unmaps a registered range that has a read trap on it. Windows 11, MinGW Release, real machine:d44291baeb):windows_read_trap_unmaplockfails after 10.02 s, twice, with "an unmap over a trapped range waited for the resolver's lock inside the allocations lock"; the other 12 modes pass.460292c8d1): 13 of 13 pass,unmaplockin 0.24 s, and 20 of 20 with--repeat until-fail:20.libcbuilds on the same head; the change is compiled out there, so no Linux test exercises it.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.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T20:45:15Z.
Review: APPROVED
Reviewed — looks good
The reviewed change at head
460292c8d19e36011f22a740109d36d15400ac91adds Windows trap resolution before unmap and protection changes; I found no verified blocking defect.What I ran
Reviewed the prepared diff and targeted excerpts from the included file copies. The pinned reader returned one excerpt, then failed when it attempted to write its read log in the read-only run folder. No tests or builds were run. Windows 11 / MinGW results below are reported by the author, not independently run.
Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The Windows test results and the reported title transition were not independently run. The prepared materials listed no excluded changed files. The reader could not provide further repository context after its logging failure.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T20:50:20Z.
Review: COMMENTED
Actionable comments posted: 1
Architecture findings (2)
Advisory architecture findings (2)
4f45d4d4-f991-4ab1-bbdd-e4e8e8491e0bReviewing files that changed from the base of the PR and between
76d0a4a7dcand460292c8d1.core/libs/prx/libc/src/GuestAllocations.cppcore/libs/prx/libc/tests/cmake/windows_read_trap_tests.cmakecore/libs/tests/WindowsReadTraps.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.