Skip to content

fix(memory): exclude arena host holes from every write-tracking query - #4186

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
Scramblrrrr:codex/host-hole-query-cross-test
Oct 12, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
Scramblrrrr:codex/host-hole-query-cross-test

Conversation

@Scramblrrrr

@Scramblrrrr Scramblrrrr commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Windows host holes inside the reserved guest-arena interval must be unwatched for every write-tracking query. Move the exclusion into WriteTracker::covers() so MarkWritten, StoreOwnBytes, WrittenSince, ChangedBlocks and the other stamp readers agree, and remove the duplicated checks. A twelve-query Windows fixture checks an actual host hole discovered with VirtualQuery.

Carries screamm's 03860b02 unchanged in content and preserving authorship, as explicitly offered in #4087. Based on main 7a84b222, including #4131's StoredOver fix; this covers the remaining queries. Original branch: https://github.com/screamm/AnyPS5/tree/fix/write-tracking-host-holes. Relates to #4087 and #3594.

Tested

Windows 11 Pro 26200, GCC 15.2 Release, RTX 5070 Ti, required Vulkan. Current-main integration 27c134117e5aa548252123d3cbb66cda0af5b82b combines this exact commit with a separate CPU-copy profiling-only change: agc_write_tracking, agc_write_watch_coverage, guest_memory, agc_driver_graphics, agc_driver_bda_device passed 5/5 in 8.53 seconds. No Linux or full-suite claim. Updated carry head b45232dda67ccea86b19f5b7a24a1b0944a01f72 passes conventions and diff checks. The fixture now prints an explicit subcase skip when Windows ASLR leaves no host allocation inside the guest arena, instead of failing the whole test. Other checks still run. On current-main integration 162daec28a730068a210268738b61f32bec05e1f, three fresh write-tracking runs passed (0.08/0.04/0.04 seconds), all with actual host-hole coverage and no skip message. A separate rendering-stack run exercised the no-hole skip and passed the other checks. The original author commit is retained unchanged; the fixture correction is a separate carry-review commit.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (original author Claude Code; carry/review/Windows cross-test Codex)

On Windows agc_write_tracking has failed since boykopovar#3594 with

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

from the check in CheckSharedBlock:

    if (!Watched(outside, unwatched.size())) Require(StoredOver(outside, unwatched.size(), TrackerGeneration()), "an unwatched range reads as not stored over");

The host stack array lies in a host hole of the guest arena. boykopovar#3594 made
Watched, collectWrites, UnchangedSince, UnchangedSinceAll and storeOwn
reject ranges overlapping such holes, but StoredOver, MarkWritten,
WrittenSince, ChangedBlocks and ImportWatched still accepted them through
WriteTracker::covers(), so StoredOver proved a range not stored over while
Watched called it unwatched (boykopovar#4087).

The exclusion now lives in WriteTracker::covers() on Windows, which every
query already asks, and the per-function checks are removed. Host holes
are padded to the allocation granularity and the tracker blocks are 64 KiB
from the arena base, so no block is shared between a hole and arena
memory, and ranges outside the holes get the same answers as before.

A new case enumerates the arena for a host hole and checks every query
against it; on the previous code StoredOver, MarkWritten, StoreOwnBytes,
WrittenSince and ChangedBlocks fail it.

Fixes boykopovar#4087

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Dextroid17

Copy link
Copy Markdown
Contributor

This does what the title says for four of the five migrated call sites — Watched, UnchangedSince, UnchangedSinceAll (which still checks covers() per-iteration inside the loop, not once outside it), and storeOwn all produce the same value the removed per-site check did, through the same tracker.covers() gate each already called early. MarkWritten, WrittenSince, ChangedBlocks, and ImportWatched were already routed through covers() before this PR and correctly inherit the exclusion without being touched.

There's a real gap in the fifth: collectWrites. The new covers() gate sits at the point the old per-site check used to be, but the function's per-thread memoization scan (threadCollectMemo) runs before that point and can return early with a nonzero generation if the hole's page-rounded range was already memoized — a path the old, unconditional first-statement check always caught regardless of memo state. So a memoized CollectWrites over a host hole can still report it as written, which is exactly the class of bug this PR exists to close. The fix is straightforward: hoist the hole check back to the top of the function, before the memo scan, the same way the original per-site check was positioned.

The new CheckHostHole test doesn't catch this gap — it calls CollectWrites cold (a fresh collect epoch each call), so the memoized path is never exercised. Worth adding a case that warms the memo (bump the collect epoch, collect once, bump again, collect the hole again) to actually pin this.

Everything here is Windows-only by construction — the non-Windows branch of covers() is untouched, and every removed check was already inside #ifdef _WIN32. #4131's StoredOver fix is confirmed live in the base this PR is built on, so the stated dependency is real, not just reviewed-but-unmerged.

Written with AI assistance.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#2863 core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp L186, L314

@Scramblrrrr

Copy link
Copy Markdown
Contributor Author

Carry-review update: head b45232d preserves the original author commit and adds a fixture-only correction. Windows ASLR can leave every host allocation outside the guest-arena interval; I reproduced that in a separate 007-stack test launch. With no hole, the fixture now explicitly reports only the host-hole subcase skipped and continues the other write-tracking checks.

Current-main test integration 162daec, three fresh agc_write_tracking runs: pass0.08/0.04/0.04s, all with an actual hole and no skip message. The separate rendering-stack default run exercised the skip path and passed; the opt-in memo run found a hole and passed the twelve queries. Production code is unchanged by this update. Conventions/diff checks pass. AI-assisted: yes (Codex).

@github-actions github-actions Bot added the agc libSceAgc* label Oct 12, 2026
@Scramblrrrr

Copy link
Copy Markdown
Contributor Author

@Dextroid17 Thanks for checking the early-return path. I am reviewing this separately from the 007 performance run. In the current code a thread memo entry is inserted only after tracker.covers(address, bytes) and a successful walkWrites; Windows host-hole boundaries come from page-aligned VirtualQuery regions/allocation-granularity rounding, and _hostRegions is fixed during arena initialization. A page-rounded memo entry for a valid range therefore should not contain a host-hole page. Bumping the collect epoch also invalidates the prior memo entry, rather than making it hit.

I agree the fixture should exercise repeated queries with a warm valid-range memo, not only cold hole queries. I will add that coverage before treating this review as resolved. If you have a concrete sequence that seeds a memo over a host hole through public APIs, please share it; I want to reproduce it rather than assume the invariant holds. No production-code change or claim of a reproduced memo bypass yet.

AI-assisted: yes (Codex).

@Scramblrrrr

Copy link
Copy Markdown
Contributor Author

Warm-memo coverage is now in 29a8435. With an actual host hole, the fixture allocates a watched range, warms and repeatedly queries it within each of two explicit collect epochs, and interleaves repeated full-range and sub-page host-hole queries. Those queries must return0 while the watched range stays collectable. This does not fabricate a memo entry over a host hole or claim a reproduced bypass.

On the current-main host-hole integration, three fresh Windows agc_write_tracking runs passed (0.14/0.04/0.04s), all with actual holes and no host-hole skip message. Production code remains the original author's commit. The invariant concern remains open for a concrete public-API counterexample; warming a valid-range memo and changing epochs did not reproduce it here.

AI-assisted: yes (Codex).

@xXPBSXx

xXPBSXx commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Test note (Windows 10, GCC Release, libs only, no other tests run): merge of this PR onto current main (git merge pr/4186 on upstream/main, 52 commits after ceb342b) against plain upstream/main, same relinked title directories, 90 s per run, alternating order.

Title main main + #4186
DREDGE PPSA09076 (Unity, write-watch path) 5 runs: 0 fatal, 14 err lines each 5 runs: 1 fatal (0xc0000005 on Job.Worker 9, app.exe+0x17f0843, run 2), 4 without fatal
Sifu PPSA03001 2 runs: both fatal 0xc0000005 at libc.prx.guest.prx+0x14270 2 runs: identical fault and address

Result: neutral for Sifu (the fault is the same on plain main, so it is not caused by this PR). DREDGE: one fatal in five runs with the PR, none without; 0/5 vs 1/5 is not significant (Fisher p = 1.0), and DREDGE is known to fault intermittently in the write-watch path, so I cannot attribute it to this PR or rule it out. I did not check whether the faulting address lies in a host hole, and I did not run the agc_write_tracking tests.

AI-assisted (Claude Code).

@Scramblrrrr

Copy link
Copy Markdown
Contributor Author

Thanks for the alternating comparison and for separating the shared Sifu fault from the DREDGE observation. I will keep the DREDGE result recorded as unresolved; the small sample does not establish a regression or rule one out.

Our Windows write-tracking fixture runs passed with actual host holes, including valid-range memo warming and queries across collect epochs, but those checks do not explain the intermittent title fault. If a future failing run gives a fault address relative to the arena/host-hole ranges or a short tracker-only stack, that would help narrow a concrete reproduction without sharing title code. No need to upload the title or shader captures.

The production patch remains the original author's host-hole exclusions; I have not changed it in response to this result. AI-assisted: Codex.

@Scramblrrrr

Copy link
Copy Markdown
Contributor Author

Additional Windows cross-test note: the current hostWriteWatchExclusionTests fixture can fail before any exclusion query checks with "write-watched arena contained no host exclusion to test". This occurred once in the 007 sparse-mirror test stack; repeating the same graphics executable passed. The fixture currently assumes a host exclusion exists inside the reserved arena, which appears sensitive to process layout. This is an observed fixture failure, not evidence that an excluded host region passed a write-watch proof. I will keep it separate from the unresolved alternating DREDGE fault report and make fixture setup explicit before treating it as reliable coverage. AI-assisted: Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants