HLE/xmem: a page-mapping copy that cannot be served leaves the buffer it showed #841
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!841
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-841"
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?
@CwWwWwW on GitHub · 2026-11-28 07:34 UTC · original
CwWwWwW:fix/xmem-map-atomicity→main· +334 −38 · 1 files · 1 commits · merged 2026-11-29 08:16 UTCPorted to trustno1-coder/VIctory-NVIDIA from the same change submitted to fxceless/victory-fork as PR #1460 (head
605182c69c, author CwWwWwW). The fork's own line was dropped when it rebased onto959dcaf(5dbf5ce), so this is submitted here directly. The description below is the original one; its 'Verification' numbers refer to the fork tree. Rebased onto main63b902f.The problem
XMemMapPhysicalPagestakes the destination's views away before it looks at the page numbers it is given:crates/victory-hle/src/modules/xmem.rs:853-unmap(base, n * PAGE)turns every view covering the range back into an uncommitted placeholder;:861, each page number is looked up in the physical page table; an unknown number returns null (:863);:875-876).A title keeps what its buffer showed on a remap that failed (
XMemMapPhysicalPagesreturns null). Its next read or write is an access violation on the placeholder, and the GPU side has already been told the range changed (title_memory_remapped), so in-place copies see a hole too.A title's page list can hold such a number:
XMemFreePhysicalPages(:626-636) drops numbers from the table while views keep the section alive, and late page lists are a documented class here (dstorage.rs:1249-1254: "a page the title has just made ... comes right a little later", runs 175-178 lost reads to it). Open #619 recycles freed numbers, which narrows the window but does not change this call's failure behaviour.The change
Every page number is now looked at before the destination is touched; when one cannot be served the call returns null with the memory unchanged. A call that can serve every page unmaps and maps as before.
Evidence
New test
xmem::tests::a_remap_with_an_unknown_page_leaves_the_pages_it_showed(maps two pages, frees the second number, remaps[known, freed]) fails on the old code - the second page isMEM_RESERVE(8192) instead ofMEM_COMMIT(4096) after the failed call - and passes with the change.Verification on this branch (base
9a9091d):cargo test -p victory-hle --lib --locked -- --test-threads=1- 104 passed, 0 failedcargo clippy -p victory-hle --all-targets --locked -- -D warnings- cleancargo clippy -p victory-hle --all-targets --locked --all-features -- -D warnings- cleanNo game launch; the test drives the real host mapping APIs (
VirtualAlloc2/MapViewOfFile3) offline, as the module's existing tests do.Scope and overlap
One file,
crates/victory-hle/src/modules/xmem.rs. Open #299 fixes the siblingmap_aliaspath (source snapshot before the destination is unmapped); this change is theXMemMapPhysicalPagespath, which #299/#1060/#1103/#619/#1005 do not touch, and no other open PR was found for it. Host failures insidemap()(commit limit, "not a placeholder") still leave a partial result as before; that needs rollback and is not attempted here.CI's
checkmay be red from main's own clippy and asset-policy failures (#1440, #1322), which this diff does not touch.Follow-up after the tree replacement: the batched path is atomic too
The third commit (b656e5d) covers the new tree's batched page-mapping path,
map_aliases(taken whenside_by_side() > 1, defaultVICTORY_MAP_THREADS=8, and whatvictory-gpu'sCopyPageMappingsBatchXuses). Before it, an unknown source page only setok=falsewhile that range's destination page was still unmapped, so a failed batch could leave the destination changed.map_aliaseskeeps its gates and callsmap_aliases_by_page(pages).groups_of(pages)computes the existing group boundaries once (same rules: a group never shows a page that another group in the batch changes or copies from).missing_source(pages, &groups)runs before anychange/unmap: underPHYSICALit resolves every source address with the same lookup as the single path (physical.slice_at), with aplannedmap for pages earlier groups will map. The first page it cannot serve: warning +false, nothing unmapped.Regression test
xmem::tests::a_batched_copy_with_an_unknown_source_leaves_every_destination_it_showed: three pages, the second group copying from an unmapped reserved address; assertsfalseand that every destination keeps its committed bytes. Without the pre-validation it fails (left: 90, right: 17??an earlier group had applied); with it, passes.Verification:
cargo check -p victory-hle --all-targets --lockedclean;cargo test -p victory-hle --lib xmem::tests26 passed / 1 ignored; fullvictory-hlelib suite 176 passed / 2 ignored;cargo clippy -p victory-hle --all-targetsclean. Remaining gaps: a host failure insidechange(as opposed to an unknown source page) can still leave earlier groups applied, and a thread unmapping a validated source mid-batch can fail after earlier groups changed; both are out of scope and documented in the commit.Verification on this tree (base
63b902f, 2026-11-27)63b902ffailed on those before this change.Hardware verification suggested
@Dukestar69 on GitHub · 2026-11-28 07:46 UTC · original · approved these changes
Tested locally merged onto
main(63b902f).cargo xtask policypassed (294 files ok).cargo test -p victory-hle --lib xmempassed (27 passed; 0 failed; 1 ignored, including the new rollback/aliasing testsa_remap_with_an_unknown_page_leaves_the_pages_it_showed,a_batched_copy_with_an_unknown_source_leaves_every_destination_it_showed,a_failed_alias_leaves_the_destination_it_showed,an_alias_that_shifts_over_its_source_keeps_both_pages, andan_alias_of_a_page_over_itself_keeps_it) with 0 compiler warnings.Strong transactional/rollback guarantees for page-mapping copies and aliases. LGTM.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).