fix(agc): compare mapped guest bytes through fault-guarded reads #24031
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24031"
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 chitters2004 on 2026-11-20T01:28:32Z.
What
GuestMemory::CompareMapped(GuestMemory.cpp) asked the cached page state whether a run was readable, then compared it with a plainmemcmp. The cache is invalidated after the protection change (GuestArenaCommitandSetProtectioncallnoteAccessafter the syscall), so an arena reset on another thread between the check and the read faulted the process. #15487 closed the same race forCopyMapped. Callers includeShaderRegistry,Dispatch,CaptureValidation,DeferredLabelsandMultisampleTarget.The race is arena-only on Windows:
GuestArenaResetonly touches arena ranges andReleaseHostRegionis#ifndef _WIN32(GuestArena.cpp), so nothing outside the arena is released under a compare. AReadProcessMemorycall per chunk (General.cpp) would also cost a syscall and a copy where the old path did a page-state lookup and amemcmp. So the split is by host:GuestArenaCompareOwned, which is fault-guarded and reports a fault asUnmapped. Every other range keeps the cached-state path. A range that straddles the arena edge or a host region also keeps it and stays unguarded; a follow-up can split such a range at the boundary.GuestCopyInUnsynced_nid_no_patch, the primitiveCopyMappeduses (GuestFaultCopy,process_vm_readv,mach_vm_read_overwrite), into a thread-local buffer and compared there. A fault givesUnmappedand errno is preserved. When a chunk faults, its pages are compared one by one, so a difference before the unmapped page is still reported asDiffers, as the page-run walk did. This covers every range #25446'scompareWithoutQueryhandled (host memory outside the arena and image on kernels withoutPROCMAP_QUERY), so that function and itsAPS5_NO_COPY_COMPAREswitch are removed;CompareMappedno longer reaches the/proc/self/mapsscan on Linux.MappedCopy.cppgetscompare-reset(the compare hook resets the range between the page-state check and the read: resultUnmapped, hook runs once, errno kept),compare-differs(a last-byte difference across two committed units is found, and equal bytes compare equal) andcompare-prefix(with the second unit reset, a difference in the readable prefix givesDiffersand an equal prefix givesUnmapped). +77 lines inGuestMemory.cppand the tests.Tested
426310bb13c(Linux gate and Windows, lavapipe),agc_mapped_copy: 9/9 pass on both, nothing new failing: https://github.com/chitters2004/AnyPS5/actions/runs/44649218166agc_linked_code_dependencies(it counts compares through the compare hook): 43/43 pass on Linux and Windows: https://github.com/chitters2004/AnyPS5/actions/runs/44652426291c3a823624fwithout the fix:agc_mapped_copy_compare-resetfails on Linux and Windows, the other 7 then-existing tests pass: https://github.com/chitters2004/AnyPS5/actions/runs/44640943648draft/ci-cc714715891):agc_mapped_copy_compare-prefixfails on Linux, the other 8 pass: https://github.com/chitters2004/AnyPS5/actions/runs/44649293683splitKnownZero.Checklist
main(c3a823624f); no other open PR implements the same functions. #20084 edits thememcmpinsideCompareMappedfor known-zero pages but does not guard it; #22156 swaps thatmemcmpfor a byte-wise atomic compare in the cached-state fallback, which this PR leaves to Windows ranges the arena does not own and to unsupported hosts. Both merge cleanly with this change bygit merge-treeNotImplemented_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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:53:38Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the targeted source review found the guarded comparison paths consistent with the stated behavior.
What I ran
Reviewed head
426310bb13c1cc639da064bb100f497789d3b8af. No commands or tests were run;repo_read.pywas used to read the prepared diff and selected source ranges.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime tests and the author-reported CI results were not independently verified. Read:
description.md,commits.md,manifest.json,diff.patch,GuestMemory.cpp,MappedCopy.cpp,agc_mapped_copy_tests.cmake,General.cpp,GuestArena.cpp, andHostThreadLocal.hpp. No changed files were excluded from reading;files.jsonwas unavailable in the review bundle.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T22:24:17Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the Linux and macOS fault guarded compare path and the Windows arena owned path are supported by the code inspected.
What I ran
Reviewed head
223e1fb4297376f60245f3e7dd401adc98f02b3cusingrepo_read.pyfor the prepared review materials and targeted source ranges. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The description reports CI on head
426310bb13c, which differs from the reviewed head, so those results are not evidence of a run on this revision. Runtime behavior across supported OSes, including races outside the covered test scenarios, was not verified. Read:GuestMemory.cpp,MappedCopy.cpp,agc_mapped_copy_tests.cmake,GuestArena.cpp,General.cpp, andHostThreadLocal.hpp. Excluded: none of the changed files listed in the manifest;files.jsonwas not available as a review document.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T14:55:03Z.
Review: APPROVED
Reviewed exact head
223e1fb4297376f60245f3e7dd401adc98f02b3cafter the #25446 integration.I ran a native CPU fixture that compiles the exact Linux/macOS branch logic against an array-backed copy test double, without touching unreadable host memory. All 7 cases passed: an unaligned range larger than 256 KiB, EOF and gap ordering, a difference before a simulated unreadable page, one-shot hook invocation, and preserved
errno. A mutation that removed the page-sized retry exited 4 because it reportedUnmappedinstead of the earlierDiffers, so the fixture is sensitive to the core fix.I also checked the exact-head Hosted Windows log: the compare reset/differs/prefix tests passed 3/3 and the job reported zero failures across 5,531 registered cases. The Linux Hosted job was skipped and the Census tests were skipped on Windows, so I am not claiming an actual Linux syscall run, Linux Census result, or performance measurement for this head. No GPU path was involved.
Within that scope, I found no remaining correctness blocker. This approval is limited to the exact commit above.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T08:45:34Z.
Review: APPROVED
Reviewed — looks good
No blocking defect was found in the changed code inspected at head
0ceac5904e2e789733bfe37c13beee954d747fcb; the full CI checks described in the PR were not run here.What I ran
Read the prepared diff and all four changed files at the pinned head. No build or test command was run; author-reported CI results are not results from this review.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The PR's reported Linux and Windows test runs and negative controls were not independently verified. The full repository contents were not read; changed file contents were read for
GuestMemory.cpp,MappedCopy.cpp,agc_mapped_copy_tests.cmake, andENVIRONMENT.md.To get this to a good state
Nothing is required.