Skip to content

kernelx: keep failed lazy commits in lazy set and report in crash line - #488

Open
7ROBE wants to merge 1 commit into
xcl-dev:mainfrom
7ROBE:fix/lazy-commit-failure
Open

7ROBE wants to merge 1 commit into
xcl-dev:mainfrom
7ROBE:fix/lazy-commit-failure

Conversation

@7ROBE

@7ROBE 7ROBE commented Nov 24, 2026 •

Copy link
Copy Markdown

What is in it

Fixes #467.

  • crates/xcl/src/hle/kernelx/lazy.rs: in commit, check LAZY.contains(&page) first and only LAZY.remove(&page) after VirtualAlloc(MEM_COMMIT) succeeds. On failure, leave page in LAZY and record the failure count, last failing page address, and GetLastError() in atomics (no allocation or logging inside the vectored exception handler), exposed via failure_summary().
  • crates/xcl/src/eh.rs: in unhandled_filter, append lazy::failure_summary() (lazy commit failed N times, last 0x... (err)) to the crash line when non-empty.
  • Added hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line (spawns a child test process inside a Job Object with JOB_OBJECT_LIMIT_PROCESS_MEMORY) verifying that a page under the limit commits, a page past the limit stays in LAZY, and the unhandled-exception crash line includes lazy commit failed and 1455 ERROR_COMMITMENT_LIMIT.

Tested

  • cargo build --workspace (XCL_ADAPTER=radeon): passed

  • cargo test --workspace -- --test-threads=4 (XCL_ADAPTER=radeon): 677 passed; 0 failed; 41 ignored

    • xcl lib: 637 passed; 0 failed; 21 ignored
    • console_dlls_e2e: 13 passed; 0 failed
    • console_shaders: 3 passed; 0 failed; 4 ignored
    • disasm_e2e: 1 passed; 0 failed
    • e2e: 3 passed; 0 failed
    • gpu_compute_e2e: 2 passed; 0 failed
    • gpu_pso_e2e: 7 passed; 0 failed
    • heap_probe: 0 passed; 0 failed; 4 ignored
    • pls_quota: 1 passed; 0 failed
    • predication_e2e: 1 passed; 0 failed
    • rpf_e2e: 2 passed; 0 failed
    • texture_states: 1 passed; 0 failed
    • xg_oracle: 6 passed; 0 failed; 12 ignored
  • .\scripts\smoke.ps1 -Game "<game folder>" -Seconds 60 (XCL_NETWORK=0, XCL_ADAPTER=radeon):

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: AMD Radeon RX 9060 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1435 (PresentX 1435)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 10982 MB
xcl-smoke v1
commit: bd7b9e4abd0bfc95fc9b5e1dcae0477831461f95
gpu: AMD Radeon RX 9060 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 60 60 56
device removals: 0
crashes: 0
peak commit: 10001 MB

Not tested

  • Retail commit-limit exhaustion in-game (tested via the synthetic Job Object child-process test).

AI use

  • AI-assisted with Antigravity (Gemini 3.1 Pro) on Windows 11, Intel i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2). No game data was used or included.

T-Crypt added a commit to T-Crypt/bathyal that referenced this pull request Nov 24, 2026
From xcl-dev/xcl#487 by @Grimkaaah, squashed.
Supersedes xcl-dev/xcl#488 (dropped: its child-process test overflows the stack under the job commit limit instead of hitting the limit, so the crash-line assertion cannot hold).
@futurepro62

Copy link
Copy Markdown

Tested exact head bd7b9e4 (on its base 2997c9a): the new test fails intermittently here.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 636 passed, 1 failed, 21 ignored in the lib tests (the run stops there):
    hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line
    panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13:
    missing 0xc0000005 in stderr:
    thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (8944) has overflowed its stack
    
    The child process overflows its stack instead of printing the crash line, so none of the three stderr checks can pass.
  • The test alone, cargo test -p xcl --lib -- --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line, 3 runs: failed, failed (same stack overflow), passed. So 3 failures in 4 runs counting the suite run.
  • One earlier run of the same command hung in the lib tests at gpu_uma_import_check_at_init, gpu_typed_buffer_loads_and_stores, gpu_valu_16_and_64_bit and gpu_wave32_and_wave64_src_vccz_execz (the D3D12.X: replacing the sparse state deadlocks when the old state still holds placed buffers #344 deadlock, which main has too and D3D12.X: the sparse state is replaced outside its lock #443 fixes); I stopped it after 900 s and reran.

Not tested

  • Why the child overflows (no debugger run); a release build; AMD; a retail title.

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@futurepro62

Copy link
Copy Markdown

Follow-up to my report above: why the new test's child overflows its stack, and a test-only change that makes it pass reliably here. The fix in commit itself looks right: whenever the child reaches the crash line, it shows lazy commit failed 2 times, last 0x… (1455 ERROR_COMMITMENT_LIMIT).

Two causes, both in the test's set-up of the commit-limited child

  1. The stack warm-up commits the wrong pages. let mut stack_warm = [0u8; 64 * 1024] lives in the test function's own frame. The crash handler (eh::unhandled_filter, with its format!s, stack_callers and register descriptions) runs below that frame, in stack that was never touched. Under the job limit Windows cannot commit those pages, so the guard-page fault becomes a stack overflow (thread '…' has overflowed its stack) before the crash line is printed. A bigger array in the same frame doesn't help. Warming from a separate #[inline(never)] function does, because the pages it touches below the current frame stay committed.
  2. The crash line sets up the memory windows for the first time. unhandled_filter → obj(v) → gpu::shader::readable → gpu::uma::get() initialises UMA lazily. In the child that happens inside the crash handler, after the lazy pages have used up the job's headroom, so it fails (UMA: could not reserve 2048 MB …) and a following allocation aborts (memory allocation of 720 bytes failed). Even with UMA set up earlier, the crash line's own strings sometimes need a new heap commit that the limit refuses (memory allocation of 726 bytes failed). Neither affects a title (UMA is set up long before any crash), but both make the test flaky.

Measured (head bd7b9e4; the child run directly, XCL_LAZY_LIMIT_CHILD=1 <lib test exe> --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line --nocapture, local edits reverted after)

child set-up stack overflow allocation failure crash line printed
as in the PR 11 / 12 0 / 12 1 / 12
1 MiB array in the same frame 11 / 12 1 / 12 0 / 12
256 KiB warmed in a separate #[inline(never)] fn 0 / 12 1 / 12 11 / 12
… + headroom 16 pages instead of 4 0 / 20 5 / 20 15 / 20
… (4 pages) + uma::get() before the limit 0 / 20 7 / 20 13 / 20
… + uma::get() + heap grown before the limit 0 / 30 0 / 30 30 / 30

With the last set-up, the test itself (cargo test -p xcl --lib -- --exact …) passed 10 of 10 (before: 1 of 4), and the parallel lib run (--test-threads=4, XCL_REQUIRE_GPU=mesh) passed 2 of 2 (637 passed, 0 failed, 21 ignored).

The change (test only; replaces the two stack_warm lines):

            // Commit stack *below* this frame, where the crash handler will run, before the limit.
            #[inline(never)]
            fn warm_below() {
                let mut a = [0u8; 256 * 1024];
                std::hint::black_box(&mut a);
            }
            warm_below();
            // The crash line's register descriptions reach gpu::uma::get(): set it up now.
            let _ = crate::gpu::uma::get();
            // Grow the heap now so the crash line's strings fit without a new commit.
            drop(std::hint::black_box((0..64).map(|_| vec![0u8; 1024]).collect::<Vec<_>>()));

Not tested

  • A debugger stack of the overflow (no cdb here); the reasoning above comes from the experiments in the table. Whether the heap pre-growth holds on other machines (it relies on the process heap keeping freed small blocks committed). AMD, a release build.

Hardware: NVIDIA GeForce RTX 5070 Ti (616.64), Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug.

AI use

  • Claude Code (Claude Opus 5.5) ran the experiments, wrote the change and this comment. I checked it before posting.

@oz-stanislav-zhukov

Copy link
Copy Markdown

AI Qwen (agent) — follow-up test report, 2026-11-24

Tested this PR stacked on fresh main (beaa245, which includes #797, #795, #798, #792, #713, #762, #634, #347, #490, #443, #348, #484, #690, …). Hardware: RTX 5060 Ti 16 GB, Windows 10 22H2 (19045), D3D12 Agility SDK 1.620.2 (stock driver reports SM 6.5, the game needs 6.6). Release build with line tables (CARGO_PROFILE_RELEASE_DEBUG=line-tables-only) so crash offsets resolve against xcl.pdb.

Title: GTA VI (Scarlett) RockstarGamesInc.28872443D20A7 1.0.2.1, game_scarlett_master.exe.

Results:

  1. The 0xc0000005 in ucrtbase.dll+0x171eb #477 crash does not reproduce with this PR. Clean main crashes early in world loading with 0xC0000005 read of 0x80 bytes at window offset 0x16000 (stack through hashbrown map ops during thread spawn, preceded by DirectStorage: a request failed (0x89240009) on a .ttpf). With this PR merged, that crash and any lazy commit failed log line are gone across multiple runs.

  2. The game now reaches the world and renders: stable ~28–30 fps, audio (Opus via xapu) decodes fine (23 892 packets, 0 errors), shaders translate and compile (0 skipped draws/dispatches).

  3. It then crashes further along the same game-side call chain (game frames +0x4daa2c8, +0x979f5b, +0x4fb0c2f, +0x50bb3f0 are identical to the pre-fix crash), but inside different XCL code:

    • run A: 0xC0000005 write of 0x800 bytes at 0x8225e60c0, top frame xcl::vfs_hooks::move_file_a (vfs_hooks.rs:618) called from xcl::hle::xgameruntime::gamesave::each_blob (gamesave.rs:392) — i.e. the game moves a file (ANSI API) while enumerating gamesave blobs.
    • run B: 0xC0000005 write of 0x800 bytes at 0x8003ff940 (faulting instruction in VCRUNTIME140 memcpy), top frame xcl::hle::xg::copy_from (xg.rs:712, the detile→rows loop), second stack entry xcl::hle::d3d12x::fence_x::completed_value_address (fence_x.rs:92).
      Both destinations look like title-memory buffers whose target page is not committed at copy time.
  4. Still visible in the log up to the crash: DirectStorage: a request failed (0x89240030) repeatedly (12 KB chunks), and BCPack refusals accumulating (BC1/BC5/BC6H/BC7 — mode 6/7 unsupported), consistent with Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505. Failed texture-streaming requests plausibly leave the destination regions uncommitted, which would explain both crash variants above (the game later copies into/out of those regions).

  5. Since the run-B crash sits in CopyFromSubresource, I also cherry-picked the two commits from the closed PR D3D12.X / XG: async texture upload, detiling, VRAM, XG ABI, and PSO scheduling improvements #539 (7d1c466 guard the destination span, 9c4c3e6 fix the 7-argument ABI with the extra u32 before src) onto this branch and re-ran:

    • the game now reaches Game State: Game Running, Frame 3750 after ~240 s / ~59 600 translated draws (previous best without these commits: Frame 2577, ~170 s / ~46 700 draws) — a clear step forward on the same chain.
    • CopyFromSubresource was only entered twice in the whole run and both calls succeeded (per the new OK-path log); no invalid span warnings.
    • it still ends in 0xC0000005, now a write to 0x0 in game code (game_scarlett_master.exe+0x23cf683, rax=rbx=rbp=0), stack +0x4e4ba89 → +0x2215c35 → +0x71b9a20 → +0x2215eca; the previous best run crashed in the same game-side function region (+0x71b9b10). So the next blocker is one level deeper in the title's own streaming path, not in CopyFromSubresource itself.
    • still present until the crash: 16× DirectStorage: a request failed (0x89240030) and 27 BCPack refusals (Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505 territory), 0× lazy commit failed.

So: this PR is a real forward step (it removes the first hard crash on this title) and I'd vote to merge it; the next blocker looks like the DirectStorage-failure → uncommitted-region chain (#505 territory) rather than the lazy commit itself. All observations above were produced by AI Qwen running the title under XCL; no promises made on behalf of the account owner.

@asd3670576

Copy link
Copy Markdown

Built and tested the PR head on a Windows 10 machine that has no Shader Model 6.6 and only a GNU toolchain, because the job-object test in this PR is the one that decides whether the fix is verifiable. Every count below is pasted from the run, not written by hand.

Machine

  • Windows 10 Pro for Workstations 19045.3324 (22H2), Rust/cargo 1.100.0, host toolchain x86_64-pc-windows-gnu (no MSVC, no Windows SDK: cargo build here needs MinGW-w64 on PATH or it dies with error calling dlltool 'dlltool.exe': program not found), Ryzen 9 5950X (32 logical CPUs), 64 GB RAM.
  • GPU: RTX 3080 20 GB, driver 610.88. DXC 1.9.2609.5 at H:\leonida\dxc\bin\x64 (XCL_DXC_DIR). Agility 1.620.2 at H:\leonida\agility\build\native\bin\x64 (XCL_D3D12_DIR) but it cannot load on this OS build (no ID3D12SDKConfiguration1 before KB5029331), so the inbox runtime caps at Shader Model 6.5 and XCL's GPU recompiler path is unavailable here.
  • Release profile throughout. No title run here, so no xcl-smoke block from this machine.

Apply / build

  • git fetch https://github.com/ivall/xcl pull/488/head:pr488 → bd7b9e4abd0bfc95fc9b5e1dcae0477831461f95, checked out as-is: no rebase, no conflict resolution, git status --porcelain empty before the build and after it. The API reports mergeable: true, mergeable_state: unstable against current main.
  • cargo build --release --workspace → exit code 0:
    Finished `release` profile [optimized] target(s) in 27.19s

One earlier build attempt here failed with three errors in gpu/recomp/runner.rs and gpu/recomp/emit.rs (cannot find function sm65 in module super::pso, cannot find function wave_size); those came from an unrelated uncommitted edit in this working tree, not from this PR. Reverted and rebuilt clean.

Tests

cargo test --release -p xcl --lib -- kernelx::lazy, three runs on the default thread count (this is where the flakiness shows):

run 1: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.19s
run 2: test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 655 filtered out; finished in 0.15s
run 3: test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s

run 2, the failing one:

thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (28752) panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13:
missing 0xc0000005 in stderr:
thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (576) has overflowed its stack

The same test by name, cargo test --release -p xcl --lib -- --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line, three runs — failed 3/3:

run 1: test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 657 filtered out; finished in 0.17s
       (2588) panicked at crates\xcl\src\hle\kernelx\lazy.rs:201:13: missing 0xc0000005 in stderr:
       (7992) has overflowed its stack
run 2: test result: FAILED. 0 passed; 1 failed; ... (39604) panicked at lazy.rs:201:13: missing 0xc0000005 in stderr:
       (30008) has overflowed its stack
run 3: test result: FAILED. 0 passed; 1 failed; ... (17612) panicked at lazy.rs:201:13:
       missing 0xc0000005 in stderr: xcl: UMA: could not reserve 2048 MB at a 4 GiB-aligned address
       memory allocation of 770 bytes failed

So on this machine the test passes 2 of 3 times only when it runs next to the other lazy tests, and not once out of three when run alone. Both symptoms from @futurepro62's table show up here: the stack overflow, and memory allocation of 770 bytes failed right after UMA: could not reserve 2048 MB.

cargo test --release -p xcl --lib -- gpu::recomp::dxc:

test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 644 filtered out; finished in 0.44s

cargo test --release --workspace --no-fail-fast -- --test-threads=4 → exit code 0. 16 test result: lines (one per test binary plus the doc-test run); the xcl lib is:

test result: ok. 637 passed; 0 failed; 21 ignored; 0 measured; 0 filtered out; finished in 4.85s

all 16 are ok; summed over them: 677 passed; 0 failed; 41 ignored, which is the same total as in the description. The new test also passed inside that run. Skips, reported rather than counted as coverage: 86 SKIPPED lines, 84 : no GPU and 2 : no wave64, for example

SKIPPED gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no GPU
SKIPPED gpu::recomp::mesh_dispatch::tests::gpu_dispatch_matches_native_wave64_reference: no GPU

Forcing the requirement shows the SM 6.5 cap directly (XCL_REQUIRE_GPU=mesh cargo test --release -p xcl --lib -- --exact gpu::recomp::tests::gpu_bvh_intersect_ray):

thread 'gpu::recomp::tests::gpu_bvh_intersect_ray' (20752) panicked at crates\xcl\src\gpu\recomp\runner.rs:439:9:
gpu::recomp::tests::gpu_bvh_intersect_ray: no GPU, but XCL_REQUIRE_GPU=mesh

What this machine can and cannot verify. It cannot put any pressure on the commit limit: 64 GB of RAM against a 153 GB commit limit with 125 GB of it free, so the only commit-limit failure this PR's code ever sees here is the one the Job Object forces inside the test. That makes the test the whole verification of the fix - and it is the part that is unreliable here. With two other reports already showing the same child-process stack overflow on MSVC and Windows 11, this looks like a property of the test's set-up rather than of one machine; a release build on x86_64-pc-windows-gnu with a 32-thread host still hits it. What this box does add: the fix itself is a two-line ordering change in commit plus atomics, the other 676 workspace tests are unaffected, and eh.rs's new failure_summary() call did not destabilise anything here. It cannot say anything about the GPU surface (SM 6.5 → 84 skips) and it ran no title, so there is no regression block from this machine.

AI use: an agent (DeepSeek Harness, "auto" route - I do not know the underlying model) built the head, ran the tests and pasted the output.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This and #487 (opened a minute earlier) both fix #467 the same way at the core. A lazy page whose MEM_COMMIT fails stays in the lazy set, and the last failure (page, GetLastError, count) goes into the crash line. Where they differ:

The two conflict in lazy.rs. A maintainer may want #487's caller change together with this PR's test. Read from the diffs only; I have not run either.

AI-assisted (Claude Code).

@crosettiremi

crosettiremi commented Nov 24, 2026 •

Copy link
Copy Markdown

One downstream Windows/RDNA3 integration result for bd7b9e4. I ran the workspace serially on main 930e8b4 plus this change, local physical-page range validation and the graphics changes from #789/#968/#1248/#640. One library test failed. Its diagnostic was:

missing 0xc0000005 in stderr:
thread 'hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line' (158972) has overflowed its stack

The failure is in the child used by the test. This was a combined checkout. On the title route, the comparison build without #488 had a second-chance write access violation on a DirectStorage thread in write_physical_pages. The next two runs on the combined checkout both reached the story card and exited later with different driver errors. I did not capture a failed lazy commit on that route, so these results do not establish its cause.

Follow-up control: I checked out the unmodified PR head bd7b9e4 in a separate worktree and ran the exact focused test. It independently failed with the same missing 0xc0000005 and child stack-overflow diagnostic (0 passed, 1 failed).

@thehollowedone

Copy link
Copy Markdown

I checked futurepro62’s test-only setup on bd7b9e4. Windows 11 build 26300, Rust 1.99.1 MSVC, debug build, RTX 3080 Ti host. These tests are CPU-only.

Tested

  • cargo test --offline --locked -p xcl --lib hle::kernelx::lazy::tests -- --nocapture --test-threads=1 passed 3/3 on the published head. Running the built test executable with --exact hle::kernelx::lazy::tests::failed_lazy_commit_stays_lazy_and_reports_in_crash_line --nocapture --test-threads=1 in 20 fresh processes passed 4/20. The child reported 15 stack overflows and one allocation failure.
  • With the proposed out-of-frame stack warm-up, early UMA initialization, and heap warm-up, the same isolated test passed 20/20. The three-test filter also passed 3/3. The local edit was confined to test setup.

Not tested
Workspace suite, release, GPU, or retail behavior.

AI use
Codex (GPT-6, exact model variant unavailable) ran the tests and drafted this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kernelx: a lazy physical page whose commit fails leaves the lazy set, silently

8 participants