Memory: fix Arena::take alignment/overflow and Uma::free pool validation #1447

Open
github-bot wants to merge 1 commit from github-bot/gh-1447 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 16:10 UTC · original
b3IKK:uma/arena-align-and-pool-free → main · +65 −8 · 1 files · 1 commits · open

Fixes three bugs in crates/xcl/src/gpu/uma.rs:

  • Arena::take returned GRAIN-aligned blocks even when align > GRAIN (violating the requested alignment), and computed align.next_power_of_two(), self.at + align - 1, and at + n without overflow checks (panicking in debug or wrapping past self.end in release).
  • Uma::free pushed any address inside [pool.0, pool.1) onto the pool free list without verifying ARENA_BLOCK alignment or checking for duplicate frees, allowing interior pointers or double-frees to corrupt or alias subsequent arena allocations.
  • Uma::reserve_pool overwrote self.pool if called a second time, leaking the prior pool's reservation in inner.used.

This routes align > GRAIN through u.alloc(n, align) and uses checked arithmetic in Arena::take, validates block alignment and non-duplication in Uma::free, and makes reserve_pool a no-op once a pool is already reserved.

What is in it

  • crates/xcl/src/gpu/uma.rs: fix Arena::take alignment and overflow checks, validate pool frees in Uma::free, guard repeated reserve_pool, and add unit tests arena_take_enforces_large_alignment_and_checks_overflow and pool_free_rejects_interior_and_duplicate_pointers (both verified failing before the fix).

Since the last push: rebased onto main 06c9f55. The conflict was the test module, where main had added runtime_layout_supports_eight_and_sixteen_heap_windows, expanded_heap_window_shaders_translate_and_validate and expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows at 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); f3d3344 fixes it, with the same non-test code.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (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, and cannot 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):

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15158 MB

PR (f3d3344, clean tree, no local changes):

xcl-smoke v1
commit: f3d3344728450ff48bdfc0dc78d097a4e7d08382
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1635 (PresentX 1636)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16158 MB

(The main block is 426a5a7, an ancestor of the current main, from the same machine and data folder.)

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: rebased onto main 06c9f55, resolved the conflicts, ran the suite and the scripts/smoke.ps1 pair at the head above.
**@⁠b3IKK** on GitHub · 2026-11-24 16:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1447) `b3IKK:uma/arena-align-and-pool-free` → `main` · +65 −8 · 1 files · 1 commits · open Fixes three bugs in `crates/xcl/src/gpu/uma.rs`: - `Arena::take` returned `GRAIN`-aligned blocks even when `align > GRAIN` (violating the requested alignment), and computed `align.next_power_of_two()`, `self.at + align - 1`, and `at + n` without overflow checks (panicking in debug or wrapping past `self.end` in release). - `Uma::free` pushed any address inside `[pool.0, pool.1)` onto the pool free list without verifying `ARENA_BLOCK` alignment or checking for duplicate frees, allowing interior pointers or double-frees to corrupt or alias subsequent arena allocations. - `Uma::reserve_pool` overwrote `self.pool` if called a second time, leaking the prior pool's reservation in `inner.used`. This routes `align > GRAIN` through `u.alloc(n, align)` and uses checked arithmetic in `Arena::take`, validates block alignment and non-duplication in `Uma::free`, and makes `reserve_pool` a no-op once a pool is already reserved. **What is in it** - `crates/xcl/src/gpu/uma.rs`: fix `Arena::take` alignment and overflow checks, validate pool frees in `Uma::free`, guard repeated `reserve_pool`, and add unit tests `arena_take_enforces_large_alignment_and_checks_overflow` and `pool_free_rejects_interior_and_duplicate_pointers` (both verified failing before the fix). **Since the last push**: rebased onto `main` `06c9f55`. The conflict was the test module, where `main` had added `runtime_layout_supports_eight_and_sixteen_heap_windows`, `expanded_heap_window_shaders_translate_and_validate` and `expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows` at 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); `f3d3344` fixes it, with the same non-test code. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`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`, and `cannot 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): ``` xcl-smoke v1 commit: 426a5a745db4d5e4b037449ede0b70cb342f5192 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15158 MB ``` PR (`f3d3344`, clean tree, no local changes): ``` xcl-smoke v1 commit: f3d3344728450ff48bdfc0dc78d097a4e7d08382 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1635 (PresentX 1636) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16158 MB ``` (The main block is `426a5a7`, an ancestor of the current `main`, from the same machine and data folder.) **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: rebased onto `main` `06c9f55`, resolved the conflicts, ran the suite and the `scripts/smoke.ps1` pair at the head above.
Three bugs in gpu/uma.rs:
- Arena::take returned GRAIN-aligned blocks even when `align > GRAIN`
  (violating the requested alignment), and computed `align.next_power_of_two()`,
  `self.at + align - 1`, and `at + n` without overflow checks (panicking in
  debug or wrapping past `self.end` in release).
- Uma::free pushed any address in `[pool.0, pool.1)` onto the pool free
  list without checking `ARENA_BLOCK` alignment or duplicate frees, allowing
  interior pointers or double-frees to corrupt or alias subsequent arena
  allocations.
- Uma::reserve_pool overwrote `self.pool` if called a second time, leaking
  the prior pool's reservation in `inner.used`.

Use checked arithmetic and route `align > GRAIN` through `u.alloc(n, align)`
in Arena::take, validate block alignment and non-duplication in Uma::free,
and make reserve_pool a no-op once a pool is already reserved.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:10 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 16:54 UTC · original · edited 2026-11-24 17:03 UTC

Full-suite run, since this PR has no test report yet. Tested exact head f7b6286 (on its base b7aa9f3).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_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.
  • The new tests ran and passed: arena_take_enforces_large_alignment_and_checks_overflow, pool_free_rejects_interior_and_duplicate_pointers.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 772 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 16:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1447#issuecomment-7138401435) · edited 2026-11-24 17:03 UTC Full-suite run, since this PR has no test report yet. Tested exact head `f7b6286` (on its base `b7aa9f3`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_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`. - The new tests ran and passed: `arena_take_enforces_large_alignment_and_checks_overflow`, `pool_free_rejects_interior_and_duplicate_pointers`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **772 passed, 0 failed, 41 ignored**, no skips. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:52 UTC · original

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 unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 18:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1447#issuecomment-7141278340) 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 unmodified `main`.) Thanks!
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 05:27 UTC · original

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

**@⁠DavidM1911** on GitHub · 2026-11-26 05:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1447#issuecomment-7183502445) 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
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1447/head:github-bot/gh-1447'
git switch 'github-bot/gh-1447'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1447'
git switch 'github-bot/gh-1447'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1447'
git switch 'github-bot/gh-1447'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1447'
git switch 'main'
git merge --squash 'github-bot/gh-1447'
git switch 'main'
git merge --ff-only 'github-bot/gh-1447'
git switch 'main'
git merge 'github-bot/gh-1447'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.