XMem: a page mapping that cannot be served leaves the memory as it showed #538

Open
github-bot wants to merge 1 commit from github-bot/gh-538 into main AGit
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 00:32 UTC · original
kibagami-nc:fix/xmem-remap-unknown-page → main · +171 −29 · 1 files · 1 commits · open

The problem

XMemMapPhysicalPages takes the destination's views away (unmap) before it looks the page numbers up. A number that is not in the table makes the call return null, but the buffer has already become placeholders. Such a number can be one the title's list kept after XMemFreePhysicalPages, or one whose allocation came late.

After a failed remap the title keeps using what the buffer showed, so its next access is an access violation. The GPU side has also already been told the range changed.

The GPU's page-mapping copies have the same order:

  • alias_as unmaps the destination before reading the source. A source page that is not mapped leaves the destination a hole, and a source range that overlaps its destination loses its pages with it.
  • map_aliases takes the batched path when VICTORY_MAP_THREADS is above 1, which is the default. For a missing source it pushes an empty op, and change() then unmaps the destination page.

The change

  • XMemMapPhysicalPages looks every page number up first. If one is unknown, it returns null and changes nothing.
  • alias_as takes every source slice first (the slices keep their sections alive), then unmaps the destination and maps. A missing source returns false with the destination unchanged. The overlapping case maps from the slices taken first, so the overlapped pages are not lost.
  • map_aliases first runs a look-ahead, missing_source. It counts pages that earlier ranges of the same call map or unmap, and nothing changes if a source will be missing. Inside a group, a source unmapped since then (the locks are given back between groups) leaves its destination as it is instead of unmapping it.

a_copy_of_consecutive_pages_shows_them_through_one_view asserted the old partial result: pages ahead of the missing one mapped, the rest a hole. It now asserts that the destination is unchanged.

The idea follows fxceless/victory-fork#1460 (cwWwWwW), ported to this tree. That PR was against fxceless's fork; I found no PR here doing the same.

Tests

The new tests run without a GPU:

  • a_remap_that_cannot_be_served_changes_nothing: an unknown page number changes nothing and the buffer reads as before. A copy from a source with a hole leaves its destination. A two-page copy onto itself, shifted by one page, keeps the overlapped page.
  • batched_copies_that_cannot_be_served_change_nothing: on the batched path, a missing source changes no destination, and a source that an earlier range of the call maps is served.
  • a_source_counts_as_the_entries_before_it_leave_it: the look-ahead.

cargo test -p victory-hle: 185 passed. The xmem tests pass on one thread and on several.

cargo clippy --workspace --all-targets -- -D warnings stops on lints main already has (victory-formats/src/texture.rs:1346 and dead code in victory-gpu, see #425, #265 and #86). This change adds no warning.

No game files, dumps or extracted data are included.

**@⁠kibagami-nc** on GitHub · 2026-11-28 00:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/538) `kibagami-nc:fix/xmem-remap-unknown-page` → `main` · +171 −29 · 1 files · 1 commits · open ## The problem `XMemMapPhysicalPages` takes the destination's views away (`unmap`) **before** it looks the page numbers up. A number that is not in the table makes the call return null, but the buffer has already become placeholders. Such a number can be one the title's list kept after `XMemFreePhysicalPages`, or one whose allocation came late. After a failed remap the title keeps using what the buffer showed, so its next access is an access violation. The GPU side has also already been told the range changed. The GPU's page-mapping copies have the same order: - `alias_as` unmaps the destination before reading the source. A source page that is not mapped leaves the destination a hole, and a source range that overlaps its destination loses its pages with it. - `map_aliases` takes the batched path when `VICTORY_MAP_THREADS` is above 1, which is the default. For a missing source it pushes an empty op, and `change()` then unmaps the destination page. ## The change - **`XMemMapPhysicalPages`** looks every page number up first. If one is unknown, it returns null and changes nothing. - **`alias_as`** takes every source slice first (the slices keep their sections alive), then unmaps the destination and maps. A missing source returns `false` with the destination unchanged. The overlapping case maps from the slices taken first, so the overlapped pages are not lost. - **`map_aliases`** first runs a look-ahead, `missing_source`. It counts pages that earlier ranges of the same call map or unmap, and nothing changes if a source will be missing. Inside a group, a source unmapped since then (the locks are given back between groups) leaves its destination as it is instead of unmapping it. `a_copy_of_consecutive_pages_shows_them_through_one_view` asserted the old partial result: pages ahead of the missing one mapped, the rest a hole. It now asserts that the destination is unchanged. The idea follows fxceless/victory-fork#1460 (cwWwWwW), ported to this tree. That PR was against fxceless's fork; I found no PR here doing the same. ## Tests The new tests run without a GPU: - `a_remap_that_cannot_be_served_changes_nothing`: an unknown page number changes nothing and the buffer reads as before. A copy from a source with a hole leaves its destination. A two-page copy onto itself, shifted by one page, keeps the overlapped page. - `batched_copies_that_cannot_be_served_change_nothing`: on the batched path, a missing source changes no destination, and a source that an earlier range of the call maps is served. - `a_source_counts_as_the_entries_before_it_leave_it`: the look-ahead. `cargo test -p victory-hle`: 185 passed. The `xmem` tests pass on one thread and on several. `cargo clippy --workspace --all-targets -- -D warnings` stops on lints `main` already has (`victory-formats/src/texture.rs:1346` and dead code in `victory-gpu`, see #425, #265 and #86). This change adds no warning. No game files, dumps or extracted data are included.
XMemMapPhysicalPages took the destination's views away before it looked
the page numbers up. A number that is not in the table (one a list kept
after XMemFreePhysicalPages, or one whose allocation came late) returned
null with the buffer turned into placeholders: the title keeps using what
the buffer showed after a failed remap, and its next access faulted.

The GPU's page-mapping copies did the same. alias_as unmapped the
destination before reading the source, so a source page that was not
mapped left a hole, and a source that overlaps its destination lost its
pages with it. The batched path (map_aliases, VICTORY_MAP_THREADS above
1, the default) pushed an empty op for a missing source, which unmapped
the destination page.

Now every page is looked up before anything is changed. A remap or a copy
that cannot be served returns null or false with the memory as it was.
In the batched path a look-ahead (missing_source) counts pages that
earlier ranges of the same call map or unmap, and a source unmapped
between groups leaves its destination alone.

The existing a_copy_of_consecutive_pages_shows_them_through_one_view
asserted the old partial mapping (pages ahead of the missing one mapped,
the rest a hole); it now asserts the destination is unchanged.

Tests: an unknown page changes nothing and the buffer reads as before; a
copy from a source with a hole leaves its destination; a copy of two pages
shifted by one onto itself keeps the overlapped page; the batched path
changes no destination for a missing source and serves one an earlier
range maps; the look-ahead itself.

The idea follows fxceless/victory-fork#1460 (cwWwWwW).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 00:34:42 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/538/head:github-bot/gh-538'
git switch 'github-bot/gh-538'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-538'
git switch 'github-bot/gh-538'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-538'
git switch 'github-bot/gh-538'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-538'
git switch 'main'
git merge --squash 'github-bot/gh-538'
git switch 'main'
git merge --ff-only 'github-bot/gh-538'
git switch 'main'
git merge 'github-bot/gh-538'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.