ProjectScarlett: clzero, monitorx and mwaitx crash on Intel CPUs (AMD-only instructions) #145

Closed
opened 2026-11-26 06:34:22 +00:00 by github-bot · 0 comments
Owner

@⁠JeffreyBytes on GitHub · 2026-11-25 05:22 UTC · original

Summary

On an Intel Core i5-12600K (Alder Lake), ProjectScarlett exits about 14 seconds after launch with EXCEPTION_ILLEGAL_INSTRUCTION. Exit code 29. The faulting instruction is clzero. The Xbox Series CPU (Zen 2) supports it, but no Intel CPU does. This is a different instruction from #71: this CPU has clwb, so the #80 handler returns straight away.

01e0:warn:seh:dispatch_exception EXCEPTION_ILLEGAL_INSTRUCTION exception (code=c000001d) raised
01e0:warn:seh:virtual_unwind backtrace: 0000000144E8AA70: L"game_scarlett_master.exe" + 0000000004E8AA70.
01e0:warn:seh:virtual_unwind backtrace: 0000000144E8A9FD: L"game_scarlett_master.exe" + 0000000004E8A9FD.
01e0:warn:seh:virtual_unwind backtrace: 0000000144E8A64D: L"game_scarlett_master.exe" + 0000000004E8A64D.
144e8aa70:  0f 01 fc       clzero
144e8aa73:  48 83 c0 40    add    rax,0x40
144e8aa77:  4c 39 d0       cmp    rax,r10
144e8aa7a:  72 f4          jb     144e8aa70

clzero zeroes the 64-byte cache line containing the address in RAX. Here it clears a range of an object one line at a time.

With clzero handled, the game ran for 70 s and then crashed the same way on monitorx, AMD's user-mode wait instruction:

144fb0bd0:  48 89 f8       mov    rax,rdi
144fb0bd3:  31 c9          xor    ecx,ecx
144fb0bd5:  31 d2          xor    edx,edx
144fb0bd7:  0f 01 fa       monitorx
144fb0bda:  48 8b 17       mov    rdx,QWORD PTR [rdi]
...
144fb0bf9:  b9 02 00 00 00 mov    ecx,0x2
144fb0bfe:  31 c0          xor    eax,eax
144fb0c00:  0f 01 fb       mwaitx

Affected sites

A full disassembly of the executable finds 14 AMD-only instructions in two functions (RVAs). The scan also matched rdpru bytes at 0x4761A33, but those are inside a call operand, not an instruction.

RVA Instruction Form
0x4e8aa70, 0x4e8aa90, 0x4e8aab0, 0x4e8aad0, 0x4e8aaf0 clzero clzero; add rax,0x40; cmp rax,rN; jb
0x4e8ab2d clzero same loop form
0x4e8ab53, 0x4e8ab72, 0x4e8ab91, 0x4e8abb4 clzero cmp rN,rM; jb back to an earlier add (other loop shape)
0x4fb0bd7, 0x4fb0d21 monitorx arm a watch on [rdi]
0x4fb0c00, 0x4fb0d52 mwaitx wait with timer (ecx=2)

Workaround (verified)

clzero can't be rewritten in place like clwb → clflushopt, because no other 3-byte instruction zeroes a line. The waits can, with a single byte. I handled both in the existing vectored exception handler:

  • clzero: zero the 64-byte line at RAX & ~63 and resume after the instruction. When the exact clzero; add rax,0x40; cmp rax,rN; jb loop follows the fault, clear every line the loop would clear, set RAX to its exit value and resume at the cmp, so one trap covers the whole loop. Writability is checked first. If the range isn't writable, it falls back to one line, and a line real hardware would fault on is left to fault.
  • monitorx / mwaitx: turn them into no-ops. Neither changes registers, flags or memory, and mwaitx may return at any time, so the caller already re-checks [rdi] in a loop. Stepping over each one in the handler works, but the wait loop runs continuously: in a 66-minute run, one thread trapped about 6,000 times a second, Wine's warn:seh lines grew the log to 53 GB, and presents fell from ~80 to ~5 per second. So on the first fault the handler rewrites the second opcode byte 01 → 1F. 0F 1F FA and 0F 1F FB are the same-length reserved-NOP form 0F 1F /r, the change is a single atomic byte store like the clwb rewrite, and later iterations run natively. A thread that faulted on the original bytes before the store resumes at the same address and runs the NOP. If the page can't be made writable, it falls back to stepping over the instruction.

Both only act when CPUID reports the instruction missing (0x8000_0008 EBX bit 0 for CLZERO, 0x8000_0001 ECX bit 29 for MONITORX) and the fault is inside the title image, like the clwb handler. Unit tests cover the game's exact bytes, the loop arithmetic against a line-by-line model, unwritable memory, the in-place rewrite (including restoring page protection, and a second thread that faulted before the store), and decoder rejections. One test executes the rewritten 0F 1F FA / 0F 1F FB natively on this CPU. The d3d12 suite passes under Wine (86/86).

Result on this machine with clzero handled and the waits stepped over (before the in-place rewrite): no unhandled fault in 66 minutes. I stopped the run by hand. All five first-group clzero loops and both wait sites were handled. The window stayed black throughout: the game presented frames and translated 6,350 shaders (1,897 refused), but I saw no image and never reached gameplay. So this fixes the CPU crashes only. It doesn't change rendering.

With the in-place rewrite (the final version): each wait site trapped once and was rewritten, and after that the wait loop ran natively. No illegal-instruction fault went unhandled in 32 minutes, and no new AMD-only site turned up. I stopped the run by hand. That isn't a stability result: the game never got past a black screen, so it reached less far than the NVIDIA runs that later crashed in Game Running. What remains is about 250 traps a second from the clzero loops, one per loop, and the log grew about 150 MB an hour instead of 50 GB. The window is still black and presents run at about 6 per second. Profiling puts that on the GPU side, not the CPU: one vkd3d queue thread spends a full core inside RADV's command-submission ioctl with the GPU 2–4% busy, while the game holds 12,000–17,000 GPU buffers. That's a separate issue, and I'll file it on its own.

The four clzero sites with the other loop shape haven't been hit yet. They would trap once per line with the current handler, which is correct but slower.

Suggested fix

Add the two handlers next to clwb.rs (clzero.rs, mwaitx.rs) and call them from the vectored exception handler in survey.rs. I have this on JeffreyBytes:fix/amd-only-cpu-instructions (one commit on 97b8ad3) and will open a PR that links here.

Environment

  • Package RockstarGamesInc.28872443D20A7 1.0.2.1, game_scarlett_master.exe SHA-256 e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993
  • CPU: Intel Core i5-12600K (has clwb and clflushopt; no clzero or monitorx in /proc/cpuinfo)
  • GPU: AMD Radeon RX 6700 XT, RADV, Mesa 26.3.1
  • Proton: 1794497090 experimental-11.0-20261112-x86_64, umu-launcher 1.4.3
  • OS: CachyOS, kernel 7.3.5
  • TuxBox: 97b8ad3 (crash), 97b8ad3 + e1262ac (fix)
  • Launched offline with unshare --user --map-current-user --net, as in the docs

Full logs are available on request. They contain local paths and the console ID, so I've quoted the relevant lines above instead.

**@⁠JeffreyBytes** on GitHub · 2026-11-25 05:22 UTC · [original](https://github.com/brcly/TuxBox/issues/145) ## Summary On an Intel Core i5-12600K (Alder Lake), ProjectScarlett exits about 14 seconds after launch with `EXCEPTION_ILLEGAL_INSTRUCTION`. Exit code 29. The faulting instruction is `clzero`. The Xbox Series CPU (Zen 2) supports it, but no Intel CPU does. This is a different instruction from #71: this CPU has `clwb`, so the #80 handler returns straight away. ``` 01e0:warn:seh:dispatch_exception EXCEPTION_ILLEGAL_INSTRUCTION exception (code=c000001d) raised 01e0:warn:seh:virtual_unwind backtrace: 0000000144E8AA70: L"game_scarlett_master.exe" + 0000000004E8AA70. 01e0:warn:seh:virtual_unwind backtrace: 0000000144E8A9FD: L"game_scarlett_master.exe" + 0000000004E8A9FD. 01e0:warn:seh:virtual_unwind backtrace: 0000000144E8A64D: L"game_scarlett_master.exe" + 0000000004E8A64D. ``` ``` 144e8aa70: 0f 01 fc clzero 144e8aa73: 48 83 c0 40 add rax,0x40 144e8aa77: 4c 39 d0 cmp rax,r10 144e8aa7a: 72 f4 jb 144e8aa70 ``` `clzero` zeroes the 64-byte cache line containing the address in RAX. Here it clears a range of an object one line at a time. With `clzero` handled, the game ran for 70 s and then crashed the same way on `monitorx`, AMD's user-mode wait instruction: ``` 144fb0bd0: 48 89 f8 mov rax,rdi 144fb0bd3: 31 c9 xor ecx,ecx 144fb0bd5: 31 d2 xor edx,edx 144fb0bd7: 0f 01 fa monitorx 144fb0bda: 48 8b 17 mov rdx,QWORD PTR [rdi] ... 144fb0bf9: b9 02 00 00 00 mov ecx,0x2 144fb0bfe: 31 c0 xor eax,eax 144fb0c00: 0f 01 fb mwaitx ``` ## Affected sites A full disassembly of the executable finds 14 AMD-only instructions in two functions (RVAs). The scan also matched `rdpru` bytes at 0x4761A33, but those are inside a `call` operand, not an instruction. | RVA | Instruction | Form | | --- | --- | --- | | `0x4e8aa70`, `0x4e8aa90`, `0x4e8aab0`, `0x4e8aad0`, `0x4e8aaf0` | `clzero` | `clzero; add rax,0x40; cmp rax,rN; jb` | | `0x4e8ab2d` | `clzero` | same loop form | | `0x4e8ab53`, `0x4e8ab72`, `0x4e8ab91`, `0x4e8abb4` | `clzero` | `cmp rN,rM; jb` back to an earlier `add` (other loop shape) | | `0x4fb0bd7`, `0x4fb0d21` | `monitorx` | arm a watch on `[rdi]` | | `0x4fb0c00`, `0x4fb0d52` | `mwaitx` | wait with timer (`ecx=2`) | ## Workaround (verified) `clzero` can't be rewritten in place like `clwb` → `clflushopt`, because no other 3-byte instruction zeroes a line. The waits can, with a single byte. I handled both in the existing vectored exception handler: - **`clzero`**: zero the 64-byte line at `RAX & ~63` and resume after the instruction. When the exact `clzero; add rax,0x40; cmp rax,rN; jb` loop follows the fault, clear every line the loop would clear, set RAX to its exit value and resume at the `cmp`, so one trap covers the whole loop. Writability is checked first. If the range isn't writable, it falls back to one line, and a line real hardware would fault on is left to fault. - **`monitorx` / `mwaitx`**: turn them into no-ops. Neither changes registers, flags or memory, and `mwaitx` may return at any time, so the caller already re-checks `[rdi]` in a loop. Stepping over each one in the handler works, but the wait loop runs continuously: in a 66-minute run, one thread trapped about 6,000 times a second, Wine's `warn:seh` lines grew the log to 53 GB, and presents fell from ~80 to ~5 per second. So on the first fault the handler rewrites the second opcode byte `01` → `1F`. `0F 1F FA` and `0F 1F FB` are the same-length reserved-NOP form `0F 1F /r`, the change is a single atomic byte store like the `clwb` rewrite, and later iterations run natively. A thread that faulted on the original bytes before the store resumes at the same address and runs the NOP. If the page can't be made writable, it falls back to stepping over the instruction. Both only act when CPUID reports the instruction missing (`0x8000_0008` EBX bit 0 for CLZERO, `0x8000_0001` ECX bit 29 for MONITORX) and the fault is inside the title image, like the `clwb` handler. Unit tests cover the game's exact bytes, the loop arithmetic against a line-by-line model, unwritable memory, the in-place rewrite (including restoring page protection, and a second thread that faulted before the store), and decoder rejections. One test executes the rewritten `0F 1F FA` / `0F 1F FB` natively on this CPU. The d3d12 suite passes under Wine (86/86). Result on this machine with `clzero` handled and the waits stepped over (before the in-place rewrite): no unhandled fault in 66 minutes. I stopped the run by hand. All five first-group `clzero` loops and both wait sites were handled. The window stayed black throughout: the game presented frames and translated 6,350 shaders (1,897 refused), but I saw no image and never reached gameplay. So this fixes the CPU crashes only. It doesn't change rendering. With the in-place rewrite (the final version): each wait site trapped once and was rewritten, and after that the wait loop ran natively. No illegal-instruction fault went unhandled in 32 minutes, and no new AMD-only site turned up. I stopped the run by hand. That isn't a stability result: the game never got past a black screen, so it reached less far than the NVIDIA runs that later crashed in Game Running. What remains is about 250 traps a second from the `clzero` loops, one per loop, and the log grew about 150 MB an hour instead of 50 GB. The window is still black and presents run at about 6 per second. Profiling puts that on the GPU side, not the CPU: one vkd3d queue thread spends a full core inside RADV's command-submission ioctl with the GPU 2–4% busy, while the game holds 12,000–17,000 GPU buffers. That's a separate issue, and I'll file it on its own. The four `clzero` sites with the other loop shape haven't been hit yet. They would trap once per line with the current handler, which is correct but slower. ## Suggested fix Add the two handlers next to `clwb.rs` (`clzero.rs`, `mwaitx.rs`) and call them from the vectored exception handler in `survey.rs`. I have this on [`JeffreyBytes:fix/amd-only-cpu-instructions`](https://github.com/JeffreyBytes/TuxBox/tree/fix/amd-only-cpu-instructions) (one commit on `97b8ad3`) and will open a PR that links here. ## Environment - Package `RockstarGamesInc.28872443D20A7` 1.0.2.1, `game_scarlett_master.exe` SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993` - CPU: Intel Core i5-12600K (has `clwb` and `clflushopt`; no `clzero` or `monitorx` in `/proc/cpuinfo`) - GPU: AMD Radeon RX 6700 XT, RADV, Mesa 26.3.1 - Proton: 1794497090 experimental-11.0-20261112-x86_64, umu-launcher 1.4.3 - OS: CachyOS, kernel 7.3.5 - TuxBox: `97b8ad3` (crash), `97b8ad3` + `e1262ac` (fix) - Launched offline with `unshare --user --map-current-user --net`, as in the docs Full logs are available on request. They contain local paths and the console ID, so I've quoted the relevant lines above instead.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:34:22 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.