macOS: agc_write_tracking fails, ImportWatched marks the whole import window as CPU-written #10344
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 krishalivaibhav on 2026-10-23T18:27:11Z.
Environment: MacBook Air M2, macOS (Darwin 27.2), AppleClang, Rosetta 2,
maind6e7ab42dplus #8658 (needed for a macOS build), Release (also reproduced in RelWithDebInfo),BUILD_TESTING=ON.Reproduction
From
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp:1151(CheckImportWindow).Findings. With a debug print before the check:
changed = {0, 1, 0}(correct, from the page-hash window) butcpu = {1, 1, 1}; the test requirescpu[2] == 0.ImportWatched(GuestMemory.cpp) opens aGuestArena::HostWriteover the whole[first, stop)window on macOS;Watch::BeginHostWrite(libc/src/GuestWriteWatch.cpp) unprotects every page in it and setsWrittenon each, because the host cannot see which pages the import will store to. Every block of the window then reports a CPU store, including blocks the import left untouched.Impact. Over-reporting only (conservative): the byte-change result is right, but CPU-written blocks inside an import window always look dirty on macOS, so cached GPU data for them is invalidated more often than on Linux.
Possible direction. See the fix attempt below: a hash-based clear is not enough, because the test needs written-but-unchanged pages to stay CPU-touched. A real fix needs per-page write detection during the import.
Not proven: whether
mainalone shows the same (it does not build on macOS without #8658; #8658 does not changeImportWatchedorGuestWriteWatch.cpp).Fix attempt (not viable as a small patch)
Tried: in
stampWrittenRun(GuestMemory.cpp), on macOS skip stamping pages whose post-import hash equals the pre-import hash (8 lines, saved as macos-import-window-attempt.diff). Result on M2, full ctest: agc_write_tracking still fails, now on the opposite assertion "a page an import window resolved no longer counts as possibly touched by the CPU" (cpu[0] must stay 1 for a page the import wrote without changing bytes). The test needs both: cpu=1 for a written-but-unchanged page and cpu=0 for an untouched page. On macOSBeginHostWriteunprotects and marks the whole windowWrittenup front, so written-unchanged and untouched pages are indistinguishable; only precise per-page write detection during the import can satisfy both.Design for a real fix (larger, not done): keep the import window write-protected and let the fault handler's
record()mark only the pages actually stored to; use the blanketBeginHostWriteunprotect only for imports that call into the kernel with the guest buffer (read()/recv into guest memory fault with EFAULT instead of SIGSEGV). That means an opt-in per call site: ImportWatched would take a flag, and the GuestBufferMemory callers (GuestBufferMemory.cpp:1774, 1787) would decide whether their import lambda is in-process. Estimated 60-120 lines plus a test; needs maintainers' view on the API.Separate observation: with RelWithDebInfo (-O2 -g) guest_user_context aborts deterministically on this M2 (passed in the Release build), so the macOS test results depend on the build type.
AI-assisted: yes (Claude).