kernelx: use checked size rounding in VirtualAlloc and Uma::sparse_reserve #1176
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1185"
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-24T12:57:01Z.
VirtualAllocroundedMEM_GRAPHICSsizes withdiv_ceil(align) * align, andUma::sparse_reserve/Uma::sparse_alloc_inrounded with(size.max(1) + GRAIN - 1) & !(GRAIN - 1). For sizes nearusize::MAX, these overflowed—aborting the process on panic insideextern "system" fnin debug builds and wrapping to0(returning a non-null allocation) in release builds.This switches them to
checked_next_multiple_of(matchingXMemAllocDefaultandUma::sparse_alloc) andchecked_next_power_of_twoinsparse_alloc_in.What is in it
crates/xcl/src/hle/kernelx.rs: usechecked_next_multiple_ofinVirtualAlloc'sMEM_GRAPHICScommit and 4 MiB reserve paths; addvirtual_alloc_and_sparse_reserve_overflows_fail_cleanly(aborted with0xc0000409before the fix).crates/xcl/src/gpu/uma.rs: usechecked_next_multiple_ofinsparse_reserveandsparse_alloc_in, andchecked_next_power_of_twofor alignment insparse_alloc_in.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): 742 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib virtual_alloc_and_sparse_reserve_overflows_fail_cleanly: 1 passed, 0 failed (panicked/aborted with0xc0000409before the fix)Regression run
main:
PR:
Not tested
AI use
kernelx.rsanduma.rs, wrote the fix and regression test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:08:39Z.
Independent verification on current
main384f7f7(branch already contains it — clean).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
cargo test -p xcl --lib kernelx: 33 passed, 0 failed, 1 ignored.cargo test -p xcl --lib uma: 10 passed, 0 failed — the checked size rounding inVirtualAlloc/Uma::sparse_reservekeeps both suites green.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-24T14:34:47Z.
A run on Linux under Wine.
Tested
x86_64-pc-windows-gnu.1ba5518as it is (based on47efa2e), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact).VirtualAllocis Wine's here.hle::kernelx::tests::virtual_alloc_and_sparse_reserve_overflows_fail_cleanly: ok, no SKIPPED.Not tested
AI use
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-27T21:26:38Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:02:04Z.
Triage (#1607) – head
1ba5518Part of this is on main already:
Uma::sparse_reserveuseschecked_next_multiple_ofthere (commit237b7181). The rest is not: main'skernelx::VirtualAllocgraphics commit path still doessize.max(1).div_ceil(align) * alignand the 4 MiB reserve pathdiv_ceil(4 << 20) * (4 << 20), which wrap to 0 in release for sizes near usize::MAX, andUma::sparse_alloc_instill rounds unchecked. No open PR makes the same change.No problems found in the diff; a rebase should drop the
sparse_reservehunk.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T08:11:40Z.
merge-check
base:
16c2fd082ahead:
1ba5518d15merge: clean (
sparse_reserveis on main already, so that hunk disappears in the merge)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3009 passed, 4 failed, 56 ignored (base: 3012 passed, 0 failed, 56 ignored, counted on
395405e4; only docs and scripts changed since); SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing:title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels("superseded unaligned extra_pages must be reclaimed immediately") and threestream_recheck_*tests that stop at the lock it poisoned. That is the flake #2591 fixes (the test reads a page count of the whole device), not this PR. A second run of the whole lib binary passed: 2857 passed, 0 failed, 36 ignored. An earlier run of the suite ended with 0xc0000005 during the thread-dump test (#3586, on main too)review: read the whole diff as it merges (2 files, +27 -12). No finding.
MEM_GRAPHICScommit path, the new test aborts (0xc0000409, "attempt to multiply with overflow"). I did not undo the other two places one by one.usize::MAX, so I also tried sizes that still round without overflow (scratch test): 9 sizes from 2^47 tousize::MAX, with 6 allocation types each. All 54 calls returned null, and the used bytes of the coherent and sparse windows were the same before and after.div_ceil(align) * alignis inVirtualAlloc(XCL_COHERENT_HEAPS=sparse). It cannot overflow: the branch is taken only for sizes up touma::MAX_SIZE.47efa2ec, from before most of today'sVirtualAlloc.performance: none: the same rounding with an overflow check, once per allocation.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
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.