xmem: hold the whole private span for a GPU tile import #660

Merged
revonateB0T merged 1 commit from upstream-pr/660 into main 2026-12-02 21:30:39 +00:00
revonateB0T commented 2026-12-02 19:56:22 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by revonateB0T on 2026-12-02T19:56:22Z.


What I see

With private backing (TUXBOX_XMEM_PRIVATE_VIEWS=1) the GPU loses the device a few seconds into a title:

radv/amdgpu: The CS has been rejected, see dmesg for more information (-1).
vkd3d-proton:d3d12_command_queue_execute: Failed to submit queue(s), vr -4.
vkd3d-proton:d3d12_device_mark_as_removed: Device 0000000073b10080 is lost (reason 0x887a0005, "VK_ERROR_DEVICE_LOST").

The kernel refuses the submission rather than the driver faulting on the pages themselves.

Which commit introduced this

c1139ab287f9b112b95c3c3862204da806b56b82 — "d3d12: convert queue-backed textures on the GPU and stop refusing their batches" (2026-12-02).

It widened the GPU tile import from one page to a run of pages, and left the hold at one page. In runtime/d3d12/src/device/heap/gpu_tiles.rs it added:

const CLUSTER_BYTES: u64 = 2 << 20;
const WHOLE_VIEW_BYTES: u64 = 256 << 20;

fn shared_window(device: &Device, page: u64) -> Option<(u64, u64)> { ... }

if let Some((window, bytes)) = shared_window(device, base).filter(|&(_, bytes)| bytes > TILE_BYTES)
    && let Ok(piece) = device.state.page_pools.direct_piece(&api, window, bytes, &guard, "GPU page cluster", None)

Before it, the tile imported the one page it was asked for:

.direct_piece(&api, base, TILE_BYTES, &guard, "GPU page mapping", Some(userptr))

The hold did not follow: resolve_backings puts only the page that was asked for into pinned_views, so view_holds counted that page alone. The import got wider than the hold.

Before that commit the private backing had no such problem, because the import was exactly the page the hold covered.

Why

A GPU tile import maps a private span as one host pointer: the driver takes the whole 64 KiB-aligned run of pages the tile belongs to, not the one page that was asked for. The import got wider than the hold in c1139ab287f9b112b95c3c3862204da806b56b82:

runtime/xmem/src/physical_pages/backing.rs, acquire_contiguous:

let mut host = runs[0].address;
if tile {
    // ... only a SharedSection page gets its own view here

resolve_backings puts the page that was asked for into pinned_views, so view_holds counts that page alone.

The pages beside it are released on their own. The title unmaps one, or the span is split, and the page is decommitted (private_views.rs, decommit_private_range) or re-protected (PAGE_NOACCESS) while the GPU still maps it. The kernel then refuses the next submission.

A section-backed page does not show this: its import names a held view of its own (writable_section_view), and the section keeps the pages mapped, so releasing a view does not release the pages.

What this changes

A hold on a tile covers the whole private span, which is the unit that is released anyway.

The pages the import covers are kept apart from the pages the hold only keeps mapped. tracking.import_views names the pages the GPU can write, and the CPU's write watch is disturbed on those alone; naming the whole span there would make the provider digest every page before every submission.

How I measured it

ProjectScarlett under GE-Proton11-16 on an AMD Radeon 780M (RADV, 1002:15bf), TUXBOX_XMEM_PRIVATE_VIEWS=1:

Build CS has been rejected Result
c1139ab2 present device lost in a few seconds, exit code 3
this branch 0 the title loads its scene and keeps running, exit code 0

What I could not run

The xmem crate is Windows-only, so its Rust tests cannot run on a Linux host; python tuxbox.py check --no-gpu type-checks the crate and its tests. The test in runtime/xmem/src/tests/physical_backing.rs (gpu_tile_hold_keeps_the_whole_private_span_mapped) states the behaviour for a host that can run it: a tile hold keeps a sibling page of the same span committed, and the page is released with the hold.

Miri is the one place those tests run on Linux, and it does not emulate VirtualAlloc, so every test in that file is marked cfg_attr(miri, ignore = ...). The new test says so as well.

The Miri job fails on two graphics reservation tests that 1b4ed472 added without the attribute. That is on main as well, and this branch does not touch it.

NVIDIA is untested here: this host has no NVIDIA card. The change only widens a hold, so the section path and the NVIDIA path keep the behaviour they had.

AI use

The code change and the measurements were prepared with an AI coding agent (DeepSeek Harness, running MiniMax-M3.1-Flash, following AGENTS.md). All runs were executed on my local machine.

<!-- greyfinch-sync:brcly/TuxBox:issue:5613670908 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/660). Originally posted by [revonateB0T](https://github.com/revonateB0T) on 2026-12-02T19:56:22Z. --- ## What I see With private backing (`TUXBOX_XMEM_PRIVATE_VIEWS=1`) the GPU loses the device a few seconds into a title: ``` radv/amdgpu: The CS has been rejected, see dmesg for more information (-1). vkd3d-proton:d3d12_command_queue_execute: Failed to submit queue(s), vr -4. vkd3d-proton:d3d12_device_mark_as_removed: Device 0000000073b10080 is lost (reason 0x887a0005, "VK_ERROR_DEVICE_LOST"). ``` The kernel refuses the submission rather than the driver faulting on the pages themselves. ## Which commit introduced this `c1139ab287f9b112b95c3c3862204da806b56b82` — *"d3d12: convert queue-backed textures on the GPU and stop refusing their batches"* (2026-12-02). It widened the GPU tile import from one page to a run of pages, and left the hold at one page. In `runtime/d3d12/src/device/heap/gpu_tiles.rs` it added: ```rust const CLUSTER_BYTES: u64 = 2 << 20; const WHOLE_VIEW_BYTES: u64 = 256 << 20; fn shared_window(device: &Device, page: u64) -> Option<(u64, u64)> { ... } if let Some((window, bytes)) = shared_window(device, base).filter(|&(_, bytes)| bytes > TILE_BYTES) && let Ok(piece) = device.state.page_pools.direct_piece(&api, window, bytes, &guard, "GPU page cluster", None) ``` Before it, the tile imported the one page it was asked for: ```rust .direct_piece(&api, base, TILE_BYTES, &guard, "GPU page mapping", Some(userptr)) ``` The hold did not follow: `resolve_backings` puts only the page that was asked for into `pinned_views`, so `view_holds` counted that page alone. The import got wider than the hold. Before that commit the private backing had no such problem, because the import was exactly the page the hold covered. ## Why A GPU tile import maps a private span as one host pointer: the driver takes the whole 64 KiB-aligned run of pages the tile belongs to, not the one page that was asked for. The import got wider than the hold in `c1139ab287f9b112b95c3c3862204da806b56b82`: `runtime/xmem/src/physical_pages/backing.rs`, `acquire_contiguous`: ```rust let mut host = runs[0].address; if tile { // ... only a SharedSection page gets its own view here ``` `resolve_backings` puts the page that was asked for into `pinned_views`, so `view_holds` counts that page alone. The pages beside it are released on their own. The title unmaps one, or the span is split, and the page is decommitted (`private_views.rs`, `decommit_private_range`) or re-protected (`PAGE_NOACCESS`) while the GPU still maps it. The kernel then refuses the next submission. A section-backed page does not show this: its import names a held view of its own (`writable_section_view`), and the section keeps the pages mapped, so releasing a view does not release the pages. ## What this changes A hold on a tile covers the whole private span, which is the unit that is released anyway. The pages the import covers are kept apart from the pages the hold only keeps mapped. `tracking.import_views` names the pages the GPU can write, and the CPU's write watch is disturbed on those alone; naming the whole span there would make the provider digest every page before every submission. ## How I measured it ProjectScarlett under GE-Proton11-16 on an AMD Radeon 780M (RADV, `1002:15bf`), `TUXBOX_XMEM_PRIVATE_VIEWS=1`: | Build | `CS has been rejected` | Result | | --- | --- | --- | | `c1139ab2` | present | device lost in a few seconds, exit code 3 | | this branch | 0 | the title loads its scene and keeps running, exit code 0 | ## What I could not run The xmem crate is Windows-only, so its Rust tests cannot run on a Linux host; `python tuxbox.py check --no-gpu` type-checks the crate and its tests. The test in `runtime/xmem/src/tests/physical_backing.rs` (`gpu_tile_hold_keeps_the_whole_private_span_mapped`) states the behaviour for a host that can run it: a tile hold keeps a sibling page of the same span committed, and the page is released with the hold. Miri is the one place those tests run on Linux, and it does not emulate `VirtualAlloc`, so every test in that file is marked `cfg_attr(miri, ignore = ...)`. The new test says so as well. The Miri job fails on two graphics reservation tests that `1b4ed472` added without the attribute. That is on `main` as well, and this branch does not touch it. NVIDIA is untested here: this host has no NVIDIA card. The change only widens a hold, so the section path and the NVIDIA path keep the behaviour they had. ## AI use The code change and the measurements were prepared with an AI coding agent (DeepSeek Harness, running MiniMax-M3.1-Flash, following `AGENTS.md`). All runs were executed on my local machine.
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
brcly/TuxBox!660
No description provided.