Watch: save a page's old bytes before any guard is opened #2237

Merged
denkencar-sketch merged 1 commit from upstream-pr/2239 into main 2026-11-25 21:55:59 +00:00
denkencar-sketch commented 2026-11-25 08:31:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T08:31:52Z.


Summary

changed_here opens the guarded pages (VirtualProtect to read-write) and only then marks them and saves their bytes for armed trackers (Changed::save, "before the write lands"). changed also opens the faulting range before it handles the pages aliasing it. Once a page is open, a write by another thread lands without a fault, and a save after that keeps the new bytes as the page's old bytes. Shadow::copy_back_marked then sees no difference between the copy and before and overwrites the other thread's write in title memory.

Change

changed marks and saves the range and its aliases first (mark_changed), and opens them after (open_guarded). Nothing else changes: same marks, same saves, same pages opened, same return value.

Testing

No new test. It is a window between two calls on two threads, which I could not hit deterministically. The existing tests pass (143 in victory-gpu, three runs, and the full workspace), and cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings is clean. This is a reordering found by reading, so please read it with that in mind.

Not tried: a run in the game. modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too (5 of 20 runs of cargo test -p victory-hle --lib); it is unrelated.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6600412614 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2239). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T08:31:52Z. --- ## Summary `changed_here` opens the guarded pages (`VirtualProtect` to read-write) and only then marks them and saves their bytes for armed trackers (`Changed::save`, "before the write lands"). `changed` also opens the faulting range before it handles the pages aliasing it. Once a page is open, a write by another thread lands without a fault, and a `save` after that keeps the new bytes as the page's old bytes. `Shadow::copy_back_marked` then sees no difference between the copy and `before` and overwrites the other thread's write in title memory. ## Change `changed` marks and saves the range and its aliases first (`mark_changed`), and opens them after (`open_guarded`). Nothing else changes: same marks, same saves, same pages opened, same return value. ## Testing **No new test.** It is a window between two calls on two threads, which I could not hit deterministically. The existing tests pass (143 in `victory-gpu`, three runs, and the full workspace), and `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` is clean. This is a reordering found by reading, so please read it with that in mind. Not tried: a run in the game. `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too (5 of 20 runs of `cargo test -p victory-hle --lib`); it is unrelated. AI-assisted.
DenRakEiw commented 2026-11-25 09:05:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:42:34Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib watch:: — 6 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean ordering fix saving a page's old bytes before any guard is opened in watch.rs. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054308619 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2239#pullrequestreview-6054308619). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:42:34Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib watch::` — **6 passed, 0 failed** - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean ordering fix saving a page's old bytes before any guard is opened in `watch.rs`. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 09:05:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:34Z.

Review: COMMENTED


Watch: a page's old bytes are saved before any guard is opened — reorders changed() so mark_changed runs for all pages/aliases before open_guarded, closing a race where a concurrent write would be kept as 'old bytes'. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same cluster; the ordering fix is subtle and correct-looking.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054381437 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2239#pullrequestreview-6054381437). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:34Z. **Review:** COMMENTED --- Watch: a page's old bytes are saved before any guard is opened — reorders changed() so mark_changed runs for all pages/aliases before open_guarded, closing a race where a concurrent write would be kept as 'old bytes'. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same cluster; the ordering fix is subtle and correct-looking.
MamaLeVrai commented 2026-11-25 10:07:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T09:13:33Z.


Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 583c14d5 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 701 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158043282 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2239#issuecomment-7158043282). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T09:13:33Z. --- Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `583c14d5` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 701 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Marvisak commented 2026-11-25 13:02:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T12:44:42Z.


Automated triage for the maintainers.

Merge candidate. In changed (crates/victory-gpu/src/watch.rs), on a write fault to a range and its aliases, main saved and opened one page at a time. Once one page was open, another thread's write could land on an alias that had not been saved yet, and that alias's "old bytes" would then already contain the write. The PR splits changed_here into mark_changed (save and mark) and open_guarded. It saves every page, the range and all its aliases, before opening any of them. The returned guarded value is computed the same way as before.

The reordering is right by my reading. There is no test, which is understandable for this race. CI check passes, an RX 6950 XT run shows the full workspace green, and the branch merges cleanly.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162795150 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2239#issuecomment-7162795150). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T12:44:42Z. --- <!-- victory-triage v1 head=583c14d5170e1a9fb2d92a15f6fdcd675e2d9b1d verdict=merge-candidate at=2026-11-25T12:52:00Z --> Automated triage for the maintainers. **Merge candidate.** In `changed` (`crates/victory-gpu/src/watch.rs`), on a write fault to a range and its aliases, `main` saved and opened one page at a time. Once one page was open, another thread's write could land on an alias that had not been saved yet, and that alias's "old bytes" would then already contain the write. The PR splits `changed_here` into `mark_changed` (save and mark) and `open_guarded`. It saves every page, the range and all its aliases, before opening any of them. The returned `guarded` value is computed the same way as before. The reordering is right by my reading. There is no test, which is understandable for this race. CI `check` passes, an RX 6950 XT run shows the full workspace green, and the branch merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 22:03:35 +00:00
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
Marvisak/VIctory!2237
No description provided.