Views guarded while they are mapped stay writable #102

Open
Castyan wants to merge 2 commits from upstream-pr/102 into main
Castyan commented 2026-11-26 20:05:15 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Castyan on 2026-11-26T20:05:15Z.


On main, independent of #61 and #64. Split out of #64.

What

  • 935bf44 Views guarded while they are mapped stay writable. Ported from avatarmanz/VIctory-7900XTX@160d222 (its watch part, adapted to our aliased blocks and clean sets). A refresh on another thread could guard a view's new blocks between the mapping and its notification. The notification then forgot them while leaving them read-only, so the title's next write was an access violation nobody caught. A test reproduced it as a STATUS_ACCESS_VIOLATION before the fix. The watch tests now forget their guards before freeing their memory.
  • 1240d8b frame's next-tick wait is checked by its time-out, not the wall clock.

Before: watch::tests::a_view_mapped_beside_a_guarded_one_makes_it_check_again failed about 1 run in 100 under load. After: 0 failures in 100 pairs of the victory-gpu test binary run two at a time, plus 100 ordinary runs (measured on the #64 tree).

Checks (RTX 5060, at 1240d8b on main)

cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean. cargo test --workspace --locked: 684 passed, 0 failed, 12 ignored.

🤖 Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5516460261 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/102). Originally posted by [Castyan](https://github.com/Castyan) on 2026-11-26T20:05:15Z. --- On `main`, independent of #61 and #64. Split out of #64. ## What - **`935bf44` Views guarded while they are mapped stay writable.** Ported from avatarmanz/VIctory-7900XTX@160d222 (its `watch` part, adapted to our `aliased` blocks and `clean` sets). A refresh on another thread could guard a view's new blocks between the mapping and its notification. The notification then forgot them while leaving them read-only, so the title's next write was an access violation nobody caught. A test reproduced it as a `STATUS_ACCESS_VIOLATION` before the fix. The `watch` tests now forget their guards before freeing their memory. - **`1240d8b` `frame`'s next-tick wait is checked by its time-out**, not the wall clock. Before: `watch::tests::a_view_mapped_beside_a_guarded_one_makes_it_check_again` failed about 1 run in 100 under load. After: 0 failures in 100 pairs of the `victory-gpu` test binary run two at a time, plus 100 ordinary runs (measured on the #64 tree). ## Checks (RTX 5060, at `1240d8b` on `main`) `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. `cargo test --workspace --locked`: 684 passed, 0 failed, 12 ignored. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
murillojndem commented 2026-11-30 22:55:08 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-30T22:55:08Z.


A crash on an RX 7900 XT matches the state this PR prevents. Build: main 4ad86927 with --features diagnostics, --profile diag. A DirectStorage worker stopped on an access violation nobody handled:

first-chance exception 0xc0000005 at victory.exe+0x6788be (write 0x129330000: read-only) on thread 46948 "dstorage 0"

With the build's PDB the stack is zlib_rs::inflate::inflate_fast_help_avx2 < zlib_rs::inflate::inflate < dstorage::inflate < dstorage::execute (dstorage.rs:901) < into_destination < fill_virtual_destination < dstorage::work. The write began a 64 KiB block (0x129330000) that was read-only and not in Guards::protected, so on_write passed it on; kernel_will_write before the inflate only opens blocks the guards know. Nothing in the log says whether a mapping changed at that address at that moment, so this matches the end state; it does not prove the interleaving.

I also checked the interleaving on main with a placeholder-backed section view, the way xmem.rs map makes them: guard() after MapViewOfFile3 and before title_memory_remapped leaves the view read-only and forgotten (the next write is that unhandled fault); with the guarded blocks given write access back in title_memory_remapped, as here, it is writable, and the next guard() reports the block and guards it again. The refreshes that reach guard() (Shadow::update_free, merge_under_writes, the texture guard check) take no title_memory_reading pin, so the Remapping held by XMemMapPhysicalPages does not keep them out.

For what it is worth, one gap is the same before and after this PR: when unmap cuts a view and part of it stays mapped, that part is a placeholder between UnmapViewOfFile2 and the map that puts it back, and a write to it then (a DirectStorage worker takes no pin) faults with nothing to open.

<!-- greyfinch-sync:DexNom/VIctory:comment:7294476154 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/102#issuecomment-7294476154). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-30T22:55:08Z. --- A crash on an RX 7900 XT matches the state this PR prevents. Build: main 4ad86927 with `--features diagnostics`, `--profile diag`. A DirectStorage worker stopped on an access violation nobody handled: ``` first-chance exception 0xc0000005 at victory.exe+0x6788be (write 0x129330000: read-only) on thread 46948 "dstorage 0" ``` With the build's PDB the stack is `zlib_rs::inflate::inflate_fast_help_avx2` < `zlib_rs::inflate::inflate` < `dstorage::inflate` < `dstorage::execute` (dstorage.rs:901) < `into_destination` < `fill_virtual_destination` < `dstorage::work`. The write began a 64 KiB block (0x129330000) that was read-only and not in `Guards::protected`, so `on_write` passed it on; `kernel_will_write` before the inflate only opens blocks the guards know. Nothing in the log says whether a mapping changed at that address at that moment, so this matches the end state; it does not prove the interleaving. I also checked the interleaving on main with a placeholder-backed section view, the way `xmem.rs` `map` makes them: `guard()` after `MapViewOfFile3` and before `title_memory_remapped` leaves the view read-only and forgotten (the next write is that unhandled fault); with the guarded blocks given write access back in `title_memory_remapped`, as here, it is writable, and the next `guard()` reports the block and guards it again. The refreshes that reach `guard()` (`Shadow::update_free`, `merge_under_writes`, the texture guard check) take no `title_memory_reading` pin, so the `Remapping` held by `XMemMapPhysicalPages` does not keep them out. For what it is worth, one gap is the same before and after this PR: when `unmap` cuts a view and part of it stays mapped, that part is a placeholder between `UnmapViewOfFile2` and the `map` that puts it back, and a write to it then (a DirectStorage worker takes no pin) faults with nothing to open.
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/102:upstream-pr/102'
git switch 'upstream-pr/102'

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