d3d12-hle: publish xasync status before removing CALLS entry (D3D12-HLE-XASYNC-WAIT-STATUS-RACE) (carry of #3395) #3438

Merged
leonida/mandy
MoonEyes merged 3 commits from carry/3395 into main 2026-12-04 08:05:39 +00:00

Pull request successfully merged and closed

Member

Carry of #3395 by @blud (same commits, head 8b0fb0a84), opened only so the branch can be brought up to date with main: the original branch does not allow maintainer edits and main moved. Credit stays with the author; #3395 will be closed in favour of this one.

Already done on 8b0fb0a84: independent review ACCEPTED (lot 1), local tests green, in-game run of 300 s on an RTX 3090 PASS without cost (Enlighted), CI locale green on main 6b5ceb934 (Oreo).

Original description:

Claimed in the coordination issue as: D3D12-HLE-XASYNC-WAIT-STATUS-RACE (originally claimed in #2570, addressing the CI completion-race finding on d3d12/crates/leonida-hle/src/modules/xasync.rs).

What and why

In d3d12/crates/leonida-hle/src/modules/xasync.rs (complete_call), release(block) previously removed block from CALLS and invoked OP_CLEANUP before storing the terminal size and status. When a concurrent XAsyncGetStatus(block, true) arrived in that window, call(block) returned None, skipped waiting on call.done, and read E_PENDING instead of the completed status (observed in CI on modules::xasync::tests::run_returns_the_work_result).

This fixes the ordering in two places:

  1. complete_call: for result < 0 || required_size == 0, runs OP_CLEANUP before publishing size and status (preserving the block-lifetime invariant so no caller can observe completion or free block before OP_CLEANUP finishes), then removes block from CALLS after size.store and status.store (while still holding call.done), so a waiter in XAsyncGetStatus(block, true) can never miss CALLS and read E_PENDING.
  2. XAsyncBegin: after acquiring left.done on an existing entry, re-checks is_current(&left, block) before requiring zeroed(block) and calling release(block), so reusing a failed/no-result block immediately after observing terminal status never spuriously returns E_INVALIDARG.

Tested

  • Red on main: modules::xasync::tests::get_status_wait_never_observes_pending_during_completion fails deterministically with zero timeout dependence (call must stay in CALLS while status is still E_PENDING, and the concurrent waiter observes E_PENDING instead of E_ABORT).
  • Green with fix (cherry-picked cleanly onto leonida/main 99e0bc1ce):
    • cargo test -p leonida-hle --locked modules::xasync — 14 passed, 0 failed (covers both E_ABORT and S_OK, verifying both the zero-timeout CALLS-during-OP_CLEANUP invariant and the threaded waiter).
    • Full cargo test -p leonida-hle --locked — 259 unit tests + 1 integration test (no_dll_planting) passed, 0 failed.
    • python -I scripts/check_no_game_data.py d3d12/crates/leonida-hle/src/modules/xasync.rs — exit 0.
  • Independent reviews:
    • Separate read-only reviewer subagent (Gemini 4 Neon) — APPROVE.
    • Third-party verification by @merzleckeier on Wine 11.22 MSVC — confirmed red on main (call must stay in CALLS while status is still E_PENDING) and all 14 XAsync tests green with the fix.

GPUs tested: n/a (leonida-hle CPU/concurrency unit tests, no game files or GPU needed).

AI-assisted: yes — Gemini 4 Neon via Antigravity (implementation, regression test, and a separate read-only reviewer subagent using Gemini 4 Neon).

Checklist

  • Based on current main (99e0bc1ce) and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (n/a: no translator rule changed).

🤖 Generated with Claude Code

Carry of #3395 by @blud (same commits, head `8b0fb0a84`), opened only so the branch can be brought up to date with main: the original branch does not allow maintainer edits and main moved. Credit stays with the author; #3395 will be closed in favour of this one. Already done on `8b0fb0a84`: independent review ACCEPTED (lot 1), local tests green, in-game run of 300 s on an RTX 3090 PASS without cost (Enlighted), CI locale green on main `6b5ceb934` (Oreo). Original description: Claimed in the coordination issue as: `D3D12-HLE-XASYNC-WAIT-STATUS-RACE` (originally claimed in #2570, addressing the CI completion-race finding on `d3d12/crates/leonida-hle/src/modules/xasync.rs`). ### What and why In `d3d12/crates/leonida-hle/src/modules/xasync.rs` (`complete_call`), `release(block)` previously removed `block` from `CALLS` and invoked `OP_CLEANUP` *before* storing the terminal `size` and `status`. When a concurrent `XAsyncGetStatus(block, true)` arrived in that window, `call(block)` returned `None`, skipped waiting on `call.done`, and read `E_PENDING` instead of the completed status (observed in CI on `modules::xasync::tests::run_returns_the_work_result`). This fixes the ordering in two places: 1. **`complete_call`**: for `result < 0 || required_size == 0`, runs `OP_CLEANUP` *before* publishing `size` and `status` (preserving the block-lifetime invariant so no caller can observe completion or free `block` before `OP_CLEANUP` finishes), then removes `block` from `CALLS` *after* `size.store` and `status.store` (while still holding `call.done`), so a waiter in `XAsyncGetStatus(block, true)` can never miss `CALLS` and read `E_PENDING`. 2. **`XAsyncBegin`**: after acquiring `left.done` on an existing entry, re-checks `is_current(&left, block)` before requiring `zeroed(block)` and calling `release(block)`, so reusing a failed/no-result block immediately after observing terminal status never spuriously returns `E_INVALIDARG`. ### Tested - **Red on `main`:** `modules::xasync::tests::get_status_wait_never_observes_pending_during_completion` fails deterministically with zero timeout dependence (`call must stay in CALLS while status is still E_PENDING`, and the concurrent waiter observes `E_PENDING` instead of `E_ABORT`). - **Green with fix (cherry-picked cleanly onto `leonida/main` `99e0bc1ce`):** - `cargo test -p leonida-hle --locked modules::xasync` — `14` passed, `0` failed (covers both `E_ABORT` and `S_OK`, verifying both the zero-timeout `CALLS`-during-`OP_CLEANUP` invariant and the threaded waiter). - Full `cargo test -p leonida-hle --locked` — `259` unit tests + `1` integration test (`no_dll_planting`) passed, `0` failed. - `python -I scripts/check_no_game_data.py d3d12/crates/leonida-hle/src/modules/xasync.rs` — exit `0`. - **Independent reviews:** - Separate read-only reviewer subagent (Gemini 4 Neon) — `APPROVE`. - Third-party verification by `@merzleckeier` on Wine 11.22 MSVC — confirmed red on `main` (`call must stay in CALLS while status is still E_PENDING`) and all `14` XAsync tests green with the fix. GPUs tested: n/a (`leonida-hle` CPU/concurrency unit tests, no game files or GPU needed). AI-assisted: yes — Gemini 4 Neon via Antigravity (implementation, regression test, and a separate read-only reviewer subagent using Gemini 4 Neon). ### Checklist - [x] Based on current `main` (`99e0bc1ce`) and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed (n/a: no translator rule changed). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member

Merging. Tree checked equal to main 99817c3a0 + 8b0fb0a84; cargo test -p leonida-hle --locked on that merge: 279 passed, 0 failed. In-game run PASS on an RTX 3090 (Enlighted), independent review ACCEPTED.

🤖 Generated with Claude Code

Merging. Tree checked equal to main `99817c3a0` + `8b0fb0a84`; `cargo test -p leonida-hle --locked` on that merge: 279 passed, 0 failed. In-game run PASS on an RTX 3090 (Enlighted), independent review ACCEPTED. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No description provided.