HLE: update shared XMA context words atomically #1536
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1537"
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 Texbirds on 2026-11-24T18:58:10Z.
Problem
In
crates/victory-hle/src/modules/audio.rs,Context::set_fieldupdates bitfields in title-shared 32-bit XMA context words using a non-atomicread_volatile-> mask/or ->write_volatile.Because the title concurrently mutates other bitfields in the same 32-bit words while the XMA decoder thread pumps audio (for example, word 0 packs
valid inputsbits 20..21 written by the title alongsidewrite blockbits 27..31 written bypump; word 1 packsinput 1 sizebits 0..11 alongsideoutput writablebit 31), a concurrent title write between the read and write is silently clobbered and can stall a voice.Fix
AtomicU32::from_ptr(load(Acquire),store(Release), andfetch_update(AcqRel, Acquire, ...)inContext::set_field).context_set_field_does_not_clobber_concurrent_bitfieldsexercising concurrent updates to disjoint bitfields of word 0 across two threads.Verification
windows-latestCI (cargo clippydefault +--all-featuresandcargo test --workspace --locked).Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T20:15:37Z.
Review: APPROVED
Tested
9ad1f21on Windows 11, RTX 5070, MSVC: builds,cargo test --workspace --no-fail-fast633 passed, 0 failed (on our fork main). The newcontext_set_field_does_not_clobber_concurrent_bitfieldspasses.set_fieldas afetch_updateon anAtomicU32over the shared word closes our side of the lost-update race: a title write to other bits of the same word between our read and our write is no longer overwritten.from_ptrneeds 4-byte alignment, which the oldread_volatileon*mut u32already required, so nothing new is assumed.get/setbecome acquire loads and release stores, which on x86 compile to the same plain moves as the volatile accesses, so there is no cost.Merged into our fork's main.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:18:59Z.
Automated triage for the maintainers.
Merge candidate.
Context::set_fieldincrates/victory-hle/src/modules/audio.rsread-modify-wrote shared XMA context words with separate volatile accesses, so a bit the title changed in between was lost. It now uses afetch_updateonAtomicU32::from_ptr, andgetandsetuse acquire and release ordering. I checked that every context access goes throughget,setandset_field, and that the words are 4-byte aligned, whichfrom_ptrrequires. The change costs nothing when there is no contention. The test checks the title-side bits survive concurrent decoder updates. It can catch the old behaviour only probabilistically, but it cannot fail on the new code.CI: no check runs reported for this head.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:01:41Z.
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because the title has no such race. It writes a context's words only during voice setup, before the enable command, and its per-tick code only reads three fields and then moves the read block by a command, which
advance_readapplies under the same per-voice lock thatpumpholds. Where a title did write concurrently, its own plain read-modify-write would still clobber ours, so the compare-and-swap would fix half at most; the new test makes both sides usefetch_update, which is not how a title writes.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed