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

Open
github-bot wants to merge 1 commit from github-bot/gh-2415 into main AGit
Owner

@⁠BastienRodz on GitHub · 2026-11-25 13:07 UTC · original
BastienRodz:gpu/remap-keeps-alias-guards → main · +57 −2 · 2 files · 1 commits · open

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

**@⁠BastienRodz** on GitHub · 2026-11-25 13:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415) `BastienRodz:gpu/remap-keeps-alias-guards` → `main` · +57 −2 · 2 files · 1 commits · open ### 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)
title_memory_remapped marked [first, last) changed through `changed`,
which follows alias links: every other address showing the same
physical pages was opened and its trackers marked changed, without
saving. Those addresses still show the same bytes. If a copy there was
armed for marked writes, copy_back_marked then found the page changed
with nothing saved and kept the title's bytes, dropping the shaders'
writes; and a later title write there no longer faulted to save the
page.

Mark only [first, last) (changed_here), and when its alias links go,
open a page that was guarded for them only, one no tracker holds itself
or through a remaining alias.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:01 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 14:11 UTC · original

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.
**@⁠kotekompotek** on GitHub · 2026-11-25 14:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7164887877) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:28 UTC · original · edited 2026-11-26 00:20 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7166908712) · edited 2026-11-26 00:20 UTC <!-- 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)_
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 15:47 UTC · original

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.

**@⁠BastienRodz** on GitHub · 2026-11-25 15:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7167320386) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:03 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 22:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7175876535) 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.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 22:22 UTC · original

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.

**@⁠BastienRodz** on GitHub · 2026-11-25 22:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#issuecomment-7176283329) 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.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 13:19 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#pullrequestreview-6058346061) · **reviewed** 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.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 14:06 UTC · original · approved these changes

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).

**@⁠DenRakEiw** on GitHub · 2026-11-25 14:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#pullrequestreview-6059089088) · **approved these changes** 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).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:18 UTC · original · approved these changes

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2415#pullrequestreview-6078893714) · **approved these changes** 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`.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2415/head:github-bot/gh-2415'
git switch 'github-bot/gh-2415'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2415'
git switch 'github-bot/gh-2415'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2415'
git switch 'github-bot/gh-2415'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2415'
git switch 'main'
git merge --squash 'github-bot/gh-2415'
git switch 'main'
git merge --ff-only 'github-bot/gh-2415'
git switch 'main'
git merge 'github-bot/gh-2415'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2415
No description provided.