KernelX: lazy pages – a thread that loses the race to commit a page retries instead of crashing #250
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!250
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/250/head"
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?
@Sr-0w on GitHub · 2026-11-23 21:52 UTC · original
Sr-0w:lazy-commit-race→main· +50 −3 · 1 files · 1 commits · closed without mergingWhat happened
About two minutes into play (in the world, frame ~1400), the retail game crashed. Two threads faulted at the same millisecond in the same 64 KiB page:
(The region part comes from a local
VirtualQueryin the crash logger, not part of this PR.) By the time the crash is logged, the page is committed read-write. That is a lazy physical page from 38b05b7's handler, which one thread committed while the other was faulting on it.Cause
lazy::handlerfirst checksLAZYunder a read lock, thencommittakes the write lock, removes the page and commits it. When two threads fault on one page:commitreturns false; orLAZY.In both cases it returns
EXCEPTION_CONTINUE_SEARCHand the process dies.Change
If the page of a read or write fault is now committed
PAGE_READWRITE, the handler returnsEXCEPTION_CONTINUE_EXECUTION, so the access is retried. A read or write on such a page cannot fault again, so this cannot loop.Testing
threads_racing_on_a_lazy_page_all_go_on: 8 threads write into the same 64 lazy pages behind a barrier.0xc0000005(3 runs out of 3).cargo test --release -p xcl --lib: 612 passed, 0 failed. A second run while the game was using the GPU had GPU-test failures (gpu_sparse_vram_descriptors_buffers_and_xmem,gpu_float_compares_random, …). They pass alone and on a quiet GPU.🤖 Generated with Claude Code
@Cattn on GitHub · 2026-11-23 21:58 UTC · original
This is a duplicate of #244 in pretty sure
@Sr-0w on GitHub · 2026-11-23 22:01 UTC · original
Closing as a duplicate of #244, which fixes the same race and was opened first. I hit the same two-thread crash in the same title and confirmed the fix there: past the point where it used to crash.
@Kalmarv on GitHub · 2026-11-23 22:02 UTC · original
This fixes the race: 10 of 10 runs pass on each of the three race tests below, all of which abort main
63b9930every time. There is one case where the fallback retries a fault that can't succeed, though.Finding: an endless retry on a genuine fault.
committed_rwasks whether the 64 KiB page's base is committedPAGE_READWRITE, and that's enough for any read or write to retry.VirtualProtect. A write to that part faults, the base is still read-write, so the handler returnsCONTINUE_EXECUTION, and the write faults again, forever.ExceptionInformation[1]) and checking the access against that protection: reads need a readable page, writes a writable one, and guard pages are refused. Doing the same incommitted_rwwould close the case.Tested
093798e, merged onto main63b9930without conflicts.threads_racing_on_a_lazy_page_all_go_on, #244's test, and a two-thread test with a barrier per page. Main: an access violation, 10 of 10 each. This PR: passes 10 of 10 each.handlerwith a write record for the read-only part returnsCONTINUE_EXECUTION. A real write in a test (#[ignore]d, run with a 15 s timeout) never returns.Not tested
🤖 Claude Opus 5.5
Pull request closed