perf(agc): answer small guest read checks without /proc/self/maps #6179
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6179"
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 milescoviello on 2026-10-15T00:41:15Z.
What
On Linux kernels without
PROCMAP_QUERY(before 6.11, including the stock Ubuntu 24.04 kernel),GuestMemory'sverify()reads and parses/proc/self/mapsup to the covering mapping for every range check that misses its page cache. That cache only covers the guest arena and the image, so a range anywhere else misses every time. ASTRO BOT (PPSA21564) checks the 96-byteShaderheaders it passes, which live in the host heap, fromRegisteredHeader(throughSameHeader). It does this on everysceAgcCreatePrimState,ResolveGraphicsAbiand interpolant mapping while it loads.Measured with a temporary counter around the
/proc/self/mapsfallback (the process has about 3,600 mappings at that stage):mainab9a47684/proc/self/mapsreads inverify()process_vm_readvThe loader's checks run on its own thread, so the slow path throttled loading. With the fast path the title does about 40 times as many checks in the same time and gets further. The 110,000 remaining reads are write checks and ranges over 4 KiB.
Now, on such a kernel, a read-only check of at most 4 KiB first reads the range into a thread-local scratch buffer with
process_vm_readvon its own process. If every byte comes back, the range is readable, which is all a read-only check asks. Anything else takes the existing path, which also builds the failure message:EPERM(for example under a seccomp profile that blocks the call);PROCMAP_QUERY.agc_driver_graphicsis registered a second time on Linux withAPS5_NO_PROCMAP_QUERY=1, so the fallback is also exercised on kernels that havePROCMAP_QUERY.LiveStackgains read-only checks for a readable range and for two ranges that end in a guard page.Tested
Ubuntu 24.04, kernel 6.8.0 (no
PROCMAP_QUERY), GCC 13.3, Release with CI's configure flags, onmainab9a47684:agc_driver_graphicsandagc_driver_graphics_maps_fallbackpass.ctestsuite passes (1,225 tests).agc_driver_graphics_maps_fallback2 of 2; this head passes it andagc_driver_graphics3 of 3, and all 663^agc_tests pass alone.tools/check_conventions.py --base upstream/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:16:10Z.
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.
core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppImported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-18T00:09:50Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainate3838332ee31af787ad311b7eadbe53d8d012e95. GPU tests ran on lavapipe (llvmpipe, LLVM 22.1.8).#6179 and #6184 together fail #6179's new test
agc_driver_graphics_maps_fallback. Each PR alone passes it (mainhas no such test). With both merged it fails (2 of 2):The message is the check at
GuestAllocations.cpp:259that #6184 adds. #6179 registers the test withAPS5_NO_PROCMAP_QUERY=1(CMakeLists.txt:1641on its head), so it runsagc_driver_graphics_testswithoutPROCMAP_QUERY. In that case #6179'sverify()(GuestMemory.cpp:680on its head; the call is at:684) answers a read check of up to 4096 bytes withprocess_vm_readvbefore it looks at the page table (readableWithoutQuery,:667). The page in that check is readable behind the registry, so the direct read succeeds andAccessiblereturns true. #6184's cache for inaccessible pages is never consulted, and the check expects false.With the
readableWithoutQuerycall at:684removed from the merge,agc_driver_graphics_maps_fallbackpasses (2 of 2). So whichever of the two lands second has to look at the cache before the direct read, or the fast path must not answer for a page the cache already holds as inaccessible.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T00:19:39Z.
Thanks @nicolasfalesy, that's the bug. The probe answered before the page table was consulted, so a page #6184 holds as inaccessible read as accessible whenever the host page was readable.
2108971566 makes the probe step aside for any range with a recorded page state.
readableWithoutQuerynow returns false when any page of the range has a non-zero entry in the arena or image page table. That coversmain's readable entries and #6184'sPageInaccessible, so the check goes throughdescribePagesand the table answers it, as before this PR. Ranges with no recorded state, such as theShaderheaders on the host heap that this PR is for, still take the probe.Checked on Ubuntu 24.04 (kernel 6.8, no
PROCMAP_QUERY), GCC 13.3, Release, RTX 4070 Ti:4a96406):agc_driver_graphics_maps_fallbackfails 2 of 2 with your line,a checked inaccessible arena page was queried again instead of read from the page table.agc_driver_graphics_maps_fallbackandagc_driver_graphicspass 3 of 3.^agc_tests pass.So the two should now land in either order.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T16:48:33Z.
Rebased onto
main889cee5f9f(4c50918d91). The only conflict was inlibSceAgcDriver/CMakeLists.txt, where #6054 addedagc_driver_image_srgb_sample_copy_forcedbeside this branch'sagc_driver_graphics_maps_fallback; both are kept. On the rebased head the 441 tests matching^agc_driver_graphics|guest|stack|procmap|mapspass,agc_driver_graphics_maps_fallbackamong them (RTX 4070 Ti, 595.99.02, Ubuntu 24.04).AI-assisted: yes (Claude Code)