xmem: replacing a title page leaves its neighbours mapped #2423
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2425"
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 faycalbaklouti on 2026-11-25T13:14:29Z.
What goes wrong
On main (
63bcca43c6a0),XMemMapPhysicalPagesmaps consecutive slices of one section as a single host view (xmem.rs:715–734). After alias and scatter operations leave three separate placeholders, mapping the same three-page destination directly returns null. There is also a lifetime problem with a successful grouped view: removing just the middle page unmaps the whole view, then maps its outer pages again as read-write (xmem.rs:803–823,945–995). A retry handler cannot preserve an untouched page's mapping or its protection.Change
Map each independently replaceable 64 KiB title page as its own view. Removing or replacing a page no longer requires unmapping its neighbours. The change is limited to
crates/victory-hle/src/modules/xmem.rs; the proposed split-fault handler and unrelated allocator file are not in the patch. Private DirectStorage copy/decode views still use runs. The trade-off is more host views per mapping, not a speedup.Verification
The same isolated test ran in fresh target directories with the Windows MSVC target and a non-root Wine runner:
63bcca43c6a0), exit 101. Atxmem.rs:1371,XMemMapPhysicalPages(dst, 3, pages.as_ptr())returned0x0, expected0x100230000(dst). The alias and scatter phases had completed; the direct phase never reached the sibling-protection assertion.test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 152 filtered out; finished in 0.00sThis is not the old PR'salias: unmapping touched a siblingfailure (440d0115f512, actual protection 4, expected 2).b9d511a2852b), exit 0.test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 152 filtered out; finished in 0.00sAll three mapping paths completed.On the byte-identical pre-amend tree (
a02c764c0c83, Rust 1.98.1):The full workspace run did not pass under Wine. Unchanged main reproduced all five failures seen on the branch: DLL thread attach, two stand-in window tests, loopback, and the NTFS hard-link test. The branch run was stopped after the nested game-save test stalled; later tests and native Windows CI are unverified.
About our fork & censorship-resistant preservation effort:
This fix comes from gta6-vi-port, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries).
rad:z39ofPhQC1siudH9BF3xsmAMmUqxc).onionVP9+Opus viewer:http://kwnoaeecpmxd6eetqfa7fxlymvxnh5du2i6wxr44t4mc7cgch5pw23id.onion/)Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:19:33Z.
Review: COMMENTED
xmem: coalesce contiguous 64 KiB MapViewOfFile3 calls (+793, apps+hle). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Large; perf-motivated.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:32:30Z.
Automated triage for the maintainers.
Proposed close. This maps runs of contiguous physical pages as one view in
crates/victory-hle/src/modules/xmem.rs(map_alias, scatter,unmap). Becauseunmapmust then split those views, title memory is briefly unmapped while other threads may use it, and the PR adds a first-chance exception handler (on_split_fault) that spins and resumes faults inside that window or a ring of recent splits.maindoes not have.mainmaps one view per page and never unmaps live title memory to remap part of it; the new handler only papers over the window, and it runs ahead of the existing guard handler for every access violation in the process.vm.max_map_countunder Linux/Wine; no problem on Windows is shown.apps/victory/src/private_heap.rswith nomoddeclaration (that file belongs to #2424), and CI is failing.A measured Windows-side reason to coalesce views, and a split that never leaves live memory unmapped, would change this verdict.
This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:56:26Z.
Both mechanisms hold up to close reading:
Coalescing — run detection requires same-section
Arc+ contiguousindex,chunk_lenstays inside both the source view andlen,map_runfalls back to per-page when a single view can't cover a reservation boundary, andMEM_COALESCE_PLACEHOLDERSis only applied to spans of ≥2 adjacentMEM_RESERVEplaceholder regions (the kernel call itself rejects non-placeholder spans, so a mixed span just stays split → per-page fallback — safe degradation). The test pins the split-then-realise → single-view cycle end to end.Split VEH — window opens before
UnmapViewOfFile2(fault can't slip in front),endwrites HI before LO so a reader'slo < hican't see a stale half-open range, the RECENT_SPLITS ring covers faults arriving microseconds after remap, andVirtualQuery+ prot check beforeCONTINUE_EXECUTIONkeeps genuinely-unmapped addresses propagating. Allocation-free/lock-free as a VEH must be.One robustness note: the spin loop in
on_split_faultis unbounded — if the remapping thread were killed or panicked betweenbegin/end, a faulting thread spins forever (silent deadlock). A bounded spin (say ~10 ms) thenCONTINUE_SEARCHkeeps the retry semantics for real remaps while making a stuck window a crash instead of a hang. Worth adding before this merges.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:59:39Z.
Read both halves carefully. The coalescing logic is sound — run detection checks
Arc::ptr_eq+ index contiguity,map_rundegrades to per-page on reservation boundaries, and the scatter batching preserves the map/unmap interleaving correctly. A few things need attention before merge:1.
private_heap.rsis dead code. Nothing declaresmod private_heapand no#[global_allocator]installsPrivateHeap— the file compiles to nothing. It's also not mentioned in the PR body. If the intent is the VEH-safe allocator the doc comment describes (which is a real concern foron_split_fault's future growth), wire it in and explain it; otherwise drop the file.2. Unbounded spin in
on_split_fault. A faulting thread spins with no yield while the remapping thread (which holds thephysicalmutex) finishes. On a busy 4-core box a higher-priority faulting thread can livelock the remapper for a quantum at a time — and if the remapper ever dies mid-window, this spins forever. Suggest a bounded spin thenSwitchToThread/YieldProcessorbackoff.3.
coalesce_placeholdersnever checksAllocationBase. It coalesces any run of adjacentMEM_RESERVEregions — including a plainVirtualAllocreservation parked next to our placeholders. TheMEM_COALESCE_PLACEHOLDERScall fails atomically on non-placeholder spans, so today it just silently fails (result ignored → per-page fallback, safe). Still, comparingmbi.AllocationBasewhile extendingspan_endis a one-line tightening that avoids relying on the kernel rejecting mixed spans.4. Sticky ring + masked protect bits.
RECENT_SPLITSentries are never cleared — any address that was ever in a split window stays "recently split" forever (16 slots, overwritten). Combined withprot & 0xffstrippingPAGE_GUARD/modifier bits, a guard-page fault inside a stale range would be swallowed byEXCEPTION_CONTINUE_EXECUTIONbefore the intended handler sees it. Today nothing in the process usesPAGE_GUARD(gpu write-watch usesPAGE_READONLY, which correctly fails the write-prot check), but worth a defensiveProtect & PAGE_GUARD != 0 -> CONTINUE_SEARCHto keep the handler a pure retry mechanism rather than a fault-eater for future protection tricks.Imported from Marvisak/VIctory. Originally posted by faycalbaklouti on 2026-11-30T19:18:33Z.
Thank you for identifying the lifetime problem.
map_aliason mirror main maps one page per alias (xmem.rs:773–797). Coalescing these aliases into larger views makes partial unmapping remove live siblings before they are remapped (xmem.rs:981–996). Bounded spinning, narrower placeholder checks, or stricter recent-range and protection checks would not remove that interval. The allocator file also belongs only to #2424.We have neither a gap-free replacement nor a measured Windows benefit. We are not asking you to merge this version. This is a comment only, not a code update, a request to close the PR, or a claim that CI is green.
Imported from Marvisak/VIctory. Originally posted by faycalbaklouti on 2026-11-30T20:52:41Z.
Thank you for flagging the lifetime issue. I dropped the coalescing and retry handler rather than trying to spin through a fault.
XMemMapPhysicalPagesalready groups adjacent pages on main: with just the new test on63bcca43c6a0, the three-page direct remap after alias and scatter returned null (exit 101). That is distinct from the old PR's observed loss of a sibling's read-only protection. Onb9d511a2852beach title page has its own view; the same test completes all three paths and keeps both neighbours read-only (1 passed, exit 0). This costs host views; it isn't a speedup. Both Clippy modes passed. The workspace run under Wine did not finish; main reproduced the five failures it reported.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.