victory-gpu: fix protect/open_unlocked race leaving block read-only #457
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/457"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from readmet3xt-lab/foxhound. Originally posted by kwaadrat on 2026-12-02T11:47:16Z.
Fixes a race condition between
protect_alias/protect_hereandopen_unlocked(VICTORY_FAULT_UNLOCKED=1) that could leave a blockPAGE_READONLYin OS memory whilePROTECTEDandg.protectedare cleared, causing subsequent writes to crash withunhandled write fault ... protected=false opening=false open_done=false.Root cause
protect_aliasandprotect_heresetPROTECTED.set(block)ahead ofVirtualProtect(..., PAGE_READONLY).VirtualProtect(..., PAGE_READONLY)has not yet completed (which can be a multi-mswineserverIPC under Wine/Proton), another thread can fault, seePROTECTED == 1, enteropen_unlocked(block)withoutguards(), setOPENING, callVirtualProtect(..., PAGE_READWRITE), and pushOpenedtoOPENED.protect_alias/protect_herethen completesVirtualProtect(..., PAGE_READONLY)(re-protecting the block) and insertsblockintog.protected.settle()popsOpened, removesblockfromg.protected, and clearsPROTECTED+OPENING, leaving the blockPAGE_READONLYwithPROTECTED == 0.VirtualProtectinopen_unlockedfailed (!done),open_unlockedstill pushedOpenedtoOPENED, causingsettle()to clearPROTECTEDeven though the block remained read-only.Fix
reopen_if_opening(block)and call it afterVirtualProtect(..., PAGE_READONLY)inprotect_aliasandprotect_here: ifOPENINGis set onblock, restorePAGE_READWRITE, clearPROTECTED, and keepblockout ofg.protected/g.clean.open_unlocked, if!done, clearTOLD/OPENINGand returnfalsewithout pushing toOPENED.protect_here_restores_block_when_opening_racesincrates/victory-gpu/src/watch.rs.Verification
vkd3d-proton, RTX 3060 12 GB) withVICTORY_FAULT_UNLOCKED=1: eliminated the reproducible multi-threadwrite ...: read-onlycrash during startup/prologue (previously observed in #407).Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-02T16:51:00Z.
This is a correctness fix that should land before the perf PRs. The race window is real:
PROTECTEDset beforeVirtualProtect(PAGE_READONLY)completes means a concurrent fault can enteropen_unlocked, push toOPENED, and latersettle()clearsPROTECTEDwhile the block is still read-only.The
reopen_if_opening()recovery is clean — check OPENING, restore PAGE_READWRITE, clear PROTECTED. The early return inopen_unlockedon!donecorrectly avoids pushing a failed open to OPENED.Minor note: in
protect_here's fast path,note(g, from, to)runs before the OPENING check, so blocks later removed fromg.protectedviareopen_if_openingmay still appear in notes. Is that intentional (the note is best-effort) or should it be guarded?This interacts with #434's
reopen_striped_block— both handle the same class of race. If #434 is rebased on top of this, it could potentially simplify its recovery path.Imported from readmet3xt-lab/foxhound. Originally posted by kwaadrat on 2026-12-02T20:33:08Z.
Thanks for the review!
Regarding
note(g, from, to)inprotect_here's fast path:noteis the local closure that insertsfrom..tointog.protectedandg.clean(both guarded byg: &mut Guards). Right after it, theif OPENING.any(from, to)block loops overfrom..toand immediately removes any reopened block viag.protected.remove(block),g.clean.remove(block), andPUBLISHED.clear(block)before returning (while keepinginsert_all(from..to)intact for the common uncontended case).This invariant is also covered by
protect_here_restores_block_when_opening_races, which asserts!g.protected.contains(b)and!g.clean.contains(b).Imported from readmet3xt-lab/foxhound. Originally posted by tillo88 on 2026-12-03T00:38:54Z.
Replay-bench measurement: no measurable difference on v0.8.3.3 in 3 of 4 runs; one slow run, cause unknown
Measured: PR head
f001988merged onto release v0.8.3.3 (same code as main7dbcdcb), 4 measured runs in two separate jobs (each job after a warm-up run that is not counted), against 4 runs of v0.8.3.3 without the PR, same route (~6.5 min).Mean fps over the three normal runs: PR 36.33 vs release 36.46 (-0.4%), which is no measurable difference. Run 2 was slower for part of the route (mean 26.91 fps, 248 frames over 100 ms); the layer logged no error in that run. Earlier the same evening, before any PR was measured, two release runs with identical switches fell into a similar slow state (6-9 fps average) for an unknown reason, so we cannot tell whether this run is related to the PR. Including it, the PR mean is 33.97 fps.
Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost).
Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default
play-foxhound.ps1settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap.Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
Imported from readmet3xt-lab/foxhound. Originally posted by kwaadrat on 2026-12-03T06:56:17Z.
Thanks for running the replay-bench on Windows 11, @tillo88!
Seeing zero crashes and no measurable delta in the 3 normal runs (
36.33vs36.46 fps,-0.4%) is the expected result here: #457 is purely a correctness fix, and the extra work only triggers whenOPENING.any(from, to)sees a concurrentopen_unlockedrace — the uncontended fast path stays unchanged.The race itself shows up on Linux / Proton Experimental (
vkd3d-proton,VICTORY_FAULT_UNLOCKED=1): without #457,protect_alias/protect_hereracing withopen_unlockedcan leave a blockPAGE_READONLY(0xc0000005write fault), whereas with #457 (alongside #460) we ran crash-free across multiple 7–10 min Proton runs.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.