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
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 (RenderHeapsinruntime/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:
mainatc2a59af+ #258 (d50a51c) + a local probe commit that only adds log lines (below). The render heap code is unchanged on currentmain(8ef909b).Evidence
1. vkd3d names a freed VA
Run without the probe (
VKD3D_CONFIG=fault):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 largeVkBuffer [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
GetDescsize) 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):
in page starting at address 0x000080011ebdf000 from client 10,GCVM_L2_PROTECTION_FAULT_STATUS:0x0060113A(TCP, mapping error), thenring gfx_0.0.0 timeout.So a 3840x2160 image placed at guest
0x15f190000gets 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));inRenderHeaps::acquire: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 changeRenderHeapsorplace_gpu_target(its diff againstc2a59afhas 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
RenderHeapskeeps only aWeakper guest range, and each image holds itsArc<RenderHeap>(plus the native heap throughIMPORTED_HEAPprivate 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 onRenderHeapsalready 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)
Drop."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=4868633with no page fault, after the save loads, with the title paused (Frame: 3164,Streaming Requests: 6175, SRL statePrestream,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/0x60113awhile the kernel logged no fault for run 3.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:
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 of0x60000and one of0x560000). This also happened in a run on8ef909bwithout #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.