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.
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.