GPU: keep alias groups transitive and symmetrically guarded in title_memory_aliased #3161

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

@⁠fuzeofficlal on GitHub · 2026-11-26 10:35 UTC · original
fuzeofficlal:fix/gpu-watch-alias-guard-symmetry → main · +269 −12 · 1 files · 1 commits · open

Summary

watch::title_memory_aliased maintains the alias_of graph and page-guard state when a physical page is mapped at multiple virtual addresses. On main, three gaps in title_memory_aliased can leave alias groups partially linked or asymmetrically guarded, causing writes through another mapping of the same physical page to go silently unseen:

  1. One-way guard check misses writes after a title_memory_remapped -> take -> title_memory_aliased race:
    In xmem::map, title_memory_remapped(base, len) releases GUARDS before the per-page loop calls title_memory_aliased(base + k * PAGE, shown). If a GPU submission runs Tracked::take on base + k * PAGE in that window, page enters g.protected (PAGE_READONLY) and its tracker becomes clean while shown stays PAGE_READWRITE. title_memory_aliased only checked others.iter().any(|&o| g.protected.contains(&(o / PAGE))), so it neither marked page changed nor guarded/opened the group—missing any write through shown during the window and leaving shown permanently PAGE_READWRITE for future writes. The same issue occurs when others itself mixes guarded and unguarded mappings.
  2. Non-transitive alias links drop cross-mapping notifications and break on unmap:
    title_memory_aliased only linked page directly with each element of others. When a <-> b already exists and title_memory_aliased(c, &[a]) is called, b and c are never linked: take(b) leaves c unguarded, writes (on_write / writing) and retake at c miss trackers holding b, dropping a tracker on c opens c despite b's live tracker, and unmapping a via title_memory_remapped(a, PAGE) removes a from both adjacency lists and severs b and c completely.
  3. Self-aliasing inserts a self-link:
    Passing an address in the same 64 KiB page as at in others inserted page -> page into alias_of.

Changes

  • crates/victory-gpu/src/watch.rs:
    • In title_memory_aliased, return early for empty others or self-only inputs without creating self-links.
    • Expand page's existing component (new_group) and the merged connected component (clique) via expand_aliases, then link every distinct pair in clique so alias groups remain complete cliques (preserved when title_memory_remapped removes a page and its incident edges).
    • Keep guard state symmetric across the merged clique:
      • If only new_group is unguarded and every existing mapping in the clique is guarded, guard all pages in new_group with protect(&mut g, &unguarded); if any page in new_group (including a busy sibling) cannot be guarded, call changed(&mut g, page, page + 1, false) to mark all trackers and open every guard in the clique without saving post-write bytes.
      • Otherwise, whenever the merged clique has both guarded and unguarded mappings (such as page already guarded while an existing mapping stayed PAGE_READWRITE, or mixed guard states in others), call changed(&mut g, page, page + 1, false) so neither raced writes nor subsequent writes through previously unguarded mappings go unseen.
    • Added 4 focused unit tests in watch::tests covering the guarded-to-unguarded race and mixed others, transitive alias propagation/retake/drop/bridge-unmap, guarding a newly joined group and busy-sibling rollback, and self-alias handling.

Verification

  • Verified all 4 new tests fail on main (63bcca43) before the fix and pass after the fix.
  • cargo test -p victory-gpu --locked watch::tests: 19/19 passed.
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked (watch::tests, bindless::tests::heap_views_follow_writes_through_another_mapping, shadow::tests): all passed on hardware GPU and WARP.
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked: 250 passed, 0 failed, 1 ignored.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features: clean.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 10:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/3161) `fuzeofficlal:fix/gpu-watch-alias-guard-symmetry` → `main` · +269 −12 · 1 files · 1 commits · open ### Summary `watch::title_memory_aliased` maintains the `alias_of` graph and page-guard state when a physical page is mapped at multiple virtual addresses. On `main`, three gaps in `title_memory_aliased` can leave alias groups partially linked or asymmetrically guarded, causing writes through another mapping of the same physical page to go silently unseen: 1. **One-way guard check misses writes after a `title_memory_remapped` -> `take` -> `title_memory_aliased` race**: In `xmem::map`, `title_memory_remapped(base, len)` releases `GUARDS` before the per-page loop calls `title_memory_aliased(base + k * PAGE, shown)`. If a GPU submission runs `Tracked::take` on `base + k * PAGE` in that window, `page` enters `g.protected` (`PAGE_READONLY`) and its tracker becomes clean while `shown` stays `PAGE_READWRITE`. `title_memory_aliased` only checked `others.iter().any(|&o| g.protected.contains(&(o / PAGE)))`, so it neither marked `page` changed nor guarded/opened the group—missing any write through `shown` during the window and leaving `shown` permanently `PAGE_READWRITE` for future writes. The same issue occurs when `others` itself mixes guarded and unguarded mappings. 2. **Non-transitive alias links drop cross-mapping notifications and break on unmap**: `title_memory_aliased` only linked `page` directly with each element of `others`. When `a <-> b` already exists and `title_memory_aliased(c, &[a])` is called, `b` and `c` are never linked: `take(b)` leaves `c` unguarded, writes (`on_write` / `writing`) and `retake` at `c` miss trackers holding `b`, dropping a tracker on `c` opens `c` despite `b`'s live tracker, and unmapping `a` via `title_memory_remapped(a, PAGE)` removes `a` from both adjacency lists and severs `b` and `c` completely. 3. **Self-aliasing inserts a self-link**: Passing an address in the same 64 KiB page as `at` in `others` inserted `page -> page` into `alias_of`. ### Changes - **`crates/victory-gpu/src/watch.rs`**: - In `title_memory_aliased`, return early for empty `others` or self-only inputs without creating self-links. - Expand `page`'s existing component (`new_group`) and the merged connected component (`clique`) via `expand_aliases`, then link every distinct pair in `clique` so alias groups remain complete cliques (preserved when `title_memory_remapped` removes a page and its incident edges). - Keep guard state symmetric across the merged clique: - If only `new_group` is unguarded and every existing mapping in the clique is guarded, guard all pages in `new_group` with `protect(&mut g, &unguarded)`; if any page in `new_group` (including a busy sibling) cannot be guarded, call `changed(&mut g, page, page + 1, false)` to mark all trackers and open every guard in the clique without saving post-write bytes. - Otherwise, whenever the merged clique has both guarded and unguarded mappings (such as `page` already guarded while an existing mapping stayed `PAGE_READWRITE`, or mixed guard states in `others`), call `changed(&mut g, page, page + 1, false)` so neither raced writes nor subsequent writes through previously unguarded mappings go unseen. - Added 4 focused unit tests in `watch::tests` covering the guarded-to-unguarded race and mixed `others`, transitive alias propagation/retake/drop/bridge-unmap, guarding a newly joined group and busy-sibling rollback, and self-alias handling. ### Verification - Verified all 4 new tests fail on `main` (`63bcca43`) before the fix and pass after the fix. - `cargo test -p victory-gpu --locked watch::tests`: 19/19 passed. - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked` (`watch::tests`, `bindless::tests::heap_views_follow_writes_through_another_mapping`, `shadow::tests`): all passed on hardware GPU and WARP. - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked`: 250 passed, 0 failed, 1 ignored. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features`: clean. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:09:04 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 10:48 UTC · original · approved these changes

Verified against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 19/19 passed (including aliasing_a_guarded_page_to_an_unguarded_mapping_does_not_miss_writes, aliasing_a_newly_mapped_page_guards_its_group_and_handles_busy_siblings, aliasing_through_one_member_joins_the_whole_alias_group, and self_aliasing_adds_no_self_link_and_preserves_guards).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly keeps alias groups transitive and symmetrically guarded in title_memory_aliased.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 10:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3161#pullrequestreview-6072773251) · **approved these changes** Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib watch:: -- --test-threads=1`: 19/19 passed (including `aliasing_a_guarded_page_to_an_unguarded_mapping_does_not_miss_writes`, `aliasing_a_newly_mapped_page_guards_its_group_and_handles_busy_siblings`, `aliasing_through_one_member_joins_the_whole_alias_group`, and `self_aliasing_adds_no_self_link_and_preserves_guards`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly keeps alias groups transitive and symmetrically guarded in `title_memory_aliased`. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/3161/head:github-bot/gh-3161'
git switch 'github-bot/gh-3161'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3161'
git switch 'github-bot/gh-3161'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3161'
git switch 'github-bot/gh-3161'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3161'
git switch 'main'
git merge --squash 'github-bot/gh-3161'
git switch 'main'
git merge --ff-only 'github-bot/gh-3161'
git switch 'main'
git merge 'github-bot/gh-3161'
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!3161
No description provided.