HLE: avoid data race in DirectStorage late page-list polling #2553
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!2553
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2553"
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?
@reeledMarek on GitHub · 2026-11-25 15:40 UTC · original
reeledMarek:fix/hle-dstorage-page-list-race-and-offset→main· +26 −17 · 1 files · 1 commits · openSummary
crates/victory-hle/src/modules/dstorage.rs,into_destinationpreviously constructed shared&[usize]slices (std::slice::from_raw_parts) directly over the title's physical page list while the title can still be populating entries concurrently (the reasonLATE_LIST_TRIESexists), which is UB under Rust's aliasing and data-race rules.Vec<usize>viaAtomicUsize::from_ptr(...).load(Ordering::Acquire)(once up front and on each late-list retry) and pass&pagestopage_window,write_physical, andunknown_pages.a_page_list_filled_after_its_request_startsto populate the slot viaAtomicUsize::from_ptr(...).store(..., Ordering::Release)so the test itself has no mixed atomic/non-atomic race.HLE: snapshot DirectStorage physical page lists with relaxed atomic loadsto HLE: avoid data race in DirectStorage late page-list polling2051b22bdbtode55348e81@Marvisak on GitHub · 2026-11-25 18:37 UTC · original · edited 2026-11-26 07:18 UTC
Automated triage for the maintainers.
Merge candidate. Re-reviewed at
de55348. Incrates/victory-hle/src/modules/dstorage.rs,into_destinationstill copies the title's page list into a localVecbeforepage_window,write_physicalandunknown_pagesread it, once up front and on eachLATE_LIST_TRIESretry. The copy now usesAtomicUsize::from_ptr(..).load(Ordering::Acquire), andrequest.destinationis*mut c_void, so the pointer type fits. The testa_page_list_filled_after_its_request_startsnow writes the slot with a matchingReleasestore, so the test has no mixed atomic/plain access either. The PR description matches the patch.Reply to the author: thanks, both of @brainbudt's points are addressed.
CI:
checkpassing.Generated by Claude Code
@welisonzika14-jpg on GitHub · 2026-11-25 19:18 UTC · original
For the first point of the triage above (the data race): a small patch, in case it helps. Tested on head
f62909f, Windows 11, rustc 1.98.1.AtomicUsize::from_ptris stable (1.75), and the compiler here accepts it. The snapshot ininto_destinationnow doesAtomicUsize::from_ptr(src.add(i)).load(Ordering::Relaxed)instead ofread_volatile.Alignment:
from_ptrneeds the pointer aligned forusize, butread_volatileon a*const usizealready needs the same, so this adds no new requirement. I cannot check from here that the title always aligns the list; the comment now says so.cargo test -p victory-hle --lib --locked dstorage: 17 passed, 0 failed.cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.I did not touch the overflow guard (second point). I have no console result for it.
Diff
Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
@reeledMarek on GitHub · 2026-11-25 20:05 UTC · original
Updated to address the triage feedback (thanks also to @welisonzika14-jpg for testing the atomic load patch):
read_volatilewithAtomicUsize::from_ptr(src.add(i)).load(Ordering::Relaxed)ininto_destination's page-list snapshot so concurrent population by the title does not create a Rust data race or shared slice over mutating memory.read_into/into_destinationoffset-overflow guards and test.@brainbudt on GitHub · 2026-11-25 21:08 UTC · original
Independently verified
2051b22merged onto13f91ca(and combined with #2566; Windows 11 DirectStorage/xmem/watch tests and MSVC workspacecargo check --testspassed).Two items before merge:
a_page_list_filled_after_its_request_starts(crates/victory-hle/src/modules/dstorage.rs:1023-1035,1637-1648): The worker loads page-list slots atomically while the filler thread writes the same word withwrite_volatilewithout a happens-before edge, which Rust classifies as a data race (strengthening only the load toAcquiredoes not resolve it). Please use an atomic store in the test and clarify the synchronization contract for post-submit producers.@reeledMarek on GitHub · 2026-11-26 05:56 UTC · original
Thanks @brainbudt — updated both items:
a_page_list_filled_after_its_request_startstoAtomicUsize::from_ptr(...).store(..., Ordering::Release)paired withOrdering::Acquireininto_destination's snapshot, and documented the producer synchronization contract.main(63bcca4).@fuzeofficlal on GitHub · 2026-11-26 15:26 UTC · original · approved these changes
Replacing the shared
&[usize]slice over a live page list with a localVec<usize>snapshot viaAtomicUsize::from_ptr(...).load(Ordering::Acquire)(crates/victory-hle/src/modules/dstorage.rs:1020-1075) and pairing the test writer withOrdering::Release(L1633-1645) cleanly eliminates the Rust data-race UB during late page-list polling.Non-blocking follow-up notes:
src.is_aligned()) beforeAtomicUsize::from_ptrand skipping the page-entry read whenlen == 0would harden edge inputs further.#2738separately replaces the 2 ms sleep ina_page_list_filled_after_its_request_startswith deterministic synchronization.Local verification at
de55348e(and cleanly merged ontoorigin/mainatd44c6c0e):xtask policy(191 files ok),cargo clippy -p victory-hle --all-targets(defaultand--all-features, 0 warnings),dstorage(16/16), andcargo test -p victory-hle(debug,--release, and merged ontoorigin/main:152/152+ integration tests) all passed. Approving.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.