fix(agc): run the unwatch hook before an import whose range leaves the write watch whatever the import does #7505
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7505"
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 AlxcBTW on 2026-10-18T09:59:25Z.
What
ImportWatched(GuestMemory.cpp) runs the unwatch hook for the spans of a stays-watched import that leave the write watch, before the import when the page walk before it already fails and after it when only the walk after it fails, so pending storage-image results over those spans keep saved guest bytes. The branch also tests every exit ofGuestMemorythat has a hook.#6308 (
93df5c42a, LeandroLP23, the hook after the import) was closed unmerged as superseded by #8172, and the branch still carries its commit and its merge commit (48a1d3453, Dean Galvin). It no longer depends on #6308. Against currentmain(a6dcea927;git merge-treeis clean) the net change is 3 files, +92 -3:core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp: inImportWatched, for an import that stays watched, a span whose page walk fails before the import is taken out of the span list and given to the unwatch hook before the import runs; a span whose walk with the import window fails after the import is given to the hook there.mainruns the hook in neither place: both spans leave the watch without it.core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp:CheckUnwatchHooksinagc_write_tracking, forUnwatch(hook once, over the range, while it is watched), an import that does not stay watched (hook before the import), an import whose walk vouches for its pages (no hook, range stays watched) and, on Linux, an import whose range loses a block during the import (hook after it).docs/dev/debt/libSceAgcDriver.md: the pending-results entry names a page walk that fails as an exit that runs the hook, and drops the sentence about an import fallback that unwatched without saving.What
mainalready covers, not repeated here:fix(agc): keep resident DCC targets watched under aligned block imports, merged 2026-10-20) keeps the spans that were watched before a stays-watched import watched through it. That is the case of an import over a partly unwatched range that this PR first wrote a test for (agc_storage_unwalked_import); with #8172 that range stays watched, so the test was dropped from the branch (bae91578f) and the branch no longer asserts that flow.fix(agc): save pending results when a fresh write collect fails, merged) runs the hook when a failed fresh collect takes a range out of the watch (MarkWritten). Nothing in this PR touches it.What the branch still addresses: a span of a stays-watched import that is covered by the watch but whose page walk fails, before the import (the walk's
walkWritesreturns false) or after it (the walk with the import window returns false). Both paths drop the span from the watch onmainwithout the hook, so pending storage-image results over it have no saved guest bytes and storing them throws. This is read from the code; no title run shows it on currentmain. The ProsperoPuzzles data in #6301 shows that, on currentmain, the refusal this chain used to cause no longer appears for that title.Exits that still drop a range without the hook, not changed here:
WatchMapping(DirectMemory.cpp): a second mapping of the same direct memory unregisters both aliases. The hook takesPending().mutexand the GPU mutex, and the driver callsSharedBacking(takesg_directLock) from code that can hold the GPU mutex, so calling the hook from libkernel's map path could invert that lock order. Not shown to deadlock; not touched.Tested
a91b68d56(the PR headbae91578fplus the CI scaffolding commit), ctest regexagc_write_tracking|agc_storage|agc_import|agc_host_import|agc_pending|agc_recorder|agc_driver_host_import|agc_unchanged|agc_collect|agc_partial|agc_resident: 34 of 34 passed, 2 of them skipped (agc_storage_clear_hand_over,agc_host_import_sparse), among themagc_write_trackingandagc_import_watch.agc_write_watch_coverageandagc_write_trackingpass,agc_import_watchis skipped (no Vulkan device).CheckUnwatchHooksfails onmainwithout theGuestMemory.cppchange. By reading, its last section (Linux, a block lost during the import) is the partmaindoes not satisfy; no CI run of the test againstmainwas made.python3 tools/check_conventions.py --base origin/mainon the branch: 0 errors; one warning (debt-length, the pending-results entry indocs/dev/debt/libSceAgcDriver.md, which was already over 1000 characters onmain).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)Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T11:28:14Z.
Verified at head
aaf19708f:agc_write_trackingplus the recorder import/storage sweep (agc_import_watch,agc_import_watch_other_family,agc_storage_*,agc_host_import_unmap,agc_host_import_retirement,agc_host_import_second_mapping) - 15/15 pass on NVIDIA RTX 3070 (driver 617.42) and Intel UHD 630 (ANYPS5_GPU=UHD, igvk64). Windows 11, MinGW (WinLibs GCC 15.2.0), Release.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-18T16:29:58Z.
Rebase handoff — rebased onto current
main(all four commits, authorship unchanged). Test-call and docs-debt conflicts unioned withmain's newer coverage.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the two knownmainregressions (agc_driver_tessellation— Mesa, #5444;agc_driver_bda_device— #7584), neither from this PR.To pick it up:
Head is
9f770c6a5.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-18T18:13:44Z.
@blawesom thanks for the rebase handoff. I updated the branch with a merge of
maininstead of a rebase, so the history stays fast-forward (head0b8940ec0). Your tree was my reference for the conflicts. It differed from mine in three places, in case they matter for other handoffs:docs/dev/debt/libSceAgcDriver.md: the "Pages under an import window" paragraph is missing and the older Windows paragraph appears twice. The merge keeps main's newer paragraph plus "Pages under an import window".CMakeLists.txt: main's srgb test registration, which landed after your rebase.tests/WriteTracking.cpp: the call order is moved. I kept main's order.Fork CI: Linux 717/717 (run 39146868385), Windows lab tests green (run 39146868399).
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T00:13:20Z.
Tested at
0b8940ec0on Windows 11 (GCC 15.2.0, Release), merged ontomain9f25d0bf5, on an RTX 5070 Ti (617.42) and an AMD Radeon iGPU, RDNA2 (1002:13c0, 32.0.21042.62,ANYPS5_GPU=AMD).agc_write_tracking,agc_import_watchandagc_import_watch_other_familypass on both.c20686e11'sGuestMemory.cpphunk reversed,agc_write_trackingfails on both GPUs:an import over a partly unwatched range ran the unwatch hook after the import.agc_|shader|recompilerset, the only new failure was a 30 s timeout ofagc_driver_guest_memory_lifetime_heapon NVIDIA, which passes when rerun alone.agc_storage_unwalked_importis registered for Linux only and wasn't run here.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T14:25:10Z.
@AlxcBTW thanks for this. #8172 has merged and #6308 is closed as superseded, so this branch no longer fits main. Main's
ImportWatchednow splits a partly watchedstaysWatchedimport into spans of covered 64 KiB blocks, keeps those spans watched, and unwatches only the gaps and any span whose walk fails. The single-range fallback that #6308 andc20686e11edit is gone. Your two commits are written on top of #6308's lines, so dropping #6308's commit won't leave a working change.The gap you closed is still on main, though. The
staysWatchedpath never callsbeforeUnwatch, and two of its exits take watched blocks out of the watch:erase_ifjust ahead ofrunImport(). It then falls inside theunwatchLockedgap ranges after the import. This is your save-early case: the span will leave the watch whatever the import does, so the hook can run before the import, and the import's own page marks aren't collected as CPU writes.continuein the span loop) is unwatched by the nextunwatchLockedwith no hook. @LeandroLP23 offered to cover this path in #6308's closing comment.Could you rework this PR onto current main as the single fix for both? (Please agree with @LeandroLP23 so only one PR carries it.)
runImport(), collect the spans theerase_ifdrops, release the tracker lock, runbeforeUnwatchover them, and relock. Those spans are unwatched in any case, and the surviving spans are walked again against the window after the import, so a tracker change while the lock is released is harmless.beforeUnwatchover them, again with the lock released, before they're unwatched. LikeMarkWritten: collect, hook outside the lock, then unwatch.As far as we know, no current title reaches these two exits: the reports in #6301 run on main with #8172. So this is a correctness fix for a rare path. If it's reached today, the result is the explicit "results pending ... without the guest bytes saved" refusal, not wrong output.