kernelx: handle self-home/reused-home mappings in map_pages and unmap away pages on VirtualFree #2534
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2544"
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 Decodere on 2026-11-25T22:32:13Z.
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.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T22:46:50Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-25T22:52:05Z.
Full-suite run, since this PR has no test report yet. Tested exact head
19abb35(on its basee1d84b7).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1414 passed, 0 failed, 44 ignored. SKIPPED (no wave64):a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,dispatch_chain_native_wave64_builds_whole,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.map_pages_at_own_home_preserves_data_without_away_entry,scatter_reusing_moved_home_does_not_decommit_new_mapping,virtual_free_unmaps_away_pages_in_plain_and_sparse_reservations.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1425 passed, 0 failed, 46 ignored. SKIPPED:f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out tests that fail on maine1d84b7too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests,const_and_null_mask_operands_agree_with_hlsl_on_the_gpuandmask_ff0_and_flbit_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
Imported from ivall/xcl. Originally posted by xpatfussy69x on 2026-11-25T22:57:06Z.
Test run on exact head
19abb35(19abb354ddcbc98bec7b6a2eb54e4d18ac9ab9df, on its basee1d84b7, currentmain), clean tree.Tested
cargo test --workspace -- --test-threads=4: 1426 passed, 0 failed, 46 ignoredV_MUL_F16/V_PK_MUL_F16/V_CVT_F16_F32(onmaintoo)cargo test -p xcl --lib map_pages_at_own_home: 1 passed, 0 failedmap_pages_at_own_home_preserves_data_without_away_entry: okscatter_reusing_moved_home_does_not_decommit_new_mapping: okvirtual_free_unmaps_away_pages_in_plain_and_sparse_reservations: okRegression run (60 s, default settings, a retail title)
main:
this PR:
No crash or device removal; frames 106 % of
main's, peak commit 100 %.Not tested
AI use
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T23:24:57Z.
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).gpu_suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.Targeted run of
map_pages_at_own_home_preserves_data_without_away_entry,scatter_reusing_moved_home_does_not_decommit_new_mapping,virtual_free_unmaps_away_pages_in_plain_and_sparse_reservations: 3 passed. CPU-side, fine under the Wine lane.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.
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T07:02:25Z.
Review: COMMENTED
Could the plain
MEM_DECOMMITpath preserve host pages outside the requested range? With a committed 64 KiB away mapping in a plainMEM_PRIVATEreservation,VirtualFree(base + 4096, 4096, MEM_DECOMMIT)now selects the enclosing away page.unmap_awaycallsrelease_at, which decommits the fullPHYS_PAGE(64 KiB) before the wrapper forwards the original 4 KiB call. On main, the plain path forwards that call directly to nativeVirtualFree.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 threeMEM_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 requestsPHYS_PAGE, so a sub-page decommit with committed sentinels on both sides would cover this difference.Exact-head source trace at
19abb354ddcbc98bec7b6a2eb54e4d18ac9ab9dfand native Win32 API probe only; I did not run XCL's wrapper or a title. AI-assisted review with Codex.Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T07:35:00Z.
@luckyteagirl Great catch — pushed
c9743291(rebased ontob49be183) fixing this and a related MBI-start boundary case:unmap_away_innow usesunmap_away_with(..., release_backing = false), detachingAWAY/LAZYbookkeeping and copying committed 64 KiB bytes back to home without callingrelease_at()for the fullPHYS_PAGE, so nativeVirtualFreeretires only the exact requested 4 KiB host pages.plain_free_range(MEM_DECOMMIT,size > 0) now bounds the range by 4 KiB OS pages (req_start..req_end) rather thanm.BaseAddress, so sub-page decommits in one away page never detach an adjacent committed away page in the same contiguousVirtualQueryregion.plain_subpage_decommit_preserves_neighbor_pages_and_home_copycovering two adjacent committed 64 KiB away pages with a middle-4 KiBMEM_DECOMMITand committed sentinels on both sides (MEM_COMMIT / MEM_RESERVE / MEM_COMMIT), verifying the adjacent page stays inAWAYand remapping restores the full 64 KiB home snapshot.hle::kernelx::tests::(44/0/1,0skipped), full release workspace (1439/0/47), and paired 60 s RTX 4060 smoke (1558frames,60 60 60,0removals/crashes).Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:20:11Z.
Triage (#1607) – head
c974329No 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
at == homecase inkernelx.rs:map_pages. In a non-consecutive map, a page placed at its own home still goes throughcopy_nonoverlapping(home, home, ..)andmove_home_away, andVirtualFreeleavesAWAY/lazyentries behind.The branch conflicts: on main,
map_pagesnow keepsaway.titleand asparse_run, and plainVirtualFreegoes throughsource_part_going. After the rebase, the new self-home path also needsaway.title.insert(at, p)like the other paths, and needs asparse_run.flush()where it commits or decommits.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.