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

Open
Dukestar69 wants to merge 1 commit from upstream-pr/2966 into main
Dukestar69 commented 2026-11-26 01:44:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T01:44:25Z.


Summary

Short-circuit zero-length (len == 0) ranges in watch::writing, Drop for Writing, and watch::title_memory_remapped so unaligned zero-byte writes and empty remaps do not mark pages dirty or unlink live aliases (credit to @tyr0nsur & @matheusfrta for identifying #2011).

Fixes #2011.

Testing

  • Added regression test unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink in crates/victory-gpu/src/watch.rs.
  • cargo test -p victory-gpu watch::tests: 16/16 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6617616147 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2966). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T01:44:25Z. --- ## Summary Short-circuit zero-length (`len == 0`) ranges in `watch::writing`, `Drop for Writing`, and `watch::title_memory_remapped` so unaligned zero-byte writes and empty remaps do not mark pages dirty or unlink live aliases (credit to @tyr0nsur & @matheusfrta for identifying #2011). Fixes #2011. ## Testing - Added regression test `unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink` in `crates/victory-gpu/src/watch.rs`. - `cargo test -p victory-gpu watch::tests`: 16/16 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 02:06:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:54:55Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1) — clean fix for #2011 and ready to merge:

  • Early-returning on len == 0 in writing (watch.rs:788-790), Writing::drop (self.first >= self.last, watch.rs:806-808), and title_memory_remapped (watch.rs:820-822) prevents unaligned zero-length ranges (at % PAGE != 0) from forming a 1-page [at / PAGE, at.div_ceil(PAGE)) span and spuriously dirtying or unlinking aliases.
  • Minor non-blocking note: neighboring pub(crate) fn retake(at: usize, len: usize) (watch.rs:849) does not yet have if len == 0 { return; } — current callers in memory.rs pass non-zero ranges, so it's harmless today, just worth adding for API symmetry if desired.

Local verification:

  • cargo test --locked -p victory-gpu --lib watch::: 16/16 passed on both RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1), including unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings: 0 warnings
  • cargo xtask policy: 191 files ok
<!-- greyfinch-sync:Marvisak/VIctory:review:6067519523 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2966#pullrequestreview-6067519523). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:54:55Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`) — clean fix for #2011 and ready to merge: - Early-returning on `len == 0` in `writing` (`watch.rs:788-790`), `Writing::drop` (`self.first >= self.last`, `watch.rs:806-808`), and `title_memory_remapped` (`watch.rs:820-822`) prevents unaligned zero-length ranges (`at % PAGE != 0`) from forming a 1-page `[at / PAGE, at.div_ceil(PAGE))` span and spuriously dirtying or unlinking aliases. - **Minor non-blocking note**: neighboring `pub(crate) fn retake(at: usize, len: usize)` (`watch.rs:849`) does not yet have `if len == 0 { return; }` — current callers in `memory.rs` pass non-zero ranges, so it's harmless today, just worth adding for API symmetry if desired. **Local verification**: - `cargo test --locked -p victory-gpu --lib watch::`: **16/16 passed** on both RTX 5090 and WARP (`VICTORY_D3D12_DEBUG=1`), including `unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink` - `cargo clippy --locked -p victory-gpu --tests -- -D warnings`: 0 warnings - `cargo xtask policy`: 191 files ok
kotekompotek commented 2026-11-26 03:04:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:19:10Z.

Review: COMMENTED


Verified the bug: writing(a+1, 0) used to register guard range [page, page) — an empty span — but the drop then dirtied anyway and remapped would unlink the alias. Both early-outs are the right fix points, and the drop's first>=last guard is consistent. The test proves a real 1-byte write afterwards still dirty-tracks through the preserved alias link.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067691043 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2966#pullrequestreview-6067691043). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:19:10Z. **Review:** COMMENTED --- Verified the bug: writing(a+1, 0) used to register guard range [page, page) — an empty span — but the drop then dirtied anyway and remapped would unlink the alias. Both early-outs are the right fix points, and the drop's first>=last guard is consistent. The test proves a real 1-byte write afterwards still dirty-tracks through the preserved alias link.
Marvisak commented 2026-11-26 06:03:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:29:03Z.


Automated triage for the maintainers.

This fixes #2011 in crates/victory-gpu/src/watch.rs. With a zero length and an unaligned start, writing and title_memory_remapped round to a one-page range. That range marks a clean page and its alias dirty, or unlinks a live alias on an empty remap. The fix returns early for len == 0, and Drop for Writing skips the empty range. A non-empty range always has first < last, so real writes are unaffected. Zero lengths can happen in practice: writing takes the title's fread size times count, and the callers in shadow.rs/list.rs pass computed lengths. The new test checks the empty write while the guard lives and after it drops, the empty remap, and that a real one-byte write still reaches the alias. No other open PR fixes #2011. CI: not run on this head yet.

Verdict: merge candidate. Recommending a look, not approving.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183525759 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2966#issuecomment-7183525759). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:29:03Z. --- <!-- victory-triage v1 head=b6b63384fe43d0fd6bb6b42bacf8d306699cd841 verdict=merge-candidate at=2026-11-26T05:28:52Z --> Automated triage for the maintainers. This fixes #2011 in `crates/victory-gpu/src/watch.rs`. With a zero length and an unaligned start, `writing` and `title_memory_remapped` round to a one-page range. That range marks a clean page and its alias dirty, or unlinks a live alias on an empty remap. The fix returns early for `len == 0`, and `Drop for Writing` skips the empty range. A non-empty range always has `first < last`, so real writes are unaffected. Zero lengths can happen in practice: `writing` takes the title's `fread` size times count, and the callers in `shadow.rs`/`list.rs` pass computed lengths. The new test checks the empty write while the guard lives and after it drops, the empty remap, and that a real one-byte write still reaches the alias. No other open PR fixes #2011. CI: not run on this head yet. **Verdict: merge candidate.** Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
cloph-dsp commented 2026-11-26 09:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T08:50:29Z.


Independent local verification of head b6b6338 on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-gpu --lib watch::tests::unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

CPU-only synthetic test; no game assets, GPU-specific hardware or DRM material used. AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187085483 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2966#issuecomment-7187085483). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T08:50:29Z. --- Independent local verification of head `b6b6338` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-gpu --lib watch::tests::unaligned_zero_length_writes_and_remaps_do_not_dirty_or_unlink` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. CPU-only synthetic test; no game assets, GPU-specific hardware or DRM material used. AI-assisted (Hy4 flash).
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/2966:upstream-pr/2966'
git switch 'upstream-pr/2966'

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