XMem: preserve overlapping source pages during GPU mapping copies #2197

Open
Razdva122 wants to merge 1 commit from upstream-pr/2199 into main
Razdva122 commented 2026-11-25 07:32:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Razdva122 on 2026-11-25T07:32:50Z.


The GPU queue calls xmem::map_alias to copy physical page mappings. On main, it removes the destination range before looking up the source pages. On an overlapping move this can erase the source before it is read. A source range with a hole can also discard a valid destination before the copy reports failure.

This addresses one existing page-mapping case from #1905. The broader lifetime of host-imported GPU memory across protection changes remains open. Coordination thread

Resolve the entire source range while the physical mapping lock is held, retaining its section references and starting page indices. Only then replace the destination page mappings. A missing source page returns before any destination change. A single source view needs no temporary vector allocation. As before, an OS refusal while installing a destination mapping can interrupt a copy.

The regression uses real Windows placeholder reservations and physical sections with synthetic contents. It checks forward and backward overlap, a self-copy, a source with a hole and repeated physical pages. A write through one address verifies that the resulting mappings still share their backing page. With the previous implementation, a one-page forward shift mapped all five addresses to the first page: reading the sentinels returned [1, 1, 1, 1, 1]. The corrected code returned [1, 1, 2, 3, 4] on the same Windows runner. The full workspace suite and both Clippy configurations passed. Windows comparison and test log A run with the title has not been performed.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6599537933 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2199). Originally posted by [Razdva122](https://github.com/Razdva122) on 2026-11-25T07:32:50Z. --- The GPU queue calls `xmem::map_alias` to copy physical page mappings. On main, it removes the destination range before looking up the source pages. On an overlapping move this can erase the source before it is read. A source range with a hole can also discard a valid destination before the copy reports failure. This addresses one existing page-mapping case from #1905. The broader lifetime of host-imported GPU memory across protection changes remains open. [Coordination thread](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155697054) Resolve the entire source range while the physical mapping lock is held, retaining its section references and starting page indices. Only then replace the destination page mappings. A missing source page returns before any destination change. A single source view needs no temporary vector allocation. As before, an OS refusal while installing a destination mapping can interrupt a copy. The regression uses real Windows placeholder reservations and physical sections with synthetic contents. It checks forward and backward overlap, a self-copy, a source with a hole and repeated physical pages. A write through one address verifies that the resulting mappings still share their backing page. With the previous implementation, a one-page forward shift mapped all five addresses to the first page: reading the sentinels returned `[1, 1, 1, 1, 1]`. The corrected code returned `[1, 1, 2, 3, 4]` on the same Windows runner. The full workspace suite and both Clippy configurations passed. [Windows comparison and test log](https://github.com/Razdva122/VIctory/actions/runs/45568944804/job/139050543733) A run with the title has not been performed. AI-assisted with Codex.
DenRakEiw commented 2026-11-25 08:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T07:42:23Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-hle --lib xmem:: — 11 passed, 0 failed (including gpu_page_copies_keep_the_source_mappings)
  • cargo clippy -p victory-hle --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean preservation of overlapping source pages during GPU mapping copies in xmem.rs. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053615479 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2199#pullrequestreview-6053615479). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T07:42:23Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-hle --lib xmem::` — **11 passed, 0 failed** (including `gpu_page_copies_keep_the_source_mappings`) - `cargo clippy -p victory-hle --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean preservation of overlapping source pages during GPU mapping copies in `xmem.rs`. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 08:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:03:06Z.

Review: COMMENTED


Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff.

XMem overlapping source pages preserved during GPU mapping copy — memmove-overlap fix; relates to #2213's xmem page-run coalescing.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053836805 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2199#pullrequestreview-6053836805). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:03:06Z. **Review:** COMMENTED --- Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff. XMem overlapping source pages preserved during GPU mapping copy — memmove-overlap fix; relates to #2213's xmem page-run coalescing.
MamaLeVrai commented 2026-11-25 09:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T08:52:09Z.


Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 365a2a49 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157573080 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2199#issuecomment-7157573080). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T08:52:09Z. --- Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `365a2a49` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 702 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Marvisak commented 2026-11-25 14:07:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:28:49Z.


Automated triage for the maintainers.

xmem::map_alias (crates/victory-hle/src/modules/xmem.rs) now resolves every source page under the physical lock before it unmaps the destination, so an overlapping copy no longer reads pages it has just erased; main's unmap-first order really does lose the source on a forward shift, and the new test covers forward/backward overlap, self-copy, a source hole and shared backing. Two smaller behaviour changes worth a glance: a source with a hole now leaves the destination mapped instead of unmapped, and unaligned addresses or lengths are refused (the only caller, copy_page_mappings in victory-gpu/src/queue.rs, always passes 64 KiB multiples). CI passes, and a tester reports the full suite passing on RDNA2.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163837420 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2199#issuecomment-7163837420). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:28:49Z. --- <!-- victory-triage v1 head=365a2a491ffde3629b57cceb3855e34565baa5ae verdict=merge-candidate at=2026-11-25T13:32:00Z --> Automated triage for the maintainers. `xmem::map_alias` (`crates/victory-hle/src/modules/xmem.rs`) now resolves every source page under the physical lock before it unmaps the destination, so an overlapping copy no longer reads pages it has just erased; main's `unmap`-first order really does lose the source on a forward shift, and the new test covers forward/backward overlap, self-copy, a source hole and shared backing. Two smaller behaviour changes worth a glance: a source with a hole now leaves the destination mapped instead of unmapped, and unaligned addresses or lengths are refused (the only caller, `copy_page_mappings` in `victory-gpu/src/queue.rs`, always passes 64 KiB multiples). CI passes, and a tester reports the full suite passing on RDNA2. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 01:04:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:51:32Z.


Code review and Windows 11 verification at head 365a2a491ffd merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-hle/src/modules/xmem.rs:773-837):
    • Snapshotting (Slice { index, section: Arc<Section> }, run_bytes) across [from, from + len) before mutating [to, to + len) cleanly fixes both forward/backward overlapping mapping copies and source holes (returning false without touching the destination), while self-copy (from == to) returns true after source validation and title_memory_remapped/title_memory_aliased keep GPU page watches and physical.shown coherent.
    • Minor note (matches prior behavior): if host map() fails partway through remapping the destination after unmap, earlier destination runs remain mapped (only reachable under host commit exhaustion / non-placeholder target).
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-hle --tests -- -D warnings: 0 warnings
    • cargo test --locked -p victory-hle -- xmem: 15/15 passed (including gpu_page_copies_keep_the_source_mappings).

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179183987 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2199#issuecomment-7179183987). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:51:32Z. --- Code review and Windows 11 verification at head `365a2a491ffd` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-hle/src/modules/xmem.rs:773-837`)**: - Snapshotting `(Slice { index, section: Arc<Section> }, run_bytes)` across `[from, from + len)` before mutating `[to, to + len)` cleanly fixes both forward/backward overlapping mapping copies and source holes (returning `false` without touching the destination), while self-copy (`from == to`) returns `true` after source validation and `title_memory_remapped`/`title_memory_aliased` keep GPU page watches and `physical.shown` coherent. - Minor note (matches prior behavior): if host `map()` fails partway through remapping the destination after `unmap`, earlier destination runs remain mapped (only reachable under host commit exhaustion / non-placeholder target). - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-hle --tests -- -D warnings`: 0 warnings - `cargo test --locked -p victory-hle -- xmem`: **15/15 passed** (including `gpu_page_copies_keep_the_source_mappings`). LGTM.
fuzeofficlal commented 2026-11-26 14:01:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T13:18:17Z.

Review: APPROVED


Reviewed and verified 365a2a49 merged locally onto origin/main (63bcca43) on Windows 11 x64 (Rust 1.98.1 MSVC; synthetic tests only, no game files).

Verification

  • git merge-tree against origin/main (63bcca43): clean.
  • cargo xtask policy (PR head): 182 files ok.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings (default and --all-features, PR head and merged): 0 warnings.
  • Dev tests (merged): cargo test --locked -p victory-hle --lib -- xmem:: — 15 passed, 0 failed (including gpu_page_copies_keep_the_source_mappings); full cargo test --locked -p victory-hle --lib — 153 passed, 0 failed.
  • Release tests (merged): cargo test --locked --release -p victory-hle --lib -- xmem:: — 15 passed, 0 failed.
  • Extra edge-case checks (dev & --release): verified len == 0, unaligned to/from/len, u64 overflow in to + len and from + len, self-copy spanning an unmapped hole returning false, and forward overlapping copies across multiple distinct non-contiguous source views.

Review Notes

  • Resolving and snapshotting (Slice { index, section: Arc<Section> }, run_bytes) across [from, from + len) under physical() (crates/victory-hle/src/modules/xmem.rs:769-792) before unmapping [to, to + len) (:796) fixes both overlapping forward copies and source holes leaving the destination unmapped, while keeping the single-view hot path allocation-free.
  • Validating the source range before the from == to early return (:793-795) preserves the contract that a self-copy containing an unmapped source page returns false.
  • Note for maintainers: merging alongside #1935 has a trivial test-only hunk conflict in crates/victory-hle/src/modules/xmem.rs (mod tests), with no production-code overlap.

Looks good to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074798358 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2199#pullrequestreview-6074798358). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T13:18:17Z. **Review:** APPROVED --- Reviewed and verified `365a2a49` merged locally onto `origin/main` (`63bcca43`) on Windows 11 x64 (Rust `1.98.1` MSVC; synthetic tests only, no game files). ### Verification - `git merge-tree` against `origin/main` (`63bcca43`): clean. - `cargo xtask policy` (PR head): `182 files ok`. - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` (default and `--all-features`, PR head and merged): 0 warnings. - **Dev tests (merged):** `cargo test --locked -p victory-hle --lib -- xmem::` — **15 passed, 0 failed** (including `gpu_page_copies_keep_the_source_mappings`); full `cargo test --locked -p victory-hle --lib` — **153 passed, 0 failed**. - **Release tests (merged):** `cargo test --locked --release -p victory-hle --lib -- xmem::` — **15 passed, 0 failed**. - **Extra edge-case checks (dev & `--release`):** verified `len == 0`, unaligned `to`/`from`/`len`, `u64` overflow in `to + len` and `from + len`, self-copy spanning an unmapped hole returning `false`, and forward overlapping copies across multiple distinct non-contiguous source views. ### Review Notes - Resolving and snapshotting `(Slice { index, section: Arc<Section> }, run_bytes)` across `[from, from + len)` under `physical()` (`crates/victory-hle/src/modules/xmem.rs:769-792`) before unmapping `[to, to + len)` (`:796`) fixes both overlapping forward copies and source holes leaving the destination unmapped, while keeping the single-view hot path allocation-free. - Validating the source range before the `from == to` early return (`:793-795`) preserves the contract that a self-copy containing an unmapped source page returns `false`. - Note for maintainers: merging alongside `#1935` has a trivial test-only hunk conflict in `crates/victory-hle/src/modules/xmem.rs` (`mod tests`), with no production-code overlap. Looks good to merge.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2199:upstream-pr/2199'
git switch 'upstream-pr/2199'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2199'
git switch 'upstream-pr/2199'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2199'
git switch 'upstream-pr/2199'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2199'
git switch 'main'
git merge --squash 'upstream-pr/2199'
git switch 'main'
git merge --ff-only 'upstream-pr/2199'
git switch 'main'
git merge 'upstream-pr/2199'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2197
No description provided.