Console CPU instructions: leave CLWB intact while single stepping #566
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/571"
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 ivall/xcl. Originally posted by Prime1997 on 2026-11-24T01:56:38Z.
When a debugger single-steps a title on a CPU without CLWB, the exception handler currently replaces the original instruction with several one-byte NOPs. A later visit to the same address sees different instruction boundaries. Keep the instruction bytes while the x86 trap flag is set.
What is in it
Tested
ff37edccb1dabb9e39985b51ecf33a5e352c699a, Windows 11 Pro build 26200, Intel Core i5-10400, NVIDIA GeForce RTX 3060 Ti, driver 32.0.16.1714, Rust 1.100.0 MSVC.508a0c7with the original four-byte CLWB replaced by four NOPs. The release exception-handler tests passed after the change (7 passed, 0 failed, 0 ignored).cargo test --workspacerun with locked dependencies, four test threads and--no-fail-fastcompleted with 681 passed, 0 failed, 41 ignored. Two GPU tests reported a wave64 hardware skip. Both the debug workspace and release CLI builds passed.Regression run
Both runs used the same retail title, RTX 3060 Ti, 60-second limit, offline mode, first-use compute setting and two DXC workers.
Main
PR head
Not tested
The focused test exercises the real exception handler with a saved Windows context. An interactive debugger session and CPUs that execute CLWB natively were outside this test. Optional retail sample tests had no external input.
AI use
OpenAI Codex (GPT-6) assisted with reproducing the behavior, implementing the guard and tests, checking overlap and preparing this report.
I use a temporary Discord to coordinate my work. Anyone helping test XCL or compare results is welcome. Test coordination on Discord
Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T03:12:03Z.
Test run of
ff37edccb1dabb9e39985b51ecf33a5e352c699aon AMD RDNA4. I merged it onto currentmaindd2ae9alocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 691 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 651 passed, 0 failed, 21 ignoredSKIPPED;clwb_single_step_keeps_code_and_normal_faults_still_patchpasses.Review: With the trap flag (
EFlags & 0x100) set the handler leaves the bytes alone and only advances RIP; without it it patches as before, and the test covers the 4-, 5- and 6-byte encodings both ways. I found nothing to change.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T04:05:18Z.
On the overlap with #321 that the description mentions: I checked it at heads
ff37edccb1(this PR) anddfa332a5a4(#321). The two conflict incrates/xcl/src/eh.rsin either order againstmainf4ce27ceb6, and #321 changes the premise of this one.code.fill(0x90)path. Several one-byte NOPs move the instruction boundaries a stepping debugger sees on its next visit.hot_patch_clwbwrites a single 2-bytejmp shortover the whole CLWB, atomically under theCLWB_PATCHESlock. After that patch, a later visit sees one instruction atripthat ends atrip + len, so the boundary problem this PR fixes no longer occurs.So if #321 lands first, this PR's change mostly becomes unnecessary. The TF check would only matter if the code should stay untouched while a debugger steps at all, in which case it would go at #321's call site (
if hot_patch_clwb(rip, ...) == ClwbPatch::Patched, line 428 at its head) and return theSteppedbehaviour. Your test cases (4-, 5- and 6-byte encodings, TF on and off) would still be useful against #321's jump patch either way.Read-only, not built. AI-assisted (Claude Code).
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-24T04:08:37Z.
Interesting. I was using 321 but I didn't think it would be an issue, but I will try and see if this gets pushed first. If anything, we can use a debugger for the lower end systems.
Good catch!
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T13:18:33Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T04:30:07Z.
NVIDIA test report for
ff37edc: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug.cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4(thehle::xaudio2tests hang on this machine, onmaintoo):no wave64). The newclwb_single_step_keeps_code_and_normal_faults_still_patchpasses.Lib tests only; no title run.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T06:50:23Z.
merge-check claim
head:
ff37edccb1Imported from ivall/xcl. Originally posted by throny on 2026-11-28T07:07:03Z.
merge-check
base:
e429936chead:
ff37edccb1merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2127 passed, 9 failed, 48 ignored (26 SKIPPED lines). The 9 failures are main's own at
e429936con this GPU (reported with a bisect on #3041: they arrive with the merge of #2959); the set is identical with and without this PR. Base alone: 2126 passed, 9 failed, 48 ignored.review: no blocking finding. XCL never sets the trap flag itself, so a run without a debugger behaves as before; with the flag set no protection change is made, so there is nothing to restore, and the path without it restores the old protection as main does. Pre-existing, not introduced: the handler continues after the emulated instruction with the trap flag still set. For whoever merges: #321 (open) conflicts in eh.rs and replaces the code path this PR adjusts, which would make this change mostly unnecessary; decide the order first.
performance: none by default; only under the trap flag does each visit fault again.
verdict: safe to merge (after deciding the order with #321)
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:46:11Z.
Review: COMMENTED
Critical review of current head
ff37edcc. The trap-flag guard is a targeted fix: while stepping, advancing RIP without rewriting a multi-byte CLWB keeps subsequent instruction boundaries stable; the new encoding fixture exercises the ordinary patch path too. I found no blocker in this head alone. It overlaps #321 in the same handler arm, and #321 changes the patching premise, so please resolve those branches in one direction and rerun the single-step fixture on the integrated result before merge. No local Windows run.Imported from ivall/xcl. Originally posted by relativespace2K on 2026-11-30T02:37:53Z.
merge-check
base:
53e85fb1head:
ff37edccb1merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2789 passed, 6 failed, 49 ignored; failing: gpu::dxil::compact_tests::gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form, gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, ram_budget::tests::windows_takes_a_working_set_maximum_and_lifts_it, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (in
--test gpu_two_pass_cache_e2e, so 5 failing tests give 6 failures). The same five fail on base53e85fb1alone (2788 passed, 6 failed, 49 ignored there), so none comes from this PR; its new test passed. 13 SKIPPED lines, all environmental: no D3D12 debug layer / d3d12SDKLayers.dll, no heap windows, no GPU_UPLOAD, per-lane f16/f32 forms refused.review: no blocking finding; one file, every hunk read. The change is one condition: when the trap flag is set in the
CONTEXTthe hot-patch is skipped, so a single-stepped consoleCLWBstays the one instruction the title asked to step instead of becoming several one-byte0x90s that the debugger would stop on separately. Everything else on that path is untouched, and the new test proves both directions: withTFthe bytes andPAGE_EXECUTE_READprotection are unchanged across two visits, without it the first bytes really become0x90and the rest of the buffer is not, for three encodings ([rax],[rsp+8],[r8]) and for an ordinary hot-patching control value. Handling the emulated instruction again on every step is the slower, correct side of that trade, and it only happens under a debugger. Notes, not blocking: the mask is written as a bare0x100with the comment namingTF; a named constant would read better, and the test zero-initialises the wholeCONTEXTrather than the fields it uses, which is fine for a hand-called emulation. No duplicate: nothing else changes theCLWBpath. Duplicate/overlap: not a duplicate of #321 (that one serialises the patch and replaces the0x90fill with ajmp shorthead, and flushes the icache; this one only declines to patch underTF), but both edit the sameClwb =>arm incrates/xcl/src/eh.rs, so whichever lands second needs a rebase and the order with #321 should be decided before merging either, as throny noted.performance: none in a normal run: the branch is only taken when the trap flag is set, which a title run never does.
verdict: safe to merge
hardware / tool and model: AMD Radeon RX 6800 XT 16 GB (RDNA2, wave64), driver 32.0.21045.29003; Ryzen 5 5600, 32 GB RAM; Windows 10 IoT Enterprise LTSC 2024, 10.0.26100 build 26100.9974; Rust 1.100.0; DXC 1.9.2602.17; debug build. DeepSeek Harness coding agent, model DeepSeek V4.1 Flash. The first full run aborted in
-p xcl --libwith0xc0000005(STATUS_ACCESS_VIOLATION) before that target printed a result, the intermittent abort under parallel scheduling (#1978); the numbers above are the clean rerun.