[PR #1539] [MERGED] RT-RADV-IMPORT-PINS: d3d12: free declined host imports at once and pin the pages of live ones (RADV CS rejection) #1567

Closed
opened 2026-11-26 20:21:42 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1539
Author: @aslan2142
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: radv-import-pins


📝 Commits (4)

📊 Changes

5 files changed (+255 additions, -12 deletions)

View changed files

📝 runtime/shims/d3d12_com.h (+3 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+49 -10)
📝 runtime/src/title_page_watch.h (+25 -0)
📝 runtime/test/d3d12_title_va_test.cpp (+125 -0)
📝 runtime/test/kernel_writes_test.cpp (+53 -2)

📄 Description

Item: RT-RADV-IMPORT-PINS, NateWeav's claim (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7141859164). The finding, the measurements and the design are theirs (that comment and https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142359977). This implements their description on current main, as offered in https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151275414. @NateWeav, if you'd rather open your own patch, say so and this one closes.

Not included: RT-SHADOW-ALIAS-GUARD (their second claim, the copy cost after the fix).

What and why

On RADV, making a page read-only while a VK_EXT_external_memory_host import of it is live makes the kernel reject that submission and every later one: radv/amdgpu: The CS has been rejected, then VK_ERROR_DEVICE_LOST. The slot-133 shadow trackers guard copied title pages exactly that way, so main loses its device right after the first present on RADV.

  • Declined imports are freed at once. create_host_buffer (runtime/shims/d3d12_vulkan_device.cpp) now destroys the buffer and frees the memory on every decline after vkCreateBuffer: below the arena, host-pointer properties, a type or offset mismatch, a failed allocation or bind. Before, the memory waited in the deferred queue while the shadow made instead guarded the same page.
  • Live imports pin their pages. The slot-133 and console-heap imports take a kernel_writes::hold pin over their pages (runtime/src/title_page_watch.h, new hold/release) before vkAllocateMemory, and release it on every path that frees the memory (decline, fail(), the resource destructor, remove_console_heap). ShadowPages and the geometry watch already pass over pinned pages. A hold records the pin even before a tracker exists and lifts a guard already on the range. Taking it before the allocation means no guard can land between the writability check and the import.
  • The pin is unconditional; a driver gate (pin only where the driver does not pin at import) can follow, as NateWeav noted.

Tests

  • kernel_writes_test: 9 checks of hold and release.
  • d3d12_title_va_test (imports-on mode, d3d12_geometry_views):
    • check_declined_imports: no import memory outlives a declined import across a submission (on the RDNA2 iGPU both buffers land below the arena, the path the first change fixes);
    • check_import_over_shadow: a shadow's tracker guards its pages (control), an import of the same pages keeps them writable across two submissions, the pin ends with the import and the guard returns. On llvmpipe the import is taken and pinned; on the iGPU it is declined and no pin is left.
  • Windows suite under Wine 11.22 (clang-cl build), llvmpipe and an RDNA2 iGPU (RADV): no test goes from pass to fail; d3d12_geometry_views goes from fail to pass on the iGPU.

Measured on the retail boot (RDNA2 iGPU, RADV, Wine; counts only)

main this branch
Run time / end 14 s, title int3 after the device loss 22-58 s, the title's crash reporter (a separate stop, under investigation)
D3D12 calls 62,677 87,892 to 99,457
Presents ok / failed 1 / 1 89 to 126 / 0
CS rejected / device lost yes / yes 0 / 0 in 5 of 5 runs

AI-assisted (Claude Code, Claude Opus 5.5).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1539 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `radv-import-pins` --- ### 📝 Commits (4) - [`599fe9f`](https://github.com/ubiquitarianism/leonida/commit/599fe9f2212e1004f93b33a199e19146cf53d7d8) d3d12: free a declined slot-133 import at once - [`9f82f13`](https://github.com/ubiquitarianism/leonida/commit/9f82f136f68a84bafa745ff61eb6eebb01128654) d3d12: pin the pages of a live host import - [`d4f3e0b`](https://github.com/ubiquitarianism/leonida/commit/d4f3e0bbc63bbd47c7b0afa762f0f22fed5a5a2e) Merge main (b07b9ecb0) into radv-import-pins - [`8665eee`](https://github.com/ubiquitarianism/leonida/commit/8665eee910cf4e3e3b86324ae025a6cbb0c64e69) Merge commit '3f81d46ac' into HEAD ### 📊 Changes **5 files changed** (+255 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_com.h` (+3 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+49 -10) 📝 `runtime/src/title_page_watch.h` (+25 -0) 📝 `runtime/test/d3d12_title_va_test.cpp` (+125 -0) 📝 `runtime/test/kernel_writes_test.cpp` (+53 -2) </details> ### 📄 Description Item: `RT-RADV-IMPORT-PINS`, **NateWeav's claim** (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7141859164). The finding, the measurements and the design are theirs (that comment and https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142359977). This implements their description on current `main`, as offered in https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151275414. @NateWeav, if you'd rather open your own patch, say so and this one closes. Not included: `RT-SHADOW-ALIAS-GUARD` (their second claim, the copy cost after the fix). ### What and why On RADV, making a page read-only while a `VK_EXT_external_memory_host` import of it is live makes the kernel reject that submission and every later one: `radv/amdgpu: The CS has been rejected`, then `VK_ERROR_DEVICE_LOST`. The slot-133 shadow trackers guard copied title pages exactly that way, so `main` loses its device right after the first present on RADV. - **Declined imports are freed at once.** `create_host_buffer` (`runtime/shims/d3d12_vulkan_device.cpp`) now destroys the buffer and frees the memory on every decline after `vkCreateBuffer`: below the arena, host-pointer properties, a type or offset mismatch, a failed allocation or bind. Before, the memory waited in the deferred queue while the shadow made instead guarded the same page. - **Live imports pin their pages.** The slot-133 and console-heap imports take a `kernel_writes::hold` pin over their pages (`runtime/src/title_page_watch.h`, new `hold`/`release`) before `vkAllocateMemory`, and release it on every path that frees the memory (decline, `fail()`, the resource destructor, `remove_console_heap`). `ShadowPages` and the geometry watch already pass over pinned pages. A hold records the pin even before a tracker exists and lifts a guard already on the range. Taking it before the allocation means no guard can land between the writability check and the import. - The pin is unconditional; a driver gate (pin only where the driver does not pin at import) can follow, as NateWeav noted. ### Tests - `kernel_writes_test`: 9 checks of hold and release. - `d3d12_title_va_test` (imports-on mode, `d3d12_geometry_views`): - `check_declined_imports`: no import memory outlives a declined import across a submission (on the RDNA2 iGPU both buffers land below the arena, the path the first change fixes); - `check_import_over_shadow`: a shadow's tracker guards its pages (control), an import of the same pages keeps them writable across two submissions, the pin ends with the import and the guard returns. On llvmpipe the import is taken and pinned; on the iGPU it is declined and no pin is left. - Windows suite under Wine 11.22 (clang-cl build), llvmpipe and an RDNA2 iGPU (RADV): no test goes from pass to fail; `d3d12_geometry_views` goes from fail to pass on the iGPU. ### Measured on the retail boot (RDNA2 iGPU, RADV, Wine; counts only) | | `main` | this branch | |---|---|---| | Run time / end | 14 s, title `int3` after the device loss | 22-58 s, the title's crash reporter (a separate stop, under investigation) | | D3D12 calls | 62,677 | 87,892 to 99,457 | | Presents ok / failed | 1 / 1 | 89 to 126 / 0 | | CS rejected / device lost | yes / yes | 0 / 0 in 5 of 5 runs | AI-assisted (Claude Code, Claude Opus 5.5). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:21:42 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#1567
No description provided.