GPU: remapping one mapping of aliased pages leaves the others guarded #2413

Open
BastienRodz wants to merge 1 commit from upstream-pr/2415 into main
BastienRodz commented 2026-11-25 13:07:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T13:07:57Z.


What's wrong

title_memory_remapped(at, len) marks [at, at + len) changed with changed, which also walks alias_of. So remapping or unmapping one address of aliased physical pages opens every other address that shows them, and marks their trackers changed without saving, while those addresses still show the same bytes. A copy over such an address that is armed for marked writes then loses the shaders' writes: copy_back_marked sees a changed page with nothing saved and keeps the title's bytes. A later title write there doesn't fault, so nothing is saved either.

What the fix does

  • title_memory_remapped marks only [first, last) itself (changed_here).
  • When the remapped pages' alias links are removed, a formerly linked page is opened only if no tracker holds it, directly or through an alias it still has. Without that it could stay guarded with no one tracking it.

Pages that do have a tracker stay guarded and unchanged, as they are when nothing is remapped.

Tests

New shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy: two pages mapped at a and b, a copy over a armed for marked writes, a shader-side byte written in each page, then b is remapped and the title writes page 1 through a. Both shader writes must go back, and so must the title's write.

  • On main (940d32f) it fails at the first check (page 0's shader write goes back).
  • With the fix it passes, and so do the other shadow::tests (5), watch::tests (6) and victory-hle's modules::xmem:: (10). Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe: the copy needs a host device, and the test returns early without one.
  • windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45620387821

Not tested

No title run, and no AMD/NVIDIA GPU. Whether the title unmaps one view of pages while a submission writes them through another is not measured. #2021 adds an early return for len == 0 at the top of the same function; the two combine without overlapping lines.

Fixes #2414

AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5491932793 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-25T13:07:57Z. --- ### What's wrong `title_memory_remapped(at, len)` marks `[at, at + len)` changed with `changed`, which also walks `alias_of`. So remapping or unmapping one address of aliased physical pages opens every other address that shows them, and marks their trackers changed without saving, while those addresses still show the same bytes. A copy over such an address that is armed for marked writes then loses the shaders' writes: `copy_back_marked` sees a changed page with nothing saved and keeps the title's bytes. A later title write there doesn't fault, so nothing is saved either. ### What the fix does - `title_memory_remapped` marks only `[first, last)` itself (`changed_here`). - When the remapped pages' alias links are removed, a formerly linked page is opened only if no tracker holds it, directly or through an alias it still has. Without that it could stay guarded with no one tracking it. Pages that do have a tracker stay guarded and unchanged, as they are when nothing is remapped. ### Tests New `shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy`: two pages mapped at `a` and `b`, a copy over `a` armed for marked writes, a shader-side byte written in each page, then `b` is remapped and the title writes page 1 through `a`. Both shader writes must go back, and so must the title's write. - On `main` (940d32f) it fails at the first check (`page 0's shader write goes back`). - With the fix it passes, and so do the other `shadow::tests` (5), `watch::tests` (6) and `victory-hle`'s `modules::xmem::` (10). Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe: the copy needs a host device, and the test returns early without one. - windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45620387821 ### Not tested No title run, and no AMD/NVIDIA GPU. Whether the title unmaps one view of pages while a submission writes them through another is not measured. #2021 adds an early return for `len == 0` at the top of the same function; the two combine without overlapping lines. Fixes #2414 AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-25 13:19:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:19:28Z.

Review: COMMENTED


Remapping one mapping of aliased pages leaves the others guarded (twin_views regression test). 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6058346061 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#pullrequestreview-6058346061). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T13:19:28Z. **Review:** COMMENTED --- Remapping one mapping of aliased pages leaves the others guarded (twin_views regression test). 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.
DenRakEiw commented 2026-11-25 14:06:34 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Leaving surviving mappings guarded when remapping one mapping of aliased pages cleanly prevents dropped marked writes.
  • cargo test -p victory-gpu shadow::: 5/5 passed on RTX 5090, 5/5 passed on WARP (including remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy).
  • cargo test -p victory-gpu watch::tests: 6/6 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6059089088 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#pullrequestreview-6059089088). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T14:06:34Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Leaving surviving mappings guarded when remapping one mapping of aliased pages cleanly prevents dropped marked writes. - `cargo test -p victory-gpu shadow::`: 5/5 passed on RTX 5090, 5/5 passed on WARP (including `remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy`). - `cargo test -p victory-gpu watch::tests`: 6/6 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
kotekompotek commented 2026-11-25 15:04:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T14:11:10Z.


Verified on Windows 10 / GTX 1050 at 487f6b4: remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy passes — real twin mappings, real guard faults.

Mechanics check out:

  • changed → changed_here is the core fix: an unmap changes only what [first, last) shows; the physical pages still exist through other mappings, so marking the aliases "changed" was wrong — and its side effect (opening the survivors' guards) let the next title write through the surviving mapping land unguarded, no saved baseline, copy_back_marked then dropping the shaders' bytes.
  • The open(g, other) fallback is the right stale-guard cleanup: unguard a surviving mapping only when nothing holds it directly or through a remaining alias — a guard kept while any alias is held is still doing its job.
  • The test covers the whole chain: alias unmap → surviving guard still armed → title write saves pre-write bytes → marked merge keeps both writers' bytes on both pages.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7164887877 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7164887877). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T14:11:10Z. --- Verified on Windows 10 / GTX 1050 at `487f6b4`: `remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy` passes — real twin mappings, real guard faults. Mechanics check out: - `changed` → `changed_here` is the core fix: an unmap changes only what `[first, last)` shows; the physical pages still exist through other mappings, so marking the aliases "changed" was wrong — and its side effect (opening the survivors' guards) let the next title write through the surviving mapping land unguarded, no `saved` baseline, `copy_back_marked` then dropping the shaders' bytes. - The `open(g, other)` fallback is the right stale-guard cleanup: unguard a surviving mapping only when nothing holds it directly or through a remaining alias — a guard kept while any alias is held is still doing its job. - The test covers the whole chain: alias unmap → surviving guard still armed → title write saves pre-write bytes → marked merge keeps both writers' bytes on both pages.
BastienRodz commented 2026-11-25 16:09:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T15:47:40Z.


Rebased onto main da82e44 (conflict only in the shadow tests block). On the new main the test still fails without the fix (page 0's shader write goes back) and passes with it; shadow:: 9/9, watch:: 12/12.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167320386 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7167320386). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-25T15:47:40Z. --- Rebased onto main da82e44 (conflict only in the shadow tests block). On the new main the test still fails without the fix (`page 0's shader write goes back`) and passes with it; `shadow::` 9/9, `watch::` 12/12.
Marvisak commented 2026-11-25 16:09:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:28:52Z.


Automated triage for the maintainers.

Merge candidate. title_memory_remapped (crates/victory-gpu/src/watch.rs) now marks changed and opens only the remapped range (mark_changed + open_guarded), instead of going through changed, which also opened and marked every alias. A page that loses its alias links is opened only when no tracker holds it, directly or through a remaining alias. The new shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy covers the lost-write case.

On your reply: the rebase applies exactly the change the second look asked for after #2239 split changed_here. It matches what changed on main does for the range itself, without the alias walk. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166908712 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7166908712). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:28:52Z. --- <!-- victory-triage v1 head=56619339195d6ef3e28f714dabf62fac2d97acfa verdict=merge-candidate at=2026-11-26T00:20:49Z --> Automated triage for the maintainers. **Merge candidate.** `title_memory_remapped` (`crates/victory-gpu/src/watch.rs`) now marks changed and opens only the remapped range (`mark_changed` + `open_guarded`), instead of going through `changed`, which also opened and marked every alias. A page that loses its alias links is opened only when no tracker holds it, directly or through a remaining alias. The new `shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy` covers the lost-write case. On your reply: the rebase applies exactly the change the second look asked for after #2239 split `changed_here`. It matches what `changed` on `main` does for the range itself, without the alias walk. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Marvisak commented 2026-11-25 22:04:45 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers, second look (a review against main, with the PR built and tested).

This is right as reviewed. It no longer builds on main, though: #2239, merged today, split changed_here in two. In crates/victory-gpu/src/watch.rs title_memory_remapped, changed_here(&mut g, first, last, false); becomes mark_changed(&mut g, first, last, false); open_guarded(&mut g, first, last);. With that change it was built and tested together with the rest.

Push the change and it will be reviewed again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175876535 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7175876535). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:03:16Z. --- Automated triage for the maintainers, second look (a review against `main`, with the PR built and tested). This is right as reviewed. It no longer builds on `main`, though: #2239, merged today, split `changed_here` in two. In `crates/victory-gpu/src/watch.rs` `title_memory_remapped`, `changed_here(&mut g, first, last, false);` becomes `mark_changed(&mut g, first, last, false); open_guarded(&mut g, first, last);`. With that change it was built and tested together with the rest. Push the change and it will be reviewed again. Thank you for the contribution.
BastienRodz commented 2026-11-25 23:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T22:22:33Z.


Rebased on main (f3578e3) as 5661933, with the change you describe: changed_here(&mut g, first, last, false) becomes mark_changed(&mut g, first, last, false); open_guarded(&mut g, first, last); in title_memory_remapped.

The shadow::tests (10, including remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy) and watch::tests (15) pass under Wine with vkd3d-proton, and cargo clippy --workspace --all-targets --locked -- -D warnings is clean. The test conflict with #2377's partial_refresh_under_marked_range_updates_saved_bytes was positional: both tests are kept.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176283329 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7176283329). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-25T22:22:33Z. --- Rebased on `main` (`f3578e3`) as `5661933`, with the change you describe: `changed_here(&mut g, first, last, false)` becomes `mark_changed(&mut g, first, last, false); open_guarded(&mut g, first, last);` in `title_memory_remapped`. The `shadow::tests` (10, including `remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy`) and `watch::tests` (15) pass under Wine with vkd3d-proton, and `cargo clippy --workspace --all-targets --locked -- -D warnings` is clean. The test conflict with #2377's `partial_refresh_under_marked_range_updates_saved_bytes` was positional: both tests are kept.
fuzeofficlal commented 2026-11-26 18:18:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:18:50Z.

Review: APPROVED


Looks good. Verified merged onto main (63bcca43) on Windows 11 (RTX 5090 + Microsoft WARP + VICTORY_D3D12_DEBUG=1):

  • Limiting title_memory_remapped (crates/victory-gpu/src/watch.rs:820-836) to mark_changed + open_guarded on [first, last) while opening an unlinked other page only when neither other nor any remaining alias of other has a holder keeps surviving mapped copies guarded and avoids leaking stale guards on orphaned aliases.
  • cargo xtask policy (191 files ok), cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features), and all 25 shadow::tests:: (10) + watch::tests:: (15) tests pass on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1.
  • An additional alias-topology probe verified both that remapping a held mapping a opens its unheld orphan alias b (no leaked guard) and that in a 3-way alias (x held, y held, z unheld), remapping x keeps y and z guarded while subsequently remapping y cleanly opens orphan z.
<!-- greyfinch-sync:Marvisak/VIctory:review:6078893714 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#pullrequestreview-6078893714). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T18:18:50Z. **Review:** APPROVED --- Looks good. Verified merged onto `main` (`63bcca43`) on Windows 11 (RTX 5090 + Microsoft WARP + `VICTORY_D3D12_DEBUG=1`): - Limiting `title_memory_remapped` (`crates/victory-gpu/src/watch.rs:820-836`) to `mark_changed` + `open_guarded` on `[first, last)` while opening an unlinked `other` page only when neither `other` nor any remaining alias of `other` has a holder keeps surviving mapped copies guarded and avoids leaking stale guards on orphaned aliases. - `cargo xtask policy` (`191 files ok`), `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`), and all 25 `shadow::tests::` (10) + `watch::tests::` (15) tests pass on both RTX 5090 and WARP under `VICTORY_D3D12_DEBUG=1`. - An additional alias-topology probe verified both that remapping a held mapping `a` opens its unheld orphan alias `b` (no leaked guard) and that in a 3-way alias (`x` held, `y` held, `z` unheld), remapping `x` keeps `y` and `z` guarded while subsequently remapping `y` cleanly opens orphan `z`.
pablogonz12 commented 2026-11-27 17:15:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-27T17:15:15Z.


I ran shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy at head 56619339195d6ef3e28f714dabf62fac2d97acfa: passed (1 test). Environment: RX 9070 XT, RADV (Mesa 26.3.1), GE-Proton11-14 and vkd3d-proton. I changed the test locally to fail rather than return early if the host device was unavailable; with vkd3d-proton loaded, it completed. The test simulates shader writes through write_host; I did not run a title or test on NVIDIA hardware.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224200470 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7224200470). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-27T17:15:15Z. --- I ran `shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy` at head `56619339195d6ef3e28f714dabf62fac2d97acfa`: **passed** (1 test). Environment: RX 9070 XT, RADV (Mesa 26.3.1), GE-Proton11-14 and vkd3d-proton. I changed the test locally to fail rather than return early if the host device was unavailable; with vkd3d-proton loaded, it completed. The test simulates shader writes through `write_host`; I did not run a title or test on NVIDIA hardware.
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/2415:upstream-pr/2415'
git switch 'upstream-pr/2415'

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