Repository navigation
kernelx: handle self-home/reused-home mappings in map_pages and unmap away pages on VirtualFree - #2544
kernelx: handle self-home/reused-home mappings in map_pages and unmap away pages on VirtualFree#2544Decodere wants to merge 1 commit into
Conversation
… away pages on VirtualFree
Fix two physical-page bookkeeping bugs in kernelx:
1. map_pages self-home and reused-home handling:
- In non-consecutive multi-page MapTitlePhysicalPages calls where a page maps
to its own home (at == home), commit the home, clear it from away.gone, and
unmap any prior away mapping directly back to home instead of falling into
ptr::copy_nonoverlapping(home, home, ...) and queuing the live home in
away.gone for decommit.
- Whenever a page is mapped onto an address at (via move_away, lazy, or the
commit/copy path before move_home_away), clear at from away.gone so
give_back_homes never decommits a home reused within the same multi-page
or scatter call.
2. VirtualFree unmapping of away-mapped physical pages:
- Unmap overlapping AWAY/LAZY entries (preserving committed bytes back to
home and clearing lazy marks) before decommitting or releasing sparse UMA
or plain MEM_PRIVATE reservations.
- Validate plain MEM_PRIVATE ranges with a zero-syscall fast path when no
away candidate overlaps, so invalid VirtualFree calls leave AWAY intact.
Part of xcl-dev#1833
Part of xcl-dev#1566
Part of xcl-dev#697
Assisted-by: Google Antigravity (Gemini 4 Neon)
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Test run on exact head Tested
Regression run (60 s, default settings, a retail title) main: this PR: No crash or device removal; frames 106 % of Not tested
AI use
|
|
Tested: current PR head merged onto current
Not tested: retail titles (no title data on this lane, counts only). AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting. |
luckyteagirl
left a comment
There was a problem hiding this comment.
Could the plain MEM_DECOMMIT path preserve host pages outside the requested range? With a committed 64 KiB away mapping in a plain MEM_PRIVATE reservation, VirtualFree(base + 4096, 4096, MEM_DECOMMIT) now selects the enclosing away page. unmap_away calls release_at, which decommits the full PHYS_PAGE (64 KiB) before the wrapper forwards the original 4 KiB call. On main, the plain path forwards that call directly to native VirtualFree.
I checked the Windows granularity separately: decommitting only the middle 4 KiB of a committed 64 KiB reservation left the 0/4K/8K offsets MEM_COMMIT / MEM_RESERVE / MEM_COMMIT; decommitting the full 64 KiB left all three MEM_RESERVE. Could this path clear the away bookkeeping and preserve its home copy while letting the native call retire only the requested plain pages? The added “partial” test requests PHYS_PAGE, so a sub-page decommit with committed sentinels on both sides would cover this difference.
Exact-head source trace at 19abb354ddcbc98bec7b6a2eb54e4d18ac9ab9df and native Win32 API probe only; I did not run XCL's wrapper or a title. AI-assisted review with Codex.
Fixes two physical-page mapping bookkeeping bugs in
crates/xcl/src/hle/kernelx.rs: self-home / reused-home decommits and UB inmap_pages, and danglingAWAY/LAZYentries left behind whenVirtualFreedecommits or releases sparse UMA or plainMEM_PRIVATEreservations. Part of #1833, Part of #1566, Part of #697.What is in it
crates/xcl/src/hle/kernelx.rs(map_pages): resolvepage_home(p)safely right after skippingp == 0; when a non-consecutive multi-page mapping places a page at its own home (at == home), commit the home viacommit_homes(home, 1), drophomefromaway.gone, unmap any prior away mapping directly back tohome, and skip the away-copy path (avoidingptr::copy_nonoverlapping(home, home, ...)UB, bogus(home, p)AWAYinsertion, and subsequentgive_back_homesdecommit).crates/xcl/src/hle/kernelx.rs(map_pages): removeatfromaway.gonewhenever another page is mapped ontoat(acrossmove_away, the lazy path, and the commit/copy path beforemove_home_away) sogive_back_homesnever decommits a reused home within the same multi-page orXMemMapPhysicalPagesScattercall.crates/xcl/src/hle/kernelx.rs(VirtualFree,unmap_away_in,unmap_away_range,plain_free_range,unmap_away_for_plain_free): unmap overlappingAWAY/LAZYpages (copying committed data back to home and clearing lazy marks) before decommitting or releasing sparse UMA reservations or validated plainMEM_PRIVATEreservations, with a zero-syscall fast path when no away candidate overlaps and strictVirtualQueryvalidation so invalidVirtualFreecalls leaveAWAYintact.crates/xcl/src/hle/kernelx.rs(hle::kernelx::tests): added 3 pure-CPU0-skip unit tests (map_pages_at_own_home_preserves_data_without_away_entry,scatter_reusing_moved_home_does_not_decommit_new_mapping, andvirtual_free_unmaps_away_pages_in_plain_and_sparse_reservations).Tested
rustc 1.100.0, DXC1.9.2609.5,--release.e1d84b7d: all 3 newhle::kernelx::testsfailed cleanly (0 passed; 3 failed:self-home page must remain committed,reused home (from home) must stay committed,partial plain MEM_DECOMMIT must unmap away page).cargo test --release -p xcl --lib -- hle::kernelx::tests:: --nocapture:43 passed, 0 failed, 1 ignored(scatter_timing),0skips on both RTX 4060 andXCL_ADAPTER=warp.cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture:37test binaries,1426 passed, 0 failed, 46 ignored(SKIPPED GPU/host tests: 29 pre-existing on 32-lane RTX 4060 without D3D12 debug layer — 21 no wave64, 3 per-lane wave32 refused, 3 no D3D12 debug layer, 1 no heap windows, 1 cannot disable driver cache; 0 skipped inhle::kernelx::tests).Regression run
main:
PR:
Not tested
scatter_timing(#[ignore]benchmark test inhle::kernelx::tests).AI use
map_pagesandVirtualFreefixes, added the 3 unit tests, verified failing-first and post-fix test suites and paired 60 s smoke runs, and drafted this PR description.