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

Open
denkencar-sketch wants to merge 1 commit from upstream-pr/2238 into main
denkencar-sketch commented 2026-11-25 08:31:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T08:31:46Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5487855878 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2238). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T08:31:46Z. --- ## 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 commented 2026-11-25 08:42:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:42:36Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6054309048 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2238#pullrequestreview-6054309048). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:42:36Z. **Review:** APPROVED --- 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 commented 2026-11-25 08:48:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:34Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054381282 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2238#pullrequestreview-6054381282). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:34Z. **Review:** COMMENTED --- 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 commented 2026-11-25 10:07:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T09:13:34Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158043732 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2238#issuecomment-7158043732). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T09:13:34Z. --- 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 2026-11-25 14:07:21 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163876360 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2238#issuecomment-7163876360). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:28Z. --- <!-- victory-triage v1 head=0c21a73bf5dcc09678ec1fabecd585811788f0f4 verdict=merge-candidate at=2026-11-26T00:22:58Z --> 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](https://claude.ai/code)_
denkencar-sketch commented 2026-11-26 00:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by denkencar-sketch on 2026-11-25T23:17:11Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177360291 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2238#issuecomment-7177360291). Originally posted by [denkencar-sketch](https://github.com/denkencar-sketch) on 2026-11-25T23:17:11Z. --- 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 commented 2026-11-26 19:44:49 +00:00 (Migrated from github.com)

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

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6079708532 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2238#pullrequestreview-6079708532). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T19:44:49Z. **Review:** APPROVED --- 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.
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/2238:upstream-pr/2238'
git switch 'upstream-pr/2238'

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