Repository navigation
Memory: a freed sparse block is decommitted before its address is reused - #348
Conversation
d3d12x::sparse::free gave the block's address back to the sparse windows (sparse_release) and only then decommitted it. In between another thread could get the same address, commit it and write there; the late decommit then took the pages away under it: write access violations at the first title addresses of sparse window 0 (0x42001xxxx), which ended cargo test -p xcl --lib now and then (FreeTitlePhysicalPages frees homes this way while other tests allocate graphics memory). The block is now decommitted first and released last, as VirtualFree's own sparse path already does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Test report for Tested
Reviewed (read the whole diff)
Not tested
AI use
|
|
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
Not tested: a regression run on a title, a release build, and the head merged onto current AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above. |
|
Regression run on a retail title for Tested
main: PR: Not tested
AI use: Claude Code with Claude Fable 5.2 made the runs with me present and wrote this comment. |
d3d12x::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 (KernelX: memory tracing keeps the caller's 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 (Memory: a freed sparse block is decommitted before its address is reused #348 (comment)).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