Console instructions: a fault raced by its own patch runs the new bytes #2614
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2614"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by gabrielecabrini on 2026-11-29T14:58:13Z.
What
A console-only instruction (
insertq,extrq,monitorx,mwaitx, aclzeroloop,clwb) is replaced in the title's code the first time it faults. When two threads hit the same site, one can fault on the old bytes while the other replaces them. The late thread's handler then reads the new bytes at itsrip(ourjmpto the stub, or the no-ops), which do not decode as console-only, soemulatereturned 0 and the title died with an unhandled0xc000001d.Evidence
4.5 minutes into play on an Intel i5-14600KF (no SSE4a), Proton Experimental, RTX 4070 SUPER (2026-11-29):
e9 …. 90at the faulting address is our own jump over a 6-byteinsertq: an illegal-instruction fault on a validjmp, which only a fault taken on the old bytes explains.Fix
crates/victory-loader/src/console_insn.rs:patch()(waits,clzeroloops, SSE4a) and theclwbpath note the address they replaced in aPATCHEDlist.emulate, when the bytes atripdo not decode andripis a noted place, it returnsCONTINUE_EXECUTIONwithout movingrip: the thread runs the new code.VICTORY_PATCH_SSE4A=0 VICTORY_PATCH_WAITS=0 VICTORY_PATCH_CLZERO=0was the only way around it, at the cost of one exception per execution (oneinsertqalone faulted ~3,700 times a second).Tests
an_sse4a_instruction_becomes_sse2now also faults a second time at the patched place, as the late thread would, and expectsCONTINUE_EXECUTIONwithripunchanged.console_insntests pass (cross-built withcargo xwin, run under Proton).cargo clippy -p victory-loader --all-targets -- -D warningsstops at an unusedcrash::unwind_copywithoutdiagnostics; that error was already onmainbefore this change.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-29T15:40:09Z.
Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch
janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with--profile diag --features diagnostics, and the CPU tests of the touched crates pass. Runs on an RTX 4090 are queued (Series X 1440p, and Series S with ray tracing, DLSS Quality). Frame times will follow here.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AimLogin on 2026-11-29T19:27:14Z.
Review note on the race fix (read from the diff, not run):
One window is still open.
note_patchedis called only after thecmpxchg16bstore,VirtualProtectandFlushInstructionCache, andwas_patchedtakes onlyPATCHED, notPATCHING. A thread that faulted on the old bytes can therefore read the new bytes atripwhile the patching thread is between the store andnote_patched. It finds no entry,emulatereturns 0, and the title still dies with0xc000001d. The two system calls make that gap wider than it looks. Theclwbpath has the same order (note_patched(rip)after the secondVirtualProtect).Either change closes it:
PATCHINGbefore the lookup inwas_patched, so a late thread waits for a patch in flight, which has recorded its site before it releases the lock;#2585 fixes the same #2393 by reading the fault bytes under the patch lock and matching them exactly against the recorded replacement, so the two PRs overlap and probably only one should land.
Review was AI-assisted.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gabrielecabrini on 2026-11-29T22:08:18Z.
Closing in favour of #2585, which fixes the same #2393 and closes the window AimLogin pointed out here (the replacement is recorded under
PATCHINGand the late fault is matched under the same lock). One fix for this is enough.Pull request closed