fix(agc): refuse a host import over read-trapped pages instead of resolving the trap under its locks #26221
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26221"
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 Gonic0 on 2026-11-23T13:55:21Z.
What
On macOS, a host import opens a host write over its pages (
GuestMemory::ImportWatched,importMayWriteGuest) while it holds the host import mutex and the write tracker's lock. If a label read trap is set on those pages after the import's access check,GuestWriteWatchBeginHostWriteruns the trap's resolver on the importing thread. The driver's resolver (ResolveLabelTrap) needs both locks to store the pending image, so the thread waits for itself (#15742):GuestWriteWatchTryBeginHostWrite_nid_postfix(andGuestArenaTryBeginHostWrite_nid_no_patch,GuestArena::HostWrite(..., HostWrite::Try)) checks for traps and registers the host write under the watch's lock in one step. If a trap covers the range, or another thread is resolving one there, it opens nothing, queues the traps on the watch's resolver thread without waiting for them, and returns false.TrapReadsalready refuses pages inside an open host write, so a trap cannot be set between the check and the import.ImportWatchedopens its host write with that attempt and returns without running the import when it is refused.importRunAtreturnsnullptrfor that request without recording it infailed,failedJoinsor the failure counts, so the request falls back to copies and a later request imports the run once the resolver thread has stored the image.#20580 also targets #15742: it queues the run's traps in
importRunAtbefore the import starts and orders the resolver thread againstGpuMutex. A trap set after that check still reachesBeginHostWrite. The new test sets the trap from the unwatch hook thatImportWatchedcalls afterimportRunAt's checks. It hangs onmainand onmain+ #20580 with the same stack, and passes with this change. This pull request does not depend on #20580.Tested
Apple M5 Pro, macOS 27.3, MoltenVK (Vulkan SDK 1.4.363), x86_64 Release under Rosetta 2,
maind4cca38480. The same build directory formainand this change.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.agc_driver_import_over_read_trap: 8 of 8 runs pass with this change. Onmain, 3 of 3 runs hang until the test's 10 salarm(SIGALRM); onmainplus #20580's non-test changes, 3 of 3 hang the same way. Asampleof each hang showsImportWatched -> GuestArenaBeginHostWrite -> GuestWriteWatchBeginHostWrite -> Watch::resolve -> Resolve -> lockTracker.write_watch|host_import|import_watch|read_trap|label|guest_arena|host_write|write_track, run on each side without and then withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(Khronos validation layer 1.4.363; each side's log shows 53Insert instance layerlines, nowas not found, noVUID-): the same 6 fail onmainand with this change, with identical messages (agc_driver_label_ordered_flush,_unimported,agc_driver_unimported_label_orderand its_draw_pipelineand_plan_verifyvariants,agc_write_tracking); 11 were not built on either side. Everything else passes on both.StoreDrawnLinear. Without this change, 2 of 2 runs that got past start-up froze in the prologue, withsampleshowing the stack above (ResolveLabelTrap -> lockTracker). With it, 3 of 3 runs played through the pad script into the prologue and ran until a GPU hang that is not caused by this change.tools/check_conventions.py --base upstream/mainandtools/debt_fold.py --checkpass.Not run on Linux or Windows, where the new export only forwards to the existing host write. The test is built and registered only on macOS, the one platform where this refusal exists.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T02:54:42Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change, and the inspected implementation and regression test support merging.
What I ran
Reviewed head
812e1df8fe1f7792288dd472c4eb7f4a75e63b7a. No build or test commands were run; the description reports author-run test results separately.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppwas excluded from the prepared review bundle as too large; only its changed range and adjacentimportRunAtlogic were read through the repository reader. All other changed files listed as reviewed inmanifest.jsonwere read. Build/test results and behavior on Linux, Windows, and physical consoles were not independently verified.files.jsonwas not provided as a separate document; the bundle listing and manifest identify the excluded file.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T22:29:19Z.
Review: APPROVED
Reviewed — looks good
The change at head
9a938510af446d18bb8a6f2192796e8c7a8f3185refuses a watched host import when a read trap overlaps it, then queues trap resolution without waiting under the import locks.What I ran
No commands were run; this review used the prepared diff and pinned reader. I did not run the author-reported builds or tests.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently verify the reported macOS runs, platform behavior, or Linux and Windows builds. The full text of
GuestBufferMemory.cppwas too large for the review folder; I read the changed hunk and the relevantimportRunAtimplementation and callers through the pinned reader. The excluded debt documentdocs/dev/debt/changes/fix-agc-import-read-trap-deadlock.mdwas not reviewed.To get this to a good state
Nothing is required.