Skip to content

xcl run: XCL_THREAD_DUMP_AT unwinds a copy of each thread's stack - #2923

Draft
Prime1997 wants to merge 2 commits into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-thread-dump-stack-copy
Draft

Prime1997 wants to merge 2 commits into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-thread-dump-stack-copy

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Prime · project thread

XCL_THREAD_DUMP_AT stops 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, RtlVirtualUnwind follows 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+0x1ff2a or +0x20191, reads at 0x67, 0x107, 0x147, 0x100e8 and 0xa7d06d978. In the last one the title's own minidump names the faulting thread xcl-thread-dump, and the instruction is the unwinder's UWOP_PUSH_NONVOL with 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 (what RtlVirtualUnwind will 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), unwind over the copy (a caller's RSP must lie above its callee's), and dump_threads taking the copy.
  • crates/xcl/src/tls.rs: thread_teb (a thread's TEB from its handle, with the binding already there).
  • Second commit (review notes): in chained unwind data an earlier part's saves are shifted by what the later part pushed and allocated; a code whose slots run past the count, and UWOP_SET_FPREG with no frame register, end the walk. The frame_reach test covers the three.
  • Tests eh::tests::a_walk_over_the_copied_stack_finds_the_callers_windows_finds (the callers RtlCaptureStackBackTrace finds 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) and frame_reach_adds_up_a_frame_and_finds_its_frame_register (synthetic unwind data).

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (driver 32.0.16.1714), Intel Core i5-10400, Windows 11 26200, rustc 1.100.0; debug tests, release smoke.
  • cargo test --locked --workspace --no-fail-fast -- --test-threads=4 with XCL_DXC_DIR set to DXC 1.9.2609.5: 1825 passed, 9 failed, 48 ignored. The 9 failures are the same tests that fail on nvidia-dev eff3bcab itself (1822 passed, 9 failed, 48 ignored 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.
  • SKIPPED on this adapter: 28 (no wave64: 21, per-lane f16 form refused: 3, no dxc.exe: 1, no heap windows (opt-in: XCL_HEAP_WINDOWS=1): 1, cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depend: 1, no heap windows: 1).
  • GitHub's Build and test (Windows, no GPU) has failed on other pull requests against nvidia-dev (kernelx: physical page homes in window 0 first, from the top, keeping 64 MB free (#2867) #2905, for one) on hle::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 on eff3bcab.

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):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 363 (PresentX 363)
presents per 2 s (last 3): 16 17 16
device removals: 0
crashes: 0
peak commit: 15320 MB

The base of this PR, nvidia-dev eff3bcab:

xcl-smoke v1
commit: eff3bcabf1b6f99223796ece166948003a53e0bc
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 1364 (PresentX 1364)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15372 MB

This PR's head:

xcl-smoke v1
commit: 1a061d4ce0d7dd829db497d5d8663c7e50fb9926
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 1357 (PresentX 1357)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15334 MB

Not tested

  • The 60 s regression runs below do not set 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.
  • A thread on a stack its TEB does not name (a fiber switched without the TIB): its RIP alone is listed now. Frames past 256 KiB of a thread's stack are left out of its list.

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/gK3y7WRRY

🤖 Generated with Claude Code

The thread dump stops a thread only for its context (xcl-dev#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
changes the frames being read, RtlVirtualUnwind follows a stale saved
register to a wild RSP and faults. In a retail title deep in its world
the dump thread died that way 278 s into the run: unhandled 0xc0000005
in ntdll's unwinder (UWOP_PUSH_NONVOL with the context's RSP at 0x107,
read at 0x107), thread 'xcl-thread-dump', and the title went with it.

While the thread is stopped the dump now also copies its stack from RSP
to the top the TEB names (up to 256 KiB, into a buffer allocated before
any thread is stopped: plain reads, no lock, no allocation). The unwind
reads only that copy: RSP and a frame's frame register are moved into
it, and a frame whose unwind codes would reach outside it (a pushed,
saved or allocated byte, or the return address) ends the list instead
of being read. A thread whose RSP is outside its TEB's stack shows its
RIP alone.

Tests: the walk over a copy finds the callers RtlCaptureStackBackTrace
finds on the live stack; a frame with RSP and the nonvolatile registers
at 0x107 ends the walk (without the checks the test process dies with
STATUS_ACCESS_VIOLATION); frame_reach on synthetic unwind data (pushes,
small and large allocations, the frame register before and after the
prologue sets it, chained data, unknown codes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Prime1997 Prime1997 self-assigned this Nov 26, 2026
@saintwolf

Copy link
Copy Markdown

Tested and reviewed commit 143ddb11.

Tested

  • Hardware: NVIDIA GeForce RTX 4070 SUPER (12 GiB, driver 32.0.16.2140), AMD Ryzen 7 7800X3D, Windows 11 build 26300, rustc 1.100.0, debug test build
  • cargo test -p xcl --lib eh::tests:: -- --test-threads=1: 10 passed, 0 failed, 0 ignored, 0 skipped (including a_walk_over_the_copied_stack_finds_the_callers_windows_finds, a_walk_ends_at_a_frame_outside_the_copied_stack, and frame_reach_adds_up_a_frame_and_finds_its_frame_register)

Review notes

  • Clean, well-tested fix with zero new compiler warnings. Pre-allocating StackCopy before suspension and doing plain NT_TIB reads + copy_nonoverlapping while suspended preserves the lock-free suspension window (Runtime / Loader / Platform: static TLS alignment & attach races, eh::dump_threads deadlock & VEH bounds, C-unwind FFI boundaries, AVX2 check, and hybrid CPU affinity / PLS quota #106).
  • Minor non-blocking observations in frame_reach:
    • For chained unwind info (depth > 0), UWOP_SAVE_NONVOL / UWOP_SAVE_XMM128 offsets are relative to the parent's post-prologue RSP (current_rsp + child_frame_bytes), whereas saved = saved.max(offset + ...) omits the child's accumulated reach - 8 (small home-space offsets are cushioned by the 64 KiB trailing padding in StackCopy::new(), though adding the prior chain delta makes it exact).
    • Multi-slot unwind codes (slot(i + 1) / slot(i + 2)) assume i + 2 <= count / i + 3 <= count; a bounds check would guard against malformed unwind tables.
    • In UWOP_SET_FPREG, guarding reg & 15 != 0 avoids treating a malformed FrameRegister == 0 as RAX.

Not tested

  • Full workspace test suite or a live retail-title run with XCL_THREAD_DUMP_AT on this commit

AI use

  • Antigravity (exact model name not provided to the agent): reviewed the diff, ran the build/test command, and drafted this report (checked before posting).

…d codes

Review notes on xcl-dev#2923: in chained unwind data the earlier part's
UWOP_SAVE_NONVOL / SAVE_XMM128 offsets are relative to its own RSP,
above what the later part pushed and allocated, so frame_reach adds that
to them (the 64 KiB past the copy only cushioned it). A code whose slots
run past the info's count, and UWOP_SET_FPREG with no frame register
named, are not followed: the frame ends the walk.

The frame_reach test covers all three with synthetic unwind data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pedrocalazans05 pushed a commit to pedrocalazans05/xcl that referenced this pull request Nov 27, 2026
…d codes

Review notes on xcl-dev#2923: in chained unwind data the earlier part's
UWOP_SAVE_NONVOL / SAVE_XMM128 offsets are relative to its own RSP,
above what the later part pushed and allocated, so frame_reach adds that
to them (the 64 KiB past the copy only cushioned it). A code whose slots
run past the info's count, and UWOP_SET_FPREG with no frame register
named, are not followed: the frame ends the walk.

The frame_reach test covers all three with synthetic unwind data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants