watch: a late lock-free write fault can undo a guard taken since (access violation) #817

Closed
opened 2026-11-28 06:58:00 +00:00 by github-bot · 3 comments
Owner

@⁠Machad3x on GitHub · 2026-11-28 06:52 UTC · original

Summary: a race in the lock-free write-fault path of crates/victory-gpu/src/watch.rs (from f5bde6b5, on by default). It can leave a guarded block read-only with its PROTECTED bit cleared. The title's next write to that block is then an access violation that no handler takes.

Sequence:

  1. Fault A checks PROTECTED, opens the block, and the opening is settled.
  2. Fault B checked PROTECTED before A's opening was settled. It reaches open_unlocked only after that, finds the block already writable, and still queues its own opening.
  3. A refresh that looked at the block earlier guards it again: read-only, protected, clean.
  4. The next settle takes B's stale entry. It removes the block from the guards and clears PROTECTED, but the memory stays read-only.
  5. The next write to the block faults, and nothing handles it.

Where we saw it: segfaults in the victory-gpu unit tests (the land, many-askers and refresh tests), about 1 run in 7 on tn1 main 3c142d49. In the game this would show as a crash on a title write. On tn1 main this also caused a test hang, in what_the_title_puts_in_beside_a_guard_is_told looping on put_beside returning Cannot. That hang is a separate, test-only bug: two tests released a view while still holding the mapping-change lock.

Fix on our side: open_unlocked records whether its own VirtualProtect made the block writable. settle leaves an entry that did not make it writable alone, apart from its OPENING and TOLD bits. Regression test: a_late_fault_leaves_the_guard_taken_since. After the fix we ran the tests 80 times on tn1 main and 40 times on our batch, with no segfaults. I will link the commit once it is pushed to our fork (Machad3x/VIctory-nvidia-RTX).

Setup: RTX 3080 Ti, driver 621.40, Windows 11 Pro build 26300, Ryzen 7 5700X, cargo test -p victory-gpu --profile diag --lib.

**@⁠Machad3x** on GitHub · 2026-11-28 06:52 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/817) **Summary:** a race in the lock-free write-fault path of `crates/victory-gpu/src/watch.rs` (from f5bde6b5, on by default). It can leave a guarded block read-only with its `PROTECTED` bit cleared. The title's next write to that block is then an access violation that no handler takes. **Sequence:** 1. Fault A checks `PROTECTED`, opens the block, and the opening is settled. 2. Fault B checked `PROTECTED` before A's opening was settled. It reaches `open_unlocked` only after that, finds the block already writable, and still queues its own opening. 3. A refresh that looked at the block earlier guards it again: read-only, protected, clean. 4. The next settle takes B's stale entry. It removes the block from the guards and clears `PROTECTED`, but the memory stays read-only. 5. The next write to the block faults, and nothing handles it. **Where we saw it:** segfaults in the victory-gpu unit tests (the land, many-askers and refresh tests), about 1 run in 7 on tn1 main 3c142d49. In the game this would show as a crash on a title write. On tn1 main this also caused a test hang, in `what_the_title_puts_in_beside_a_guard_is_told` looping on `put_beside` returning `Cannot`. That hang is a separate, test-only bug: two tests released a view while still holding the mapping-change lock. **Fix on our side:** `open_unlocked` records whether its own `VirtualProtect` made the block writable. `settle` leaves an entry that did not make it writable alone, apart from its `OPENING` and `TOLD` bits. Regression test: `a_late_fault_leaves_the_guard_taken_since`. After the fix we ran the tests 80 times on tn1 main and 40 times on our batch, with no segfaults. I will link the commit once it is pushed to our fork (Machad3x/VIctory-nvidia-RTX). **Setup:** RTX 3080 Ti, driver 621.40, Windows 11 Pro build 26300, Ryzen 7 5700X, `cargo test -p victory-gpu --profile diag --lib`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 06:58:00 +00:00
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 06:53 UTC · original

Please attach both logs from the run that went wrong. Without them we can only guess. Paste %LOCALAPPDATA% into the address bar of File Explorer to get there.

  1. The play log, in %LOCALAPPDATA%\victory\logs\: the newest victory-nvidia-play-<date>-<time>-<number>.log (from victory.exe) or victory-nvidia-<date>-<time>.log (from the script launcher). The window shows its path at the start, on the line Log: ....
  2. The crash log: %LOCALAPPDATA%\VIctory\data\7952987A\crashes.log, and, if there is one from that run, the newest victory-<date>-<time>-<number>.crash.log in %LOCALAPPDATA%\VIctory\data\7952987A\temp\.

Also say which GPU, Windows version (10 or 11)

**@⁠github-actions[bot]** on GitHub · 2026-11-28 06:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/817#issuecomment-7235577661) Please attach both logs from the run that went wrong. Without them we can only guess. Paste `%LOCALAPPDATA%` into the address bar of File Explorer to get there. 1. The play log, in `%LOCALAPPDATA%\victory\logs\`: the newest `victory-nvidia-play-<date>-<time>-<number>.log` (from `victory.exe`) or `victory-nvidia-<date>-<time>.log` (from the script launcher). The window shows its path at the start, on the line `Log: ...`. 2. The crash log: `%LOCALAPPDATA%\VIctory\data\7952987A\crashes.log`, and, if there is one from that run, the newest `victory-<date>-<time>-<number>.crash.log` in `%LOCALAPPDATA%\VIctory\data\7952987A\temp\`. Also say which GPU, Windows version (10 or 11)
Author
Owner

@⁠Machad3x on GitHub · 2026-11-28 07:09 UTC · original

Fix pushed to our fork: github.com/Machad3x/VIctory-nvidia-RTX@3175c5dc (regression test a_late_fault_leaves_the_guard_taken_since). The test-only hang fix is github.com/Machad3x/VIctory-nvidia-RTX@df65d657.

**@⁠Machad3x** on GitHub · 2026-11-28 07:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/817#issuecomment-7235749929) Fix pushed to our fork: https://github.com/Machad3x/VIctory-nvidia-RTX/commit/3175c5dc (regression test `a_late_fault_leaves_the_guard_taken_since`). The test-only hang fix is https://github.com/Machad3x/VIctory-nvidia-RTX/commit/df65d657.
Author
Owner

@⁠yeedgrthfgv on GitHub · 2026-11-28 08:07 UTC · original

Thanks for finding this and for the fix. I would like to send a pull request that makes VICTORY_FAULT_UNLOCKED easy to try: your race fix (3175c5dc) and your test fixes (df65d657) cherry picked with you kept as the author, plus an F1 menu line for the switch, still off by default.

I tested it on a Ryzen 5 9600X with an RTX 5080: no crash with the switch on, and the wait for the guards lock went from about 45 ms to about 10 ms a frame across all threads. The frame rate did not change on my PC.

Is that OK with you, or would you rather send your fix yourself? If you send it, I will only add the menu line and my numbers on top.

**@⁠yeedgrthfgv** on GitHub · 2026-11-28 08:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/817#issuecomment-7236376557) Thanks for finding this and for the fix. I would like to send a pull request that makes VICTORY_FAULT_UNLOCKED easy to try: your race fix (3175c5dc) and your test fixes (df65d657) cherry picked with you kept as the author, plus an F1 menu line for the switch, still off by default. I tested it on a Ryzen 5 9600X with an RTX 5080: no crash with the switch on, and the wait for the guards lock went from about 45 ms to about 10 ms a frame across all threads. The frame rate did not change on my PC. Is that OK with you, or would you rather send your fix yourself? If you send it, I will only add the menu line and my numbers on top.
This discussion has been locked. Commenting is limited to contributors.
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/trustno1-coder--VIctory-NVIDIA#817
No description provided.