fix(agc): reject inaccessible speculative mapped-copy sources #15487
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15487"
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 JJenkx on 2026-11-03T14:56:33Z.
What
CopyMappedtrusts cached access flags beforememcpy. Arena pages can already be reset to no-access before that cache is invalidated, so speculative draw-cache key reads can segfault instead of returning a miss.Add libc's internal
GuestCopyInUnsynced_nid_no_patch, sharing the existing checked native-copy backend but skipping host-read preparation.CopyMappeduses it and preserveserrnoon normal returns. OrdinaryGuestCopyInand path reads still run their existing read guard/GPU-flush hook. Empty/null/overflow handling remains explicit; inaccessible or short copies returnUnmapped. Other hosts retain the existing walk. The debt note distinguishes checked copying from pinning or an atomic snapshot. Linux retains the existing backend policy:EFAULT/short reads return a miss; otherprocess_vm_readverrors (such as a denied or unavailable host facility) still throw. This intentionally exposes unsupported host facilities, with no unsafememcpyfallback. That failure-policy limitation is not exercised by the title measurements below.Six host fixtures cover valid data, full/partial arena resets after access-cache priming, recommit, range boundaries, and hook behavior. The hook fixture checks both that speculative copies skip preparation and that ordinary checked copies still prepare.
Overlap: the original audit scanned 1,714 open PRs,141 shared-file candidates; all 67 failed-closed heads/sharedpatches were reviewed. No same correction was found. Keep #6188's
requireNotSpeculativeprecondition if combined; this PR does not depend on it. The new internal helper name is absent from2,945 pinned PR refs checked locally. #13664 changes errno handling in the shared libc backend; preserve that independent change when combining.Tested
Linux 7.2.11, GCC 16.2.1, Release, Ryzen 9 7950X (16 cores/32 threads).
4f41f4c375plus the original five fixtures (73cc4f7aaecd6365e46820eb15f86b90010db89e) segfaults on full/partial reset; valid/reuse/boundary cases pass. Original controls and qualification, SHA-256d97729c86e4c4dcd5ea3b59dc3ef078122da51901fadeb1a6d8e2eae9655ee33.46941c1c37aplus the exact new hook fixture fails onlyagc_mapped_copy_hooks:a speculative mapped copy ran read guards or flushed GPU writes. The other five cases pass.beed64fa73ba7446c9a00fd07059b478d8d0b068: all six host cases pass three repetitions each (18 passes, zero skips), ICD disabled. Public-header audit, conventions and whitespace checks pass.73cc4f7aaec: 7/7 each, zero skips and zero VUIDs, actual Khronos layer insertion in both verbose logs. Same RX 6650 XT / RADV NAVI23, Mesa 26.2.6, Linux 7.2.11 and requiredANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Control GuestMemory/General sources are byte-identical to main4f41f4c375; that unchanged control was reused, not rerun.1e658521a0a, after the depth/DCC/pool merges): main + common #15436 (de31b5b25c4) and the same base + this PR (91842997246) each pass the same 15/15 focused tests on RX 6650 XT / Mesa 26.2.6 / Linux 7.2.11, actual VVL, zero VUIDs/skips, unchanged source/library hashes. The revised six host-only cases also pass with ICD disabled. No source changes were needed to integrate the five PR commits. Fresh matrix, verbose logs, build/host results and provenance, SHA-2563f3bf172ce441c9c726bca26f850d394579c3bbe6bfbc2bdc5a9fa8cec506d72(GitHub digest verified). The frame-time table below remains explicitly for the earlier pinned4f41f4c375base.BUILD_TESTING; ON/OFF configuration checks are documented in the preceding CMake-only follow-up.4199ddb20550) completed one 603.3-second cold OuterWilds run with normal native/GDB exit and reviewed outdoor night/daylight captures. That is not a title result for the new unsynchronized revision.beed64fa73; the identical-fixture negative controla2b477f661fails only hooks. The worker verified the new helper is exported from libc and imported by AGC. Host-only; no Windows GPU/title claim.Latest hook negative control,18 host passes,7/7 regression logs,source hashes and revision patch — SHA-256
75f74a5c093be979d34ffcd2465e0b21e33e28d6640cb75a0d38ec2d7f0d0ea1(GitHub digest verified). No game assets, requests, shaders or saves are included.Native title cost and speculative-copy traffic
Outer Wilds PPSA08102 01.000.000, same Ryzen 9 7950X / RX 6650 XT RADV Mesa 26.2.6 / Linux 7.2.11, 3840×2160. Both arms include the same adopted-main-stack prerequisite #15436 (
4199ddb20550) over main4f41f4c375; the change adds only this PR (beed64fa73, integrationfa835ef16fe8). These are not vanilla-main results. Same fresh seed including memory saves, scripted wake at 180 s, warm separate caches with the same shader SourceVersion, same camera and 270:20 trace window, ordinary close at 440 s. Production arms contain no copy counter, draw profiler or CPU sampler.Failed attempt retained: A2 control crashed with SIGSEGV in
describePages<CopyMapped> → CopyMapped → relocatedContentKey → drawRegisterKeyat 137.6 s, before its trace. Its observer exits 86; it has no timing result. Actual order was A1, B1, B2, failed A2, separate private count diagnostic, then one bounded A3 control retry. This is not a completed original ABBA sequence. All four successful production runs and the separate diagnostic have verified normal native exit, scheduled close, no remaining native PID, unchanged SDK/generated hashes and restored kernel setting.Pooled successful production windows: control 12.757 FPS / 78.388 ms per present, change 12.042 FPS / 83.046 ms per present. The observed change is +5.94% ms/present / -5.61% FPS. These slower measurements are retained. Controls vary substantially, the sky/lighting/celestial positions animate, and GPU busy time differs; this small dataset does not isolate a causal CopyMapped cost or establish statistical significance. No zero-overhead claim.
All successful traces report no dropped events. Sampled build/profiler process lists were empty during the measurement windows; this does not exclude all desktop/background load. Direct review confirms the pre-wake prompt and same outdoor camera/trees/tower/tutorial. Primary and X11 post-trace captures are attached; flagged small differences and animated-world limitations remain in the scene reviews.
Separate count diagnostic: private
79d494c7ca98adds only a window-gated counter over the production integration; its patch and 3-copies/28-bytes CPU self-check are attached. While trace recording is active, 1,606 attempts / 321,792 requested bytes / 242 presents = 6.636 attempts and 1329.719 requested bytes per present. These are attempted requests, not successful-copy bytes. Diagnostic timing is excluded from every production comparison.Current native backend microbenchmark: exact production libc, valid 256-byte
GuestCopyInUnsynced, five × 200,000 calls with data/checksum verification: median 843.353 ns/call. This measures only the native helper, not the full CopyMapped wrapper, a main/change difference, or game frame cost.Traces, full summaries/digests, captures, success/failure receipts, count patch/self-check, SDK hashes, helper benchmark and Windows/CI references — SHA-256
cfd4860f6813ee33d25e3f48ff23ba31ce8c1290787c48af7f066da696199c2a(internal manifest verified; no game assets, binaries, shaders, requests or saves).All four production summary lines (diagnostic excluded)
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 XairRrR on 2026-11-03T15:22:45Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The checked native copy stops the
CopyMappedSIGSEGV on reset arena pages, and the negative control confirms it. But at this head, every speculativeCopyMappedread now goes through the AGC host-read hook. That hook runs a read guard that can throw and a GPU-write flush, and the old path did neither.What I ran
Head
46941c1c37a9de3d8d719b769bc8741c2de61a25,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree203ccfa893ab7dd1a4f857a179bb9f0b750b65ea(Release, GCC 14.2.0, Ninja, Debian 13 VM, lavapipe).Results
git diff --checkcheck_conventions.pymain;agc_driver_alpha_to_coverage_sample_mask_exportpassed after a rerunVUID-linesagc_mapped_copy_{valid,reset,partial,reuse,boundaries}on merged treemain'sGuestMemory.cpp/.hppresetandpartialSegFault; the other 3 passgit status --porcelainempty; 5/5 pass againNegative control output
Negative control
I restored only the production files (
Execution/src/GuestMemory.cpp,Execution/include/GuestMemory.hpp) frommainand rebuiltagc_mapped_copy_tests.resetandpartialcrash with SIGSEGV, as the description says, andvalid,reuseandboundariespass on both arms. Then I restored the merged files, rebuilt, and the tests passed again with a clean worktree.Findings
Blocking
1. Speculative
CopyMappedreads now run the host-read hook, which can throw and flushes GPU writes.core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:2988-2992callsGuestCopyIn_nid_no_patch. That leads toCopyGuestBytes(core/libs/prx/libc/src/General.cpp:86-87), then toGuestArenaPrepareHostRead_nid_no_patch, and then to the AGC hookPrepareHostRead(GuestMemory.cpp:2806-2808). The hook runs:The read guard. It is installed as
guardReads(core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp:911-912), which callsRequireNoMultisampleTarget, and that throwsstd::runtime_errorwhen the range overlaps a guarded multisampled color target or FMASK (MultisampleTarget.cpp:1676-1686). Two calls are affected:DrawRelocate.cpp:101copies 4 KiB from any user-data pair that looks like a callee pointer, to test whether it holds code.DrawRelocate.cpp:54reads relocation content for the draw key. That read runs fromdrawRegisterKey(Draw.cpp:418) before the cache lookup.Both are guesses: the old walk just read the bytes or answered
Unmapped. Now a guess that lands on a host-only multisample target aborts the draw with an exception. That is a new failure mode, a throw in place of the old SIGSEGV for this class of address. Nobody has raised this part before.FlushGpuWrites.oneandonlydeanalready raised this. I confirm it on the merged tree: the hook is installed byRecorder.cpp:1308(FlushForAccess), and it also now runs insidevalidateCaptured's masked re-read (Execution/src/Driver/Memory/CaptureValidation.cpp:85). The author agreed in the discussion that this was not intended and said a revision is coming. This head does not contain it yet.Suggested fix: as the author proposed, split the checked native copy from the host-read preparation. For example, add a libc helper that does only the
process_vm_readv/ReadProcessMemory/mach_vm_read_overwritestep, and use it fromCopyMapped. Then add a fixture that installs a throwing read guard and a counting flush hook, and checks thatCopyMappedcalls neither whileReadstill calls both.Non-blocking
2. A non-
EFAULTfailure inprocess_vm_readvnow throws from a speculative read.core/libs/prx/libc/src/General.cpp:95throws for any errno other thanEFAULT, for exampleEPERMorENOSYSunder a restrictive seccomp or ptrace policy. Before this PR,CopyMappednever made that syscall. A checked-copy helper for speculative use could map those errors toUnmapped, or the PR could state that throwing is intended.3. Cost on the draw path is unmeasured.
oneandonlydeanalready raised this. The description's own microbenchmark goes from about 11 ns to about 911 ns per 256-byte copy, andrelocatedContentKeymakes one copy per chunk of up to 64 words on every productive-relocation draw, cache hits included. No title frame-time comparison is attached. The author has said those numbers are coming. This PR claims no speedup, so it is not a perf PR, but the cost should be known before merge.Not verified
ReadProcessMemory) and macOS (mach_vm_read_overwrite): I only built and ran on Linux.To get this to a good state
CopyMappedpath skipGuestArenaPrepareHostRead(no read guard, noFlushGpuWrites), keeping the checked native copy and the reset and partial-reset fixtures.CopyMappedcalls neither the read guard nor the flush hook. Ideally, also show that a throwing guard does not escape from it.EFAULTerrors from the native copy are handled on the speculative path.main/change frame-time comparison that were requested in the discussion.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T16:29:43Z.
Review: APPROVED
Re-checked — approved
Since my last review,
a2b477f661adds a hook fixture andbeed64fa73switchesCopyMappedto a new libc helper,GuestCopyInUnsynced_nid_no_patch. The helper makes the checked native copy withoutGuestArenaPrepareHostRead, so the blocking finding is resolved.What changed since my last review
core/libs/prx/libc/src/General.cpp:86-87:CopyGuestBytesnow takes aprepareflag. The newGuestCopyInUnsynced_nid_no_patch(General.cpp:856) has the same empty, null and overflow checks asGuestCopyIn_nid_no_patchand passesprepare = false. It is declared incore/libs/prx/libc/include/General.hpp.core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:2990:CopyMappedcalls the unsynced helper instead ofGuestCopyIn_nid_no_patch.tests/MappedCopy.cpp: a newhooksmode installs counting read-guard and flush hooks. It checks thatCopyMappedcalls neither hook and thatGuestCopyIn_nid_no_patchstill calls each hook once. The CMake fragment registers this sixth mode.What I ran
Head
beed64fa73ba7446c9a00fd07059b478d8d0b068,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree4bcca7692fa617f50d931caf5ced9d00be98d1ef. Release build with GCC 14.2.0 and Ninja, on a Debian 13 VM with lavapipe.git diff --checkcheck_conventions.pymainVUID-linesagc_mapped_copy_*on the merged treemainproduction files)resetandpartialSegFault; the other 4 pass46941c1c37production files)hooksfails:a speculative mapped copy ran read guards or flushed GPU writesgit status --porcelainemptyThe script's check also reports
guest_net_ctlas an unexpected skip, butmainhas the same skip, so it is not from this PR.Negative control B output
Control A confirms that the reset fixtures still catch the original crash. Control B confirms that the new
hooksfixture catches the read preparation this revision removes. Both results match the author's description.Previous findings
CopyMappedruns the host-read hook (read guard that can throw,FlushGpuWrites). Resolved.CopyMappednow callsCopyGuestBytes(..., false), which skipsGuestArenaPrepareHostRead. Thehooksfixture shows the speculative path calls neither hook while the ordinary path still calls both, and it fails on the previous head (control B). Because the guard is never called, a throwing guard cannot escapeCopyMapped, so I don't need a separate throwing-guard fixture. The masked re-read inCaptureValidation.cppreturns tomain's behaviour: no flush.EFAULTprocess_vm_readvfailure throws from a speculative read (non-blocking). Still open.core/libs/prx/libc/src/General.cpp:95still throws for any errno other thanEFAULT, and the unsynced helper inherits that throw. Onmain,CopyMappednever made this syscall. This only matters under a seccomp or ptrace policy that denies the syscall, so I'm not blocking on it. Mapping those errors tofalsein the unsynced path, or stating that the throw is intended, would settle it.New findings
Blocking
None.
Non-blocking
None.
Not verified
ReadProcessMemory) and macOS (mach_vm_read_overwrite) behaviour of the unsynced path. I only built and ran on Linux. The author has asked for a Windows run, and no result is posted yet.