xmem: a secondary alias whose backing a host import holds can never be promoted, and the first CPU access through it kills the title #456

Closed
opened 2026-11-29 07:54:18 +00:00 by Jerkin42 · 1 comment
Jerkin42 commented 2026-11-29 07:54:18 +00:00 (Migrated from github.com)
Contributor

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-29T07:54:18Z.


Seen on: RX 9060 XT (RADV), ProjectScarlett 1.0.2.1, main 28717263 plus #389, #390, #436 (and later #442, #443, #445, #448), GE-Proton11-14, with and without our local userptr shim.

What happens. With #409 and #428 merged, the first story mission gets past the BLAS faults from #403. About 100-170 game frames in, the title dies on an unhandled access violation in title memory:

wine: Unhandled page fault on write access to 000000041F190000 at address ... (XCRDAPI.dll + 0x3AA9E)

The writer was first our storage DLL (a decoded read copied into its destination). After we routed those writes around it (below), the title's own code hit the same thing on a read (game+0x465C80, write=0).

Why, as far as we can tell. physical_pages/private_views.rs: the second VA mapping of a physical page is a secondary alias. It stays inaccessible and secondary_alias_veh promotes it on the first fault (promote_faulting_alias). That returns ERROR_BUSY when the page's private span has a hold (has_hold) or a deferred unmap. The VEH then returns EXCEPTION_CONTINUE_SEARCH and the title dies.

A host import (TuxBoxAcquirePhysicalBacking* from d3d12/src/device/heap/backing.rs) keeps its hold for as long as the imported heap lives. So an alias registered before the import is never promoted while the heap is alive. We added a local log to the VEH that retries ERROR_BUSY for 2 s:

TuxBox xmem: LOCAL: alias 0x540b20000 write fault not promoted (error 170, 2000 retries, write=1)
TuxBox xmem: LOCAL: alias 0x52a750000 write fault not promoted (error 170, 2000 retries, write=0)
TuxBox xmem: LOCAL: alias 0x501a50000 write fault not promoted (error 170, 2000 retries, write=1)

What we tried locally.

  1. Storage writes through the backing. xcrdapi writes decoded reads through TuxBoxAcquirePhysicalAccess runs instead of storing to the destination VA. This removed every storage-thread fault (32k+ reads in one run).
  2. Promote aliases before an import takes its hold. In acquire_runs(import = true), first promote every secondary alias of the range's tokens. Many were refused because an earlier import already held the span (promoted 3 secondary alias(es) first, 36 refused). Worse, moving the backing under live imports made root-view imports fail: 36 command list failed 0x80004001 in root_buffer, so labels were never written and the title stopped. We dropped this one.

Question. On the console every mapping of a physical page is the same memory, and the title reads and writes through whichever VA it likes, with no first-touch step. PageBacking::SharedSection already gives that. Would it work to keep XMem physical pages section-backed from the start (perhaps only pages a title maps at a second VA, or every page when a switch is set), so that an alias never needs promotion and a hold never blocks it? Or is there a reason private backing must come first (host import of section memory, map count)? vm.max_map_count here is 1048576. Happy to test a branch; we can reproduce in about 15 minutes.

Logs and the local patches (no game data) are available on request.

<!-- greyfinch-sync:brcly/TuxBox:issue:6676347319 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/456). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-29T07:54:18Z. --- **Seen on:** RX 9060 XT (RADV), ProjectScarlett 1.0.2.1, `main` 28717263 plus #389, #390, #436 (and later #442, #443, #445, #448), GE-Proton11-14, with and without our local userptr shim. **What happens.** With #409 and #428 merged, the first story mission gets past the BLAS faults from #403. About 100-170 game frames in, the title dies on an unhandled access violation in title memory: ```text wine: Unhandled page fault on write access to 000000041F190000 at address ... (XCRDAPI.dll + 0x3AA9E) ``` The writer was first our storage DLL (a decoded read copied into its destination). After we routed those writes around it (below), the title's own code hit the same thing on a read (`game+0x465C80`, `write=0`). **Why, as far as we can tell.** `physical_pages/private_views.rs`: the second VA mapping of a physical page is a *secondary alias*. It stays inaccessible and `secondary_alias_veh` promotes it on the first fault (`promote_faulting_alias`). That returns `ERROR_BUSY` when the page's private span has a hold (`has_hold`) or a deferred unmap. The VEH then returns `EXCEPTION_CONTINUE_SEARCH` and the title dies. A host import (`TuxBoxAcquirePhysicalBacking*` from `d3d12/src/device/heap/backing.rs`) keeps its hold for as long as the imported heap lives. So an alias registered before the import is never promoted while the heap is alive. We added a local log to the VEH that retries `ERROR_BUSY` for 2 s: ```text TuxBox xmem: LOCAL: alias 0x540b20000 write fault not promoted (error 170, 2000 retries, write=1) TuxBox xmem: LOCAL: alias 0x52a750000 write fault not promoted (error 170, 2000 retries, write=0) TuxBox xmem: LOCAL: alias 0x501a50000 write fault not promoted (error 170, 2000 retries, write=1) ``` **What we tried locally.** 1. **Storage writes through the backing.** `xcrdapi` writes decoded reads through `TuxBoxAcquirePhysicalAccess` runs instead of storing to the destination VA. This removed every storage-thread fault (32k+ reads in one run). 2. **Promote aliases before an import takes its hold.** In `acquire_runs(import = true)`, first promote every secondary alias of the range's tokens. Many were refused because an earlier import already held the span (`promoted 3 secondary alias(es) first, 36 refused`). Worse, moving the backing under live imports made root-view imports fail: 36 `command list failed 0x80004001` in `root_buffer`, so labels were never written and the title stopped. We dropped this one. **Question.** On the console every mapping of a physical page is the same memory, and the title reads and writes through whichever VA it likes, with no first-touch step. `PageBacking::SharedSection` already gives that. Would it work to keep XMem physical pages section-backed from the start (perhaps only pages a title maps at a second VA, or every page when a switch is set), so that an alias never needs promotion and a hold never blocks it? Or is there a reason private backing must come first (host import of section memory, map count)? `vm.max_map_count` here is 1048576. Happy to test a branch; we can reproduce in about 15 minutes. Logs and the local patches (no game data) are available on request.
Jerkin42 commented 2026-11-29 08:35:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-29T08:35:45Z.


A local experiment answers part of the question. It's a switch that sends every newly mapped page through map_shared_page / map_contiguous (section-backed from the start) instead of the private paths.

  • It fixes this. The run got past the mission start for the first time: no alias faults, no held-label stalls, no GPU faults.
  • The cost. Section-backed pages aren't write-watched (as tracking.rs says), so the d3d12 provider re-checks every placed texture. Frame time went from normal to 10-30 s per frame right after the mission start, and the title's own watchdog ended the run.

So the trade-off is coherence vs write watch. Two directions we can see:

  1. Keep pages private and tracked, and section-back only pages that get a second CPU mapping. That needs a way to promote a held page, e.g. re-import after the move, as held_private_arena_promotion_notifies_invalidation_and_keeps_hold_live does for arenas.
  2. Section-back everything and make the provider's change detection cheap without write watch (content fingerprints / GPU-side compare).

We'll try 2 on the d3d12 side next. Which of these fits xmem better for you?

<!-- greyfinch-sync:brcly/TuxBox:comment:7253205811 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/456#issuecomment-7253205811). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-29T08:35:45Z. --- A local experiment answers part of the question. It's a switch that sends every newly mapped page through `map_shared_page` / `map_contiguous` (section-backed from the start) instead of the private paths. - **It fixes this.** The run got past the mission start for the first time: no alias faults, no held-label stalls, no GPU faults. - **The cost.** Section-backed pages aren't write-watched (as `tracking.rs` says), so the d3d12 provider re-checks every placed texture. Frame time went from normal to 10-30 s per frame right after the mission start, and the title's own watchdog ended the run. So the trade-off is coherence vs write watch. Two directions we can see: 1. Keep pages private and tracked, and section-back only pages that get a second CPU mapping. That needs a way to promote a held page, e.g. re-import after the move, as `held_private_arena_promotion_notifies_invalidation_and_keeps_hold_live` does for arenas. 2. Section-back everything and make the provider's change detection cheap without write watch (content fingerprints / GPU-side compare). We'll try 2 on the d3d12 side next. Which of these fits xmem better for you?
Sign in to join this conversation.
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
brcly/TuxBox#456
No description provided.