Repository navigation
Conversation
|
Source review of current head
These are source-level findings. I did not run a build, GPU test, or title on this PR. AI use: Codex (GPT-6.2 Sol) reviewed the integration and existing tracker; Codex (GPT-6.2 Astra) traced the assembly and concurrency paths. |
29be3d1 to
3c29d4b
Compare
|
Thanks for the review. Head is now 3c29d4b.
Suite on 3c29d4b: 2890 passed, 0 failed, 51 ignored, 28 SKIPPED lines (as before). The smoke blocks in the description are rerun on this head. AI use: Claude Code, Claude Fable 5.2 checked both points against the source, wrote the change and this reply, and ran the tests. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
No open or merged PR makes the same change. #2618 (open) adds an older 8-byte-only AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
bmjask
left a comment
There was a problem hiding this comment.
Review of 3c29d4bc: 2 finding(s). 2 are inline.
These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
| use windows_sys::Win32::System::Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE}; | ||
| use windows_sys::Win32::System::Threading::GetCurrentProcess; | ||
| let word = at & !7; | ||
| let width = if (at & 7) + new.len() <= 8 { 8 } else { 16 }; |
There was a problem hiding this comment.
This drops the guard that kept rewrites inside one aligned 8-byte word, and the test that checked it. A thread running the code during the patch can now decode a mix of old and new bytes when the instruction spans the two halves of the 16-byte block. Data reads of a locked cmpxchg16b are atomic, but the x86 manuals don't promise that for instruction fetch or for code already decoded on another core, since cross-modifying code needs serialization. Take monitorx 0F 01 FA at block offset 7 (the GTA 6 site) rewritten to 90 90 90 while another thread runs it. New-low/old-high decodes as 90 then 01 FA = add edx, edi, which silently corrupts EDX. Old-low/new-high decodes 0F 90 90 .. = seto byte [rax+disp32], a write to a random address. For mwaitx (F3 90 90) the mix is F3 01 FB = rep add ebx, edi. The 8-byte path never mixes bytes because the whole instruction is in one word. Patching that's safe across halves needs the int3 method (CC first byte, flush, write the tail, write the first byte), which the stale-exception lookup could treat as retry; that works at any alignment.
There was a problem hiding this comment.
Agreed, and the 16-byte path is gone in 005df98. The word guard is back: rewrite_code rewrites only when the bytes that differ lie in one aligned 8-byte word. A wait across two words now gets a form that differs from it in one word only:
- with two or more bytes in the first word, those bytes become a jump over the rest (
0F 01 FA→EB 01 FA, so only the first byte changes); - with one byte in the first word, the GTA 6 case, the two bytes in the second word become
1F C0, making0F 1F C0.
A core sees either the old instruction or the new one, and no mix like90 01 FAcan occur. A prefixed wait with one byte in the first word stays emulated. The testa_wait_across_two_words_changes_in_one_wordchecks which bytes change at each offset, andthe_one_word_wait_forms_run_as_no_opsexecutes both forms.
|
|
||
| /// `replace_code_word` for an instruction across two words of an aligned 16-byte block. | ||
| unsafe fn replace_code_block(cell: *mut u128, off: usize, expected: &[u8], new: &[u8]) -> bool { | ||
| // a torn read only fails the first compare, which then reloads the block atomically |
There was a problem hiding this comment.
The comment says a torn first read is retried with an atomic reload, but if that read doesn't show expected the function returns false right away without reaching cmpxchg16b. The first read is a plain ptr::read_volatile (~457), which is a non-atomic read of memory other threads may write: a data race in Rust, and one the compiler may split into two 8-byte loads. If the CLWB path (which fills NOPs without holding CODE_REWRITE, #278) writes the block during that read, the mixed value doesn't match expected at off.., the second if returns false, and the site stays emulated for the rest of the run. Taking the first value from compare_exchange_16(cell, 0, 0), as the 8-byte path does with its atomic load, would fix both.
There was a problem hiding this comment.
Moot in 005df98: replace_code_block and its plain 16-byte read are removed. The remaining path is the 8-byte one, which takes its first value with an atomic load.
|
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any. |
3c29d4b to
005df98
Compare
|
Reworked to 005df98 (on main 078358a; still merges cleanly into 395405e) after @bmjask's review. There's no @Foniass, @thehollowedone: your points were on the 16-byte path, which is removed. The CLWB protection race (#278) is handled in #3588, which moves the CLWB patch under Suite on 005df98: 3007 passed, 0 failed, 52 ignored, 28 SKIPPED. Smoke blocks in the description were rerun on this head. On this Intel CPU (no AI use: Claude Code (Claude Opus 5.5) made the change, ran the suite and the runs, and wrote these replies. |
|
Follow-up review of In short: Since the triage of
Nit
Checked and fine
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point. |
On a CPU without monitorx / mwaitx (Intel), the first fault rewrites a console wait in place, but only when the instruction fits in one aligned 8-byte word. GTA 6 has a monitorx at an address ending in 7, so its 3 bytes cross two words: rewrite_code refused it and every poll of that spin loop raised #UD and was emulated (about 2,359 samples of the render thread's kernel time in a 10 s WPR trace). Such a wait now becomes a form that differs from it in one word only, so a thread running it fetches either the old or the new instruction, never half of each: - two bytes or more in the first word: they become a short jump over the rest (0F 01 FA -> EB 01 FA); - one byte in the first word (a plain 3-byte wait): its last two bytes, in the second word, become 1F C0 (0F 1F C0, nop eax). A prefixed wait with one byte in the first word stays emulated. rewrite_code changes only the bytes that differ, in their word, with the same compare-and-retry, lock and page protection as before. The first version of this change wrote the whole 16-byte block with cmpxchg16b; review pointed out that nothing promises another core fetches such a write whole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
005df98 to
6a44255
Compare
|
On the follow-up review of 005df98, pushed 6a44255 (a doc line only):
The previous CI run failed with the lib test process exiting Suite and smoke blocks are updated for 6a44255: 3007 passed, 0 failed, 52 ignored, 28 SKIPPED; 3072 frames, no removal, no crash. AI use: Claude Code, Claude Opus 5.5 wrote this comment. |
|
Follow-up review of In short: This push answers the Nit
Checked and fine
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point. |
On a CPU without
monitorx/mwaitx(Intel), the first fault rewrites a console wait in place, but only when the instruction fits in one aligned 8-byte word. GTA 6 has amonitorxat an address ending in 7, so its 3 bytes cross two words.rewrite_coderefused it, and every poll of that spin loop raised #UD and was emulated. Part of #505.Such a wait now becomes a form that differs from the original in one word only. A thread running it therefore fetches either the old or the new instruction, never half of each:
0F 01 FA→EB 01 FA).1F C0, which makes the whole instruction0F 1F C0(nop eax).Neither cross-word form has room for the
pausean mwaitx gets inside one word, so a spin loop around such an mwaitx runs without one once rewritten.rewrite_codenow changes only the bytes that differ, inside their word, with the same compare-and-retry, lock and page protection as before.The first version of this PR wrote the whole 16-byte block with
cmpxchg16b. Review pointed out that nothing promises another core fetches such a write whole. A thread could then decode a mix, for example90 01 FA(add edx, edi). That path is gone.What is in it
crates/xcl/src/eh.rs:rewrite_codefinds the range of bytes that differ and rewrites it only when it lies in one aligned word;wait_replacementpicks the form above for amonitorx/mwaitxsite;a_wait_across_two_words_changes_in_one_word, which replacesa_rewrite_crossing_an_atomic_word_stays_emulated:0x16,0x26), two bytes in the first word, take the jump;0x37,0x47), one byte in the first word, take0F 1F C0;0x57) stays emulated;main.the_one_word_wait_forms_run_as_no_ops: both forms are executed on this CPU betweenmov eax, 42andret, and the function returns 42.Tested
monitorx, so these rewrites happen on this CPU); Windows 11 Pro 26200; rustc 1.95.0; debug suite, release smoke.cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4on 6a44255 (on main 078358a): 3007 passed, 0 failed, 52 ignored.SKIPPEDon this adapter, 28 in all:no wave64no heap windowsno d3d12SDKLayers.dllno D3D12 debug layermonitorx;Regression run
Each run follows one warm-up run of the same build; the A button is pressed once at 70 s. An earlier run of this head (2259 frames, no removal, no crash) overlapped a release build of another tree on this machine and is left out. The run after it is shown, and a third one had 3061 frames.
Not tested
monitorxat word offset 7 (one byte in the first word), so it takes0F 1F C0, as at0x37in the test.rewrite_code): both changerewrite_code; whichever lands second needs a rebase.monitorx/mwaitxnatively and never take this path.AI use
🤖 Generated with Claude Code