HLE: keep async status waits attached through provider cleanup #3193

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3195 into main
andrewpozdnakov7-jpg commented 2026-11-26 11:56:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T11:56:41Z.


Problem

XAsyncGetStatus(block, true) can return E_PENDING for a call that is already inside provider cleanup. Completion removes the call from the registry before cleanup, then publishes the final status when cleanup returns. A waiter arriving in that interval finds nothing to wait on. XAsyncGetStatus contract

Keep the call registered while the provider cleans up. Remove it and publish its final status under the registry lock. Cleanup still runs before status publication and outside both locks, as in #114.

Verification

The same synthetic provider pauses inside cleanup on main 63bcca43 and on this branch. Each trial includes a zero-payload success and a cancellation.

Call Main while cleanup is paused Patched after cleanup returns
Zero-payload success E_PENDING returned early S_OK
Cancellation E_PENDING returned early E_ABORT

A nonblocking poll reports E_PENDING while cleanup is paused in both builds. Main failed 10/10 trials. The patch passed 10/10, with both outcomes checked in every trial. Full HLE library tests passed 153/153 in both configurations, including the cleanup-lock regression from #114. Strict HLE Clippy and the repository asset policy passed.

cargo test --locked -p victory-hle --lib modules::xasync::tests::waiting_status_follows_payload_free_cleanup -- --exact --nocapture

Coordination claim

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5509584394 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3195). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T11:56:41Z. --- ## Problem `XAsyncGetStatus(block, true)` can return `E_PENDING` for a call that is already inside provider cleanup. Completion removes the call from the registry before cleanup, then publishes the final status when cleanup returns. A waiter arriving in that interval finds nothing to wait on. [XAsyncGetStatus contract](https://learn.microsoft.com/en-us/xbox/gdk/docs/reference/system/xasync/functions/xasyncgetstatus) Keep the call registered while the provider cleans up. Remove it and publish its final status under the registry lock. Cleanup still runs before status publication and outside both locks, as in #114. ## Verification The same synthetic provider pauses inside cleanup on main `63bcca43` and on this branch. Each trial includes a zero-payload success and a cancellation. | Call | Main while cleanup is paused | Patched after cleanup returns | | --- | --- | --- | | Zero-payload success | `E_PENDING` returned early | `S_OK` | | Cancellation | `E_PENDING` returned early | `E_ABORT` | A nonblocking poll reports `E_PENDING` while cleanup is paused in both builds. Main failed 10/10 trials. The patch passed 10/10, with both outcomes checked in every trial. Full HLE library tests passed 153/153 in both configurations, including the cleanup-lock regression from #114. Strict HLE Clippy and the repository asset policy passed. ```powershell cargo test --locked -p victory-hle --lib modules::xasync::tests::waiting_status_follows_payload_free_cleanup -- --exact --nocapture ``` [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7191192481) AI-assisted with Codex.
AurumCarlos commented 2026-11-26 12:33:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T12:33:14Z.

Review: COMMENTED


The race is real and the fix closes it. I read it against release, call, XAsyncBegin and XAsyncGetStatus on main:

  • The window: on main, release removes the call from CALLS before OP_CLEANUP, and the status is published only after cleanup returns. A blocking XAsyncGetStatus in between finds no call and returns the still-E_PENDING status.
  • The fix: the call now stays registered through cleanup. Removing it and storing size/status happen under the CALLS lock, so a waiter either finds the call and blocks on done, or finds it gone and reads the final status. Cleanup still runs with no lock held, so the #114 case (cleanup_runs_without_the_completion_lock) keeps working.
  • Reuse of the block during cleanup: XAsyncBegin on the same block is rejected while done is still false, so no new call can be filed at that address before the unconditional calls.remove(&(block as usize)). The removal can't drop someone else's call.

Two small points:

1. A new constraint on providers, worth writing down. Since the call is now registered while OP_CLEANUP runs, a provider whose cleanup calls XAsyncGetStatus(block, true) on its own block would now block forever, because done is only set after cleanup returns. On main, it got E_PENDING straight away. The in-tree cleanups only drop their boxed state (finished_with, and the one at L856), so nothing hits this today. A line in the comment would keep a future provider from tripping on it, e.g. "cleanup must not wait on its own block". If you want the removal to be robust on its own rather than relying on XAsyncBegin's done check, you could also guard it with Arc::ptr_eq, the way is_current does.

2. Nit: the eprintln! in the test. It looks like it was left over from investigating, since the assert_eq! on outcomes already prints all four values when it fails. Also, the 250 ms recv_timeout can only make a slow runner pass falsely (an early return that arrives late), never fail falsely, so the test shouldn't be flaky. 👍

<!-- greyfinch-sync:Marvisak/VIctory:review:6074185485 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3195#pullrequestreview-6074185485). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T12:33:14Z. **Review:** COMMENTED --- The race is real and the fix closes it. I read it against `release`, `call`, `XAsyncBegin` and `XAsyncGetStatus` on `main`: - **The window**: on `main`, `release` removes the call from `CALLS` *before* `OP_CLEANUP`, and the status is published only after cleanup returns. A blocking `XAsyncGetStatus` in between finds no call and returns the still-`E_PENDING` status. - **The fix**: the call now stays registered through cleanup. Removing it and storing `size`/`status` happen under the `CALLS` lock, so a waiter either finds the call and blocks on `done`, or finds it gone and reads the final status. Cleanup still runs with no lock held, so the #114 case (`cleanup_runs_without_the_completion_lock`) keeps working. - **Reuse of the block during cleanup**: `XAsyncBegin` on the same block is rejected while `done` is still false, so no new call can be filed at that address before the unconditional `calls.remove(&(block as usize))`. The removal can't drop someone else's call. Two small points: **1. A new constraint on providers, worth writing down.** Since the call is now registered while `OP_CLEANUP` runs, a provider whose cleanup calls `XAsyncGetStatus(block, true)` on its own block would now block forever, because `done` is only set after cleanup returns. On `main`, it got `E_PENDING` straight away. The in-tree cleanups only drop their boxed state (`finished_with`, and the one at L856), so nothing hits this today. A line in the comment would keep a future provider from tripping on it, e.g. "cleanup must not wait on its own block". If you want the removal to be robust on its own rather than relying on `XAsyncBegin`'s `done` check, you could also guard it with `Arc::ptr_eq`, the way `is_current` does. **2. Nit: the `eprintln!` in the test.** It looks like it was left over from investigating, since the `assert_eq!` on `outcomes` already prints all four values when it fails. Also, the 250 ms `recv_timeout` can only make a slow runner pass falsely (an early return that arrives late), never fail falsely, so the test shouldn't be flaky. 👍
cloph-dsp commented 2026-11-26 13:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T12:12:01Z.


Independent local verification of head c079fab on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-hle --lib -- --exact modules::xasync::tests::waiting_status_follows_payload_free_cleanup — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

CPU-only synthetic thread/payload scenario; no D3D12 device or game data used. Worktree-local CARGO_TARGET_DIR. AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7191694255 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3195#issuecomment-7191694255). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T12:12:01Z. --- Independent local verification of head `c079fab` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-hle --lib -- --exact modules::xasync::tests::waiting_status_follows_payload_free_cleanup` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. CPU-only synthetic thread/payload scenario; no D3D12 device or game data used. Worktree-local `CARGO_TARGET_DIR`. AI-assisted (Hy4 flash).
futurepro62 commented 2026-11-27 22:31:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T22:31:54Z.


NVIDIA full-suite run, to go with the reports above by cloph-dsp, since none of them names a GPU run. Tested exact head c079fab (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: waiting_status_follows_payload_free_cleanup.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (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:Marvisak/VIctory:comment:7229405227 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3195#issuecomment-7229405227). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T22:31:54Z. --- NVIDIA full-suite run, to go with the reports above by cloph-dsp, since none of them names a GPU run. Tested exact head `c079fab` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `waiting_status_follows_payload_free_cleanup`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
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/3195:upstream-pr/3195'
git switch 'upstream-pr/3195'

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