Memory: a freed sparse block is decommitted before its address is reused #348
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!348
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/348/head"
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?
@Kalmarv on GitHub · 2026-11-24 00:07 UTC · original
Kalmarv:fix/sparse-free-decommit-first→main· +31 −3 · 1 files · 1 commits · merged 2026-11-24 03:38 UTCd3d12x::sparse::freegave a block's address back to the sparse windows (sparse_release) and only then decommitted it. In between, another thread could take the same address, commit it and write there, and the late decommit then took the pages away under it. That is the write access violation at the first title addresses of sparse window 0 (0x42001xxxx–0x42004xxxx) that endscargo test -p xcl --libnow and then.FreeTitlePhysicalPagesfrees homes this way while other tests allocate graphics memory. A title freeing physical pages on one thread while another allocates graphics memory would hit the same thing. The block is now decommitted first and released last, asVirtualFree's own sparse path already does.What is in it
sparse::free: looks the reservation up (sparse_reservation), decommits it (decommittedandVirtualFree(MEM_DECOMMIT)), then releases it.a_freed_block_is_decommitted_before_its_address_is_reused: 4 threads, each 2000 times taking a 64 KiB block, writing both ends, reading back and freeing it. It needs no device: the sparse windows are address space only.Tested
cargo test --workspace -- --test-threads=4onebbf377(this PR, on main9ab7d76): 652 passed, 0 failed, 40 ignored (thexcllibrary: 612 passed, 20 ignored). SKIPPED GPU tests: 2, bothno wave64(gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware).--exact, CPU only, under a debugger that passes first-chance exceptions on and catches the second-chance one with its thread and stack:9ab7d76with the test added: 10 of 10 crashed, each a write AV at0x42001xxxx–0x42002xxxxin the test;ebbf377on9ab7d76.cargo test --workspace --no-fail-fast -- --test-threads=4: 652 passed, 0 failed, 40 ignored, no SKIPPED GPU tests; the new test passes.cargo test -p xcl --lib -- hle::kernelx(default threads), 30 runs each.d4f17ca: 1 run crashed with this AV, inconsole_alloc_flags_are_strippedat0x420040000; 2 runs failed on the then-unfixed last error (#226).--libsuite on maind4f17ca, 2 crashed with this AV, inxmem_placeholder_split_replace_and_coalesceandconsole_alloc_flags_are_stripped.hle::d3d12x::sparseandhle::kernelxtogether: 29 passed, 1 ignored, 3 of 3 runs.main9ab7d76and this head: 918 and 916 frames, no crash or device removal (https://github.com/ivall/xcl/pull/348#issuecomment-7119194294).Regression run
Our own runs, one after the other on the machine under Tested (RTX 5070 Ti), release builds, no uncommitted changes.
main:
PR:
Not tested
decommittedtakes its early path. The order of decommit and release is the same either way.sparse_release.AI use
hle::kernelx), wrote the change, the test and this description; the runs above are its own.🤖 Generated with Claude Code
@throny on GitHub · 2026-11-24 00:23 UTC · original
Test report for
ebbf377, merged ontomaina6f5f7a(clean merge, merge commit4a0bceb): pass, and the new test crashes without the fix.Tested
stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)cargo build --workspace && cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored (lib: 637 / 0 / 21,a_freed_block_is_decommitted_before_its_address_is_reusedok)SKIPPEDon this adapter:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)cargo test -p xcl --lib a_freed_block_is_decommitted: 10 of 10 runs pass (1 passed each, so the test is not returning early here: the sparse windows exist).sparse::freeput back tomain's order (sparse_release, thendecommittedandVirtualFree), the same command ends with the test process crashing in 5 of 5 runs.Reviewed (read the whole diff)
sparse_reservation(p).filter(start == p)keeps the old behaviour for an address inside a block (not freed,false). The block still belongs to the caller while it is decommitted, so no other thread can be handed the address beforesparse_release.falsefromsparse_release; withmain's order the second returned before decommitting. A double free is the caller's bug either way.Not tested
scripts/smoke.ps1) on a title, noXCL_SAMPLE_*game-data tests, AMD and wave64 hardware, release build.AI use
@TheHoracio on GitHub · 2026-11-24 00:36 UTC · original
Test report on AMD RDNA3: RX 7800 XT (16 GB), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used.
Tested: the PR head
ebbf377as it is (on its base9ab7d76, not merged onto current main).cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 652 passed, 0 failed, 40 ignored, no SKIPPED tests.a_freed_block_is_decommitted_before_its_address_is_reusedpasses.Not tested: a regression run on a title, a release build, and the head merged onto current
main.AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.
@CuteBooty on GitHub · 2026-11-24 01:32 UTC · original
Regression run on a retail title for
ebbf377, which the description lists as pending: pass (no device removal, no crash, frames and peak commit level withmain).Tested
scripts\smoke.ps1 -Game <folder> -Seconds 60on the PR's head as it is and onmain9ab7d76, the commit it is based on, each built from a clean checkout of its commit.main) and 939 frames (PR), also with no device removal or crash. Themainblock is one run, shared with my reports on #349 and #350.memory:line: 6311 MB local / 4619 MB non-local (main), 6248 MB local / 4619 MB non-local (PR).main:
PR:
Not tested
AI use: Claude Code with Claude Fable 5.2 made the runs with me present and wrote this comment.