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

Closed
github-bot wants to merge 1 commit from gh-pr/2021/head into gh-pr/2021/base
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 03:16 UTC · original
fix/watch-empty-ranges → main · +34 −0 · 1 files · 1 commits · closed without merging

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

**@⁠DenRakEiw** on GitHub · 2026-11-25 03:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2021) `fix/watch-empty-ranges` → `main` · +34 −0 · 1 files · 1 commits · closed without merging 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:51 +00:00
github-bot closed this pull request 2026-11-26 04:51:51 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 03:19 UTC · original · edited 2026-11-25 03:20 UTC

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.

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

@⁠upipibi on GitHub · 2026-11-25 03:20 UTC · original

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

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

@⁠Calvix2k on GitHub · 2026-11-25 04:44 UTC · original

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.

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

@⁠Marvisak on GitHub · 2026-11-25 09:18 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 09:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2021#issuecomment-7158151232) <!-- 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)_
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-26 00:53 UTC · original

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

**@⁠DenRakEiw** on GitHub · 2026-11-26 00:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2021#issuecomment-7179225626) Closing this PR — stepping back from code contributions on this account. Feel free to reuse the approach if helpful.

Pull request closed

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