kernelx: forget a graphics reservation before Windows can hand its address out #2772
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!2772
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@inf1425 on GitHub · 2026-11-26 11:38 UTC · original
inf1425:kernelx/graphics-release-before-windows→nvidia-dev· +72 −11 · 1 files · 1 commits · draftVirtualFreeof 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
VirtualFree of a whole graphics reservation (MEM_RELEASE, size 0) unpaired it before Windows released it, but removed it from GRAPHICS_RESERVATIONS, forgot the title's page mappings there (forget_title_mappings) and cleared the places of shown pages kept there (mirrors::place_gone) only afterwards. Once Windows has released the range, another thread can be given the same address; that bookkeeping then took the new reservation's record, mappings and places too. The new reservation stopped being a graphics reservation, its GPU-view pages showed nothing, and its later release skipped the unpairing (no record), leaving a stale pair that kept the next CPU view at that address from pairing. The kernelx tests hit this in parallel runs (reserve_watched memory is released and reserved by several tests at once): with --test-threads=4, memory_under_a_shown_page_is_told_to_sparse_before_it_goes, a_page_leaving_plain_memory_has_the_tiles_over_it_linked_again (both `Shows::Nothing` right after apply_batches) and cpu_view's pairing assert failed in about 1 of 13 runs of hle::kernelx; with this change, 0 in 80 runs. The bookkeeping now happens before Windows is called, as the sparse and unified-memory release paths above already do; if Windows refuses the release, the reservation's record is put back. The shown pages are still told to sparse (remapped) after the call. New test: a_reservation_made_where_a_graphics_reservation_just_went_keeps_its_own_record reserves the released address again from a test-only hook that runs right after Windows released it (AFTER_WINDOWS_RELEASE), maps a page there, and checks both survive. It fails with the old order ("the new reservation is still a graphics reservation"). Assisted-by: Claude Code (Claude Opus 5.5)@Anon64 on GitHub · 2026-11-26 12:00 UTC · original
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.
@Prime1997 on GitHub · 2026-11-26 12:40 UTC · original · reviewed
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.
@Prime1997 on GitHub · 2026-11-26 13:19 UTC · original · reviewed
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.
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.