Skip to content

Watch: dropping a tracker keeps a mapping guarded while a tracker holds its alias - #2238

Open
denkencar-sketch wants to merge 1 commit into
Marvisak:mainfrom
denkencar-sketch:fix/watch-alias-drop
Open

denkencar-sketch wants to merge 1 commit into
Marvisak:mainfrom
denkencar-sketch:fix/watch-alias-drop

Conversation

@denkencar-sketch

Copy link
Copy Markdown
Contributor

Summary

When a tracker is dropped, Drop for Tracked opens (PAGE_READWRITE) every page that no tracker holds any more. That includes a page which guard_aliases guarded for a tracker of another mapping of the same memory. A write through the opened mapping then goes unseen, and the other tracker's take() finds nothing changed (it returns early when its changed set is empty, before it could guard the alias again).

The other direction is a stale guard: when the last tracker goes, aliases that only guard_aliases had guarded stay read-only until a write faults.

Change

A page stays guarded while a tracker holds it or a page showing the same memory (watched). When a page is freed, it and its aliases are opened only if nothing watches them any more.

Testing

Two tests on two views of one section (twin_views), both failing on main:

  • a_tracker_dropped_leaves_the_other_mapping_guarded: trackers on both views, both taken, drop the first, write through the first view: the second tracker's take must see the page (on main it returns nothing).
  • dropping_the_last_tracker_opens_both_mappings: after the only tracker is dropped, neither page is left in protected.

The suite passed three times in a row. 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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib watch:: — 8 passed, 0 failed (including a_tracker_dropped_leaves_the_other_mapping_guarded and dropping_the_last_tracker_opens_both_mappings)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean alias-aware guard retention when dropping a tracker whose alias is still tracked. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch: dropping a tracker keeps a mapping guarded while another tracker holds aliases of the same pages (watched check over alias_of). 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. Same cluster; fixes alias guard lifetime.

@MamaLeVrai

Copy link
Copy Markdown

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 6d86640a into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 703 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (worth a look). After the rebase, main already keeps a dropped page guarded while a tracker holds one of its aliases. What this adds, in Drop for Tracked (crates/victory-gpu/src/watch.rs), is the other half: when the last tracker on a page goes, its aliases (guarded by guard_aliases when the page was taken) are opened too, unless another tracker still holds them or one of their own aliases (watched). Without it those alias pages stay read-only with no tracker left. The test dropping_the_last_tracker_opens_both_mappings covers it. CI check passes and it merges cleanly.

On your reply: confirmed. The part already in main is gone from the diff, and what remains is the alias opening and its test.


Generated by Claude Code

main already keeps a dropped page guarded while a tracker holds its alias. When the last tracker on any mapping drops, the other mappings that guard_aliases guarded still stayed read-only in protected until a write faulted. Drop now opens those unwatched aliases too.
@denkencar-sketch

Copy link
Copy Markdown
Contributor Author

Rebased onto current \main\ (\842b0cb). \main\ now already keeps the dropped page guarded while an alias is held; this rebased commit keeps the remaining part (opening unwatched aliases in \protected\ when the last tracker drops) and its test. \watch::tests\ (16/16) and \clippy\ pass.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified 0c21a73bf5dcc09678ec1fabecd585811788f0f4 merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP, --features diagnostics, Rust 1.98.1 MSVC).

Code Audit

  • In Drop for Tracked (crates/victory-gpu/src/watch.rs:436-453), once a page leaves g.holders, iterating std::iter::once(page).chain(others) and calling open(&mut g, p) only when !watched(&g, p) handles both invariants under the single guards() lock (no additional locks or lock-order changes):
    • While any tracker remains on p or any alias of p, p stays guarded.
    • Once the last tracker across the alias group drops, every alias guarded solely via guard_aliases is opened back to PAGE_READWRITE and removed from g.protected, eliminating stale read-only guards.

Local Verification

  • cargo xtask policy — pass (191 files ok).
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) — 0 warnings.
  • cargo test --locked -p victory-gpu --features diagnostics --lib watch::tests:: — 17/17 passed, including a_tracker_dropped_on_one_mapping_leaves_the_other_guarded and dropping_the_last_tracker_opens_both_mappings (L1455-1467).
  • Additional 3-view alias clique probe (a <-> b <-> c <-> a, matching xmem::map): verified dropping tracker ta while tb lives keeps all three views (a, b, c) guarded and faults/marks tb on a write through untracked view c, and dropping the final tracker tb opens all three views with zero lingering entries in g.protected.
  • Also verified a 4-way co-merge with #2295, #2294, and #2283 (which also touches watch.rs) on 63bcca43c6a0 merges with zero conflicts, passes strict clippy (--all-features), and passes all 6 targeted tests on both RTX 5090 and WARP.

Looks good to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants