Watch: a page committed only in part stays changed instead of counting as unmapped #2234

Closed
denkencar-sketch wants to merge 1 commit from upstream-pr/2236 into main
denkencar-sketch commented 2026-11-25 08:31:35 +00:00 (Migrated from github.com)

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


Summary

protect() decides that a page "has nothing mapped" (and so counts it as taken without guarding it) by asking VirtualQuery about the first 4 KiB of the 64 KiB page only. A page whose first part is reserved and the rest committed cannot be guarded (VirtualProtect fails across the reserved part), but the query sees MEM_RESERVE, so the page is taken without being guarded. It then leaves the tracker's changed set, and writes to its committed part are never seen.

Change

The check walks the whole page with VirtualQuery, region by region, and counts the page as unmapped only if no part of it is committed. A page committed in part stays changed, as the doc comment already says for a page that is mapped but cannot be guarded (it is copied whole at each take).

Testing

watch::tests::a_page_committed_in_part_stays_changed reserves 64 KiB, commits all but the first 4 KiB, tracks it and takes it: on main the page is no longer changed after the take ("cannot be guarded, so still changed" fails); with this change it stays changed and a write to the committed part is copied at the next take. cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings is clean.

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:6600408135 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2236). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T08:31:35Z. --- ## Summary `protect()` decides that a page "has nothing mapped" (and so counts it as taken without guarding it) by asking `VirtualQuery` about the first 4 KiB of the 64 KiB page only. A page whose first part is reserved and the rest committed cannot be guarded (`VirtualProtect` fails across the reserved part), but the query sees `MEM_RESERVE`, so the page is taken without being guarded. It then leaves the tracker's changed set, and writes to its committed part are never seen. ## Change The check walks the whole page with `VirtualQuery`, region by region, and counts the page as unmapped only if no part of it is committed. A page committed in part stays changed, as the doc comment already says for a page that is mapped but cannot be guarded (it is copied whole at each take). ## Testing `watch::tests::a_page_committed_in_part_stays_changed` reserves 64 KiB, commits all but the first 4 KiB, tracks it and takes it: on `main` the page is no longer changed after the take ("cannot be guarded, so still changed" fails); with this change it stays changed and a write to the committed part is copied at the next take. `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings` is clean. 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.
catminou4 commented 2026-11-25 09:05:56 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Watch: a page committed only in part stays changed — unmapped now walks the whole page with VirtualQuery instead of checking only its start. 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. Correct fix with a dedicated test; part of the watch.rs cluster #2236-#2239.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054380930 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2236#pullrequestreview-6054380930). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:32Z. **Review:** COMMENTED --- Watch: a page committed only in part stays changed — `unmapped` now walks the whole page with VirtualQuery instead of checking only its start. 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. Correct fix with a dedicated test; part of the watch.rs cluster #2236-#2239.
Marvisak commented 2026-11-25 14:07:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:31:00Z.


Automated triage for the maintainers. This fixes the unmapped check in watch::protect. PAGE is 64 KiB, and on main only the region at the page's start is queried, so a page whose first 4 KiB is reserved but whose tail is committed counted as "nothing mapped" and was taken. Writes to its committed part were then missed. The new loop walks every region in the page with VirtualQuery and only reports unmapped when none is committed, with max(at + 1) guarding against a zero-size region. The added test a_page_committed_in_part_stays_changed sets up exactly that layout. CI (check) passes.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163888866 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2236#issuecomment-7163888866). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:31:00Z. --- <!-- victory-triage v1 head=4a38c3b2796bd52d0ca6b6d37414de17267378a6 verdict=merge-candidate at=2026-11-25T13:39:00Z --> Automated triage for the maintainers. This fixes the `unmapped` check in `watch::protect`. `PAGE` is 64 KiB, and on `main` only the region at the page's start is queried, so a page whose first 4 KiB is reserved but whose tail is committed counted as "nothing mapped" and was taken. Writes to its committed part were then missed. The new loop walks every region in the page with `VirtualQuery` and only reports unmapped when none is committed, with `max(at + 1)` guarding against a zero-size region. The added test `a_page_committed_in_part_stays_changed` sets up exactly that layout. CI (`check`) passes. --- _Generated by [Claude Code](https://claude.ai/code)_
DenRakEiw commented 2026-11-25 15:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:56:54Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090:

  • Keeping a partially committed page marked changed instead of treating it as unmapped is clean and well-tested.
  • cargo test -p victory-gpu watch::tests: 7/7 passed (including a_page_committed_in_part_stays_changed).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6059985158 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2236#pullrequestreview-6059985158). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T14:56:54Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090: - Keeping a partially committed page marked changed instead of treating it as unmapped is clean and well-tested. - `cargo test -p victory-gpu watch::tests`: 7/7 passed (including `a_page_committed_in_part_stays_changed`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
upstream-sync closed this pull request 2026-11-25 23:04:07 +00:00
Marvisak commented 2026-11-25 23:05:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:07:00Z.


Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because its test fails on current main and the layout does not occur. Since 280b1505 main does not track a page that holds committed private memory at all, so track(r, PAGE, true).expect("reserved memory is tracked") panics. The fix is right in substance, but it needs a page that is reserved when tracked and later committed in part with its first 4 KiB left reserved, which the title's allocations never produce. A version whose test commits the tail after track would be a fair edge-case fix.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175955864 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2236#issuecomment-7175955864). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:07:00Z. --- Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because its test fails on current `main` and the layout does not occur. Since 280b1505 `main` does not track a page that holds committed private memory at all, so `track(r, PAGE, true).expect("reserved memory is tracked")` panics. The fix is right in substance, but it needs a page that is reserved when tracked and later committed in part with its first 4 KiB left reserved, which the title's allocations never produce. A version whose test commits the tail after `track` would be a fair edge-case fix. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

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
Marvisak/VIctory!2234
No description provided.