kernelx: forget a graphics reservation before Windows can hand its address out #2762
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2772"
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?
Imported from ivall/xcl. Originally posted by inf1425 on 2026-11-26T11:38:32Z.
VirtualFreeof a whole graphics reservation (MEM_RELEASE, size 0) unpairs it before Windows releases it. Three other cleanup steps only ran after the release: removing it fromGRAPHICS_RESERVATIONS, forgetting the title's page mappings there (forget_title_mappings), and clearing the places of shown pages kept there (mirrors::place_gone). Once Windows has released the range, it can give the same address to another thread, and those late steps then wiped the new reservation's records too. The new reservation was no longer a graphics reservation, and its GPU-view pages showed nothing. Its own later release then skipped the unpairing, because the record was gone, which left a stale pair that kept the next CPU view at that address from pairing. In a title, this happens whenever one thread releases graphics memory while another reserves it. Found while checking thenvidia-devtest failures reported in #42.The cleanup now runs before Windows is called, as the sparse and unified-memory release paths in the same function already do. If Windows refuses the release, the reservation's record is put back. Sparse is still told about the shown pages (
remapped) after the call.What is in it
crates/xcl/src/hle/kernelx.rs,VirtualFree: the graphics-reservation cleanup moves before the Windows call, and the record is restored on failure.crates/xcl/src/hle/kernelx.rs, tests:AFTER_WINDOWS_RELEASE, a test-only hook that runs right after Windows released memory on this thread, anda_reservation_made_where_a_graphics_reservation_just_went_keeps_its_own_record. The test reserves the released address again from the hook, maps a page there, and checks that the reservation and the mapping survive the release. It fails with the old order ("the new reservation is still a graphics reservation").Tested
cargo test --workspace --no-fail-fast -- --test-threads=4at this PR's head: 1746 passed, 5 failed, 48 ignored. The 5 failures are the ones reported in #42: four are fixed by #2770 and #2771, and the mesh test is in #2632.XCL_HEAP_WINDOWS=1.cargo test -p xcl --lib hle::kernelx -- --test-threads=4, repeated:nvidia-dev: 10 failures in 40 runs, across 3 tests;a_page_leaving_plain_memory_has_the_tiles_over_it_linked_againfailed 3 times in 40 runs, andcpu_view's pairing assert failed once in 24;Regression run
This changes runtime code. Smoke blocks from
nvidia-devand from this head will be added once a title is available; until then this stays a draft.main:
PR:
Not tested
AI use
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-26T12:00:59Z.
Regression run of
18b34a9on a newer retail title: no device removal, no crash, frames and commit within the limits.Setup: RTX 3060 12 GB (NVIDIA 581.80), i9-14900KF, Windows 11 26200, release builds of main
b49be18(this PR's base) and of this PR's exact head,scripts/smoke.ps1 -Game <title>for 60 s withXCL_NETWORK=0and A pressed every 4 s from 20 s.main:
this PR:
105 % of main's frames, 102 % of its peak commit. One run each.
Not tested: the suite on this head; whether the title reaches the reservation path this PR changes in its first 60 s; AMD.
AI use: Claude Code (Claude Opus 5.5) ran these runs on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-26T12:40:44Z.
Review: COMMENTED
Needs changes: preserve title-page mappings when Windows rejects a release. On head
18b34a9d992f02b5b3c12c3799e9add8acb847d8, the pre-release cleanup clears the title mapping before calling Windows, but failure restores only the graphics-reservation record. Please preserve/restore the mapping on failure while retaining the successful-release address-reuse fix.I verified this with the same test-only CPU fixture added to the exact NVIDIA base and PR head; runtime code was unchanged. It maps one owned physical page into a watched reservation, calls
VirtualFree(r, 0, MEM_RELEASE | MEM_DECOMMIT), and checks the mapping survives rejection. On both revisions Windows rejected the call,VirtualQueryshowed the allocation and page state remained, and cleanup assertions passed. Only the head lost the mapping:title_at(r)wasNoneinstead ofSome(16).af2cecc40886a8682ecf3267f5328c6dc4b66ad718b34a9d992f02b5b3c12c3799e9add8acb847d8Both built with
cargo test --locked --offline -p xcl --lib --no-run --message-format=json --target-dir <isolated-target>, then ran<test-exe> hle::kernelx::tests::a_rejected_graphics_release_keeps_the_title_page_mapping --exact --test-threads=1 --nocapture. Only private executable/target paths are placeholders. Fresh processes usedXCL_UMA_WINDOWS=4 XCL_UMA_MB=16 XCL_COHERENT_MB=16 XCL_HEAP_WINDOWS=0.Windows 11 Pro 26200, i5-10400, 32 GiB RAM, Rust 1.100.0 MSVC debug tests. The fixture has no skip branch and cleans its owned allocation before the final assertion. This tests rejected-call bookkeeping; no GPU, full-suite, successful-release race or retail-title result is claimed. Test overlay SHA-256: base
21c7aa67a5514a7a1483330c8a58091ae6d42e87eff0d43b1c866578c39c8b52, head34abd3a8a8514bcb76569e14f2d5bb39f0cf6007d72cff1bad563a9f4f771e8a(identical added test, different patch context).AI use: Codex (GPT-6) reviewed the source, prepared the fixture, ran the paired checks and independently audited the raw results. Optional temporary Discord for coordinating contributor work, testing and comparing results.
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #172Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-26T13:19:18Z.
Review: COMMENTED
Follow-up to the paired base/head regression report. Exact PR head
18b34a9d992f02b5b3c12c3799e9add8acb847d8. GitHub rejected editing that review, so this adds the new measured repair results separately.Additional controlled repair check, 2026-11-26: a local, uncommitted repair keeps the existing ownership locks across the Windows call and commits title/pair/shown-page removal only after success. It preserves the successful-release reuse protection. This has not been pushed to this PR.
The three red failures were lost title mapping, changed shown-page metadata, and lost CPU/GPU pairing after a rejected release. Each fixture checked the retained OS allocation and completed its owned-allocation cleanup before the final failing assertion. The existing successful address-reuse and CPU-view decommit tests passed on both variants.
Exact filters, using
cargo test --locked --offline -p xcl --lib --no-run --message-format=json --target-dir <isolated-target>, then<test-exe> <exact-name> --exact --test-threads=1 --nocapture;XCL_UMA_WINDOWS=4 XCL_UMA_MB=16 XCL_COHERENT_MB=16 XCL_HEAP_WINDOWS=0:hle::kernelx::tests::a_rejected_graphics_release_keeps_the_title_page_mappinghle::kernelx::tests::a_rejected_graphics_release_keeps_a_shown_page_placehle::kernelx::tests::a_rejected_cpu_view_release_keeps_its_pair_and_shown_pagehle::kernelx::tests::a_reservation_made_where_a_graphics_reservation_just_went_keeps_its_own_recordhle::kernelx::tests::a_decommit_or_release_of_a_cpu_view_is_told_to_sparse_firstRepair overlay SHA-256:
888c2a6c45813f0424fd16749d324797afa40c68eaeb411148daed15efcdf422. Test-only red overlay:6064921abe6461844c7b3a2b7bd06d3e40653c4400718b236abd327f996ab29c. These finite CPU tests validate the measured rejected-call ownership behavior; they do not establish contention safety, GPU-cache recreation, latest-main integration, or retail gameplay. Both variants are based on the exact PR head above.AI use: Codex (GPT-6) reviewed the source, prepared the fixture, ran the paired checks and independently audited the raw results. Optional temporary Discord for coordinating contributor work, testing and comparing results.
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-26T17:51:05Z.
Linux (Wine) dual-lane verification at head
18b34a9dTwo Linux hosts, two different Wine stacks, both lanes running the suite twice-over against today's
nvidia-devbase (af2cecc4) run on the same day:Suite:
cargo test --release --locked -p xcl --lib --target x86_64-pc-windows-gnu -- --test-threads=2 --skip gpu::(real GPU + DXC present in env,XCL_NETWORK=0).Results at
18b34a9d:hle::kernelx::tests::a_reservation_made_where_a_graphics_reservation_just_went_keeps_its_own_record, green here. The 6 reds are byte-identical to the base red set.nvidia-dev, none new.Why the Wine lanes matter for this one: #2772 is the direct sibling of #2773's sentinel change in the same sparse-VA family we documented under #2582. The race window (a fresh reservation grabbing an address a graphics reservation just released, then having its bookkeeping stolen) is exactly what Wine's allocator stresses differently: our Wine address space layout is its own, and the whole family behaved differently under Wine on #2582. Both Wine stacks agree the fix's regression test passes and nothing regressed.
Not tested: no real title run, no gameplay memory traces.
AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:55:29Z.
Triage (#1607) – head
18b34a9No open or merged PR makes the same change.
VirtualFreenow removes the graphics-reservation record and callsforget_title_mappingsandplace_gonebefore Windows releases the address, as the sparse and view paths on main already do. The new test uses theAFTER_WINDOWS_RELEASEhook to reserve the address again, and it would fail on main. One issue in the failure path: whenmem::VirtualFreereturns 0, the record is put back, but the title's mappings and shown-page places are already forgotten, andsparse::remapped(&gone)is still sent. Before this change, none of that happened on failure. Consider callingremappedonly whenok != 0, or explain why a failed release can be ignored here.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.