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

Closed
github-bot wants to merge 2 commits from github-bot/gh-2723 into main AGit
Owner

@⁠HailLucifer666 on GitHub · 2026-11-29 16:37 UTC · original
HailLucifer666:fix/xmem-va-bifurcation → main · +345 −27 · 2 files · 2 commits · closed without merging

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).
**@⁠HailLucifer666** on GitHub · 2026-11-29 16:37 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2723) `HailLucifer666:fix/xmem-va-bifurcation` → `main` · +345 −27 · 2 files · 2 commits · closed without merging 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`).
On v2026.11.29.01, XMemVirtualAlloc caps 64-bit title allocations strictly
below 1 << TITLE_TOP_BITS (128 GiB, required by the GPU by-address directory:
victory_shader::emit::MEMORY_PAGES = 2^21 * 64 KiB). After D3D12, Streamline,
pipeline caches, and smaller allocations run, no contiguous 6.09 GiB
(0x185c00000) hole remains below 128 GiB, causing VirtualAlloc2 to fail with
os error 8 and crashing System Init (#2356, #2339).

Solve strictly inside < 1 << 37 (no 40-bit fallback, zero GPU directory risk):
- Lock TITLE_TOP_BITS = 37 to 2^21 * 64 KiB with a compile-time const assert.
- Bifurcate [4 GiB, 128 GiB) in address_ranges_for_size(): allocations < 512 MiB
  search [4 GiB, 96 GiB) first, large arenas >= 512 MiB search [96 GiB, 128 GiB)
  first, both falling back to [4 GiB, 128 GiB) only if full; ADDRESS_32BIT stays
  strictly in [0, u32::MAX].
- Reserve a 16 GiB MEM_RESERVE | MEM_RESERVE_PLACEHOLDER guard slab (0 RAM /
  0 commit) inside [96 GiB, 128 GiB) at early xmem::module() init and carve
  large placeholder requests via VirtualFree(..., MEM_PRESERVE_PLACEHOLDER)
  if normal VirtualAlloc2 fails.
- Add VirtualQueryEx VA-map summary (largest free hole, region counts) to
  XMemVirtualAlloc refusal warnings, and VICTORY_VA_BIFURCATION=0 kill switch.

Verified:
- cargo test -p victory-hle --lib modules::xmem::tests:: -- --test-threads=1
  -> 46 passed, 0 failed, 1 ignored (including real 32-scatter + 6.09 GiB
  TileHeap placeholder reservation strictly in [96 GiB, 128 GiB)).
- cargo clippy -p victory-hle --lib --tests -> exit 0, 0 warnings in xmem.rs.
- Mutation probe (disabling bifurcation) verified red (exit 101) before restore.
When a plausible 40-bit console address in [128 GiB, 1 TiB) reaches
memory.rs::possible(), increment ABOVE_CEILING and emit a power-of-two
rate-limited tracing::warn! instead of silently returning false, so any
above-1<<37 escape surfaces loudly at the consumer.

Verified:
- cargo test -p victory-gpu --lib memory::tests::above_ceiling -> 1 passed, 0 failed.
- cargo clippy -p victory-gpu --lib --tests -> exit 0, 0 new warnings in memory.rs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 16:38:01 +00:00
Author
Owner

@⁠ags-filipe on GitHub · 2026-11-29 20:54 UTC · original

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

**@⁠ags-filipe** on GitHub · 2026-11-29 20:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2723#issuecomment-7262457609) I was having this issue with the latest builds from today (4090) and your fix worked, no more instant crash at the beginning 😸
github-bot closed this pull request 2026-11-29 21:55:46 +00:00
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-29 21:53 UTC · original

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.

**@⁠HailLucifer666** on GitHub · 2026-11-29 21:53 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2723#issuecomment-7263235923) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!2723
No description provided.