HLE: retain DirectStorage file references across queued reads #2987
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2987
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2987"
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?
@fuzeofficlal on GitHub · 2026-11-26 02:24 UTC · original
fuzeofficlal:fix/hle-dstorage-retain-file-ref→main· +140 −39 · 1 files · 1 commits · openProblem
enqueue_requestincrates/victory-hle/src/modules/dstorage.rscopied the rawRequeststruct (including itssourcefile pointer) without retaining a reference onInstance<File>. Unlikeenqueue_status(which callsadd_ref_instanceand releases onStatus::drop), if a title released its final reference to a file object after enqueueing/submitting a read,release::<File>dropped theInstance<File>and closed the underlying host file handle while the request was still queued or running, causing the worker thread to dereference freed memory inread_into/source_name.Fix
CopyQueuedRequestholdingOption<NonNull<Instance<File>>>:add_ref_instanceon enqueue for file-backed non-null requests (options & MEMORY_SOURCE == 0).releaseinDropwhen the request completes, is rejected by a closed queue, or is discarded byclose_lane.Jobby value intoLanes::finishand dropQueuedRequestbefore callinglane.flush()so the file handle is guaranteed closed before completion is published to the title'sStatusArray.request.sourceinread_into(returningErr(E_INVALIDARG)) andsource_name(returning"null").Verification
modules::dstorage::tests:queued_reads_keep_the_file_open_until_completion: enqueues 2 reads, callsReleaseimmediately (asserting refcount2), submits, waits forS_OK, verifiesstd::fs::remove_filesucceeds immediately upon completion (confirming zero handle leak on WindowsFILE_SHARE_READhandle), and verifies both read buffers match.closing_a_queue_releases_unsubmitted_file_reads: verifies unsubmitted file reads drop their file references when the queue closes (remove_filesucceeds).read_into_rejects_a_null_source: verifies both file and memory null sources returnE_INVALIDARG.cargo test --locked -p victory-hle --lib modules::dstorage::tests -- --test-threads=1: 19/19 passed.cargo clippy --locked -p victory-hle --tests -- -D warnings(default &--all-features): 0 warnings.cargo xtask policy: 191 files ok.@kotekompotek on GitHub · 2026-11-26 02:36 UTC · original · reviewed
Verified: real use-after-free — a queued read held only the raw Request's source pointer, so a title closing the file while reads sat unsubmitted or in-flight left a dangling Instance. QueuedRequest add_refs on enqueue (non-memory sources) and releases on drop, which covers job completion, closed-queue command drops, and lane teardown. The drop-in-finish ordering before flush/publish is right, and the null-source guards in read_into/source_name are a sensible belt. Tests cover both the completion path and the close-drops-reads path via refcounts.
@futurepro62 on GitHub · 2026-11-26 05:07 UTC · original
Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head
3223996(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo 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: 869 passed, 0 failed, 10 ignored.queued_reads_keep_the_file_open_until_completion,closing_a_queue_releases_unsubmitted_file_reads,read_into_rejects_a_null_source.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#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_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
@Marvisak on GitHub · 2026-11-26 05:41 UTC · original
Automated triage for the maintainers.
Merge candidate. In
crates/victory-hle/src/modules/dstorage.rs,enqueue_requestcopied theRequestwith a raw file pointer and took no reference, soread_into/source_namerelied on the title keeping the file open (main'sSAFETYcomment says as much). Queued reads are now aQueuedRequestthat holds a reference on theInstance<File>from enqueue until the job is finished or dropped by a closed queue. This is the same patternenqueue_statusalready uses for status arrays.Lanes::finishtakes the job by value and releases the file beforeflushpublishes completion. I checked the paths that drop a request: a finished job,queueon a closed lane, andclose_lane's unsubmitted list. Each releases exactly once, and memory-source requests take no reference. The two new tests cover early release and close, and the null-source guard inread_intoturns a crash intoE_INVALIDARG.Note for the maintainer: this is defensive. No title run shows the title releasing a file with reads in flight, and a title-visible
Releasecount is now higher while reads are queued. The change is cheap and removes a use-after-free if that ever happens.CI: passing (
check).Recommending a look, not approving.
Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 07:50 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-hle dstorage: all tests passed.cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.