GPU/watch: give a remapped view's pages their write access back #1447

Closed
CwWwWwW wants to merge 1 commit from upstream-pr/1447 into main
CwWwWwW commented 2026-11-27 08:51:48 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T08:51:48Z.


Problem

title_memory_remapped forgets the 64 KiB blocks a guard made read-only when the runtime says the pages were mapped again, but it removed them from protected/clean and cleared PUBLISHED without restoring PAGE_READWRITE. A refresh (texback / texture pass / draw) that guards the pages in the window between MapViewOfFile3 and the runtime's post-map word leaves a view the title owns read-only with no guard to open it: the title's next plain store faults, the vectored handler finds no guard and the page not writable, and the access violation ends the process. The same window can leave host copies stale. The unmap side is unaffected (the protection dies with the mapping). look_at_holes already documents and avoids this window by taking the mapping lock; the refresh path has no such lock.

Fix

Open the blocks through open_here before forgetting them: it removes them from protected/clean, clears PUBLISHED and restores PAGE_READWRITE, so the guard's forgetting is complete in one step. One file changed (crates/victory-gpu/src/watch.rs, +27/-7).

Regression test

watch::tests::a_guard_forgotten_by_the_remap_gives_its_page_back maps a pagefile section view, guards it, sends the remap word and checks VirtualQuery: PAGE_READWRITE expected. On the old code it fails with PAGE_READONLY (left: 2, right: 4).

Verification

  • cargo test -p victory-gpu --lib --locked -- --test-threads=1: 243 passed, 0 failed, 7 ignored
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean
  • git diff --check: clean; one file changed

Found by this mission's GPU shadow/memory audit in an earlier round; independently implemented for this tree, no external code used. Rebased onto main 9a9091d (the branch fix/remap-restore-protection is the earlier base).

The PR's Clippy check fails on main already: at 9a9091d cargo clippy --workspace --all-targets fails in victory-shader (wave64_after_loop.rs precedence; valu_tests.rs simplifiable/negated partial-ord comparisons); open PR #1440 fixes exactly those lints. This diff touches only victory-gpu/src/watch.rs, whose clippy is clean here (default and --all-features).

<!-- greyfinch-sync:fxceless/victory-fork:issue:5523838750 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1447). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T08:51:48Z. --- ## Problem `title_memory_remapped` forgets the 64 KiB blocks a guard made read-only when the runtime says the pages were mapped again, but it removed them from `protected`/`clean` and cleared `PUBLISHED` **without restoring `PAGE_READWRITE`**. A refresh (texback / texture pass / draw) that guards the pages in the window between `MapViewOfFile3` and the runtime's post-map word leaves a view the title owns read-only with no guard to open it: the title's next plain store faults, the vectored handler finds no guard and the page not writable, and the access violation ends the process. The same window can leave host copies stale. The unmap side is unaffected (the protection dies with the mapping). `look_at_holes` already documents and avoids this window by taking the mapping lock; the refresh path has no such lock. ## Fix Open the blocks through `open_here` before forgetting them: it removes them from `protected`/`clean`, clears `PUBLISHED` and restores `PAGE_READWRITE`, so the guard's forgetting is complete in one step. One file changed (`crates/victory-gpu/src/watch.rs`, +27/-7). ## Regression test `watch::tests::a_guard_forgotten_by_the_remap_gives_its_page_back` maps a pagefile section view, guards it, sends the remap word and checks `VirtualQuery`: `PAGE_READWRITE` expected. On the old code it fails with `PAGE_READONLY` (`left: 2`, `right: 4`). ## Verification - `cargo test -p victory-gpu --lib --locked -- --test-threads=1`: 243 passed, 0 failed, 7 ignored - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean - `git diff --check`: clean; one file changed Found by this mission's GPU shadow/memory audit in an earlier round; independently implemented for this tree, no external code used. Rebased onto main 9a9091d (the branch `fix/remap-restore-protection` is the earlier base). The PR's Clippy check fails on main already: at 9a9091d `cargo clippy --workspace --all-targets` fails in `victory-shader` (wave64_after_loop.rs precedence; valu_tests.rs simplifiable/negated partial-ord comparisons); open PR #1440 fixes exactly those lints. This diff touches only `victory-gpu/src/watch.rs`, whose clippy is clean here (default and --all-features).
CwWwWwW commented 2026-11-27 16:21:33 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T16:21:33Z.


Superseded on the VIctory-NVIDIA tree that replaced main: watch::title_memory_remapped now reopens the guard and gives the pages their write access back (crates/victory-gpu/src/watch.rs), with the regression test a_block_guarded_before_we_were_told_of_its_view_can_be_written. Closing.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7223165719 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1447#issuecomment-7223165719). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T16:21:33Z. --- Superseded on the VIctory-NVIDIA tree that replaced main: watch::title_memory_remapped now reopens the guard and gives the pages their write access back (crates/victory-gpu/src/watch.rs), with the regression test a_block_guarded_before_we_were_told_of_its_view_can_be_written. Closing.

Pull request closed

Sign in to join this conversation.
No reviewers
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
fxceless/victory-fork!1447
No description provided.