Tests: tell a leaked XApu buffer from another allocation at its address #2690

Open
sage-sage wants to merge 1 commit from upstream-pr/2700 into main
sage-sage commented 2026-11-26 07:12:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sage-sage on 2026-11-26T07:12:23Z.


hle::acphal::tests::xapu_connect_returns_oom_and_cleans_up_on_failure is flaky in parallel runs: it checks that the data buffer was released by asking VirtualQuery whether its address is free, and another test's thread can get an allocation at that address between the release and the check (left: 4096, right: 65536, a 4 KiB committed region where the 64 KiB buffer was). Test-only change.

What is in it

  • crates/xcl/src/hle/acphal.rs: the test's allocator reserves 0x53000 bytes (a size nothing else in the process allocates) and commits the buffer at its start (a failed commit releases the reservation); the check fails only if an allocation of exactly that size still starts at the buffer's address. Another allocation there, or none, passes.

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0, debug build, base b49be18, head c8a7d45
  • cargo test --workspace -- --test-threads=4: 1435 passed, 0 failed, 47 ignored
  • hle:: lib tests at --test-threads=12: before this change (main plus an unrelated d3d12x fix), about 200 runs: this test failed 7 times; with it (b4ea470, the previous head; c8a7d45 only adds the failed-commit cleanup below), 300 runs: 0 times (the other failures in those runs were the known a_dispatch_with_a_pipeline_still_building_waits_at_the_submit and placed_title_textures_share_vram_and_preserve_pixels flakes, which #2691 / #1453 and #2591 fix, and one device removal)
  • with the VirtualFree in xapu_connect_with taken out (local only), the test fails (data buffer must be released); with another allocation made at the freed address just before the check (local probe), it passes

Regression run

  • None needed: test-only change (only the #[cfg(test)] test in acphal.rs changes).

Not tested

  • Nothing outside the test changes; AMD / Intel.

AI use

  • Claude Code, Claude Opus 5.5: found the flake in repeated parallel runs, wrote the change, ran the tests and wrote this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5505655562 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2700). Originally posted by [sage-sage](https://github.com/sage-sage) on 2026-11-26T07:12:23Z. --- `hle::acphal::tests::xapu_connect_returns_oom_and_cleans_up_on_failure` is flaky in parallel runs: it checks that the data buffer was released by asking `VirtualQuery` whether its address is free, and another test's thread can get an allocation at that address between the release and the check (`left: 4096, right: 65536`, a 4 KiB committed region where the 64 KiB buffer was). Test-only change. **What is in it** - `crates/xcl/src/hle/acphal.rs`: the test's allocator reserves 0x53000 bytes (a size nothing else in the process allocates) and commits the buffer at its start (a failed commit releases the reservation); the check fails only if an allocation of exactly that size still starts at the buffer's address. Another allocation there, or none, passes. **Tested** - RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0, debug build, base `b49be18`, head `c8a7d45` - `cargo test --workspace -- --test-threads=4`: 1435 passed, 0 failed, 47 ignored - `hle::` lib tests at `--test-threads=12`: before this change (`main` plus an unrelated `d3d12x` fix), about 200 runs: this test failed 7 times; with it (`b4ea470`, the previous head; `c8a7d45` only adds the failed-commit cleanup below), 300 runs: 0 times (the other failures in those runs were the known `a_dispatch_with_a_pipeline_still_building_waits_at_the_submit` and `placed_title_textures_share_vram_and_preserve_pixels` flakes, which #2691 / #1453 and #2591 fix, and one device removal) - with the `VirtualFree` in `xapu_connect_with` taken out (local only), the test fails (`data buffer must be released`); with another allocation made at the freed address just before the check (local probe), it passes **Regression run** - None needed: test-only change (only the `#[cfg(test)]` test in `acphal.rs` changes). **Not tested** - Nothing outside the test changes; AMD / Intel. **AI use** - Claude Code, Claude Opus 5.5: found the flake in repeated parallel runs, wrote the change, ran the tests and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
luckyteagirl commented 2026-11-26 08:23:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T08:23:46Z.

Review: COMMENTED


At head b4ea470062ddef4c949c044524b68b556eca3750, the new test allocator reserves RESERVED bytes and then commits sz (acphal.rs:1299-1303). If the reserve succeeds but the commit returns null, then_some(p) discards the only base pointer and returns None; the 0x53000-byte reservation remains until the test process exits. This is particularly possible under the commit pressure where this OOM fixture runs. Could the failed-commit branch call VirtualFree(p, 0, MEM_RELEASE) before returning None? Microsoft's VirtualFree contract specifies the reserved base and zero size for MEM_RELEASE.

This is a source-derived test-only review of the exact head; I did not inject a commit failure. AI use: OpenAI Codex (GPT-6.2 Sol) identified the partial-allocation path, and I checked the diff and Win32 contract before posting.

<!-- greyfinch-sync:ivall/xcl:review:6070633476 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2700#pullrequestreview-6070633476). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T08:23:46Z. **Review:** COMMENTED --- At head `b4ea470062ddef4c949c044524b68b556eca3750`, the new test allocator reserves `RESERVED` bytes and then commits `sz` (`acphal.rs:1299-1303`). If the reserve succeeds but the commit returns null, `then_some(p)` discards the only base pointer and returns `None`; the 0x53000-byte reservation remains until the test process exits. This is particularly possible under the commit pressure where this OOM fixture runs. Could the failed-commit branch call `VirtualFree(p, 0, MEM_RELEASE)` before returning `None`? [Microsoft's VirtualFree contract](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualfree) specifies the reserved base and zero size for `MEM_RELEASE`. This is a source-derived test-only review of the exact head; I did not inject a commit failure. AI use: OpenAI Codex (GPT-6.2 Sol) identified the partial-allocation path, and I checked the diff and Win32 contract before posting.
sage-sage commented 2026-11-26 09:07:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sage-sage on 2026-11-26T08:55:55Z.


@luckyteagirl thank you, fixed in c8a7d45 (squashed): when the commit fails, the test allocator now releases the reservation (VirtualFree(p, 0, MEM_RELEASE)) before returning None. cargo test --workspace -- --test-threads=4 on c8a7d45: 1435 passed, 0 failed, 47 ignored (RTX 4080 SUPER, debug); I did not inject a commit failure either.

Claude Code (Claude Opus 5.5) made the change, ran the tests and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7187198330 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2700#issuecomment-7187198330). Originally posted by [sage-sage](https://github.com/sage-sage) on 2026-11-26T08:55:55Z. --- @luckyteagirl thank you, fixed in `c8a7d45` (squashed): when the commit fails, the test allocator now releases the reservation (`VirtualFree(p, 0, MEM_RELEASE)`) before returning `None`. `cargo test --workspace -- --test-threads=4` on `c8a7d45`: 1435 passed, 0 failed, 47 ignored (RTX 4080 SUPER, debug); I did not inject a commit failure either. Claude Code (Claude Opus 5.5) made the change, ran the tests and wrote this reply.
rgroenewoudt commented 2026-11-26 16:39:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by rgroenewoudt on 2026-11-26T16:39:31Z.


Tested on AMD Radeon RX 9070 (RDNA4) at this PR's head c8a7d45: xapu_connect_returns_oom_and_cleans_up_on_failure passed in all 20 parallel runs.

Tested

  • AMD Radeon RX 9070, driver 32.0.32029.2010; AMD Ryzen 9 5950X; Windows 11 Pro build 26300; Rust 1.100.0 MSVC; DXC 1.9.2602.17; debug build
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1433 passed, 2 failed, 47 ignored. The 2 failures are fuzz_validate_and_gpu_1 (seed 722) and _3 (seed 1599), the AMD ones from #2115, not touched here.
  • cargo test -p xcl --lib -- hle:: --test-threads=12, 20 runs: this test passed 20/20. Other failures in those runs, not touched here: a_dispatch_with_a_pipeline_still_building_waits_at_the_submit 13/20, a_tile_decommitted_and_committed_again_keeps_its_video_memory 2/20 (#2775).
  • SKIPPED (7): 6 × f16 / f32 per-lane forms refused (#1426); heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Not tested

  • main without this change at --test-threads=12 on this card, so I have no failure rate from before

AI use

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs.
<!-- greyfinch-sync:ivall/xcl:comment:7197930957 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2700#issuecomment-7197930957). Originally posted by [rgroenewoudt](https://github.com/rgroenewoudt) on 2026-11-26T16:39:31Z. --- **Tested on AMD Radeon RX 9070 (RDNA4) at this PR's head `c8a7d45`**: `xapu_connect_returns_oom_and_cleans_up_on_failure` passed in all 20 parallel runs. **Tested** - AMD Radeon RX 9070, driver 32.0.32029.2010; AMD Ryzen 9 5950X; Windows 11 Pro build 26300; Rust 1.100.0 MSVC; DXC 1.9.2602.17; debug build - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1433 passed, 2 failed, 47 ignored. The 2 failures are `fuzz_validate_and_gpu_1` (seed 722) and `_3` (seed 1599), the AMD ones from #2115, not touched here. - `cargo test -p xcl --lib -- hle:: --test-threads=12`, 20 runs: this test passed 20/20. Other failures in those runs, not touched here: `a_dispatch_with_a_pipeline_still_building_waits_at_the_submit` 13/20, `a_tile_decommitted_and_committed_again_keeps_its_video_memory` 2/20 (#2775). - SKIPPED (7): 6 × f16 / f32 per-lane forms refused (#1426); `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) **Not tested** - `main` without this change at `--test-threads=12` on this card, so I have no failure rate from before **AI use** - Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs.
github-actions[bot] commented 2026-12-01 02:35:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:35:16Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298776605 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2700#issuecomment-7298776605). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:35:16Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 08:44:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:44:32Z.


Triage (#1607) – head c8a7d45

No open or merged PR makes the same change. Main's xapu_connect_returns_oom_and_cleans_up_on_failure still checks MEM_FREE at the buffer's address, which another test thread's allocation can take.
The fix looks correct. The test reserves a 0x53000 region, commits only sz, and xapu_connect_with releases the whole reservation with VirtualFree(MEM_RELEASE). The loop then adds up the regions with AllocationBase == allocated_ptr and fails only when the full RESERVED size is still there. If the release is removed, the test still fails. The red check is PR description; the Windows build and test job passes.
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:7305718126 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2700#issuecomment-7305718126). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:44:32Z. --- **Triage (#1607)** – head c8a7d45 No open or merged PR makes the same change. Main's `xapu_connect_returns_oom_and_cleans_up_on_failure` still checks `MEM_FREE` at the buffer's address, which another test thread's allocation can take. The fix looks correct. The test reserves a 0x53000 region, commits only `sz`, and `xapu_connect_with` releases the whole reservation with `VirtualFree(MEM_RELEASE)`. The loop then adds up the regions with `AllocationBase == allocated_ptr` and fails only when the full `RESERVED` size is still there. If the release is removed, the test still fails. The red check is `PR description`; the Windows build and test job passes. 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/2700:upstream-pr/2700'
git switch 'upstream-pr/2700'

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/2700'
git switch 'upstream-pr/2700'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2700'
git switch 'upstream-pr/2700'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2700'
git switch 'main'
git merge --squash 'upstream-pr/2700'
git switch 'main'
git merge --ff-only 'upstream-pr/2700'
git switch 'main'
git merge 'upstream-pr/2700'
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!2690
No description provided.