GPU: keep untracked pages writable in Tracked::taken #3011

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3013 into main
fuzeofficlal commented 2026-11-26 03:25:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:25:49Z.


Summary

  • Filter pages in crates/victory-gpu/src/watch.rs::Tracked::taken against g.holders for self.changed before calling aliases, guard_aliases, and protect, returning early if none of the pages belong to this tracker.
  • Fixes a page-protection leak when a Shadow buffer or 4 MiB loose window spans both MEM_WRITE_WATCH runtime pages and adjacent untracked/foreign committed pages: previously Shadow::copy_back, copy_back_page, and copy_back_marked called t.taken(...), which passed untracked pages to VirtualProtect(..., PAGE_READONLY) and inserted them into g.protected without a g.holders entry (leaving them permanently read-only even after Tracked::drop, and risking a VEH + heap-lock deadlock if a process-heap page is touched).
  • Add regression test watch::tests::taken_skips_untracked_and_foreign_pages covering both direct Tracked::taken on a mixed foreign/pool window and end-to-end Shadow::copy_back + Shadow::copy_back_page over adjacent pool and plain committed pages.

Verification

  • Regression check: watch::tests::taken_skips_untracked_and_foreign_pages fails on main (PAGE_READONLY instead of PAGE_READWRITE) and passes with the fix.
  • cargo test --locked -p victory-gpu watch::tests::: 16/16 passed on RTX 5090 (shadow::tests:: 9/9 passed).
  • VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --all-features: 247 passed, 0 failed, 1 ignored.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features): 0 warnings.
  • cargo xtask policy: 191 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6618833786 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3013). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T03:25:49Z. --- ## Summary - Filter `pages` in `crates/victory-gpu/src/watch.rs::Tracked::taken` against `g.holders` for `self.changed` before calling `aliases`, `guard_aliases`, and `protect`, returning early if none of the pages belong to this tracker. - Fixes a page-protection leak when a `Shadow` buffer or 4 MiB loose window spans both `MEM_WRITE_WATCH` runtime pages and adjacent untracked/foreign committed pages: previously `Shadow::copy_back`, `copy_back_page`, and `copy_back_marked` called `t.taken(...)`, which passed untracked pages to `VirtualProtect(..., PAGE_READONLY)` and inserted them into `g.protected` without a `g.holders` entry (leaving them permanently read-only even after `Tracked::drop`, and risking a VEH + heap-lock deadlock if a process-heap page is touched). - Add regression test `watch::tests::taken_skips_untracked_and_foreign_pages` covering both direct `Tracked::taken` on a mixed foreign/pool window and end-to-end `Shadow::copy_back` + `Shadow::copy_back_page` over adjacent pool and plain committed pages. ## Verification - Regression check: `watch::tests::taken_skips_untracked_and_foreign_pages` fails on `main` (`PAGE_READONLY` instead of `PAGE_READWRITE`) and passes with the fix. - `cargo test --locked -p victory-gpu watch::tests::`: 16/16 passed on RTX 5090 (`shadow::tests::` 9/9 passed). - `VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --all-features`: 247 passed, 0 failed, 1 ignored. - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): 0 warnings. - `cargo xtask policy`: 191 files ok.
Dukestar69 commented 2026-11-26 04:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:32:58Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-gpu --lib watch::tests: 16 passed, 0 failed (including new taken_skips_untracked_and_foreign_pages).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6068192295 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3013#pullrequestreview-6068192295). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:32:58Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-gpu --lib watch::tests`: **16 passed, 0 failed** (including new `taken_skips_untracked_and_foreign_pages`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
pickles976 commented 2026-11-26 04:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-26T03:29:15Z.


Exact PR head 0f2fb8c55b1a7c9814c5eeada6ee3de0cebf3d87, Windows-target Wine 11.0/vkd3d-proton 3.2.0 on a 16 GiB host with physical NVIDIA RTX 4060 Laptop GPU (8 GiB) (dxgi.hideNvidiaGpu = False): watch::tests::taken_skips_untracked_and_foreign_pages 1/1 passed, 0 ignored. Build log confirms Compiling victory-gpu from the clean PR checkout, and DXVK enumerated the laptop NVIDIA adapter. The regression exercises direct mixed owned/foreign pages and Shadow::copy_back/copy_back_page; it leaves foreign/plain pages PAGE_READWRITE while guarding only the tracked page. Local log: .compat-runtime/logs/verify-pr3013-wine-mixed-pages.log (not attached).

This is a useful Wine page-protection/liveness check, not a GPU command-dispatch or guarded title test; device enumeration does not mean this fixture rendered on the GPU. It does not resolve the separate 16 GiB world-load RAM floor, so no gameplay/FPS claim.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181761510 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3013#issuecomment-7181761510). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-26T03:29:15Z. --- Exact PR head `0f2fb8c55b1a7c9814c5eeada6ee3de0cebf3d87`, Windows-target Wine 11.0/vkd3d-proton 3.2.0 on a 16 GiB host with physical NVIDIA **RTX 4060 Laptop GPU (8 GiB)** (`dxgi.hideNvidiaGpu = False`): `watch::tests::taken_skips_untracked_and_foreign_pages` **1/1 passed**, 0 ignored. Build log confirms `Compiling victory-gpu` from the clean PR checkout, and DXVK enumerated the laptop NVIDIA adapter. The regression exercises direct mixed owned/foreign pages and `Shadow::copy_back`/`copy_back_page`; it leaves foreign/plain pages `PAGE_READWRITE` while guarding only the tracked page. Local log: `.compat-runtime/logs/verify-pr3013-wine-mixed-pages.log` (not attached). This is a useful Wine page-protection/liveness check, **not** a GPU command-dispatch or guarded title test; device enumeration does not mean this fixture rendered on the GPU. It does not resolve the separate 16 GiB world-load RAM floor, so no gameplay/FPS claim.
kotekompotek commented 2026-11-26 05:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:39:06Z.

Review: APPROVED


LGTM — filtering pages to this tracker's holders before aliases/protect stops foreign and untracked pages inside a buffer window from being left read-only. Lock ordering still covers protect+remove; the test lays out a foreign + write-watch page in one window.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068625889 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3013#pullrequestreview-6068625889). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:39:06Z. **Review:** APPROVED --- LGTM — filtering pages to this tracker's holders before aliases/protect stops foreign and untracked pages inside a buffer window from being left read-only. Lock ordering still covers protect+remove; the test lays out a foreign + write-watch page in one window.
Marvisak commented 2026-11-26 07:01:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:17:51Z.


Automated triage for the maintainers.

In main, Tracked::taken (victory-gpu/src/watch.rs) protects every page its caller passes in. Two callers can pass pages that this tracker never registered in g.holders:

  • Shadow::copy_back passes every synced page in range.
  • copy_back_page passes the page it wrote.

Such pages include foreign or plain committed memory inside a buffer or window. They get made PAGE_READONLY and added to g.protected, and Tracked::drop never unprotects them, because it only walks the tracker's own pages. The PR filters the pages down to those this tracker holds before the alias and protect steps. It keeps the existing lock order (guards first, then changed) and returns early when no pages are left. The new test covers direct taken calls and both Shadow copy-back paths over a mix of write-watched and plain pages.

This looks like a real fix for a latent leak of read-only protection onto memory the tracker doesn't own.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184289953 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3013#issuecomment-7184289953). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:17:51Z. --- <!-- victory-triage v1 head=0f2fb8c55b1a7c9814c5eeada6ee3de0cebf3d87 verdict=merge-candidate at=2026-11-26T06:23:00Z --> Automated triage for the maintainers. In `main`, `Tracked::taken` (`victory-gpu/src/watch.rs`) protects every page its caller passes in. Two callers can pass pages that this tracker never registered in `g.holders`: - `Shadow::copy_back` passes every synced page in range. - `copy_back_page` passes the page it wrote. Such pages include foreign or plain committed memory inside a buffer or window. They get made `PAGE_READONLY` and added to `g.protected`, and `Tracked::drop` never unprotects them, because it only walks the tracker's own pages. The PR filters the pages down to those this tracker holds before the alias and `protect` steps. It keeps the existing lock order (guards first, then `changed`) and returns early when no pages are left. The new test covers direct `taken` calls and both `Shadow` copy-back paths over a mix of write-watched and plain pages. This looks like a real fix for a latent leak of read-only protection onto memory the tracker doesn't own. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3013:upstream-pr/3013'
git switch 'upstream-pr/3013'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3013'
git switch 'upstream-pr/3013'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3013'
git switch 'upstream-pr/3013'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3013'
git switch 'main'
git merge --squash 'upstream-pr/3013'
git switch 'main'
git merge --ff-only 'upstream-pr/3013'
git switch 'main'
git merge 'upstream-pr/3013'
git push origin 'main'
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!3011
No description provided.