xcl run: XCL_THREAD_DUMP_AT unwinds a copy of each thread's stack #2923
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2923"
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-26T23:42:02Z.
Requested by Prime
XCL_THREAD_DUMP_ATstops each thread only to take its context (#106: the unwinder and the module lookup take locks the stopped thread may hold), then unwinds the stack of a thread that is running again. When that thread rewrites the frames being read,RtlVirtualUnwindfollows a stale saved value to a wild RSP and faults on the dump thread, and the title goes with it. The dump now also copies each thread's stack while the thread is stopped (from RSP to the top its TEB names, at most 256 KiB, into a buffer allocated before any thread is stopped) and unwinds over that copy only: a frame whose unwind data would reach outside the copy ends that thread's list instead of being read.Why
In five runs of a retail title on the card below, the dump thread died this way right at a dump (300, 300, 361, 400 and 795 s): unhandled 0xc0000005 at
ntdll.dll+0x1ff2aor+0x20191, reads at 0x67, 0x107, 0x147, 0x100e8 and 0xa7d06d978. In the last one the title's own minidump names the faulting threadxcl-thread-dump, and the instruction is the unwinder'sUWOP_PUSH_NONVOLwith the context's RSP at 0x107. The title itself was running in its world at the time.What is in it
crates/xcl/src/eh.rs:StackCopy(taken while the thread is suspended: plain reads of the TEB's stack bounds and of the stack, no lock, no allocation; RSP and a frame register are moved into it),frame_reach(whatRtlVirtualUnwindwill read for a frame: pushes, allocations, saved registers and the return address, from RSP or from the frame register once the prologue has set it, chained unwind data followed, unknown codes end the walk),unwindover the copy (a caller's RSP must lie above its callee's), anddump_threadstaking the copy.crates/xcl/src/tls.rs:thread_teb(a thread's TEB from its handle, with the binding already there).UWOP_SET_FPREGwith no frame register, end the walk. Theframe_reachtest covers the three.eh::tests::a_walk_over_the_copied_stack_finds_the_callers_windows_finds(the callersRtlCaptureStackBackTracefinds on the live stack),a_walk_ends_at_a_frame_outside_the_copied_stack(RSP and the nonvolatile registers at 0x107: without the checks the test process dies with STATUS_ACCESS_VIOLATION) andframe_reach_adds_up_a_frame_and_finds_its_frame_register(synthetic unwind data).Tested
cargo test --locked --workspace --no-fail-fast -- --test-threads=4withXCL_DXC_DIRset to DXC 1.9.2609.5: 1825 passed, 9 failed, 48 ignored. The 9 failures are the same tests that fail onnvidia-deveff3bcabitself (1822passed,9failed,48ignored there, same command):async_compute_pso_registers_real_pso_and_not_standin,console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly,gpu::recomp::tests::gpu_compute_thread_limits_leave_the_lanes_past_them_out,hle::d3d12x::texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays,hle::d3d12x::texture_upload::tests::pieces_hold_the_texels_of_their_levels,split_compute_prefers_the_offline_whole_pipeline,two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.Build and test (Windows, no GPU)has failed on other pull requests againstnvidia-dev(#2905, for one) onhle::d3d12x::sparse::tests::a_gpu_write_into_a_gpu_view_lands_in_its_cpu_view(the WARP device is removed, 0x887a0005). That test passes on the card above, on this branch and oneff3bcab.Regression run
A commit of
main(b49be183, the last one before the shader preparation screen of #2555, which prepares every record before the title and so does not fit a 60 s run):The base of this PR,
nvidia-deveff3bcab:This PR's head:
Not tested
XCL_THREAD_DUMP_AT; with this change the dump ran 15 times (every 20 s from 120 s) in a 420 s run of the same retail title in its world on the card above, with no crash; the five crashes above came from runs with 2 to 4 dumps.AI use
Claude Code (Claude Opus 5.5) wrote the code, ran the suite and the regression runs on the hardware above, and wrote this description; Prime asked for it and owns the account. We coordinate the 8 GB work on the XCL Discord too: https://discord.gg/6B4TykyC4W
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-27T00:04:50Z.
Tested and reviewed commit
143ddb11.Tested
32.0.16.2140), AMD Ryzen 7 7800X3D, Windows 11 build 26300,rustc 1.100.0, debug test buildcargo test -p xcl --lib eh::tests:: -- --test-threads=1: 10 passed, 0 failed, 0 ignored, 0 skipped (includinga_walk_over_the_copied_stack_finds_the_callers_windows_finds,a_walk_ends_at_a_frame_outside_the_copied_stack, andframe_reach_adds_up_a_frame_and_finds_its_frame_register)Review notes
StackCopybefore suspension and doing plainNT_TIBreads +copy_nonoverlappingwhile suspended preserves the lock-free suspension window (#106).frame_reach:depth > 0),UWOP_SAVE_NONVOL/UWOP_SAVE_XMM128offsets are relative to the parent's post-prologueRSP(current_rsp + child_frame_bytes), whereassaved = saved.max(offset + ...)omits the child's accumulatedreach - 8(small home-space offsets are cushioned by the 64 KiB trailing padding inStackCopy::new(), though adding the prior chain delta makes it exact).slot(i + 1)/slot(i + 2)) assumei + 2 <= count/i + 3 <= count; a bounds check would guard against malformed unwind tables.UWOP_SET_FPREG, guardingreg & 15 != 0avoids treating a malformedFrameRegister == 0asRAX.Not tested
XCL_THREAD_DUMP_ATon this commitAI use
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-27T05:43:03Z.
Review: COMMENTED
frame_reachcounts pushes, allocations and register saves that have yet to execute when RIP is in the prologue. OnlyUWOP_SET_FPREGchecks the unwind-code offset against RIP. In an isolated Windows harness using the exact function from1a061d4c, I put RIP at the start of a supported prologue that subtracts 72 bytes from RSP.frame_reachrequired 80 bytes.RtlVirtualUnwindrecovered the correct caller and advanced RSP by 8 bytes. With a larger prologue allocation, the 256 KiB snapshot cap can make the walk stop even though all the bytes Windows needs are present. Could the reach calculation skip unwind operations whose prologue offsets are after the current RIP, with the existing early-offset fixture checking the reduced reach? Reach calculation · Windows unwind procedureAI use: OpenAI Codex (GPT-6.2 Sol) reviewed the source, ran the isolated CPU-only harness, and drafted this comment. No title or full suite was run.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T22:38:27Z.
merge-check
base:
beeb81be4b(checked against current main: merge conflicts)head:
1a061d4ce0merge: conflicts on current main (was clean on
765b2c5b/beeb81be)build: cargo check -p xcl --all-targets -> ok (on
beeb81be)tests: non-GPU lib tests of touched modules (eh 14 passed, tls 4 passed / 1 ignored). Full workspace suite and GPU tests not run.
review: none blocking. Stack copy is allocated before thread suspension and bounded to [StackLimit, StackBase); unwind codes are bounds-checked and chained infos capped at depth 32. Diagnostic path only.
performance: none by default (runs only during thread dumps). Tested in a combined 600 s retail run on main
beeb81be+ 13 PRs (warm cache, defaults) vs baseline: presents/2 s 3.27 vs 3.29, peak commit 35,016 vs 35,767 MB, local video memory 14.19-14.76 vs 14.32-14.95 GB, 0 pipeline waits >= 1 s vs 5, 0 device removals, 0 crashes. Combined result across all 13 PRs, not isolated to this PR.verdict: not yet: needs rebase onto current main; full workspace suite not run on its own merge.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:46:02Z.
Review: COMMENTED
Critical review of current head
1a061d4c. The copied-stack design addresses the central race: unwinding a running thread's changing stack after suspension ends. The copy is allocated before suspension and the read is bounded by the captured stack range; I found no new code blocker in that diagnostic path. The PR currently conflicts with main, so it needs a rebase and focused unwind tests on the merge result, especially chained unwind info and a thread modifying its stack immediately after resume. This is off the normal frame path. No local Windows run.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:01:29Z.
Review (head
1a061d4c, diff read, not a merge-check; draft and conflicting, so not built or run):f67e35ae("xcl run: thread dumps unwind a copy of each stopped thread's stack", #253) does the same fix on main: it copies each stopped thread's stack and unwinds over the copy, reading it withVirtualQuery+ReadProcessMemory(which can't fault), with 64 KiB of slack and a stress test (thread_dumps_while_threads_run_and_exit). That commit is the conflict.frame_reach, the caller-RSP-above-callee check, stack bounds from the TEB) only matters on main for stacks deeper than 256 KiB, and no crash on main shows it's needed. Two small points about this version:StackCopy::take(eh.rs~772-782) reads the TEB and the stack with plain reads, less safe than main'sReadProcessMemoryif the thread has exited; and a thread on a stack its TEB doesn't name (a fiber) gets only its RIP.Fine: the copy buffer is allocated before any thread is stopped, the
frame_reachbounds checks work, and the tests are good. Recommendation: close as superseded byf67e35ae; if a dump still crashes on main, a small follow-up addingframe_reachto main'sunwindwould be the place for it.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.