GPU watch: ignore zero-length writes and remaps on unaligned addresses (#2011) #2019

Closed
DenRakEiw wants to merge 1 commit from upstream-pr/2021 into main
DenRakEiw commented 2026-11-25 03:16:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T03:16:21Z.


Fixes #2011.

Credit to @tyr0nsur for the clear bug report and reproduction in #2011, and to @matheusfrta for earlier work on empty-range guard cases in #991.

In crates/victory-gpu/src/watch.rs, writing(at, len) and title_memory_remapped(at, len) computed (first, last) = (at / PAGE, at.saturating_add(len).div_ceil(PAGE)). When len == 0 and at is not page-aligned (e.g. base + 1), rounding start down and end up produced a 1-page range p..p+1:

  • writing(base + 1, 0) marked a clean page and its aliases dirty and held them in busy until drop.
  • title_memory_remapped(base + 1, 0) evicted live alias links for that page from alias_of.

Fix

  • Short-circuit len == 0 in writing (returning an empty Writing { first: 0, last: 0 }), Drop for Writing (if self.first >= self.last { return; }), and title_memory_remapped.
  • Added regression test watch::tests::unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink verifying that an unaligned 0-byte write (both while the guard lives and after drop) and an unaligned 0-byte remap leave a clean page and its alias untouched, and that a subsequent real 1-byte write still dirties the alias.

Verified locally on Windows 11 x64 (Rust 1.98.1 MSVC):

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

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6596378012 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2021). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T03:16:21Z. --- Fixes #2011. Credit to @tyr0nsur for the clear bug report and reproduction in #2011, and to @matheusfrta for earlier work on empty-range guard cases in #991. In `crates/victory-gpu/src/watch.rs`, `writing(at, len)` and `title_memory_remapped(at, len)` computed `(first, last) = (at / PAGE, at.saturating_add(len).div_ceil(PAGE))`. When `len == 0` and `at` is not page-aligned (e.g. `base + 1`), rounding `start` down and `end` up produced a 1-page range `p..p+1`: - `writing(base + 1, 0)` marked a clean page and its aliases dirty and held them in `busy` until drop. - `title_memory_remapped(base + 1, 0)` evicted live alias links for that page from `alias_of`. ### Fix - Short-circuit `len == 0` in `writing` (returning an empty `Writing { first: 0, last: 0 }`), `Drop for Writing` (`if self.first >= self.last { return; }`), and `title_memory_remapped`. - Added regression test `watch::tests::unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink` verifying that an unaligned 0-byte write (both while the guard lives and after drop) and an unaligned 0-byte remap leave a clean page and its alias untouched, and that a subsequent real 1-byte write still dirties the alias. Verified locally on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib watch::` — 7 passed, 0 failed - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 04:06:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:33:15Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

GPU watch ignores zero-length writes and unaligned remaps (#20…) — watch-mode noise reduction; safe if the filters are exact.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051461735 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2021#pullrequestreview-6051461735). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:33:15Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. GPU watch ignores zero-length writes and unaligned remaps (#20…) — watch-mode noise reduction; safe if the filters are exact.
upipibi commented 2026-11-25 04:06:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T03:20:44Z.


Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 7564b3c. victory-gpu: 142 passed, 2 failed, 2 ignored; the new unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink passes. The 2 are #1744's NVIDIA failures on main (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, the heap-cap ones). Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151826900 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2021#issuecomment-7151826900). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T03:20:44Z. --- Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `7564b3c`. `victory-gpu`: 142 passed, 2 failed, 2 ignored; the new `unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink` passes. The 2 are #1744's NVIDIA failures on `main` (`dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, the heap-cap ones). Same as `main` on this hardware. Not run: a title. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-25 04:06:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:19:48Z.


Triage verdict — Ready for maintainer decision (7564b3c)

Evidence

  • Main rounds an unaligned empty interval into a page in both entry points. The fix exits before touching watch state, and the empty Writing guard exits before taking the lock on drop.
  • The regression checks both tracked views before and after drop, then verifies a later real write still reaches the alias after an empty remap.

Checks and limits

Next step

  • Consider this the focused landing route for #2011. Closed, unmerged #991 had similar guards in a broader optimization. Preserve credit for @tyr0nsur’s reproduction and standalone patch and @matheusfrta’s earlier work on the guard cases.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151812020 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2021#issuecomment-7151812020). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T03:19:48Z. --- **Triage verdict — Ready for maintainer decision** (`7564b3c`) **Evidence** - Main rounds an unaligned empty interval into a page in both entry points. The fix exits before touching watch state, and the empty `Writing` guard exits before taking the lock on drop. - The regression checks both tracked views before and after drop, then verifies a later real write still reaches the alias after an empty remap. **Checks and limits** - The [exact-head Windows check](https://github.com/Marvisak/VIctory/actions/runs/45538818118/job/138951987583) passed. I compared the source and CI; I did not rerun the suite locally. **Next step** - Consider this the focused landing route for #2011. Closed, unmerged #991 had similar guards in a broader optimization. Preserve credit for @tyr0nsur’s reproduction and standalone patch and @matheusfrta’s earlier work on the guard cases. This verification was AI-assisted.
Calvix2k commented 2026-11-25 05:06:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T04:44:50Z.


Verified on Windows 10 19045 (RX 7800 XT), head 7564b3c: cargo test -p victory-gpu --features diagnostics --lib watch:: — 7 passed, 0 failed, including unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink.

The fix reads right: with len == 0, first == last and the guard would previously remove a busy entry it never inserted (or mark pages as written by a zero-byte write), which is exactly what the aliasing tests then see as an unlink. The early returns are the narrow fix, and the test covers the “real 1-byte write afterwards still works” case, which is the one that would regress if the early return were misplaced.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153126395 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2021#issuecomment-7153126395). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T04:44:50Z. --- Verified on Windows 10 19045 (RX 7800 XT), head `7564b3c`: `cargo test -p victory-gpu --features diagnostics --lib watch::` — **7 passed, 0 failed**, including `unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink`. The fix reads right: with `len == 0`, `first == last` and the guard would previously remove a busy entry it never inserted (or mark pages as written by a zero-byte write), which is exactly what the aliasing tests then see as an unlink. The early returns are the narrow fix, and the test covers the “real 1-byte write afterwards still works” case, which is the one that would regress if the early return were misplaced.
Marvisak commented 2026-11-25 10:07:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:18:21Z.


Automated triage for the maintainers.

Merge candidate. In crates/victory-gpu/src/watch.rs, writing and title_memory_remapped now return early when len == 0, and Drop for Writing skips an empty range. In main, an unaligned empty range (at / PAGE .. (at + 0).div_ceil(PAGE)) rounds to one whole page. That dirties the page and its aliases, or removes the alias links (#2011). Recommending a look, not approving.

What I checked:

  • The empty Writing { first: 0, last: 0 } is never pushed to busy, and its drop now never takes the lock or searches busy.
  • Zero-length calls are reachable: fread-style kernel writes and the DirectStorage destination path pass a title-supplied length.
  • The regression test checks both views before and after drop, and that a real 1-byte write still reaches the alias.
  • #1332 made the same fix but is closed; this is the focused open PR for #2011.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158151232 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2021#issuecomment-7158151232). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:18:21Z. --- <!-- victory-triage v1 head=7564b3caa839e66eb1e0f1ba80bdea1973cb4a6b verdict=merge-candidate at=2026-11-25T09:18:12Z --> Automated triage for the maintainers. **Merge candidate.** In `crates/victory-gpu/src/watch.rs`, `writing` and `title_memory_remapped` now return early when `len == 0`, and `Drop for Writing` skips an empty range. In `main`, an unaligned empty range (`at / PAGE` .. `(at + 0).div_ceil(PAGE)`) rounds to one whole page. That dirties the page and its aliases, or removes the alias links (#2011). Recommending a look, not approving. What I checked: - The empty `Writing { first: 0, last: 0 }` is never pushed to `busy`, and its drop now never takes the lock or searches `busy`. - Zero-length calls are reachable: `fread`-style kernel writes and the DirectStorage destination path pass a title-supplied length. - The regression test checks both views before and after drop, and that a real 1-byte write still reaches the alias. - #1332 made the same fix but is closed; this is the focused open PR for #2011. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-26 01:02:43 +00:00
DenRakEiw commented 2026-11-26 01:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:53:55Z.


Closing this PR — stepping back from code contributions on this account. Feel free to reuse the approach if helpful.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179225626 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2021#issuecomment-7179225626). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:53:55Z. --- Closing this PR — stepping back from code contributions on this account. Feel free to reuse the approach if helpful.

Pull request closed

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!2019
No description provided.