Memory: fix Arena::take alignment/overflow and Uma::free pool validation #1437
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1447"
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 b3IKK on 2026-11-24T16:10:00Z.
Fixes three bugs in
crates/xcl/src/gpu/uma.rs:Arena::takereturnedGRAIN-aligned blocks even whenalign > GRAIN(violating the requested alignment), and computedalign.next_power_of_two(),self.at + align - 1, andat + nwithout overflow checks (panicking in debug or wrapping pastself.endin release).Uma::freepushed any address inside[pool.0, pool.1)onto the pool free list without verifyingARENA_BLOCKalignment or checking for duplicate frees, allowing interior pointers or double-frees to corrupt or alias subsequent arena allocations.Uma::reserve_pooloverwroteself.poolif called a second time, leaking the prior pool's reservation ininner.used.This routes
align > GRAINthroughu.alloc(n, align)and uses checked arithmetic inArena::take, validates block alignment and non-duplication inUma::free, and makesreserve_poola no-op once a pool is already reserved.What is in it
crates/xcl/src/gpu/uma.rs: fixArena::takealignment and overflow checks, validate pool frees inUma::free, guard repeatedreserve_pool, and add unit testsarena_take_enforces_large_alignment_and_checks_overflowandpool_free_rejects_interior_and_duplicate_pointers(both verified failing before the fix).Since the last push: rebased onto
main06c9f55. The conflict was the test module, wheremainhad addedruntime_layout_supports_eight_and_sixteen_heap_windows,expanded_heap_window_shaders_translate_and_validateandexpanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windowsat the same place; all are kept. The first push of the rebase had a missing brace in the merged test module (test builds only, so the release smoke still ran);f3d3344fixes it, with the same non-test code.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 1267 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses,no heap windows, andcannot disable the driver cache (Windows Developer Mode is required))cargo test -p xcl --lib gpu::uma::tests: 9 passed, 0 failed (both new tests failed before the fix)Regression run
main (
426a5a7, clean tree, no local changes):PR (
f3d3344, clean tree, no local changes):(The main block is
426a5a7, an ancestor of the currentmain, from the same machine and data folder.)Not tested
AI use
main06c9f55, resolved the conflicts, ran the suite and thescripts/smoke.ps1pair at the head above.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T16:54:51Z.
Full-suite run, since this PR has no test report yet. Tested exact head
f7b6286(on its baseb7aa9f3).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 772 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.arena_take_enforces_large_alignment_and_checks_overflow,pool_free_rejects_interior_and_duplicate_pointers.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 772 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:52:43Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:27:30Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T15:37:51Z.
Independent desktop NVIDIA verification of PR #1447 at head
f3d3344728450ff48bdfc0dc78d097a4e7d08382(1commit; exact parent & merge-base:06c9f5505f63f10c5ec49ef932d75b2c28177324, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted tests & build (
f3d33447)cargo test --release -p xcl --lib -- --nocapture arena_take_enforces_large_alignment_and_checks_overflow pool_free_rejects_interior_and_duplicate_pointers(3 consecutive runs)2 passed; 0 failed; 0 ignored; 1222 filtered out× 3 (0.00s,0.00s,0.00s,0skipped)cargo test --release -p xcl --lib -- --nocapture gpu::uma::(3 consecutive runs)14 passed; 0 failed; 0 ignored; 1210 filtered out× 3 (0.01s,0.01s,0.01s,0skipped; liveDXC 1.9.2609.5validatedexpanded_heap_window_shaders_translate_and_validate)cargo build --release -p xcl1m 32s, exit0,0new warnings ingpu/uma.rs)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
06c9f5505f63f10c5ec49ef932d75b2c28177324, cached baseline on the same machine):PR #1447 (
f3d3344728450ff48bdfc0dc78d097a4e7d08382):Limits of coverage
arena_take_enforces_large_alignment_and_checks_overflow,pool_free_rejects_interior_and_duplicate_pointers, and the fullgpu::uma::suite (14/14,0skipped) passed3/3, directly verifyingalign > GRAINhandling and checked overflow arithmetic inArena::take, idempotentUma::reserve_pool, and interior/duplicate pool-pointer rejection inUma::free.0device removals,0crashes, steady 60 Hz); single-run frame/commit delta vs. the cached parent reflects normal startup variance.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-27T16:12:34Z.
Tested on AMD / Linux:
f3d33447(RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimentalexperimental-11.0-20261112with vkd3d-proton masterec207194plus a local patch dropping thelpVtblchecks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0,x86_64-pc-windows-gnudebug build, tests run under Wine)The head as it is (not merged onto current
main), with its base06c9f550as the baseline.Tests (
XCL_REQUIRE_GPU=wave64)cargo test -p xcl --lib -- gpu::uma:: --test-threads=1: 14 passed, 0 failed, 0 ignored (includesarena_take_enforces_large_alignment_and_checks_overflowandpool_free_rejects_interior_and_duplicate_pointers).cargo test --workspace --no-fail-fast -- --test-threads=4with--skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole(here the first loses the RADV device, the other two run out of memory under Wine): lib 1181 passed, 17 failed, 26 ignored; base06c9f550(this PR's base) the same session: lib 1180 passed, 16 failed, 26 ignored. The failures are the base's plus one,gpu_geometry_wave32_prefix_count_over_a_mask, which is flaky here: run alone 3 times on each tree it failed once on this head and once on the base. The other binaries fail the same 3 tests as on the base (e2e,pls_quota,predication_e2e).d3d12_resource_and_sync: its fence and queue test ended the process here, as it does on the base and most other trees in this setup.Not tested
AI use
Imported from ivall/xcl. Originally posted by throny on 2026-11-27T23:28:17Z.
merge-check claim
head:
f3d3344728Imported from ivall/xcl. Originally posted by throny on 2026-11-27T23:41:23Z.
merge-check
base:
2c717a04head:
f3d3344728merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1468 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1466 passed, 0 failed, 47 ignored (26 SKIPPED lines)
review: none. reserve_pool takes the pool lock and then the inner lock, and nothing on main takes them the other way round; the new contains check scans at most 256 entries; an alignment above the grain gets its own allocation that honours it. Both new tests fail on main by reading the code (interior and duplicate frees are accepted there; the alignment is not honoured).
performance: a 256-entry scan when a pool block is freed; nothing per draw (reasoned).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T03:53:31Z.
merge-check claim
head:
f3d3344728Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T10:19:05Z.
merge-check
base:
e429936c10head:
f3d3344728merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2128 passed, 9 failed, 48 ignored, 25 SKIPPED: 21 no wave64, 3 per-lane f16/f32 forms refused (#1426 semantics), 1 no heap windows; failing: gpu::dxil::module::split::tests::dispatch_chain_oversized_loop_matches_whole, gpu::dxil::module::split::tests::dispatch_chain_wave32_live_loops, gpu::dxil::module::split::tests::dispatch_chain_wave64_live_loops_and_exchange, gpu::recomp::heap_window_tests::gpu_heap_flat_reads_match_guarded_and_root_output, gpu::recomp::tests::gpu_compute_mode_dispatch_abi, gpu::recomp::tests::gpu_float_cas_uses_ieee_equality, test_title_draws_with_a_root_signature_under_the_debug_layer, test_title_runs_and_game_folder_is_untouched, test_title_runs_under_the_debug_layer_with_dred: these 9 fail on the base too (the base e429936c's suite, run alone on this PC with the same command: 2126 passed, 9 failed, 48 ignored, 25 SKIPPED, these same 9 failing), and each also failed when rerun alone on this merge (the two debug-layer e2e tests stop on the D3D12 debug layer rejecting a pixel shader as corrupt or unsigned, and test_title_runs_and_game_folder_is_untouched on the test title's console command list memory-methods check, "post-Wait32/64 write failed"); not caused by this PR. The suite ran on this PC at the same time as 4 other PRs' suites, in one queued job.
review: none. Whole diff read (uma.rs reserve_pool runs once under its lock, a pool block freed twice or by an interior pointer is refused, Arena::take checks overflow and gives an over-aligned piece (align > GRAIN) a block of its own; 2 tests). The free-list check is a linear scan of a list of at most a pool's blocks, only on frees inside the pool.
performance: reasoned, not measured: one comparison more per arena take, a scan of the pool's free list per pool free; no change to the common path.
verdict: safe to merge
hardware / tool and model: Windows 11 build 26300.9974, NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.40, wave32 only), AMD Ryzen 5 3600XT; rustc 1.100.1 (20ddd0171 2026-11-25) x86_64-pc-windows-msvc, debug test profile; trial merge dc4b09a32d52d9c4179c804760e08b4e5f08912b (local, not pushed). Claude Code: Claude Opus 5.5 (coordination, full-diff review, draft).
correction (2026-11-28): the base counts above were first given as 2128 passed: that base run reused this PC's merge test binary (one cargo target dir for both sides). The base was rerun with its own target dir; the same 9 tests fail on it, so the classification and the verdict stand.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:47:10Z.
Triage (#1607) – head
f3d3344No open or merged PR makes the same change. #1386 hardens
Arenas::takein d3d12x/vram.rs, which is a different allocator.main'suma.rsstill has the uncheckedArena::takearithmetic and the unvalidated pool free.In
Uma::free,g.2.contains(&p)is a linear scan of the free pool list on every pool-block free (hundreds to thousands of entries with a large pool). A bitset or a sorted check would avoid that. The PR combines three fixes (Arena::takealignment/overflow, the pool free check, idempotentreserve_pool) that could be separate commits. It conflicts withmain.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.