Windows: agc_write_tracking fails since #3594, StoredOver still trusts block stamps for arena host holes #4087

Closed
opened 2026-10-11 22:59:09 +00:00 by screamm · 4 comments
screamm commented 2026-10-11 22:59:09 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T22:59:09Z.


Environment: Windows 11 Pro 10.0.26220, WinLibs GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON; main 1a7b96b5b plus #4021 (needed for libkernel to compile).

Reproduction

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=C:/winlibs/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/winlibs/mingw64/bin/g++.exe
cmake --build build --parallel
ctest --test-dir build -R '^agc_write_tracking$' --output-on-failure

First bad merge: 8a13a1b8e, #3594 "fix(agc): exclude host arena holes from write-watch proofs" by @Scramblrrrr. Its parent 07eacac68 passes; the merge fails.

Failure

write tracking test failed: an unwatched range reads as not stored over

This comes from core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp:95 (in CheckSharedBlock):

std::array<std::uint8_t, 64> unwatched{};
const auto outside = reinterpret_cast<std::uint64_t>(unwatched.data());
if (!Watched(outside, unwatched.size())) Require(StoredOver(outside, unwatched.size(), TrackerGeneration()), "an unwatched range reads as not stored over");

Analysis

unwatched sits on the main thread's host stack. On Windows that address lies inside the guest arena's address interval but in a host hole the arena was reserved around, so WriteTracker::covers() (coverage.Covers) returns true for it.

  • Before #3594, Watched() returned true for the host hole, so the test skipped the StoredOver check.
  • #3594 made Watched, collectWrites, UnchangedSince and UnchangedSinceAll return "not watched" when GuestArenaHostRegionOverlaps_nid_postfix is true. It did not change StoredOver (core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:1305). StoredOver still passes its covers() check, finds no newer stamps on the block, and returns false ("not stored over").
  • The tracker now contradicts itself: the range is reported as unwatched but also as proven not stored over. The test exists to catch exactly that.

This only affects Windows. The host-hole exclusion is #ifdef _WIN32. On other platforms covers() goes through GuestWriteWatchCovers_nid_postfix, which does not cover an unregistered stack, so StoredOver returns true early.

The test is not the only thing affected. StoredOver is used as a proof by Graphics/src/Draw.cpp:210 (CMASK proofs) and Graphics/src/Texture.cpp:1725 and :4023, so a host-hole range can still be treated as not stored over in production. The other stamp readers that #3594 left without the exclusion are UnchangedSinceCollected, WrittenSince, ChangedBlocks, MarkWritten and ImportWatched. Each should be checked for the same inconsistency.

Minimal fix (verified locally, not committed)

In StoredOver, treat host holes as unwatched, the same way #3594 does in Watched:

    if (!tracker.watched || generation == 0 || bytes == 0 || !tracker.covers(address, bytes)) return true;
#ifdef _WIN32
    if (GuestArena::GuestArenaHostRegionOverlaps_nid_postfix(address, bytes)) return true;
#endif

I rebuilt agc_write_tracking_tests with only this change against the 1a7b96b5b build. It printed write tracking tests passed 3/3; the unmodified exe fails.

A broader option is to do the host-region exclusion once inside WriteTracker::covers() on Windows. Then every caller gives the same answer, including the five functions listed above.


Found and bisected with Claude Code assistance (five full Windows builds, each with #4021 applied to make libkernel compile); reviewed before posting.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5806040228 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4087). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T22:59:09Z. --- **Environment:** Windows 11 Pro 10.0.26220, WinLibs GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`; `main` `1a7b96b5b` plus #4021 (needed for `libkernel` to compile). **Reproduction** ``` cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_C_COMPILER=C:/winlibs/mingw64/bin/gcc.exe -DCMAKE_CXX_COMPILER=C:/winlibs/mingw64/bin/g++.exe cmake --build build --parallel ctest --test-dir build -R '^agc_write_tracking$' --output-on-failure ``` **First bad merge:** `8a13a1b8e`, #3594 "fix(agc): exclude host arena holes from write-watch proofs" by @Scramblrrrr. Its parent `07eacac68` passes; the merge fails. **Failure** ``` write tracking test failed: an unwatched range reads as not stored over ``` This comes from `core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp:95` (in `CheckSharedBlock`): ```cpp std::array<std::uint8_t, 64> unwatched{}; const auto outside = reinterpret_cast<std::uint64_t>(unwatched.data()); if (!Watched(outside, unwatched.size())) Require(StoredOver(outside, unwatched.size(), TrackerGeneration()), "an unwatched range reads as not stored over"); ``` **Analysis** `unwatched` sits on the main thread's host stack. On Windows that address lies inside the guest arena's address interval but in a host hole the arena was reserved around, so `WriteTracker::covers()` (`coverage.Covers`) returns true for it. - Before #3594, `Watched()` returned true for the host hole, so the test skipped the `StoredOver` check. - #3594 made `Watched`, `collectWrites`, `UnchangedSince` and `UnchangedSinceAll` return "not watched" when `GuestArenaHostRegionOverlaps_nid_postfix` is true. It did not change `StoredOver` (`core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:1305`). `StoredOver` still passes its `covers()` check, finds no newer stamps on the block, and returns `false` ("not stored over"). - The tracker now contradicts itself: the range is reported as unwatched but also as proven not stored over. The test exists to catch exactly that. This only affects Windows. The host-hole exclusion is `#ifdef _WIN32`. On other platforms `covers()` goes through `GuestWriteWatchCovers_nid_postfix`, which does not cover an unregistered stack, so `StoredOver` returns true early. The test is not the only thing affected. `StoredOver` is used as a proof by `Graphics/src/Draw.cpp:210` (CMASK proofs) and `Graphics/src/Texture.cpp:1725` and `:4023`, so a host-hole range can still be treated as not stored over in production. The other stamp readers that #3594 left without the exclusion are `UnchangedSinceCollected`, `WrittenSince`, `ChangedBlocks`, `MarkWritten` and `ImportWatched`. Each should be checked for the same inconsistency. **Minimal fix (verified locally, not committed)** In `StoredOver`, treat host holes as unwatched, the same way #3594 does in `Watched`: ```cpp if (!tracker.watched || generation == 0 || bytes == 0 || !tracker.covers(address, bytes)) return true; #ifdef _WIN32 if (GuestArena::GuestArenaHostRegionOverlaps_nid_postfix(address, bytes)) return true; #endif ``` I rebuilt `agc_write_tracking_tests` with only this change against the `1a7b96b5b` build. It printed `write tracking tests passed` 3/3; the unmodified exe fails. A broader option is to do the host-region exclusion once inside `WriteTracker::covers()` on Windows. Then every caller gives the same answer, including the five functions listed above. --- Found and bisected with Claude Code assistance (five full Windows builds, each with #4021 applied to make `libkernel` compile); reviewed before posting.
screamm commented 2026-10-12 00:21:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-12T00:21:34Z.


Fix branch ready: screamm:fix/write-tracking-host-holes (03860b02, one commit on main bab7b328). I cannot open it as a PR under the intake rule while #4081 is open; anyone eligible is welcome to carry it, keeping the commit as is.

  • One place instead of five: on Windows WriteTracker::covers() now returns false for any range overlapping an arena host hole, so every query (Watched, StoredOver, UnchangedSince*, WrittenSince, ChangedBlocks, MarkWritten, StoreOwnBytes, ImportWatched, collectWrites) gives a hole the answer an unwatched range always got; the five separate #ifdef _WIN32 checks from #3594 are removed, their range-overflow early returns stay. Each query's "not covered" answer is already the safe one for its callers (Draw.cpp CMASK proofs, Texture.cpp keep checks, VulkanDevice.cpp). Ranges outside holes behave as before: the arena is reserved in allocation-granularity pieces around the holes and tracker blocks are 64 KiB from the arena base, so no block is shared between a hole and arena memory.
  • New CheckHostHole() in WriteTracking.cpp (Windows only) finds a hole with VirtualQuery the way BdaResources.cpp does and checks all twelve queries against it; against main the StoredOver, MarkWritten, StoreOwnBytes, WrittenSince and ChangedBlocks checks fail, and with only the covers() change reverted it fails at the first check. Like #3594's own test it assumes the arena contains a host hole.
  • Overlaps open #3874 near StoredOver/WrittenSince but not on the same lines.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: agc_write_tracking, agc_write_watch_coverage, guest_memory 3/3 (also agc_shared_write*); ctest -j8 -E "^agc_driver_|^video_out_flip" 582/583, the one failure being #4088; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux (the change is inside #ifdef _WIN32).

Written with Claude Code assistance (fix by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115543265 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4087#issuecomment-6115543265). Originally posted by [screamm](https://github.com/screamm) on 2026-10-12T00:21:34Z. --- Fix branch ready: [`screamm:fix/write-tracking-host-holes`](https://github.com/screamm/AnyPS5/tree/fix/write-tracking-host-holes) (`03860b02`, one commit on `main` `bab7b328`). I cannot open it as a PR under the intake rule while #4081 is open; anyone eligible is welcome to carry it, keeping the commit as is. - One place instead of five: on Windows `WriteTracker::covers()` now returns false for any range overlapping an arena host hole, so every query (`Watched`, `StoredOver`, `UnchangedSince*`, `WrittenSince`, `ChangedBlocks`, `MarkWritten`, `StoreOwnBytes`, `ImportWatched`, `collectWrites`) gives a hole the answer an unwatched range always got; the five separate `#ifdef _WIN32` checks from #3594 are removed, their range-overflow early returns stay. Each query's "not covered" answer is already the safe one for its callers (`Draw.cpp` CMASK proofs, `Texture.cpp` keep checks, `VulkanDevice.cpp`). Ranges outside holes behave as before: the arena is reserved in allocation-granularity pieces around the holes and tracker blocks are 64 KiB from the arena base, so no block is shared between a hole and arena memory. - New `CheckHostHole()` in `WriteTracking.cpp` (Windows only) finds a hole with `VirtualQuery` the way `BdaResources.cpp` does and checks all twelve queries against it; against `main` the `StoredOver`, `MarkWritten`, `StoreOwnBytes`, `WrittenSince` and `ChangedBlocks` checks fail, and with only the `covers()` change reverted it fails at the first check. Like #3594's own test it assumes the arena contains a host hole. - Overlaps open #3874 near `StoredOver`/`WrittenSince` but not on the same lines. Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `agc_write_tracking`, `agc_write_watch_coverage`, `guest_memory` 3/3 (also `agc_shared_write*`); `ctest -j8 -E "^agc_driver_|^video_out_flip"` 582/583, the one failure being #4088; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux (the change is inside `#ifdef _WIN32`). Written with Claude Code assistance (fix by a subagent, reviewed and validated in this session).
Scramblrrrr commented 2026-10-12 00:34:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T00:34:50Z.


Thanks for catching the missing StoredOver exclusion, and for the Windows bisection/negative control. #3594's focused checks did not cover that existing assertion; I should have included agc_write_tracking. I see #4131 is now merged and will include that check in my next Windows current-main build. I am reviewing the remaining stamp readers listed in #4087 before proposing any further change, rather than duplicating the merged fix. AI-assisted: yes (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115661850 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4087#issuecomment-6115661850). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T00:34:50Z. --- Thanks for catching the missing StoredOver exclusion, and for the Windows bisection/negative control. #3594's focused checks did not cover that existing assertion; I should have included agc_write_tracking. I see #4131 is now merged and will include that check in my next Windows current-main build. I am reviewing the remaining stamp readers listed in #4087 before proposing any further change, rather than duplicating the merged fix. AI-assisted: yes (Codex).
Scramblrrrr commented 2026-10-12 00:37:12 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T00:37:12Z.


I have picked up screamm's public 03860b02 for a Windows current-main cross-test, preserving author/commit attribution. It applies cleanly on 7a84b222 with #4131 already merged (local integration1b4baaee2). The arena's host-region list is fixed during reservation and OverlapsHostRegion does not take the allocation mutex, so moving the exclusion into covers does not introduce that lock acquisition under the tracker lock.

I will run the existing write-tracking/coverage/guest-memory checks plus the new twelve-query fixture after my current bounded 007 measurement ends. No competing implementation; I have not claimed a tested result or opened a carry PR yet. AI-assisted: yes (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115683339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4087#issuecomment-6115683339). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T00:37:12Z. --- I have picked up screamm's public **03860b02** for a Windows current-main cross-test, preserving author/commit attribution. It applies cleanly on **7a84b222** with #4131 already merged (local integration1b4baaee2). The arena's host-region list is fixed during reservation and OverlapsHostRegion does not take the allocation mutex, so moving the exclusion into covers does not introduce that lock acquisition under the tracker lock. I will run the existing write-tracking/coverage/guest-memory checks plus the new twelve-query fixture after my current bounded 007 measurement ends. No competing implementation; I have not claimed a tested result or opened a carry PR yet. AI-assisted: yes (Codex).
Scramblrrrr commented 2026-10-12 00:56:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T00:56:31Z.


The canonical carry is now #4186, preserving screamm's author/commit content on main 7a84b222. Windows current-main integration 27c134117 passed write tracking (including the twelve-query fixture), write-watch coverage, guest memory, graphics and BDA device 5/5 in8.53s. Description distinguishes the standalone carry head from that profiling-only integration; no full-suite/Linux claim. Thanks for the correction and explicit carry offer. AI-assisted: yes (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115853309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4087#issuecomment-6115853309). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T00:56:31Z. --- The canonical carry is now #4186, preserving screamm's author/commit content on main 7a84b222. Windows current-main integration 27c134117 passed write tracking (including the twelve-query fixture), write-watch coverage, guest memory, graphics and BDA device 5/5 in8.53s. Description distinguishes the standalone carry head from that profiling-only integration; no full-suite/Linux claim. Thanks for the correction and explicit carry offer. AI-assisted: yes (Codex).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#4087
No description provided.