Repository navigation
fix(agc): compare mapped guest bytes through fault-guarded reads - #24031
oneandonlydean merged 3 commits into
Conversation
CompareMapped read guest bytes with a plain memcmp after the cached page state said they were readable. Invalidation of that state runs after the protection change, so an arena reset on another thread between the check and the read faulted the process. boykopovar#15487 closed the same race for CopyMapped. On Windows, ranges the arena owns go through the guarded arena compare. Only arena memory is reset under a compare there (host regions are never released on Windows), so every other range keeps the cached-state path. On Linux and macOS the bytes are copied in chunks through the fault-guarded guest copy (the same primitive CopyMapped uses) and compared there. A fault reports the range unmapped and leaves errno alone. When a chunk faults, its pages are compared one by one, so a difference before the unmapped page is still reported as a difference. Tests reset the range from the compare hook, between the page-state check and the read, check that unequal bytes across two committed units are still reported, and check that a difference or an equal prefix before a reset unit reports Differs or Unmapped.
|
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.
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.
|
|
Head No new failures and no new validation messages on either GPU.
Layer runs used AI-assisted: yes |
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full On Windows the new code path is the AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
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.py was used to read the prepared diff and selected source ranges.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | All three changed files were read |
| Automated tests | not run | CI results in the description were author-reported |
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, and HostThreadLocal.hpp. No changed files were excluded from reading; files.json was unavailable in the review bundle.
To get this to a good state
Nothing is required.
|
Merged #25446 added Tested on Windows 11 after the merge: the 56 runnable tests matching AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
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 223e1fb4297376f60245f3e7dd401adc98f02b3c using repo_read.py for the prepared review materials and targeted source ranges. No build or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Changed code and relevant helpers read |
| Build and tests | not run | No local execution |
| Author-reported CI | not run | Description reports passing CI on a different head |
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, and HostThreadLocal.hpp. Excluded: none of the changed files listed in the manifest; files.json was not available as a review document.
To get this to a good state
Nothing is required.
mihiii1337
left a comment
There was a problem hiding this comment.
Reviewed exact head 223e1fb4297376f60245f3e7dd401adc98f02b3c after 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 reported Unmapped instead of the earlier Differs, 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
MarcZX10
left a comment
There was a problem hiding this comment.
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
| Check | Result | Note |
|---|---|---|
| Changed code inspection | passed | Four changed files read |
| Build and tests | not run | CI results supplied by author |
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, and ENVIRONMENT.md.
To get this to a good state
Nothing is required.
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 perf(agc): take the /proc/self/maps fallback off the draw path on kernels without PROCMAP_QUERY #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(c3a8236); no other open PR implements the same functions. fix(agc): keep the driver's reads of known-zero guest pages out of Windows write-watch #20084 edits thememcmpinsideCompareMappedfor known-zero pages but does not guard it; fix(agc): copy guest memory shared with other threads byte-wise atomically #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