Skip to content

Loader: resume late faults through recorded console instruction replacements (#2393) - #2585

Open
fainty0 wants to merge 2 commits into
trustno1-coder:mainfrom
fainty0:fix/2393-late-console-fault
Open

fainty0 wants to merge 2 commits into
trustno1-coder:mainfrom
fainty0:fix/2393-late-console-fault

Conversation

@fainty0

@fainty0 fainty0 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #2393

What it changes

A late illegal-instruction fault could go unhandled if another thread had already replaced the faulting instruction. The handler now snapshots code under the patch lock and resumes only when the bytes exactly match a replacement it installed at that address. It enters generated stubs directly and retries inline replacements in place. Stubs are flushed before their jumps are installed. The site flush is best-effort: the bytes were already written and must remain recognisable even if the flush fails. CLWB falls back to emulation when it cannot be patched atomically.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): none; no GPU or game used.
  • Before: the handler could not decode the replacement bytes and returned the late fault unhandled.
  • After: Windows cross-target clippy showed no new diagnostics in either workspace gate or either loader-only gate. The CPU-only regression covers insertq, extrq, monitorx, mwaitx, the clzero loop and clwb, and rejects altered or unrecorded bytes. It was type-checked but not run (no Windows); runtime behaviour was not verified.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): n/a; no shader changes.
  • cargo test passed for the crates it touches: no. Eleven Linux loader unit tests passed; one unchanged PE-only test failed on the Linux test executable with Unknown file magic on both main and the branch. Windows tests were not run (no Windows).

Checked for overlap

usehoplite Bot and others added 2 commits November 29, 2026 14:13
…cements (trustno1-coder#2393)

Co-authored-by: Andrei Turcan <360425173+fainty0@users.noreply.github.com>
Co-authored-by: Andrei Turcan <360425173+fainty0@users.noreply.github.com>
@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-fix] Loader: resume late faults through recorded console instruction replacements (#2393) Loader: resume late faults through recorded console instruction replacements (#2393) Nov 29, 2026
@Kassadd

Kassadd commented Nov 29, 2026

Copy link
Copy Markdown

Independent confirmation of the race under Wine, with a runtime result this
branch does not have.

Environment: RTX 4080 SUPER 16 GB, i9-14900K (no SSE4a), CachyOS,
NVIDIA 620.73.04, Series X 1.0.2.1, victory.exe from release v2026.11.29.01.
Two runtimes, same result: GE-Proton 11-14 and Proton Experimental
(experimental-bleeding-edge-11.0-482815-20261128, vkd3d-proton 71cae0).

The same fault, in the same shape as #2614's report. Two run-ending
0xc000001d in a few minutes of play, at different addresses, both with our
own e9 … 90 where a console instruction used to be:

unhandled exception 0xc000001d at victory-image-b99f876b74d4a77f.dll+0x27c8f2
  (code e9 69 3a a0 ff 90 90 c4 e2 79 31 c9 c5 e1 72)

unhandled exception 0xc000001d at victory-image-b99f876b74d4a77f.dll+0x55b1811
  (code e9 4a eb 6c fa 90 c4 e2 79 21 c9 c5 f8 5b c9)

The bytes in the file at those RVAs are f2 44 0f 78 cf 08 00 and
f2 0f 78 c9 08 18: insertq in both cases. So the rip holds our jump, and
only a fault taken on the old bytes explains it, exactly as #2614 says.

A control that settles it without patching any code. This tree already has
VICTORY_PATCH_SSE4A=0, which emulates every time instead of replacing. With
it the crash does not happen at all: a 4-minute run reached 464,947 fences and
the only failure after that was a device lost (0x887A0005), which is a
different problem. Without it, the run ends in 0xc000001d in 1-3 minutes. That
is the race, isolated by a switch: no code touched, no build needed.

And I built your branch and ran it here, on top of #2060/#2160/#2240/#2188
(Rust 1.98.1, cargo-xwin, MSVC target; the merge applied with no conflict):

  • 0xc000001d: gone. Before, a run ended in 1-3 minutes; this one did not
    fault once.
  • In the world: 9.6 to 29.5 fps, ending at 29.5 fps / 33.8 ms with
    5,551-5,661 draws/frame — against 3.7 fps for the same configuration
    before the fix. The spread is the pipeline building, not steady state.
  • The run ended on a device lost (0x887A0005) at fence 243,453 after
    several minutes. That is a separate problem (VRAM), not this one, and it is
    what the game now reaches because the fault no longer stops it.

For comparison, a fix I wrote that only took E9 jumps gave 30.5 fps and 4,773
draws: the same place, so your broader coverage (monitorx/mwaitx/clwb)
costs nothing and closes the cases mine would have left open. Yours is the one
worth taking.

Not the same as the libnvidia-gpucomp crash. docs/linux-proton.md
records a 0xc000001d inside NVIDIA's shader compiler during
vkCreateComputePipelines; that one is avoided by changing Proton. The fault
here is in the title's code and is unchanged by the runtime, which fits the
diagnosis in this PR being platform-independent.

What I did not do: test on Windows, or run it long enough to reach a steady
state past pipeline building. Logs and the exact invocation are available on
request.

@tempodat

Copy link
Copy Markdown

@Kassadd Weirdly enough i just encountered this same crash under wine (following the same docs/linux-proton.md file as a guide). might actually be an indicator that it's a wine/proton specific issue. for future reference adding --set VICTORY_PATCH_SSE4A=0 to the end of the victory.exe play line got around the issue.

@AimLogin

Copy link
Copy Markdown

Review note (read from the diff, not run on this branch):

The ordering looks right to me. The replacement is recorded while PATCHING is still held, and emulate copies the fault bytes and does the lookup under the same lock, so a late thread that sees the new bytes always finds the record. The exact byte match means a site that changed again afterwards is not mistaken for ours. #2614 handles the same issue but records after the store and looks up without the patch lock, which leaves a short window open (details there).

Two small points:

  • patch_sse4a now accepts 5–8 bytes instead of 5–16. SSE4a sites of 9–16 bytes, which can occur with extra prefixes, are no longer replaced and go back to one exception per execution. That costs speed, not correctness. If it is intended, a line in the description would help.
  • Since the description says the Windows tests were not run: we implemented the same scheme independently in a local tree (record under the patch lock, exact byte match). On Windows 11, a test that faults a second time at a replaced mwaitx, at the 12-byte clzero loop and at an insertq resumes and writes nothing again. Its control, the old logic without the record, returns the unhandled fault. That supports the design but is not a run of this branch.

Review was AI-assisted.

@Kassadd

Kassadd commented Nov 29, 2026

Copy link
Copy Markdown

Update: rerun on the current tree (v2026.11.29.03). The numbers in my earlier
comment were from v2026.11.29.01, before the 29.02/29.03 hotfixes. This is what
changed.

Built main at cec481f4 (the tree of v2026.11.29.03) with this PR merged on top — it
applied with no conflict — and ran it. Environment unchanged from my earlier comment:
RTX 4080 SUPER 16 GB, i9-14900K (no SSE4a), CachyOS, NVIDIA 620.73.04, Proton
Experimental ...-20261128 (vkd3d-proton 71cae0), Series X 1.0.2.1,
--res 1080to1440, shader cache emptied first as the release notes ask.

  • No 0xc000001d in a 5-minute run at 4,000–11,795 draws/frame. On the same tree
    without this PR a run ends in 0xc000001d within 1–3 minutes, with
    e9 b9 ba 3f fa 90 c4 e2 79 21 c0 at +0x5084782 — the shape Console instructions: a fault raced by its own patch runs the new bytes #2614 reports. So the
    fault this PR closes is still present in the .03 tree and still reachable in play.
  • 19–29 fps in the world, single samples throughout (I did not take a distribution).
  • About 300 draws a frame still dropped, with 0 being made, constant rather than
    growing. That is not this PR: it also happens with the console-instruction patch
    turned off entirely (VICTORY_PATCH_SSE4A=0), so it is the bind path or the sky miss
    and I have not isolated which.

On attribution, to be precise about what I have. Three runs on this tree:

run duration ended
.03 as released 1–3 min 0xc000001d (SSE4a race)
.03 + this PR only 5m 06s still running when I stopped it; no fault
.03 + this PR + #2455 6m 13s still running when I stopped it; no fault

So this PR alone did carry a run past five minutes, which is why the table is here rather
than a claim; what #2455 adds on top I cannot separate from these numbers. The useful
part is the first line against the other two: the fault fires in 1–3 minutes on the
released tree and did not fire at all with this PR.

What I did not verify: Windows, or a run past the opening. Logs on request.

@gabrielecabrini

Copy link
Copy Markdown
Contributor

I closed my #2614 for this one: it fixes the same #2393 without the gap between the store and note_patched that mine left open. +1 for landing this.

@superuser404notfound

Copy link
Copy Markdown

The Windows unit tests of this branch, run (the description says they were type-checked only).

Environment: i7-13700KF (no SSE4a), RTX 4080, CachyOS kernel 7.3.6, GE-Proton 11-11
(wine-staging 11.0), Series X 1.0.2.1. Built with cargo xwin (Rust 1.98.1, MSVC target) on
main at 716a0c9 with this PR merged on top; the merge applied with no conflict.

Tests: cargo xwin test --release --locked -p victory-loader --lib console_insn, the test
executable run under Wine 11 as the cargo runner: 10 passed, 0 failed, including the new
late_faults_resume_only_through_the_exact_installed_replacement. These are the tests that were
not run anywhere before.

The fault, a third time on other hardware and another Proton: on 716a0c9 without this PR,
a run ended about six minutes in (game frame 57,957) with

VIctory: unhandled exception 0xc000001d at victory-image-b99f876b74d4a77f-p2f9ea84c.dll+0x5084782
  (code e9 79 bb 0f 06 90 c4 e2 79 21 c0 c5 f8 5b c0)

the same site and shape as #2614 and Kassadd's .03 run.

Not done: an in-game run of this branch here (the runtime result above is Kassadd's), or
Windows. Unrelated to this PR, noted only so nobody chases it: crash::tests::concurrent_crash_records_stay_together
fails under Wine on main as well.

Tests run and comment written with Claude Code (AI-assisted).

@Kassadd

Kassadd commented Nov 30, 2026

Copy link
Copy Markdown

The fault is still there on v2026.11.29.05, which is the point: this PR has to
reach main to have any effect, and each release since .01 has shipped without it.

Ran the released v2026.11.29.05 binary (SHA-256
80612b22a3cb7650…) with no patches, same machine and Proton Experimental as my
comment above. It died on the way into the world with

unhandled exception 0xc000001d at victory-image-b99f876b74d4a77f-p2f9ea84c.dll+0x5084782
  (code e9 b9 ba bf fa 90 c4 e2 79 21 c0 c5 f8 5b c0)

+0x5084782 again — the same site and shape as #2614, as superuser404notfound's run
on 716a0c9, and as my .03 run. Then main (41adb551, the .05 tree) with this PR and #2455 merged
ran for over four minutes in the world at 17-18 fps and 6,077 draws a frame, with no
0xc000001d in the log at all. So .04 and .05 changed neither the bug nor its address.

That is why I think this one should not wait for a quiet moment: every release the
Linux users get is a build where the opening dies at random, and the only alternative
they have is VICTORY_PATCH_SSE4A=0, which emulates every SSE4a instruction instead of
replacing it — measurably slower, and it leaves the monitorx/mwaitx half of the
race open (as this PR's own description says).

Nothing new about the code itself; the tests above and gabrielecabrini's and
superuser404notfound's reports cover that ground better than I could.

@Kassadd

Kassadd commented Nov 30, 2026 •

Copy link
Copy Markdown

@tempodat — thanks for confirming it under Wine, another independent report at the same site.

But VICTORY_PATCH_SSE4A=0 is a workaround, not a fix: it emulates every SSE4a instruction
instead of replacing it, and it leaves the monitorx/mwaitx half of the race open.

You no longer need to wait for anything. main has had this fix since 1cdcb94, co-authored
by @fainty0 — the same change, landed 26 minutes before this PR was opened. I built main at
c71899d with no patch: no 0xc000001d. Drop the switch and get the speed back.


On closing this PR — the remaining diff against main is one line:

-    flush_code(at, len);
+    let _ = flush_code(at, len);

Everything else is already in main point for point, which is what this thread's four reports
were measuring. That line is a real improvement — if the flush fails the bytes are still written,
so aborting the record loses them — but it does not need 131 lines, and a merge would land it
under a description that no longer matches.

The thread is now doing the opposite of what it was written for: two people have concluded they
need a fork build or the slow switch. Neither is true.

My suggestion: close this one, keeping the credit for the diagnosis, and open a small PR with that
line plus a test where flush_code is made to fail. If you would rather merge it as a one-liner,
that is fine too — the fix lands either way.

Not tested by me: Windows, and the failing-flush path itself.

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

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intel: 0xc000001d when two threads reach an SSE4a instruction while it's being replaced (#1653)

6 participants