Repository navigation
Conversation
|
Rerun on the new head ( merge-check
Earlier report on 9ac6998 (base 6bfb5c5) |
|
Review (head 9ac6998, diff read, not a merge-check):
Fine: the patch now takes AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
A CLWB on a CPU without it is patched out at its first fault. The patch made the bytes writable, filled them with NOPs one at a time and put the protection back, with nothing shared between threads (xcl-dev#278, item 4): - two threads patching on one page could restore each other's protection (also against the wait rewrite, which holds CODE_REWRITE); - another thread could run the half-written bytes (90 0F AE 30 is a nop and xsaveopt [rax]); - a thread that faulted on the CLWB just before the patch found NOPs, which do not decode, and its fault went on to the title's handlers; - the instruction cache was never flushed. The patch now goes through rewrite_code, like the waits: the first two bytes become a short jump over the instruction in one atomic word write under CODE_REWRITE, the protection is restored, the cache is flushed, and a thread that faulted on the old bytes is retried at the jump. The bytes after the jump stay as they were. A site whose first two bytes cross an aligned 8-byte word cannot take the jump in one write. Its opcode and ModRM bytes, which are both in the second word, become those of the NOP with the same operand (0F AE /6 -> 0F 1F /0): the prefixes and the operand bytes stay, so the length is the same and the site is patched once like the others (rewrite_code_within records the site with its unchanged prefix). A visit with TF set still leaves the code alone (xcl-dev#571). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
9ac6998 to
81ad460
Compare
|
On the review of 9ac6998: both points checked against the source; the first is fixed in 81ad460. One CLWB site in eight faulted at every visit: right. Clash with #1829: yes, its Suite on 81ad460: 2906 passed, 0 failed, 51 ignored, 28 SKIPPED lines. The smoke block in the description is rerun on this head (3082 frames, no device removal, no crash). Not done: the NOP form was not executed on a CPU, the test checks bytes. AI use: Claude Code, Claude Fable 5.2 checked the points against the source, wrote the change and this comment and ran the tests. |
|
Follow-up review (head 81ad460, since 9ac6998, diff read, not a merge-check):
New:
Fine: only the opcode and ModRM bytes change, both in one aligned word; AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
On a CPU without CLWB (older Intel), XCL patches the instruction out at its first fault. The patch made the bytes writable, filled them with NOPs one at a time and restored the protection, with nothing shared between threads. This is item 4 of #278, the part #321 addressed before it was closed with conflicts; #571 fixed only the single-step case. Part of #278.
What could go wrong on
main:CODE_REWRITE. The page could stay writable, or turn read-only while the other thread still wrote.90 0F AE 30is a nop followed byxsaveopt [rax]).The patch now goes through
rewrite_code, like the waits: the first two bytes become a short jump over the instruction (EB, len - 2) in one atomic word write underCODE_REWRITE, the protection is restored, the cache is flushed, and a thread that faulted on the old bytes is retried at the jump. The bytes after the jump stay as they were.A site whose first two bytes cross an aligned 8-byte word (one address in eight) cannot take the jump in one write. Its opcode and ModRM bytes, which are both in the second word, become those of the NOP with the same operand (
0F AE /6to0F 1F /0, e.g.66 0F AE 30to66 0F 1F 00): prefixes and operand bytes stay, the length is the same, and the site is patched once like the others (review on 9ac6998).What is in it
crates/xcl/src/eh.rs, theConsoleOnly::Clwbarm ofemulate_console_only: callsrewrite_code(rip, first two bytes, [EB, len - 2])instead of its own protect / fill / restore. A visit with TF set still leaves the code alone (Console CPU instructions: leave CLWB intact while single stepping #571). A site whose first two bytes cross an aligned 8-byte word takes the NOP form throughrewrite_code_within, which writes inside the instruction and records the site with its unchanged prefix, so a stale fault is retried there too.clwb_and_a_wait_patched_at_once_on_one_page_keep_its_protection: 32 threads fault at once on a CLWB and on amonitorxin one page; every fault is handled, both sites are patched whole and the page is read-execute afterwards.clwb_across_an_atomic_word_becomes_a_nop_with_its_operand: a CLWB at word offset 7, with and without a REX prefix, becomes the NOP of the same length, the bytes around it stay, and a second fault at the site is retried there.clwb_single_step_keeps_code_and_normal_faults_still_patch(changed): expects the jump and the untouched tail, and checks that a second fault at the patched address is retried there.Tested
cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4on 81ad460 (on main 6bfb5c5): 2906 passed, 0 failed, 51 ignored.SKIPPEDon this adapter: 28: 22no wave64; 2no heap windows; 2no d3d12SDKLayers.dll; 1no D3D12 debug layer; 1 cannot disable the driver cache (no Developer Mode).illegal instruction ... code bytes 90 90 90 90 90 90(the late faulter) and one run ended inSTATUS_ACCESS_VIOLATION(the protection race).Regression run
Each run follows one warm-up run of the same build; the A button is pressed once at 70 s. Earlier in this session the title lost the D3D12 device (0x887a0006, DRED state 7, no breadcrumbs) between 118 s and 123 s in 2 of 4 runs of main 6bfb5c5 and in 2 of 4 runs of the previous head, interleaved; the two runs of this head (warm-up and the block above) had none. The log has no CLWB patch line in any run (this CPU executes CLWB), so the changed code did not run in them.
Not tested
CONTEXT. The smoke runs are a regression check only.66 [REX] 0F 1F /0with the site's operand bytes) was not executed: the test checks the patched bytes, the bytes around them and the retry of a stale fault.clwb_patches_instruction_bytes_to_nop_and_advances_rip, which expects NOP bytes at an ordinary site; whichever of the two lands second has to adjust that test.AI use
🤖 Generated with Claude Code