Skip to content

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

In review

Description

@requiemsnkrp

On main (2997c9a), lazy::commit (crates/xcl/src/hle/kernelx/lazy.rs:39-45) removes the page from LAZY (l. 41) before VirtualAlloc(MEM_COMMIT) (l. 44). When that commit fails – ERROR_COMMITMENT_LIMIT near the system's commit limit, which the retail title reaches on 16 GB machines (#333: 0.44–0.98 GiB of headroom left in three runs) – then:

This is not the race #244 fixed: there the page ends up committed, here it never is.

Proposed (small, one PR):

  1. Remove the page from LAZY only once the commit succeeded.
  2. Count failed commits and keep the last failing page and GetLastError() in atomics (no logging or allocation inside the vectored handler). The unhandled-exception filter (eh.rs) adds them to the crash line: lazy commit failed N times, last 0x… (1455 ERROR_COMMITMENT_LIMIT).
  3. Test: a child test process in a job object with a process memory limit marks lazy pages past the limit. The touch must fail with the new crash line instead of a bare 0xc0000005, and a page under the limit must still commit.

Not a fix for running out of commit (#333 / #194 / #345), only an honest failure. Before I write it: does this fit, or would you rather have it folded into #194's memory line?

AI use: found while analysing #333 with Claude Code (Claude Opus 5.5).

Activity

  1. Grimkaaah commented on Nov 24, 2026

    @Grimkaaah

    PR opened: leave the page in LAZY until MEM_COMMIT succeeds, record failures for the crash line, and make DirectStorage refuse destinations that could not be committed.

    Made with Cursor

  2. requiemsnkrp commented on Nov 24, 2026

    @requiemsnkrp
    ContributorAuthor

    Three PRs now implement this issue: #487, #488 and #502. As the issue's author, here is a side-by-side check to help pick one. All three are based on main 2997c9a and merge into it cleanly. I built each head and ran its tests on an RTX 3060 / Ryzen 5 5600X / Windows 11 26200 machine, Rust 1.100.0, debug.

    #487 (bf21bcb) #488 (bd7b9e4) #502 (be9423c)
    page stays in LAZY until MEM_COMMIT succeeds yes yes yes
    failure recorded without logging or allocating in the vectored handler yes (atomics) yes (atomics) no: xlog_warn! in commit_with, which the handler calls
    failure named in the crash line (eh.rs) yes, AV only, error as a number yes, error named (1455 ERROR_COMMITMENT_LIMIT) no
    test hits a real commit limit no (commits at a released address) yes (child process in a job with JOB_OBJECT_LIMIT_PROCESS_MEMORY) no (injected failing allocator)
    new test here 3 of 3 passed failed 6 of 9 runs (below) 3 of 3 passed
    hle::kernelx + hle::dstorage tests 38 passed 38 passed in that run 38 passed
    PR checks failing failing failing

    What I checked, per PR:

    • kernelx: keep failed lazy commits in lazy set and report in crash line #488 is the closest to the plan in the issue, but its test is not stable here. Run alone (--exact) it failed 4 of 4 times: missing 0xc0000005 in stderr, and the child had ended with 0xc00000fd, "has overflowed its stack". With the job limit at PagefileUsage + 4 * PAGE, the crash path cannot grow its stack, so the child dies before the filter writes the line. Within hle::kernelx::lazy it failed 2 of 3 runs. The 64 KiB stack warm-up looks too small for that margin. The PR's own regression run reports frames shown: none logged, which pr_check.py reads as fewer frames than main.
    • kernelx: keep lazy pages on failed MEM_COMMIT (#467) #487: the dstorage.rs hunk does not change behaviour. writable() already checks every page with VirtualQuery after ensure, so a page that stayed reserved already failed the request. The new test releases a reservation and then commits at that address. In a test process running other tests in parallel, another allocation can take that address in between, and the commit would then succeed into foreign memory (unlikely, but possible). The description has no Tested / Not tested / AI use sections and no regression run, both of which pr_check.py asks for.
    • kernelx: a lazy page whose commit fails stays lazy, and says so #502 logs from inside the vectored exception handler (format! plus the log file's mutex). It does so exactly when the system is out of commit, where that allocation can itself fail. It also leaves out the crash-line part. The author already says the diff was written with a model that CONTRIBUTING does not accept.

    My suggestion, the maintainer's call: #488's approach with its test made reliable (more commit headroom in the job, or more stack committed before assigning it), and the atomics-only recording that #487 and #488 share.

    AI use: comparison, builds and test runs done with Claude Code (Claude Opus 5.5) on the machine above; each point was checked against the diffs and the runs before posting.

  3. Toons29 commented on Nov 24, 2026

    @Toons29

    Second machine for the three PRs on this issue, same heads as the comparison above (#487 bf21bcb, #488 bd7b9e4, #502 be9423c; all three still merge cleanly into current main 508a0c7). Each head built and tested as-is.

    Tested

    • AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0 (stable MSVC), debug
    • cargo test --workspace --no-fail-fast -- --test-threads=4, 0 GPU tests SKIPPED on any run:
    #487 #488 #502
    whole suite 677 passed, 0 failed, 41 ignored 676 passed, 1 failed, 41 ignored 677 passed, 0 failed, 41 ignored
    the PR's new test passed failed 9 of 10 alone (--exact), 3 of 5 within hle::kernelx::lazy passed

    I also checked two points of the comparison against the code and agree: #502's commit_with runs xlog_warn! from the vectored handler's call to commit (lazy.rs, handler), and in #487 writable() in dstorage.rs already refuses a page that is not committed through its VirtualQuery loop, so the new early return there does not change the outcome.

    Not tested

    • No regression run (scripts/smoke.ps1): I have no retail title.
    • A real commit-limit exhaustion in a title; only the PRs' own tests cover it.
    • NVIDIA / wave32-only GPUs.

    AI use

    • Claude Code (Claude Opus 5.5) ran the builds and tests and drafted this report on the machine above; I checked each point against the diffs and the logs before posting.
  4. lordon1a commented on Nov 24, 2026

    @lordon1a

    Comparison of the three open PRs for #467 (#487, #488, #502), to help pick one.

    All three fix the core bug the same way: commit checks LAZY.contains(&page) and removes the page only after VirtualAlloc(MEM_COMMIT) succeeds. Each one merges cleanly into main f4ce27c. I read the three diffs before running them. They touch only lazy.rs, eh.rs and dstorage.rs. #488's test starts a child copy of the test binary itself, and none of them make network calls or read files outside the tests' own.

    PR head PR description check xcl-smoke lib tests on the merge with main
    #487 bf21bcb fail: Tested / Not tested / AI use sections missing, no smoke blocks 0 661 passed, 0 failed
    #488 bd7b9e4 fail: same three sections missing, and "fewer frames than main's (None against 1435)" 2 660 passed, 1 failed
    #502 be9423c fail: no smoke block 0 661 passed, 0 failed

    Differences that matter:

    • kernelx: keep failed lazy commits in lazy set and report in crash line #488's test is flaky here. failed_lazy_commit_stays_lazy_and_reports_in_crash_line failed in 8 of 10 runs when started on its own (cargo test -p xcl --lib failed_lazy_commit_stays_lazy). It also failed in the full lib run. When it fails, the child prints has overflowed its stack and nothing else, so the 0xc0000005 / lazy commit failed asserts fail on an empty stderr. The job limit is PagefileUsage + 4 * PAGE, measured before the job is set up. That leaves no room for stack growth or for the crash handler's own allocations, so the child dies of the limit before it reaches the report the test looks for. A test that depends on that margin will likely fail on CI machines too. (Caveat: my toolchain is x86_64-pc-windows-gnullvm, not MSVC, which can change stack use.)
    • kernelx: a lazy page whose commit fails stays lazy, and says so #502 logs from inside the vectored handler's path. commit is called from handler, and kernelx: a lazy page whose commit fails stays lazy, and says so #502 adds xlog_warn! (formatting and a lock) on the failure path. The issue's plan asks for atomics only there, since the faulting thread may hold the heap or log lock. The description also says the diff was written by DeepSeek V4.1 Flash, which CONTRIBUTING.md does not accept.
    • kernelx: keep lazy pages on failed MEM_COMMIT (#467) #487 is closest to the plan. It keeps atomics only in the handler and appends the summary only to the access-violation crash line. ensure now returns bool, so a DirectStorage destination that cannot be committed fails the request instead of being written while still reserved. Its test is deterministic: it commits on a released reservation, so the commit always fails. Two small points:

    Suggestion: take #487 once its description has the Tested / Not tested / AI use sections and a regression run. #488's error names could be folded into it. #488's test needs a margin that does not depend on the stack, or should become #502-style allocator injection. Close #502 per the model rule.

    Tested on an i7-12700H with an RTX 3070 Ti Laptop, Windows 11 build 26200. Toolchain: rustc 1.100.0 x86_64-pc-windows-gnullvm, debug, cargo test -p xcl --lib -- --test-threads=4 on each PR merged into main f4ce27c. Not tested: the MSVC toolchain, cargo test --workspace, smoke runs, a real commit-limit failure under a title.

    Written with Claude Code (Claude Opus 5.5). I checked each point against the diffs and the runs above.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions