Render heaps are freed when the title releases its image, but the GPU still reads the guest range minutes later (use-after-free, device lost) #323

Closed
opened 2026-11-27 18:42:33 +00:00 by Kayotic1337 · 1 comment
Kayotic1337 commented 2026-11-27 18:42:33 +00:00 (Migrated from github.com)
Contributor

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-27T18:42:33Z.


What happens

After loading a story save, ProjectScarlett runs for 15 to 18 minutes and then loses the device. With VKD3D_CONFIG=fault, vkd3d's device-fault report names the faulting address as a VA that belonged to a render heap (RenderHeaps in runtime/d3d12/src/device/heap.rs) that the provider had already freed. In the run below the shader read it 11 minutes after the heap was freed.

Keeping every render heap alive (local experiment, one line) removes the page fault in the next run. The device is still lost later, but now from a gfx ring timeout without any fault, which looks like a separate problem (see the end).

Setup

RX 9070 XT 16 GB (1002:7550, RADV GFX1201, Mesa 26.3.1), 64 GB RAM, Linux 7.3.6, GE-Proton11-14 (vkd3d-proton v3.1-83), ProjectScarlett 1.0.2.1 offline, 3840x2160, shaders prepared, no preload.
Build: main at c2a59af + #258 (d50a51c) + a local probe commit that only adds log lines (below). The render heap code is unchanged on current main (8ef909b).

Evidence

1. vkd3d names a freed VA

Run without the probe (VKD3D_CONFIG=fault):

d3d12_device_poll_device_faults: Address [0]: [ffff80044fd40000, ffff80044fd40fff], type WriteInvalid
vkd3d_address_binding_tracker_check_va: Fault address is currently unmapped. This is very likely use-after-free.

Kernel: comp_1.0.1, Faulty UTCL2 client ID: TCP, GCVM_L2_PROTECTION_FAULT_STATUS:0x00541041, then a ring timeout. In this run the address history showed several large VkBuffer [global-buffer] allocations (3.68 GB, 985 MB twice with sparse unbinds, 152 MB) bound and freed at that VA within a few seconds. I have not identified which path those came from; they are larger than any render heap in the next runs.

2. The probe ties it to a render heap

Local probe (not proposed): log every render heap the provider creates (guest range, requested and GetDesc size) and frees (impl Drop for RenderHeap), and every placed image whose real footprint would overrun its heap.

Run 2 (same save, ~17.6 min, exit code 3):

  • 592 render heaps created, 3.1 GB, largest 57 MB. That matches the flat 3.0 GB in #292. Only about 10 are freed in the whole run.
  • 0 images overrun their heap, so heap sizing is not the problem.
  • vkd3d's report for the fault:
Address [0]: [ffff80011ebdf000, ffff80011ebdffff], type ReadInvalid
VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)]  BIND    T: 8696.999 s  VkDeviceMemory [memoryTypeIndex = 0]
VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)]  BIND    T: 8696.999 s  VkBuffer [global-buffer]
VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)]  BIND    T: 8696.999 s  VkImage [3840 x 2160 x 1] [levels = 1 ...
VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)]  UNBIND  T: 9081.801 s  VkImage / VkBuffer / VkDeviceMemory
(afterwards the last page is reused by a 2 KB driver object, bound and unbound every ~7 s)
Received fault @ 9748.92 s
  • The probe's lines for that heap:
probe heap: render heap create guest=0x15f190000..0x161170000 size=0x1fe0000 actual=0x1fe0000 replaced=0
probe heap: render heap free end=0x161170000 size=0x1fe0000      (logged at ~9081 s, together with two other heaps of 0x28e0000 and 0x310000)
  • Kernel: in page starting at address 0x000080011ebdf000 from client 10, GCVM_L2_PROTECTION_FAULT_STATUS:0x0060113A (TCP, mapping error), then ring gfx_0.0.0 timeout.

So a 3840x2160 image placed at guest 0x15f190000 gets a render heap, the title releases the image at about 9081 s, the heap goes with it, and a shader reads the last page of that VA 11 minutes later.

3. Experiment: never free a render heap

One line after heaps.insert(start, Arc::downgrade(&heap)); in RenderHeaps::acquire:

std::mem::forget(Arc::clone(&heap));

Run 3 (same save, 1030 s, exit code 3): 0 render heaps freed, render heaps still 3.1 GB (only ~10 heaps were being freed anyway), no vkd3d VA fault and no page fault in the kernel log. This is one run, so it is a strong hint and not proof.

Relation to #258

All runs were on main + #258 (d50a51c), because without it the menu runs at about 1 fps here (copy path) and the title never gets this far. #258 does not change RenderHeaps or place_gpu_target (its diff against c2a59af has no lines in that code), so I don't think it causes this; it only makes it reachable. The same runs are the ones in my report on #258 (fault 4 there is run 1 here). I have not run without #258 long enough to rule it out completely.

Why I think it happens

RenderHeaps keeps only a Weak per guest range, and each image holds its Arc<RenderHeap> (plus the native heap through IMPORTED_HEAP private data). When the title releases the last image at a guest range, the native heap is freed right away. On the console, releasing the image object does not free the memory behind it: the title still owns the guest range and can keep reading it through descriptors it built or copied earlier. The comment on RenderHeaps already says later images at the same guest address should alias "as they do in console memory". The heap's lifetime follows the image object instead of the guest range.

I have not found which descriptor still points at the old VA (an old SRV in a title-managed heap would fit the 11-minute gap, but that is a guess).

Possible directions (not tested)

  • Keep a render heap while its guest range is still allocated or committed, for example release it from the same path that sees the guest pages freed or remapped, instead of from the image's Drop.
  • Or delay the release until the guest range is reused by a different placement, and alias as now.

"Never free" is only the experiment; it would leak across a long session.

What remains after the experiment

Run 3 still ends in ring gfx_0.0.0 timeout, signaled seq=4868630, emitted seq=4868633 with no page fault, after the save loads, with the title paused (Frame: 3164, Streaming Requests: 6175, SRL state Prestream, Unsignaled CrossQueueBarrier). One earlier run without the probe ended the same way. The devcoredump shows the CP busy in IB1 (CP_STALLED_STAT2 0x00010800); I can't decode the stuck packet without umr.

Note for anyone reading amdgpu devcoredumps: the "Faulty page" field holds the last fault since boot, not necessarily one from this hang. My dump for run 3 showed run 2's 0x80011ebdf000 / 0x60113a while the kernel logged no fault for run 3.

<!-- greyfinch-sync:brcly/TuxBox:issue:6652597740 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/323). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-27T18:42:33Z. --- ## What happens After loading a story save, ProjectScarlett runs for 15 to 18 minutes and then loses the device. With `VKD3D_CONFIG=fault`, vkd3d's device-fault report names the faulting address as a VA that belonged to a **render heap** (`RenderHeaps` in `runtime/d3d12/src/device/heap.rs`) that the provider had already freed. In the run below the shader read it 11 minutes after the heap was freed. Keeping every render heap alive (local experiment, one line) removes the page fault in the next run. The device is still lost later, but now from a gfx ring timeout without any fault, which looks like a separate problem (see the end). ## Setup RX 9070 XT 16 GB (`1002:7550`, RADV GFX1201, Mesa 26.3.1), 64 GB RAM, Linux 7.3.6, GE-Proton11-14 (vkd3d-proton v3.1-83), ProjectScarlett 1.0.2.1 offline, 3840x2160, shaders prepared, no preload. Build: `main` at `c2a59af` + #258 (`d50a51c`) + a local probe commit that only adds log lines (below). The render heap code is unchanged on current `main` (`8ef909b`). ## Evidence ### 1. vkd3d names a freed VA Run without the probe (`VKD3D_CONFIG=fault`): ```text d3d12_device_poll_device_faults: Address [0]: [ffff80044fd40000, ffff80044fd40fff], type WriteInvalid vkd3d_address_binding_tracker_check_va: Fault address is currently unmapped. This is very likely use-after-free. ``` Kernel: `comp_1.0.1`, `Faulty UTCL2 client ID: TCP`, `GCVM_L2_PROTECTION_FAULT_STATUS:0x00541041`, then a ring timeout. In this run the address history showed several large `VkBuffer [global-buffer]` allocations (3.68 GB, 985 MB twice with sparse unbinds, 152 MB) bound and freed at that VA within a few seconds. I have not identified which path those came from; they are larger than any render heap in the next runs. ### 2. The probe ties it to a render heap Local probe (not proposed): log every render heap the provider creates (guest range, requested and `GetDesc` size) and frees (`impl Drop for RenderHeap`), and every placed image whose real footprint would overrun its heap. Run 2 (same save, ~17.6 min, exit code 3): - 592 render heaps created, 3.1 GB, largest 57 MB. That matches the flat 3.0 GB in #292. Only about 10 are freed in the whole run. - 0 images overrun their heap, so heap sizing is not the problem. - vkd3d's report for the fault: ```text Address [0]: [ffff80011ebdf000, ffff80011ebdffff], type ReadInvalid VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)] BIND T: 8696.999 s VkDeviceMemory [memoryTypeIndex = 0] VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)] BIND T: 8696.999 s VkBuffer [global-buffer] VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)] BIND T: 8696.999 s VkImage [3840 x 2160 x 1] [levels = 1 ... VA range [ffff80011cc00000, ffff80011ebe0000) [size = 33423360 (0x1fe0000)] UNBIND T: 9081.801 s VkImage / VkBuffer / VkDeviceMemory (afterwards the last page is reused by a 2 KB driver object, bound and unbound every ~7 s) Received fault @ 9748.92 s ``` - The probe's lines for that heap: ```text probe heap: render heap create guest=0x15f190000..0x161170000 size=0x1fe0000 actual=0x1fe0000 replaced=0 probe heap: render heap free end=0x161170000 size=0x1fe0000 (logged at ~9081 s, together with two other heaps of 0x28e0000 and 0x310000) ``` - Kernel: `in page starting at address 0x000080011ebdf000 from client 10`, `GCVM_L2_PROTECTION_FAULT_STATUS:0x0060113A` (`TCP`, mapping error), then `ring gfx_0.0.0 timeout`. So a 3840x2160 image placed at guest `0x15f190000` gets a render heap, the title releases the image at about 9081 s, the heap goes with it, and a shader reads the last page of that VA 11 minutes later. ### 3. Experiment: never free a render heap One line after `heaps.insert(start, Arc::downgrade(&heap));` in `RenderHeaps::acquire`: ```rust std::mem::forget(Arc::clone(&heap)); ``` Run 3 (same save, 1030 s, exit code 3): 0 render heaps freed, render heaps still 3.1 GB (only ~10 heaps were being freed anyway), **no vkd3d VA fault and no page fault in the kernel log**. This is one run, so it is a strong hint and not proof. ## Relation to #258 All runs were on `main` + #258 (`d50a51c`), because without it the menu runs at about 1 fps here (copy path) and the title never gets this far. #258 does not change `RenderHeaps` or `place_gpu_target` (its diff against `c2a59af` has no lines in that code), so I don't think it causes this; it only makes it reachable. The same runs are the ones in my report on #258 (fault 4 there is run 1 here). I have not run without #258 long enough to rule it out completely. ## Why I think it happens `RenderHeaps` keeps only a `Weak` per guest range, and each image holds its `Arc<RenderHeap>` (plus the native heap through `IMPORTED_HEAP` private data). When the title releases the last image at a guest range, the native heap is freed right away. On the console, releasing the image object does not free the memory behind it: the title still owns the guest range and can keep reading it through descriptors it built or copied earlier. The comment on `RenderHeaps` already says later images at the same guest address should alias "as they do in console memory". The heap's lifetime follows the image object instead of the guest range. I have not found which descriptor still points at the old VA (an old SRV in a title-managed heap would fit the 11-minute gap, but that is a guess). ## Possible directions (not tested) - Keep a render heap while its guest range is still allocated or committed, for example release it from the same path that sees the guest pages freed or remapped, instead of from the image's `Drop`. - Or delay the release until the guest range is reused by a different placement, and alias as now. "Never free" is only the experiment; it would leak across a long session. ## What remains after the experiment Run 3 still ends in `ring gfx_0.0.0 timeout, signaled seq=4868630, emitted seq=4868633` with no page fault, after the save loads, with the title paused (`Frame: 3164`, `Streaming Requests: 6175`, SRL state `Prestream`, `Unsignaled CrossQueueBarrier`). One earlier run without the probe ended the same way. The devcoredump shows the CP busy in IB1 (`CP_STALLED_STAT2 0x00010800`); I can't decode the stuck packet without umr. Note for anyone reading amdgpu devcoredumps: the "Faulty page" field holds the **last fault since boot**, not necessarily one from this hang. My dump for run 3 showed run 2's `0x80011ebdf000` / `0x60113a` while the kernel logged no fault for run 3.
Kayotic1337 commented 2026-11-27 20:45:47 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-27T20:45:47Z.


Reproduced on current main (c05ce00, includes #258 and #324), same setup as above, with only the two log-only probe commits on top.

Identical crash to run 2 in the report:

Address [0]: [ffff80011ebdf000, ffff80011ebdffff], type ReadInvalid
vkd3d_address_binding_tracker_check_va: Fault address is currently unmapped. This is very likely use-after-free.
VA range [ffff80011cc00000, ffff80011ebe0000) [size = 0x1fe0000]  BIND    T: 17343.07 s  VkImage [3840 x 2160 x 1]
VA range [ffff80011cc00000, ffff80011ebe0000) [size = 0x1fe0000]  UNBIND  T: 17785.25 s
fault @ 18815.69 s

Same VA, same render heap (guest=0x15f190000..0x161170000, 0x1fe0000), and the same set of render heap frees at the same guest addresses in every run so far (0x161170000, 0x163a50000, 0x164810000, 0xd5a1e0000, three of 0x60000 and one of 0x560000). This also happened in a run on 8ef909b without #258, where I stopped before the save loaded far enough to fault.

One more pattern, across all 7 runs I made today on this save: the first GPU fault or hang comes 7 to 57 s after the first vkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory. With #324 that point moved later (about 1010 s after loading the save, against 581 to 829 s before), and the crash moved with it. So the stale read seems to happen once VRAM runs out, which may be when the title falls back to the old image. That last part is a guess.

<!-- greyfinch-sync:brcly/TuxBox:comment:7227816230 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/323#issuecomment-7227816230). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-27T20:45:47Z. --- Reproduced on current `main` (`c05ce00`, includes #258 and #324), same setup as above, with only the two log-only probe commits on top. Identical crash to run 2 in the report: ```text Address [0]: [ffff80011ebdf000, ffff80011ebdffff], type ReadInvalid vkd3d_address_binding_tracker_check_va: Fault address is currently unmapped. This is very likely use-after-free. VA range [ffff80011cc00000, ffff80011ebe0000) [size = 0x1fe0000] BIND T: 17343.07 s VkImage [3840 x 2160 x 1] VA range [ffff80011cc00000, ffff80011ebe0000) [size = 0x1fe0000] UNBIND T: 17785.25 s fault @ 18815.69 s ``` Same VA, same render heap (`guest=0x15f190000..0x161170000`, `0x1fe0000`), and the same set of render heap frees at the same guest addresses in every run so far (`0x161170000`, `0x163a50000`, `0x164810000`, `0xd5a1e0000`, three of `0x60000` and one of `0x560000`). This also happened in a run on `8ef909b` without #258, where I stopped before the save loaded far enough to fault. One more pattern, across all 7 runs I made today on this save: the first GPU fault or hang comes 7 to 57 s after the first `vkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory`. With #324 that point moved later (about 1010 s after loading the save, against 581 to 829 s before), and the crash moved with it. So the stale read seems to happen once VRAM runs out, which may be when the title falls back to the old image. That last part is a guess.
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#323
No description provided.