HLE: retain IDStorageFile references across queued DirectStorage read requests #2523

Closed
github-bot wants to merge 1 commit from gh-pr/2523/head into gh-pr/2523/base
Owner

@⁠reeledMarek on GitHub · 2026-11-25 15:16 UTC · original
reeledMarek:fix/hle-dstorage-file-lifetime → main · +74 −17 · 1 files · 1 commits · closed without merging

Problem

dstorage::enqueue_request stored raw Request values without calling AddRef on file-backed request.source (Instance<File>), unlike enqueue_status which retains its StatusArray.

Under DirectStorage / COM rules, a caller may call Release() on an IDStorageFile immediately after enqueueing reads. Doing so drops Box<Instance<File>> and closes the underlying OS file handle while the request is still queued or running on a worker thread, causing a heap use-after-free.

Fix

  • Introduce ReadRequest wrapping Request + optional Instance<File> reference: ReadRequest::new calls add_ref_instance for non-null file-backed requests, and Drop releases the reference (covering completion, closed lanes, and queue teardown).
  • Release the file reference immediately after execute() finishes and before lanes.finish() publishes status completion so callers see the OS handle closed once status reports S_OK.

Testing

  • Added synthetic unit test queued_file_read_survives_caller_releasing_file in crates/victory-hle/src/modules/dstorage.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2523) `reeledMarek:fix/hle-dstorage-file-lifetime` → `main` · +74 −17 · 1 files · 1 commits · closed without merging ### Problem `dstorage::enqueue_request` stored raw `Request` values without calling `AddRef` on file-backed `request.source` (`Instance<File>`), unlike `enqueue_status` which retains its `StatusArray`. Under DirectStorage / COM rules, a caller may call `Release()` on an `IDStorageFile` immediately after enqueueing reads. Doing so drops `Box<Instance<File>>` and closes the underlying OS file handle while the request is still queued or running on a worker thread, causing a heap use-after-free. ### Fix - Introduce `ReadRequest` wrapping `Request` + optional `Instance<File>` reference: `ReadRequest::new` calls `add_ref_instance` for non-null file-backed requests, and `Drop` releases the reference (covering completion, closed lanes, and queue teardown). - Release the file reference immediately after `execute()` finishes and before `lanes.finish()` publishes status completion so callers see the OS handle closed once status reports `S_OK`. ### Testing - Added synthetic unit test `queued_file_read_survives_caller_releasing_file` in `crates/victory-hle/src/modules/dstorage.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:09 +00:00
github-bot closed this pull request 2026-11-26 05:08:09 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:53 UTC · original

Automated triage for the maintainers. Needs work.

The change itself reads cleanly: ReadRequest in crates/victory-hle/src/modules/dstorage.rs takes a reference on the file in enqueue_request and drops it after execute or when the request is discarded. But it changes runtime behaviour on an assumption the code on main explicitly makes the other way (read_into: "a file object we created; the title keeps it open"), and the PR gives no evidence that the title, or the real runtime, releases a file while reads on it are still queued, or that queued requests keep the file alive. The new test asserts the new reference count rather than a documented behaviour. What would move this forward: a reference (public documentation of the queue's file lifetime rules, or a trace showing the title releasing a file with reads in flight). CI: the check job passes.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2523#issuecomment-7167403137) <!-- victory-triage v1 head=352ac30bf12ee4dbad9361128921290b123661c9 verdict=needs-work at=2026-11-25T15:53:14Z --> Automated triage for the maintainers. Needs work. The change itself reads cleanly: `ReadRequest` in crates/victory-hle/src/modules/dstorage.rs takes a reference on the file in `enqueue_request` and drops it after `execute` or when the request is discarded. But it changes runtime behaviour on an assumption the code on main explicitly makes the other way (`read_into`: "a file object we created; the title keeps it open"), and the PR gives no evidence that the title, or the real runtime, releases a file while reads on it are still queued, or that queued requests keep the file alive. The new test asserts the new reference count rather than a documented behaviour. What would move this forward: a reference (public documentation of the queue's file lifetime rules, or a trace showing the title releasing a file with reads in flight). CI: the `check` job passes. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-25 20:05 UTC · original

Closing per triage — checked Microsoft's DirectStorage documentation and confirmed the caller is required to keep IDStorageFile alive until queued requests complete, matching main's existing assumption. Thanks for the review!

**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2523#issuecomment-7173178640) Closing per triage — checked Microsoft's DirectStorage documentation and confirmed the caller is required to keep `IDStorageFile` alive until queued requests complete, matching `main`'s existing assumption. Thanks for the review!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2523
No description provided.