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
|
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.
… 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:
- Detach 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 without calling release_at() for the
whole 64 KiB PHYS_PAGE, so native VirtualFree retires only the exact
requested 4 KiB OS pages (preserving neighboring committed pages on
sub-64 KiB MEM_DECOMMIT).
- Validate plain MEM_PRIVATE ranges at 4 KiB OS-page granularity (req_start..req_end
rather than m.BaseAddress) with a zero-syscall fast path when no away
candidate overlaps, so invalid calls and neighboring committed pages in
the same MBI region leave unrelated AWAY entries intact.
Part of xcl-dev#1833
Part of xcl-dev#1566
Part of xcl-dev#697
Assisted-by: Google Antigravity (Gemini 4 Neon)
19abb35 to
c974329
Compare
|
@luckyteagirl Great catch — pushed
|
…ort upstream xcl-dev#2544) Windows hle/kernelx.rs hunks verbatim reference-only (cfg(windows)-only): unmap_away_in/unmap_away_range, plain_free_range (VirtualQuery-validated MEM_PRIVATE free range), unmap_away_for_plain_free + both VirtualFree call sites, the map_pages at == home branch (recommit the home, drop the gone run entry, unmap a stale away view) with away.gone.retain on every successful mapping path, and all three upstream tests verbatim. Linux hle/kernelx_linux.rs twin: unmap_away_in/unmap_away_range (entries dropped, each page's bytes copied back to its live home; no note_mapping_at counterpart, the queue record has no Linux twin) wired into the graphics-pool VirtualFree paths, where the same stale-entry bug lived: release now unmaps the whole allocation range (the old code only forgot the exact base) and decommit unmaps its range first. No twin for plain_free_range/unmap_away_for_plain_free (every away mapping lives in the mmap'd graphics pool, so plain munmap/madvise paths cannot overlap one), nor for at == home / gone.retain (no gone runs on Linux; calloc homes and pool targets are disjoint). Failing-first: the new virtual_free_unmaps_away_pages_across_gfx_ reservations FAILED pre-fix (stale entries survived decommit/release), green after; full kernelx_linux group green with --test-threads=4 (the repo's setting; default-thread contention failures pre-exist on the base and are unrelated).
|
No open or merged PR makes the same change: #879 (paired GPU views), #1831, #2585 and #2652 share only the linked issues and touch other code. main still has no AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
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_with,unmap_away_in,unmap_away_range,plain_free_range,unmap_away_for_plain_free): detach overlappingAWAY/LAZYpages (copying committed bytes back to home and clearing lazy marks) before decommitting or releasing sparse UMA reservations or validated plainMEM_PRIVATEreservations without callingrelease_at()for the fullPHYS_PAGE(64 KiB), so nativeVirtualFreeretires only the exact requested 4 KiB OS pages and preserves neighboring committed host pages on sub-64 KiBMEM_DECOMMIT; validate plainMEM_PRIVATEMEM_DECOMMITranges at 4 KiB OS-page granularity (req_start..req_endinstead ofm.BaseAddress) with a zero-syscall fast path when no away candidate overlaps so invalid calls and adjacent committed away pages in the same MBI region leave unrelatedAWAYentries intact.crates/xcl/src/hle/kernelx.rs(hle::kernelx::tests): added 4 pure-CPU0-skip unit tests:map_pages_at_own_home_preserves_data_without_away_entryscatter_reusing_moved_home_does_not_decommit_new_mappingvirtual_free_unmaps_away_pages_in_plain_and_sparse_reservationsplain_subpage_decommit_preserves_neighbor_pages_and_home_copy(verifying middle-4 KiBMEM_DECOMMITon a committed 64 KiB away page inside a two-page contiguousMEM_PRIVATEreservation leaves neighboring 4 KiB pagesMEM_COMMITwith sentinels intact, detaches only the affected away page while leaving the adjacent away page in the same MBI run untouched, and preserves the full 64 KiB home snapshot on remap).Tested
rustc 1.100.0, DXC1.9.2609.5,--release.e1d84b7d: all 3 initialhle::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:: --test-threads=1 --nocapture:44 passed, 0 failed, 1 ignored(scatter_timing),0skips on both WARP (XCL_ADAPTER=warp,1.54 s) and RTX 4060 (1.48 s).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture:37test binaries,1439 passed, 0 failed, 47 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 (
origin/mainancestor889ef3e8aa7f267323ab4879e735e65da6bcef10, ancestor ofb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):PR:
Not tested
scatter_timing(#[ignore]benchmark test inhle::kernelx::tests) and the 47#[ignore]workspace tests.AI use
map_pagesandVirtualFreefixes (including sub-pageMEM_DECOMMITpreservation and 4 KiB OS-page range bounds), added the 4 unit tests, verified failing-first and post-fix test suites and paired 60 s smoke runs, and drafted this PR description.