GPU: keep a guarded block's write fault from being declined in a race #77

Manually merged
github merged 1 commit from gh-pr/77/head into gh-pr/77/base 2026-11-26 03:49:24 +00:00
Owner

@⁠Exorion1er on GitHub · 2026-11-24 00:15 UTC · original
Exorion1er:fix/guard-fault-race → main · +5 −2 · 1 files · 1 commits · merged 2026-11-24 00:40 UTC

What

on_write (the vectored handler behind guarded view memory in watch.rs) calls open() under the guard lock, then falls back to writable(at) after releasing it. A second thread can slip in between:

  1. Thread A writes to guarded block B and faults.
  2. Thread C faults on B too; its handler opens B (out of protected, read-write).
  3. A copy calls guard(), which protects B again and marks it protected and clean.
  4. A's handler finally runs: open() saw no guarded block, and writable(at) now sees B read-only → EXCEPTION_CONTINUE_SEARCH, and the title crashes on an ordinary write.

The fix holds the guard lock across both checks, so nothing can re-guard the block in between.

Evidence

Under Wine/Proton (where exception dispatch is slow enough to hit the window), world runs ended 1–3 minutes in, three runs out of three, with an unhandled write fault in title code (memcpy in ucrtbase, or title code directly) to view memory around 0x1d…–0x20…. A temporary log in the decline path showed the faulting block in protected and clean at the time it was declined, i.e. guarded by us, which is step 3 above.

With the fix, the same runs went the full 8 minutes without that crash.

Tested

  • Fedora 44, GE-Proton11-12, RX 9070 XT (RADV), on 35b054e.
  • cargo test -p victory-gpu -p victory-loader -p victory-game --lib under Wine: all pass (including watch.rs's guard tests).
  • Not run on Windows: the same race exists there, with a much smaller window.

🤖 Generated with Claude Code

**@⁠Exorion1er** on GitHub · 2026-11-24 00:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/77) `Exorion1er:fix/guard-fault-race` → `main` · +5 −2 · 1 files · 1 commits · merged 2026-11-24 00:40 UTC ## What `on_write` (the vectored handler behind guarded view memory in `watch.rs`) calls `open()` under the guard lock, then falls back to `writable(at)` after releasing it. A second thread can slip in between: 1. Thread A writes to guarded block B and faults. 2. Thread C faults on B too; its handler opens B (out of `protected`, read-write). 3. A copy calls `guard()`, which protects B again and marks it `protected` and `clean`. 4. A's handler finally runs: `open()` saw no guarded block, and `writable(at)` now sees B read-only → `EXCEPTION_CONTINUE_SEARCH`, and the title crashes on an ordinary write. The fix holds the guard lock across both checks, so nothing can re-guard the block in between. ## Evidence Under Wine/Proton (where exception dispatch is slow enough to hit the window), world runs ended 1–3 minutes in, three runs out of three, with an unhandled write fault in title code (`memcpy` in ucrtbase, or title code directly) to view memory around `0x1d…`–`0x20…`. A temporary log in the decline path showed the faulting block **in `protected` and `clean`** at the time it was declined, i.e. guarded by us, which is step 3 above. With the fix, the same runs went the full 8 minutes without that crash. ## Tested - Fedora 44, GE-Proton11-12, RX 9070 XT (RADV), on `35b054e`. - `cargo test -p victory-gpu -p victory-loader -p victory-game --lib` under Wine: all pass (including `watch.rs`'s guard tests). - Not run on Windows: the same race exists there, with a much smaller window. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The write-fault handler opens the guarded block under the guard lock,
then, if it found none, asks whether the address is writable without
it. Between the two, another thread's fault could open the block and a
copy could guard it again: the handler then saw a read-only block that
is in fact ours, declined the fault, and the title crashed on a plain
write (seen 1-3 minutes into the world under Wine, where exception
dispatch is slow enough to hit it every run).

The lock is now held across both checks, so a block that is not ours
while it is held really is not ours.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:23 +00:00
github manually merged commit 4c1766c235 into gh-pr/77/base 2026-11-26 03:49:24 +00:00
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!77
No description provided.