D3D12.X: reject zero alignment and size overflow in Arenas::take #1376

Open
b3IKK wants to merge 1 commit from upstream-pr/1386 into main
b3IKK commented 2026-11-24 15:30:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T15:30:15Z.


Fixes two bugs in crates/xcl/src/hle/d3d12x/vram.rs:

  • Arenas::take divided/modded by align without guarding align == 0 and computed va + bytes, a.base + a.size, and bytes.div_ceil(align) * align with unchecked arithmetic.
  • When Pages::bind hit OOM mid-way through a multi-tile placement, rollback called release_tiles(..., immediate_cool = true) on every tile acquired so farÔÇöevicting pre-existing cached idle pages (whose users count dropped back from 1 to 0) into cooling instead of leaving their cached VRAM intact.

This guards align == 0 and uses checked arithmetic in Arenas::take, and extracts acquire_tiles() so OOM rollback restores every pre-existing page's users and idle_since intact while removing only freshly inserted pages and returning their never-mapped tiles to free.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: guard align == 0 and checked arithmetic in Arenas::take; extract acquire_tiles() with exact rollback for Pages::bind; add unit tests arenas_take_rejects_zero_align_and_overflow (verified failing before the fix) and acquire_tiles_oom_preserves_preexisting_idle_pages_and_returns_new_tiles.

Since the last push: rewritten. main now takes the tile batch through TilePool::take_batch before inserting any page, so the acquire_tiles / Pages::bind rollback half no longer applies and was dropped with its test. What remains is the still-present Arenas::take bug: zero align divides by zero, va + bytes and the size rounding overflow, and an arena whose base + size wraps is treated as containing the placement. The new test arenas_take_rejects_zero_align_and_overflow fails on main's code with attempt to divide by zero at vram.rs:94.

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): 1266 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 arenas_take_rejects_zero_align_and_overflow and acquire_tiles_oom_preserves_preexisting_idle_pages_and_returns_new_tiles: both pass (arenas_take_rejects_zero_align_and_overflow panicked 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 (a76cf16, clean tree, no local changes):

xcl-smoke v1
commit: a76cf162b5923e931252ebf047b672818291b341
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1646 (PresentX 1646)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16021 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.
<!-- greyfinch-sync:ivall/xcl:issue:5475192906 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1386). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T15:30:15Z. --- Fixes two bugs in `crates/xcl/src/hle/d3d12x/vram.rs`: - `Arenas::take` divided/modded by `align` without guarding `align == 0` and computed `va + bytes`, `a.base + a.size`, and `bytes.div_ceil(align) * align` with unchecked arithmetic. - When `Pages::bind` hit OOM mid-way through a multi-tile placement, rollback called `release_tiles(..., immediate_cool = true)` on every tile acquired so farÔÇöevicting pre-existing cached idle pages (whose `users` count dropped back from `1` to `0`) into `cooling` instead of leaving their cached VRAM intact. This guards `align == 0` and uses checked arithmetic in `Arenas::take`, and extracts `acquire_tiles()` so OOM rollback restores every pre-existing page's `users` and `idle_since` intact while removing only freshly inserted pages and returning their never-mapped tiles to `free`. **What is in it** - `crates/xcl/src/hle/d3d12x/vram.rs`: guard `align == 0` and checked arithmetic in `Arenas::take`; extract `acquire_tiles()` with exact rollback for `Pages::bind`; add unit tests `arenas_take_rejects_zero_align_and_overflow` (verified failing before the fix) and `acquire_tiles_oom_preserves_preexisting_idle_pages_and_returns_new_tiles`. **Since the last push**: rewritten. `main` now takes the tile batch through `TilePool::take_batch` before inserting any page, so the `acquire_tiles` / `Pages::bind` rollback half no longer applies and was dropped with its test. What remains is the still-present `Arenas::take` bug: zero `align` divides by zero, `va + bytes` and the size rounding overflow, and an arena whose `base + size` wraps is treated as containing the placement. The new test `arenas_take_rejects_zero_align_and_overflow` fails on `main`'s code with `attempt to divide by zero` at `vram.rs:94`. **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`): **1266 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 arenas_take_rejects_zero_align_and_overflow` and `acquire_tiles_oom_preserves_preexisting_idle_pages_and_returns_new_tiles`: both pass (`arenas_take_rejects_zero_align_and_overflow` panicked 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 (`a76cf16`, clean tree, no local changes): ``` xcl-smoke v1 commit: a76cf162b5923e931252ebf047b672818291b341 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1646 (PresentX 1646) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16021 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.
futurepro62 commented 2026-11-24 16:07:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:34:25Z.


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

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: 753 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: arenas_take_rejects_zero_align_and_overflow, acquire_tiles_oom_preserves_preexisting_idle_pages_and_returns_new_tiles.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 753 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.
<!-- greyfinch-sync:ivall/xcl:comment:7136254667 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1386#issuecomment-7136254667). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:34:25Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `a46822f` (on its base `930e8b4`). **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`: **753 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: `arenas_take_rejects_zero_align_and_overflow`, `acquire_tiles_oom_preserves_preexisting_idle_pages_and_returns_new_tiles`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **753 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.
DavidM1911 commented 2026-11-24 17:06:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:55:31Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7138417925 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1386#issuecomment-7138417925). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T16:55:31Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
upstream-sync changed title from [PR #1386] D3D12.X: check Arenas::take overflow and preserve pre-existing pages on Pages::bind OOM to [PR #1386] D3D12.X: reject zero alignment and size overflow in Arenas::take 2026-11-25 16:10:37 +00:00
thiagocalile commented 2026-11-25 19:09:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thiagocalile on 2026-11-25T18:49:26Z.


Independent test and smoke report for head a76cf162b5923e931252ebf047b672818291b341 on an AMD Radeon RX 6600 (8 GB VRAM, RDNA2, native wave64).

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver 32.0.21045.29003, XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • XCL_ADAPTER=radeon cargo test --no-fail-fast -p xcl --lib -- arena --test-threads=4: 8 passed, 0 failed, 1 ignored (0 skipped).

Regression run (scripts/smoke.ps1, release builds, XCL_ADAPTER=radeon)

main (50a9fde):

xcl-smoke v1
commit: 50a9fdef81cb796b8756a31defb0648301d002ce
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1501 (PresentX 1501)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 11951 MB

PR #1386 (a76cf16):

xcl-smoke v1
commit: a76cf162b5923e931252ebf047b672818291b341
gpu: AMD Radeon RX 6600
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1544 (PresentX 1544)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17344 MB

Not tested: NVIDIA/Intel GPUs, Linux/Wine, or world load past the 60 s smoke window.

AI use: Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.

<!-- greyfinch-sync:ivall/xcl:comment:7171449037 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1386#issuecomment-7171449037). Originally posted by [thiagocalile](https://github.com/thiagocalile) on 2026-11-25T18:49:26Z. --- Independent test and smoke report for head `a76cf162b5923e931252ebf047b672818291b341` on an **AMD Radeon RX 6600** (8 GB VRAM, RDNA2, native wave64). **Tested** - Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver `32.0.21045.29003`, `XCL_ADAPTER=radeon`), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (`10.0.26200.0`), Rust `1.100.0` (`stable-x86_64-pc-windows-msvc`), DXC `1.8.2502.11`. - `XCL_ADAPTER=radeon cargo test --no-fail-fast -p xcl --lib -- arena --test-threads=4`: **8 passed, 0 failed, 1 ignored** (`0` skipped). **Regression run** (`scripts/smoke.ps1`, release builds, `XCL_ADAPTER=radeon`) `main` (`50a9fde`): ``` xcl-smoke v1 commit: 50a9fdef81cb796b8756a31defb0648301d002ce gpu: AMD Radeon RX 6600 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1501 (PresentX 1501) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 11951 MB ``` PR `#1386` (`a76cf16`): ``` xcl-smoke v1 commit: a76cf162b5923e931252ebf047b672818291b341 gpu: AMD Radeon RX 6600 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1544 (PresentX 1544) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17344 MB ``` **Not tested:** NVIDIA/Intel GPUs, Linux/Wine, or world load past the 60 s smoke window. **AI use:** Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.
bmjask commented 2026-11-25 21:46:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T21:46:15Z.

Review: COMMENTED


No concrete source defect found. Zero-alignment and checked arithmetic guards close described div-by-zero/overflow paths, with strong Windows/GPU/smoke evidence. Optional: add a rounding-only overflow case at va=0; I found no blocker.

<!-- greyfinch-sync:ivall/xcl:review:6065416774 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1386#pullrequestreview-6065416774). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T21:46:15Z. **Review:** COMMENTED --- No concrete source defect found. Zero-alignment and checked arithmetic guards close described div-by-zero/overflow paths, with strong Windows/GPU/smoke evidence. Optional: add a rounding-only overflow case at va=0; I found no blocker.
DavidM1911 commented 2026-11-26 05:05:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:03:28Z.


Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7183141547 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1386#issuecomment-7183141547). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T05:03:28Z. --- Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
Foniass commented 2026-12-01 05:36:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:36:46Z.


Triage (#1607) – head a76cf16

No open or merged PR makes the same change. #1447 hardens uma::Arena::take, a different function.
Main has since renamed this function to Arenas::take_for (with a dev key), so the branch conflicts and needs a rebase. The only caller (vram.rs, placing on arenas) passes align = Alignment.max(PAGE) and the size of a resource at a real address, so neither a zero align nor the va + bytes overflow can happen today: the guards are defensive, not a fix for a reachable bug. No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301951982 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1386#issuecomment-7301951982). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:36:46Z. --- **Triage (#1607)** – head a76cf16 No open or merged PR makes the same change. #1447 hardens `uma::Arena::take`, a different function. Main has since renamed this function to `Arenas::take_for` (with a `dev` key), so the branch conflicts and needs a rebase. The only caller (`vram.rs`, placing on arenas) passes `align = Alignment.max(PAGE)` and the size of a resource at a real address, so neither a zero `align` nor the `va + bytes` overflow can happen today: the guards are defensive, not a fix for a reachable bug. No problems found in the diff. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1386:upstream-pr/1386'
git switch 'upstream-pr/1386'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1386'
git switch 'upstream-pr/1386'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1386'
git switch 'upstream-pr/1386'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1386'
git switch 'main'
git merge --squash 'upstream-pr/1386'
git switch 'main'
git merge --ff-only 'upstream-pr/1386'
git switch 'main'
git merge 'upstream-pr/1386'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1376
No description provided.