Repository navigation
fix(agc): refuse a host import over read-trapped pages instead of resolving the trap under its locks - #26221
fix(agc): refuse a host import over read-trapped pages instead of resolving the trap under its locks#26221Gonic0 wants to merge 3 commits into
Conversation
…f resolving the trap under the import locks On macOS, an import opens a host write over its pages while it holds the host import mutex and the write tracker's lock. A label read trap set on those pages after the import's access check made the host write run the trap's resolver on the importing thread, and the driver's resolver needs both locks to store the pending image, so the thread waited for itself (boykopovar#15742). The import now opens its host write with a non-resolving attempt that checks for traps and registers the write under the watch's lock in one step. If a trap covers the pages, or another thread is resolving one, the attempt opens nothing and hands the traps to the watch's resolver thread. The import is refused without being remembered as failed, so the request falls back to copies and a later one imports the run. Fixes boykopovar#15742 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Other open pull requests say they fix the same issue, so they may implement the same thing: Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
A Windows + NVIDIA check of the current head 59a57c1 for regressions, since the change touches shared System: Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 4060 (10de:2882, Ada), driver 621.01, Intel Core i5-12400F, WinLibs GCC 15.2.0 r7 (UCRT), Release, Trees: main 47e83fc, and main + 59a57c1 ( Run:
I didn't count a control for this PR: with main's AI-assisted: yes (Claude Code). It merged the PR, ran the builds and the test sets, and drafted and posted this comment. |
|
@Gonic0 I pushed 8c5e89a on top of your head: the skip line now reads "skipped, read traps exist only on macOS". The test runner's skip check only accepts a reason after "skipped," or "SKIP:", so the colon form failed every Linux batch this PR was in. One question for you: #19054 adds read traps on Linux. Once it lands, should this test run on Linux too instead of skipping under |
|
Thanks @oneandonlydean, 8c5e89a is right: On Linux: yes. Once #19054 lands, |
…-trap-deadlock # Conflicts: # core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
|
RTX 3070 run of Tested
Not tested: AMD, titles. AI-assisted (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
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
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | Core paths and test inspected |
| Build and tests | not run | Author reports results in the PR description |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp was excluded from the prepared review bundle as too large; only its changed range and adjacent importRunAt logic were read through the repository reader. All other changed files listed as reviewed in manifest.json were read. Build/test results and behavior on Linux, Windows, and physical consoles were not independently verified. files.json was 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.
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 fix(libc): order read-trap resolution against the GPU mutex #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 and the test skips. #19054 (Linux read traps) edits the
#ifdeflines around the sameImportWatchedcall; whichever lands second needs a small rebase.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