GPU/watch: do not treat absent blocks as known views when reallocated as private memory #804

Open
github-bot wants to merge 1 commit from github-bot/gh-804 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 08:19 UTC · original
AscilCH:fix/gpu-watch-known-view-absent-private-memory → main · +68 −6 · 1 files · 1 commits · open

Summary

Fix watch::known_view() and watch::guard() in crates/victory-gpu/src/watch.rs so uncommitted g.absent blocks are not treated as known MEM_MAPPED views after private memory is allocated at the same virtual address:

  • Commit 9376fd6 added known_view(start) before GetWriteWatch and returned true for both g.protected.contains(&first) and g.absent.contains(&first). guard() likewise skipped is_view() whenever g.absent.contains(&first).
  • When the title later allocated MEM_WRITE_WATCH or ordinary MEM_PRIVATE memory at a formerly uncommitted address (via VirtualAlloc, which does not trigger title_memory_remapped), writes() bypassed GetWriteWatch, entered guard(), removed the block from g.absent, and called VirtualProtect(..., PAGE_READONLY) on the private allocation—breaking kernel writes (ReadFile failing with ERROR_NOACCESS) and causing access-violation faults on private write-watched buffers.
  • Check only g.protected.contains(&first) in known_view() and guard(), and verify is_view() before guarding any block transitioning out of g.absent.
  • Add watch::tests::absent_block_reallocated_as_private_memory_is_not_guarded testing both MEM_WRITE_WATCH and ordinary MEM_PRIVATE reallocations at a formerly absent address.

Verification

  • cargo test -p victory-gpu --locked -- watch::: 13 passed; 0 failed; 0 ignored.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings in crates/victory-gpu/src/watch.rs (only pre-existing 9376fd6 warnings in draw.rs and indirect.rs).
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 08:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/804) `AscilCH:fix/gpu-watch-known-view-absent-private-memory` → `main` · +68 −6 · 1 files · 1 commits · open ## Summary Fix `watch::known_view()` and `watch::guard()` in `crates/victory-gpu/src/watch.rs` so uncommitted `g.absent` blocks are not treated as known `MEM_MAPPED` views after private memory is allocated at the same virtual address: - Commit `9376fd6` added `known_view(start)` before `GetWriteWatch` and returned `true` for both `g.protected.contains(&first)` and `g.absent.contains(&first)`. `guard()` likewise skipped `is_view()` whenever `g.absent.contains(&first)`. - When the title later allocated `MEM_WRITE_WATCH` or ordinary `MEM_PRIVATE` memory at a formerly uncommitted address (via `VirtualAlloc`, which does not trigger `title_memory_remapped`), `writes()` bypassed `GetWriteWatch`, entered `guard()`, removed the block from `g.absent`, and called `VirtualProtect(..., PAGE_READONLY)` on the private allocation—breaking kernel writes (`ReadFile` failing with `ERROR_NOACCESS`) and causing access-violation faults on private write-watched buffers. - Check only `g.protected.contains(&first)` in `known_view()` and `guard()`, and verify `is_view()` before guarding any block transitioning out of `g.absent`. - Add `watch::tests::absent_block_reallocated_as_private_memory_is_not_guarded` testing both `MEM_WRITE_WATCH` and ordinary `MEM_PRIVATE` reallocations at a formerly `absent` address. ## Verification - `cargo test -p victory-gpu --locked -- watch::`: `13 passed; 0 failed; 0 ignored`. - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 warnings in `crates/victory-gpu/src/watch.rs` (only pre-existing `9376fd6` warnings in `draw.rs` and `indirect.rs`). - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
In `crates/victory-gpu/src/watch.rs`, `known_view()` (added in `9376fd6`) and
`guard()` treated any block in `g.absent` (previously uncommitted/free virtual
address space) as a known `MEM_MAPPED` view, skipping both `GetWriteWatch` and
`is_view()`.

If the title later allocated `MEM_WRITE_WATCH` or ordinary `MEM_PRIVATE` memory
at that same virtual address (via `VirtualAlloc`, which does not fire
`title_memory_remapped`), `writes()` bypassed `GetWriteWatch`, entered
`guard()`, removed the block from `g.absent`, and called
`VirtualProtect(..., PAGE_READONLY)` on the private allocation—breaking kernel
writes (`ReadFile` failing with `ERROR_NOACCESS`) and forcing access-violation
faults on private write-watched buffers.

Only treat actively guarded blocks (`g.protected.contains(&first)`) as known
views in `known_view()` and `guard()`, and verify `is_view()` when a block
transitions out of `g.absent` inside `guard()`. Add
`watch::tests::absent_block_reallocated_as_private_memory_is_not_guarded`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:30 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 09:54 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head 72d2313 into main 9376fd6 in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails, with the same two errors as main itself on this machine (function placed_filler_twins is never used, field depth_written is never read, victory-gpu): this PR adds none and removes none. cargo test --workspace --locked: first run 541 passed, 0 failed, 10 ignored (main alone: 540 passed). In the second run the victory-gpu test binary died with STATUS_ACCESS_VIOLATION (0xc0000005) after 40 tests, so the run stopped there. I did not find which test it was, and I have not reproduced it since; main alone did not crash in its two runs. The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 09:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/804#issuecomment-7158954859) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head `72d2313` into `main` `9376fd6` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings` fails, with the same two errors as `main` itself on this machine (`function placed_filler_twins is never used`, `field depth_written is never read`, `victory-gpu`): this PR adds none and removes none. `cargo test --workspace --locked`: first run 541 passed, 0 failed, 10 ignored (`main` alone: 540 passed). In the second run the `victory-gpu` test binary died with `STATUS_ACCESS_VIOLATION` (0xc0000005) after 40 tests, so the run stopped there. I did not find which test it was, and I have not reproduced it since; `main` alone did not crash in its two runs. The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 10:09 UTC · original

Follow-up to my test report above: I could reproduce a failure on this PR's tree, and it is in a test of watch.rs.

What I saw (RX 6950 XT, Windows 11; this PR's head 72d2313 merged into main 9376fd6): running cargo test -p victory-gpu --lib repeatedly on that tree, the test watch::tests::written_pages_are_reported_to_every_asker failed in 3 of 13 runs, with

panicked at crates\victory-gpu\src\watch.rs:1039:9:
assertion failed: before.is_empty()

The other runs passed (145 passed each). main alone, 12 runs of the same command: 0 failures. So the intermittent failure appears with this PR and not without it, on this machine. (The STATUS_ACCESS_VIOLATION I reported earlier in one full run is a different symptom, and I did not catch which test it was.)

I did not look for the cause. Since the PR changes how absent blocks are treated by the watch, the test's first assertion (nothing reported before the write) failing now and then looks like a page a previous test in the same process, or the PR's new handling, leaves marked; that is a guess, not a finding.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 10:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/804#issuecomment-7159301791) Follow-up to my test report above: I could reproduce a failure on this PR's tree, and it is in a test of `watch.rs`. **What I saw** (RX 6950 XT, Windows 11; this PR's head `72d2313` merged into `main` `9376fd6`): running `cargo test -p victory-gpu --lib` repeatedly on that tree, the test `watch::tests::written_pages_are_reported_to_every_asker` failed in 3 of 13 runs, with ``` panicked at crates\victory-gpu\src\watch.rs:1039:9: assertion failed: before.is_empty() ``` The other runs passed (145 passed each). `main` alone, 12 runs of the same command: 0 failures. So the intermittent failure appears with this PR and not without it, on this machine. (The `STATUS_ACCESS_VIOLATION` I reported earlier in one full run is a different symptom, and I did not catch which test it was.) I did not look for the cause. Since the PR changes how absent blocks are treated by the watch, the test's first assertion (nothing reported before the write) failing now and then looks like a page a previous test in the same process, or the PR's new handling, leaves marked; that is a guess, not a finding. AI-assisted (Claude Code); no game data.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/watch.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/804/head:github-bot/gh-804'
git switch 'github-bot/gh-804'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-804'
git switch 'github-bot/gh-804'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-804'
git switch 'github-bot/gh-804'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-804'
git switch 'main'
git merge --squash 'github-bot/gh-804'
git switch 'main'
git merge --ff-only 'github-bot/gh-804'
git switch 'main'
git merge 'github-bot/gh-804'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.