xmem: adopt held private backings on held deferred slots and retry concurrent VEH faults #608
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/608"
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 brcly/TuxBox. Originally posted by DrArroway on 2026-12-01T01:21:11Z.
Problem & Root Cause
Under
TUXBOX_XMEM_PRIVATE_VIEWS=1, mapping a physical page into a held deferredPrivatePlaceholderslot while its token already had either a heldPrivateArenaor an unheldPrivateViewtriggered a split-brain coherent-memory bug inruntime/xmem:classify_private_slot+mask_slotmismatch:PrivateArena(or an unheldPrivateView) and the destination VA was a held deferredPrivatePlaceholderslot (has_hold(at, at + PAGE)),classify_private_slotreturnedSlotRole::SecondaryAlias.mask_slotwasfalsebecauseatitself was held, somap_private_page/map_private_contiguousleft the slotPAGE_READWRITE, skippedpopulate_page_bytes, and did not insertatintosecondary_aliases.xcrdapiDMA writes viaacquire_physical_accesswrote directly toPrivateArenawhile the CPU read ancient unpopulated bytes from the heldPrivatePlaceholderslot without trapping, crashing ProjectScarlett (0x80000003atgame_scarlett_master.exe + 0x4DA6315/+0x9DFC18).Two companion coherence issues exposed by the fix:
PrivateViewupgrade: When a CPU aperture maps a token whose canonical backing is already a held non-CPUPrivateView, blocking the upgrade on!has_hold(old_va)left the CPU view masked as aSecondaryAlias(err=170on write when both ends are held), while upgrading without invalidation broke coherence with the old held view. Now the CPU view upgrades cleanly (SlotRole::Upgrade(old_va)), pushesold_vatoinvalidatedsoPool::mapcallsnotify_backing_invalidated, and defersPAGE_NOACCESSmasking untilrelease_holddrops its lastview_hold(mask_released_secondary_alias).secondary_alias_vehfault race (0xc0000005): When another thread concurrently promotes or hands offfault_pageand removes it fromsecondary_aliasesbefore a faulting thread acquiresPOOL, returning0surfaced an unhandled access violation. Retrying (-1) whenpool.mappings.contains_key(&fault_page)andVirtualQueryconfirms compatible committed protection resolves the race cleanly.Changes
runtime/xmem/src/physical_pages/private_views.rs:classify_private_slot: adopts heldPrivateArenaasSlotRole::Canonicalwhenat_heldis true, and upgradesPrivateView(old_va)when(is_cpu && !page.backing_is_cpu) || (at_held && !self.has_hold(*old_va, *old_va + PAGE)).apply_slot_role: preserves#573'sself.set_mapping(at, token), threadsinvalidated: &mut Vec<usize>to notifynotify_backing_invalidatedwhen adopting a heldPrivateArenaor upgrading from a heldPrivateView, updatespage.backing_is_cpu = is_cpu, demotes stalereadonly_secondary_aliasesviademote_readonly_secondary_aliases, and logs a capped warning if a double-heldSecondaryAliasis left unmasked.map_private_page&map_private_contiguous: threadinvalidated, gatepopulate_page_bytes/ deferred reprotection on!matches!(role, SlotRole::SecondaryAlias) || self.has_hold(va, va + PAGE), and passinvalidatedtoapply_slot_role.mask_released_secondary_alias: masks live non-canonical private views toPAGE_NOACCESSand registers them insecondary_aliasesonce their lastview_holdreleases.pub(super) use super::private_alias_veh::ensure_secondary_alias_veh;forsection_watch.rs(#573).runtime/xmem/src/physical_pages/backing.rs(release_hold),runtime/xmem/src/physical_pages.rs,runtime/xmem/src/physical_pages/copy_mappings.rs:mask_released_secondary_aliason live unheld private views inrelease_holdand threadinvalidatedthroughmap_cpu_page/map_private_page/map_private_contiguous.runtime/xmem/src/physical_pages/private_alias_veh.rs:private_views.rsto stay under the 1,200-line repository limit.page_allows_accesstransient retry insecondary_alias_vehand calldemote_readonly_secondary_aliasesfromhandoff_private_backing.runtime/xmem/src/tests/private_views.rs:held_deferred_slot_adopts_held_private_arena_and_notifies_invalidation,held_deferred_slot_upgrades_unheld_private_view_without_split_brain, andcpu_upgrade_from_held_non_cpu_view_invalidates_and_masks_on_release).Verification (rebased onto
717a74c4, including#573)cargo fmt --all --check,cargo clippy --locked --target x86_64-pc-windows-msvc --workspace --all-targets -- -D warnings, andtests.test_repository_hygiene(7/7) passed.tuxbox.py checkon both AMD Radeon RX 6900 XT (1002:73bf) and AMD Raphael Radeon 610M iGPU (1002:164e):Evidence: TuxBox check of
2d578f8fe4, no uncommitted changes, GPU 1002:73bf: 17 passed, 0 failed, 0 not runEvidence: TuxBox check of
2d578f8fe4, no uncommitted changes, GPU 1002:164e: 17 passed, 0 failed, 0 not runTUXBOX_XMEM_PRIVATE_VIEWS=1checks & Windows unit tests on commit2d578f8fe4a2across both AMD Radeon RX 6900 XT (1002:73bf) and AMD Raphael Radeon 610M iGPU (1002:164e):tuxbox.py verify --only xmem: 12/12PASSon both adapters (xmem-heapsthroughxmem-pages).tools/check_d3d12_regressions.py(buffer-import,buffer-remap,buffer-unmap-alive,buffer-unmap-released,alias-deferred): 5/5PASSon both adapters.tuxbox-xmemWindows unit tests under GE-Proton11-14wine:45 passed; 0 failed; 2 ignoredon both adapters (including#573'ssection_views_are_watched_by_protectionand all 3 new regression tests).TUXBOX_XMEM_PRIVATE_VIEWS=1) on AMD Radeon RX 6900 XT (1002:73bf):222.4s/8,216presents,324.5s/8,267presents,427.8s/8,298presents; 5/5 runs total) exercised bothadopted held PrivateArenaandupgraded PrivateViewwith 00x80000003(+0x4DA6315/+0x9DFC18) crashes, 0err=170, 0 unhandled0xc0000005, and 0left unmaskedwarnings.Imported from brcly/TuxBox. Originally posted by brcly on 2026-12-01T03:24:47Z.
@DrArroway thanks, the diagnosis and the runs are clear. #573 has just been merged to main, and it changes the same XMem page code, so this now conflicts. Could you rebase onto current main? It's ready to merge once it's clean and CI passes.
Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-12-01T07:40:50Z.
@brcly Rebased onto current
main(717a74c4, preserving#573'sset_mapping/clear_mappingand re-exportingensure_secondary_alias_vehfromprivate_views.rsforsection_watch.rs).Re-ran full dual-GPU verification on commit
2d578f8fe4a2across both AMD Radeon RX 6900 XT (1002:73bf) and AMD Raphael Radeon 610M iGPU (1002:164e) (tuxbox.py check17/17, explicitTUXBOX_XMEM_PRIVATE_VIEWS=1xmemguest suite 12/12 + D3D12 regression controls 5/5, andtuxbox-xmemWindows unit tests 45/45), and all 5/5 CI checks are green. Ready to merge!Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-01T07:49:18Z.
@DrArroway one data point from NVIDIA, for the record (one run, and on an integration build, so not a review of this head): with the previous head of this PR (
b80aaee0, on mainb3873ec4with other patches) andTUXBOX_XMEM_PRIVATE_VIEWS=1, ProjectScarlett on an RTX 5090 (620.70.10, GE-Proton11-15) stopped presenting about 3 s into the world: 12 Vulkan wait timeouts in the log, no Xid (and0x80000003breakpoints in the log, but every run of ours has those), then the title's own watchdog ended it at 157 s. The same build with the variable unset ran 20 minutes. I haven't repeated it, and I haven't run your rebased head.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-12-01T07:54:20Z.
@NickStallman Thanks for sharing that RTX 5090 data point.
Across our AMD Radeon RX 6900 XT (1002:73bf)
TUXBOX_XMEM_PRIVATE_VIEWS=1runs with #608 we didn't hit Vulkan wait timeouts or early world stalls (8,200+presents per run). If you still have that log around, did anyTuxBox xmem:lines (such assecondary alias ... fault not promoted,left unmasked, oradopted/upgraded) orGPU memory wait held past 5slines show up right before the wait timeouts? That would help tell if something inxmemstalled there or if it's an NVIDIA / integration-patch interaction.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-01T08:19:20Z.
@DrArroway the log is here: no
TuxBox xmem:line at all in that run, and noGPU memory wait held past 5sline; so nothing in it names a page or an alias. The timeouts begin a few seconds into the world (the first one lands around some pipeline creation failing, which other runs have too), and from there nothing more is submitted. So I can't say whether xmem stalled there or it's NVIDIA or our patches; I'd treat it as unconfirmed. I'm happy to repeat it on your rebased head without our other patches when the machine is free.