hle(xmem): bifurcate <128 GiB VA space, reserve upper-32 GiB guard slab, and add map-time ceiling guard (#2356, #2339) #2723

Closed
HailLucifer666 wants to merge 2 commits from upstream-pr/2723 into main
HailLucifer666 commented 2026-11-29 16:37:13 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by HailLucifer666 on 2026-11-29T16:37:13Z.


Fixes #2356 and #2339

What it changes

On v2026.11.29.01, XMemVirtualAlloc enforces TITLE_TOP_BITS = 37 (128 GiB, required by the GPU by-address directory: victory_shader::emit::MEMORY_PAGES = 2^21 * 64 KiB). As empirically confirmed in #2356 (and #218), allocating above 1 << 37 causes green/flickering by-address shader read corruption. After D3D12, Streamline, pipeline caches, and smaller allocations fragment [4 GiB, 128 GiB), no contiguous 6.09 GiB (0x185c00000) VA hole remains for the title's TileHeap placeholder, causing VirtualAlloc2 to fail with os error 8 and crash System Init.

Solves this strictly inside < 1 << 37 (zero 40-bit fallback, zero GPU directory corruption risk):

  • Compile-time ceiling lock: const assertion tying TITLE_TOP_BITS = 37 to (1 << 21) * 64 KiB.
  • VA range bifurcation (address_ranges_for_size): allocations < 512 MiB search [4 GiB, 96 GiB) first; large arenas >= 512 MiB search [96 GiB, 128 GiB) first; both fall back to [4 GiB, 128 GiB) only if full. ADDRESS_32BIT stays strictly in [0, u32::MAX].
  • Early boot-time placeholder guard slab: reserves a 16 GiB MEM_RESERVE | MEM_RESERVE_PLACEHOLDER slab (0 bytes RAM / 0 bytes commit) inside [96 GiB, 128 GiB) during early xmem::module() init — before D3D12/Streamline/caches load — and carves large placeholder requests via VirtualFree(..., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER) if normal VirtualAlloc2 fails.
  • Consumer-side map-time guard (memory.rs): rate-limited tracing::warn! + ABOVE_CEILING counter if a plausible 40-bit console address in [128 GiB, 1 TiB) ever reaches memory.rs::possible().
  • Diagnostics & kill switch: VirtualQueryEx VA-map summary (largest free hole, region counts) logged on refusal; VICTORY_VA_BIFURCATION=0 restores legacy flat [4 GiB, 128 GiB) search.

How it was tested

  • Not verified here: Live title boot on a cache-populated RTX 4090 / 3090 rig (no game dump in this environment).
  • cargo test -p victory-hle --lib modules::xmem::tests:: -- --test-threads=1 → 46 passed, 0 failed, 1 ignored (includes real 32-scatter + 6.09 GiB TileHeap placeholder reservation strictly in [96 GiB, 128 GiB)).
  • cargo test -p victory-gpu --lib memory::tests::above_ceiling → 1 passed, 0 failed.
  • cargo clippy -p victory-hle --lib --tests and cargo clippy -p victory-gpu --lib --tests → exit 0, 0 new warnings in xmem.rs / memory.rs. (Pre-existing diagnostics feature errors on 829188e9 untouched.)
  • Mutation probe (2026-11-29): disabling bifurcation in address_ranges_for_size verified red (exit 101) before restore.
  • cargo test passed for the crates it touches: yes

Checked for overlap

  • Searched open PRs at 829188e9 for xmem / TITLE_TOP_BITS / TileHeap / #2356 / #2339. Related: #2439 (xmem test parallelism fix, non-colliding; our tests run cleanly under --test-threads=1).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5552788361 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2723). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-29T16:37:13Z. --- Fixes #2356 and #2339 ## What it changes On `v2026.11.29.01`, `XMemVirtualAlloc` enforces `TITLE_TOP_BITS = 37` (128 GiB, required by the GPU by-address directory: `victory_shader::emit::MEMORY_PAGES = 2^21 * 64 KiB`). As empirically confirmed in #2356 (and #218), allocating above `1 << 37` causes green/flickering by-address shader read corruption. After D3D12, Streamline, pipeline caches, and smaller allocations fragment `[4 GiB, 128 GiB)`, no contiguous 6.09 GiB (`0x185c00000`) VA hole remains for the title's `TileHeap` placeholder, causing `VirtualAlloc2` to fail with `os error 8` and crash `System Init`. Solves this strictly **inside `< 1 << 37`** (zero 40-bit fallback, zero GPU directory corruption risk): - **Compile-time ceiling lock:** `const` assertion tying `TITLE_TOP_BITS = 37` to `(1 << 21) * 64 KiB`. - **VA range bifurcation (`address_ranges_for_size`):** allocations `< 512 MiB` search `[4 GiB, 96 GiB)` first; large arenas `>= 512 MiB` search `[96 GiB, 128 GiB)` first; both fall back to `[4 GiB, 128 GiB)` only if full. `ADDRESS_32BIT` stays strictly in `[0, u32::MAX]`. - **Early boot-time placeholder guard slab:** reserves a 16 GiB `MEM_RESERVE | MEM_RESERVE_PLACEHOLDER` slab (0 bytes RAM / 0 bytes commit) inside `[96 GiB, 128 GiB)` during early `xmem::module()` init — before D3D12/Streamline/caches load — and carves large placeholder requests via `VirtualFree(..., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)` if normal `VirtualAlloc2` fails. - **Consumer-side map-time guard (`memory.rs`):** rate-limited `tracing::warn!` + `ABOVE_CEILING` counter if a plausible 40-bit console address in `[128 GiB, 1 TiB)` ever reaches `memory.rs::possible()`. - **Diagnostics & kill switch:** `VirtualQueryEx` VA-map summary (largest free hole, region counts) logged on refusal; `VICTORY_VA_BIFURCATION=0` restores legacy flat `[4 GiB, 128 GiB)` search. ## How it was tested - **Not verified here:** Live title boot on a cache-populated RTX 4090 / 3090 rig (no game dump in this environment). - `cargo test -p victory-hle --lib modules::xmem::tests:: -- --test-threads=1` → **46 passed, 0 failed, 1 ignored** (includes real 32-scatter + 6.09 GiB `TileHeap` placeholder reservation strictly in `[96 GiB, 128 GiB)`). - `cargo test -p victory-gpu --lib memory::tests::above_ceiling` → **1 passed, 0 failed**. - `cargo clippy -p victory-hle --lib --tests` and `cargo clippy -p victory-gpu --lib --tests` → exit 0, **0 new warnings** in `xmem.rs` / `memory.rs`. *(Pre-existing `diagnostics` feature errors on `829188e9` untouched.)* - **Mutation probe (2026-11-29):** disabling bifurcation in `address_ranges_for_size` verified red (`exit 101`) before restore. - `cargo test` passed for the crates it touches: **yes** ## Checked for overlap - [x] Searched open PRs at `829188e9` for `xmem` / `TITLE_TOP_BITS` / `TileHeap` / `#2356` / `#2339`. Related: #2439 (xmem test parallelism fix, non-colliding; our tests run cleanly under `--test-threads=1`).
ags-filipe commented 2026-11-29 20:54:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ags-filipe on 2026-11-29T20:54:56Z.


I was having this issue with the latest builds from today (4090) and your fix worked, no more instant crash at the beginning 😸

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262457609 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2723#issuecomment-7262457609). Originally posted by [ags-filipe](https://github.com/ags-filipe) on 2026-11-29T20:54:56Z. --- I was having this issue with the latest builds from today (4090) and your fix worked, no more instant crash at the beginning 😸
HailLucifer666 commented 2026-11-29 21:53:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by HailLucifer666 on 2026-11-29T21:53:38Z.


Closing as superseded by upstream commit f72cec77 (XMem: keep 8 GiB of the title's window spare at start, give it back if the 6.5 GB heap is refused), which directly addresses the 6.5 GB heap refusal (os error 8 / +0x1e6c284) in xmem.rs.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7263235923 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2723#issuecomment-7263235923). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-29T21:53:38Z. --- Closing as superseded by upstream commit f72cec77 (XMem: keep 8 GiB of the title's window spare at start, give it back if the 6.5 GB heap is refused), which directly addresses the 6.5 GB heap refusal (os error 8 / +0x1e6c284) in xmem.rs.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!2723
No description provided.