fix(libSceAgcDriver): refresh heap mirrors when the range is not write-watched #6546
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6546"
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 mariuszkreft on 2026-10-15T19:46:19Z.
What
GuestMemory::CollectWritesreturns 0 when the guest arena write watch does not cover a range.GuestMemory.hppdocuments that callers must survive this by falling back to comparing bytes, andDispatchLookup.cppand the mirror creation path (GuestBufferMemory.cpp,if (generation == 0) { ++state.heapUnwatched; return nullptr; }) both do. The three heap mirror refresh paths calledRequireinstead, so on a host without write watching the first heap mirror refresh ended the process:They now count the case in the existing
heapUnwatchedcounter and continue.ChangedBlocksalready reports every block as written when the range is unwatched, so the refresh stays conservative and correct, just slower.Tested
Ubuntu 24.04.5, kernel 7.0.0-31-generic. Grand Theft Auto V (PPSA04264), NVIDIA GeForce RTX 3090, driver 580.159.03. Write watching is off on this host (
vm.unprivileged_userfaultfd = 0), which is how the crash reproduces; with this change the title gets past the shader that killed it and reaches its main menu and Story Mode, where it stops later, on an unrelated unimplemented path.agc_write_tracking,agc_write_watch_coverage,agc_buffer_pool,agc_storage_written_buffer_order,nid_buffer_validation,agc_driver_typed_heapsandagc_driver_graphicspass, and the AGC/driver/buffer/shader ctest subset (498 tests) is green.Caveat worth stating plainly: those runs used a local checkout whose base is roughly 1,500 commits behind
main, since that was the tree the change was developed and debugged in. The branch itself is based on currentmainand passes the Conventions check, but the branch was not itself built and tested here. Reviewers may want to re-run the suite against this branch.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 github-actions[bot] on 2026-10-15T20:24:15Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppL2094-2095, L2196, L2231Some 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.
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppImported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-16T05:03:10Z.
Minecraft Dungeons II (PPSA16064), Windows 11, RTX 5070 Laptop (NVIDIA 617.42), a build of
mainwith other open PRs: loading the world stopped once in 7 attempts of one job (6 gameplay rows, the aborted one was retried and loaded) withabout 51 s after the start of the row, in the loading screens. The line before the throw in the periodic report had no heap mirror yet (
0 heap,unwatched heaps 0), so the mirror was built and lost its watch within 10 s. A heap mirror is built only whileCollectWritescovers its whole range (acquireMirror), but the range can leave the write watch afterwards: an import that does not stay watched excludes its 64 KiB blocks, and a staying import whose range is already partly outside the watch drops the whole window. Each build then calledCollectWritesover the mirror's range, got 0 and threw. An earlier lab row stopped the same way.This PR makes that case survive. A test that reproduces it,
unwatchedHeapMirrorTestsintests/BdaResources.cpp: it builds a heap mirror over three 64 KiB blocks, takes the middle block out of the watch withGuestMemory::Unwatch, writes three bytes into three blocks from the CPU, builds again (which must not throw and must show all three bytes in the mirror), writes a fourth byte and builds once more.Run on Windows with Mesa 26.2.4 lavapipe (windows-latest has no Vulkan device; the lavapipe ICD is registered in the loader's registry), ctest entry
agc_driver_graphics:03c4cb5e7(the base of this PR) plus the testAGC graphics: a heap mirror's range is no longer write-watched1924189f9(this PR) plus the testGraphics validation tests passed)The test needs a Vulkan device and a write-watched guest arena, so it runs on Windows with a GPU or lavapipe; the Linux lavapipe job skips it (
guest arena unavailable or not write-watched), and a windows-latest runner has no Vulkan device. Patch on top of this PR's head:AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-16T13:55:11Z.
@mariuszkreft a note from #6646, which handles the same
Requires, in case it's useful.Both PRs keep a heap mirror whose range has left the write watch from failing the build: #6546 refreshes such a mirror in full, and #6646 does too for a refused heap (and plans the range again when the host import path can take it).
One case behaves differently on this branch: a run of adjacent heap mirrors, which
refreshHeapMirrorsandrefreshHeapRunscollect as one range, where only one heap has left the watch.collectWritesreturns 0 without walking a range the tracker doesn't fully cover (GuestMemory.cpp:1210at1924189f92), so the CPU's writes into the run's watched heaps aren't collected into their block stamps, andappendChangedBlocksthen finds their blocks unchanged.A test for it: two adjacent 2 MiB heaps registered as one run, one 64 KiB block of the first taken off the watch, a write into each heap, then the next build. On this branch's head, with only the test added, it fails on Linux and Windows, with and without the address-space cache (run):
The unwatched heap does serve its new bytes there.
#6646 handles it by collecting each mirror of such a run on its own (
appendHeapRun): the unwatched one is refreshed in full, and its watched neighbours by the blocks the CPU wrote. The test isRunHeapMirrorRunUnwatchTestsin #6646'stests/BdaResources.cpp(agc_heap_mirror_run_unwatchand_no_space_cache). Happy to share it as a patch for this branch, or to help in any other way.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T06:07:59Z.
Thanks for the fix and for tracking down the crash. Closing this one in favour of #6646, which handles the same three
Requires and one more case this branch gets wrong:GuestMemory::CollectWritesreturns 0 without walking a range the tracker doesn't fully cover.refreshHeapMirrorsandrefreshHeapRunscollect a run of adjacent heap mirrors as one range, so when only one heap has left the watch, the CPU writes into its watched neighbours are never collected andappendChangedBlocksreports their blocks unchanged. CountingheapUnwatchedand continuing hides the abort but serves stale bytes there.the watched heap beside an unwatched one missed the CPU's write(run). #6646 collects each mirror of such a run on its own (appendHeapRun) and carries that test.Both PRs edit the same lines in
GuestBufferMemory.cpp, so only one can land. Feel free to reopen if you rework it to collect per mirror and include a regression test.Pull request closed