HLE: avoid data race in DirectStorage late page-list polling #2551
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:40:13Z.
Summary
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:37:07Z.
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
Imported from Marvisak/VIctory. Originally posted by welisonzika14-jpg on 2026-11-25T19:18:18Z.
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.
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:30Z.
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.[PR #2553] HLE: avoid data race in DirectStorage late page-list polling and guard read_into offset overflowto [PR #2553] HLE: snapshot DirectStorage physical page lists with relaxed atomic loadsImported from Marvisak/VIctory. Originally posted by brainbudt on 2026-11-25T21:08:35Z.
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.[PR #2553] HLE: snapshot DirectStorage physical page lists with relaxed atomic loadsto [PR #2553] HLE: avoid data race in DirectStorage late page-list pollingImported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:56:04Z.
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).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:26:28Z.
Review: APPROVED
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.