Lazy physical pages: a thread that loses the race to commit a page retries #244
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!244
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/244/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?
@Cattn on GitHub · 2026-11-23 21:46 UTC · original
Cattn:fix-lazy-page-race→main· +52 −2 · 1 files · 1 commits · merged 2026-11-23 23:16 UTCProblem
kernelx::lazy(38b05b7) commits a lazy physical page from a vectored handler on first touch. When two threads fault on the same lazy page at the same time:LAZYand commits it;containsis false, orcommit'sremovereturns false) and returnsEXCEPTION_CONTINUE_SEARCH.So the second access ends the process as an unhandled access violation, although the page is committed by then.
Seen with a retail title on main while it loads its world: two threads crash within 1 ms at the same instruction, writing two addresses in one 64 KiB page:
Change
lazy.rsonly. The handler also lets the faulting instruction run again when the faulting address is now committed and its protection allows the access: reads and writes only, not execute or guard pages. The retry then succeeds. A fault whose access is still not allowed goes on to the next handler as before.Testing
threads_first_touching_one_lazy_page_together_all_go_on: 8 threads first-touch each of 256 lazy pages at the same moment through a barrier, and every write is checked afterwards.0xc0000005(3 of 3 runs).cargo test --release -p xcl --lib kernelx::: 19 passed.XCL_RUN_SECONDS.Not related to #236, whose race is between upload scanning and decommit in
sparse.rs.idxenreads from a CBV ignore the index – measured on Linux, Windows measurement wanted #307@gw1337x on GitHub · 2026-11-23 21:49 UTC · original
Confirming on GTA VI (retail), RX 7800 XT,
maind4f17ca: without this change the title crashed in every run once it loaded its world (3 of 3, at 70–150 s) – two or three threads at+0x13936/+0x1398b/+0x2926872, writing into the same 64 KiB page in the same millisecond. With an equivalent retry applied it passed that point every time (3 of 3) and ran until the next, unrelated wall (video memory, ~110 s).@Kalmarv on GitHub · 2026-11-23 22:02 UTC · original
I compared this with #250, which fixes the same race. Both fix it. They differ in one case, a genuine fault, and this PR handles that case correctly.
Findings
The race. Every race test aborts main (
63b9930) with an unhandled access violation, 10 of 10 runs each:threads_first_touching_one_lazy_page_together_all_go_on;threads_racing_on_a_lazy_page_all_go_on.Merged onto main, this PR (
77905f6) passes all three, 10 of 10 runs each. So does #250.The lost race, made deterministic. The test calls
handlerwith an access-violation record for a page another thread has just committed. Main answersCONTINUE_SEARCHfor both the write and the read: the crash. This PR answersCONTINUE_EXECUTIONfor both.Where the two differ: a genuine fault inside a committed lazy page. Take a lazy page that was committed and then had 4 KiB of it made read-only. A write there faults again on every retry.
PAGE_READWRITE, so it retries the write forever. The same real write hangs until killed.Both refuse execute accesses and pages that are only reserved.
Tested
63b9930; this PR merged onto it, with no conflicts.lazy.rsrelies on, and catches the second-chance one.Not tested
commitmakes every lazy pagePAGE_READWRITE, before and after this PR).🤖 Claude Opus 5.5
@mariuslozo-boop on GitHub · 2026-11-23 22:03 UTC · original
Test report on NVIDIA with this PR's head, on top of current main.
Setup: RTX 5070 Ti (16 GB), driver 616.92, Ryzen 7 7700X / 32 GB RAM, Windows 11 26300, release builds. Retail GTA VI 1.0.2.1 with
XCL_NETWORK=0. One run each.60565c4+0x13936(write at 0xc434223b0) and+0x1398b(write at 0xc43420000), same millisecond, same 64 KiB page7a033c8+0x35a4999(write at 0xc43450000) and+0x35a47bc(write at 0xc43450010), one 64 KiB page7a033c8+ this PR (77905f6, merged locally, no conflicts)CreatePlacedResourceX … a resource of its own (0x8007000e)lines (3540x8007000elines counting 8 view failures), 2D textures from 4×4 to 1024×1024, most of them 512×512. The title then hits a breakpoint (0x80000003at+0x193e00f, withrax=0x8007000e). That looks unrelated to this PR.Not tested: AMD, the PR's own test (
cargo test), more than one run per build.AI-assisted: Claude Code (Claude Opus 5.5) ran the builds and the game and wrote this report.
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175