Skip to content

Watch: a late lock-free fault no longer undoes the guard taken since (#817) - #834

Open
GRG-DA wants to merge 2 commits into
trustno1-coder:mainfrom
GRG-DA:fix/watch-late-fault-817
Open

GRG-DA wants to merge 2 commits into
trustno1-coder:mainfrom
GRG-DA:fix/watch-late-fault-817

Conversation

@GRG-DA

@GRG-DA GRG-DA commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #817.

Why

A write fault can check PROTECTED, then reach open_unlocked only after another fault has opened the block and that opening was settled. It finds the block already writable, but still queues an Opened record. A refresh that looked at the block earlier can guard it again in the meantime (read-only, protected, clean). The next settle() takes that stale record, removes the block from the guards and clears PROTECTED while the memory stays read-only. The title's next write there is an access violation no handler takes — seen as segfaults in the victory-gpu unit tests (land, many-askers, refresh) in roughly 1 run in 7.

What

  • open_unlocked records took = !(done && old == PAGE_READWRITE): whether that fault's own VirtualProtect made the block writable. A failed VirtualProtect still takes the genuine path and the locked fallback.
  • settle() leaves a stale entry's guard alone. It clears only that entry's TOLD bits and OPENING, so unsettled() drains and the newer guard, its clean notes, PROTECTED, PUBLISHED, BESIDE and opened_at all survive.
  • Regression test a_late_fault_leaves_the_guard_taken_since: guards two views, queues a stale entry that tells the other view as written, settles, checks that TOLD/OPENING drain while both views keep their guard notes and PROTECTED bit with the block still read-only, then checks that a genuine fault opens it and it is reported once at the next asking. The non-empty others means the TOLD.clear branch of the fix is covered too.

Credit

The root cause and fix are from @Machad3x (issue #817), who published the fix as commit 3175c5dc in Machad3x/VIctory-nvidia-RTX but had not opened a pull request here. This is a port of that commit onto current main, with a longer regression test.

Checks

  • New test: 40 consecutive runs, 0 failures both before and after the others/TOLD coverage was added. cargo test -p victory-gpu --lib watch: 48 passed.
  • cargo test -p victory-gpu --lib: 454 passed, 0 failed on five consecutive runs. The single failure on the first run is a source-documented flake that also reproduces on unmodified main.
  • Whole watch module 100×: 4 failures, all in pre-existing flaky tests; unmodified main under the same loop: 3 failures (the source predicts 1–4 per 100).
  • Negative control: the new test fails on unmodified main at assert!(g.protected.contains(b) && g.clean.contains(b)), so it detects the bug rather than merely describing it.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: only the pre-existing clippy::manual_is_multiple_of at shadow.rs:1708 in an untouched file; with that lint allowed, no findings in changed lines.
  • cargo xtask policy: 294 files ok. git diff --check: clean. No cargo fmt (the tree is not rustfmt-clean).

Not covered

  • No in-game or RTX-card validation. The change is in lock-free bookkeeping and is covered by unit tests only.
  • On unmodified 63b902f in this environment, cargo test --workspace --locked already fails at victory-loader's console_insn::tests::a_clzero_loop_becomes_plain_stores. That is pre-existing and unrelated to this change.

Implemented with OpenCode using parallel agents for issue scouting, contributor-convention mapping, invariant auditing, implementation and independent review.

A write fault that checked PROTECTED, and reached open_unlocked only after
another fault had opened the block and that was settled, found the block
writable already but queued its opening anyway. A refresh that had looked at
the block before guarded it again (read-only, protected, clean); the next
settle then took the stale entry, removed the block from the guards and
cleared PROTECTED while the memory stayed read-only. The title's next write
there was an access violation no handler took.

open_unlocked records took = !(done && old == PAGE_READWRITE): whether that
fault's own VirtualProtect made the block writable. settle leaves an entry
that did not take the block alone, apart from its OPENING and TOLD bits, so
the guard taken since survives. Test a_late_fault_leaves_the_guard_taken_since.

Reported in trustno1-coder#817 by @Machad3x, who published the fix as commit 3175c5dc in
Machad3x/VIctory-nvidia-RTX. Ported onto current main with a longer test.
The regression test queued a stale entry with no `others`, so the
`TOLD.clear(other)` branch added by the fix was never exercised. Let the
entry tell the other view as written, as `open_unlocked` does, and assert
that after settling TOLD and OPENING are gone while both views keep their
guard notes and PROTECTED bit. On the unfixed code the other view's notes
are removed, so this also detects the bug on that path.
@POMXARK

POMXARK commented Nov 28, 2026

Copy link
Copy Markdown

Validated this fix in unit tests and a full 20-minute 3D run on Windows 11 with VICTORY_FAULT_UNLOCKED=1 enabled by default — PASS (0 errors, 0 exceptions, 0 frames >=250 ms across 20 minutes).

Setup

20-Minute Live 3D Validation Results

Metric Result (v22_r11_pr834_20m, 1200 s)
Errors / DevRem / Exceptions 0 / 0 / 0
GPU>=50ms / F>=250ms / F>=500ms 0 / 0 / 0 (worst 3D frame across 20m: 210.1 ms)
1s frame_times (3D, n=1049) 63.8 ms med / 83.1 ms p95 / 93.8 ms p99
Draw-count buckets 1k–4k: 18.80 FPS (n=96), 4k–7k: 15.80 FPS (n=66), 7k–10k: 10.90 FPS (n=37), >=10k: 9.30 FPS (n=8)
HW / Memory (hw.csv) DedMax 11,134 MB, SharedMax 9,680 MB (final 6,482 MB), CommitMax 30,317 MB, MinFreeC 10.90 GB, Resp 329/330

No regressions or rendering anomalies observed under continuous lock-free write-watch fault load.

@yeedgrthfgv

Copy link
Copy Markdown
Contributor

Tested this fix (same change as Machad3x's 3175c5dc) on a Ryzen 5 9600X (6 cores) with an RTX 5080, Windows 11, Series X 4K output, DLSS Performance, frame generation 2x, THIN on, opening prison scene, about 4,800 draws a frame.

One diagnostics run with VICTORY_AB=30,VICTORY_FAULT_UNLOCKED, so the switch flipped every 30 s in the same scene. Per frame, all threads:

guards waits write faults under the lock waiting for it
off 43 to 50 ms 316 to 333 23 to 26 ms
on 7.5 to 12.5 ms 3 to 4 under 0.1 ms

So the switch takes about 35 to 40 ms a frame of waiting off the helper threads. The frame rate did not move on this PC: settled phases were 42.2 ms a frame both ways, and two 4 minute release runs gave 23.1 fps off and 23.5 fps on (within the run to run spread). Here the frame is set by the submitting thread, so the freed time does not show. It may matter more on CPUs with fewer free cores.

No crash, no access violation and no warning with the switch on, both in the run where it flipped 13 times and in a 4 minute run with it on throughout.

Also from the same fork, df65d657 fixes the watch tests that hang or fail together (on this PC the full victory-gpu lib suite failed 19 of 60 runs on 63b902f, 1 of 60 with both commits). Might be worth taking with this one.

@jptorres96

Copy link
Copy Markdown

The new a_late_fault_leaves_the_guard_taken_since passes, and the full victory-gpu lib suite (454 tests) is green.

Env: RTX 4080 SUPER (driver 621.01), Ryzen 5 5600X, Windows build 26300, rustc 1.98.1, DXC 1.9.2609.5 (VICTORY_DXIL), --test-threads=1. VICTORY_INDIRECT_REST=1 set to sidestep main's two indirect budget-test failures (fixed in #67), unrelated to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants