d3d12: refuse section-backed imports that RADV silently substitutes #199

Closed
smith-3 wants to merge 2 commits from upstream-pr/199 into main
smith-3 commented 2026-11-25 21:11:36 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by smith-3 on 2026-11-25T21:11:36Z.


On RADV, every GPU import of XMem physical pages silently reads zeros. XMem pages are section views, which Wine maps as shared memory. RADV refuses shared memory as a host pointer, and vkd3d-proton then allocates unrelated memory while OpenExistingHeapFromAddress still succeeds. Strict mode (TUXBOX_REQUIRE_BUFFER_IMPORT=1) does not notice, because a CPU Map of the heap still returns the guest pointer. This matches the buffer-remap failure in #189.

This PR probes once per device with a GPU copy from an imported section view. When the copy misses the canary, imports of section-backed ranges fail with E_NOTIMPL and a log line, instead of aliasing nothing. If the probe itself cannot run, the previous behaviour is kept. The first commit only improves the buffer-remap diagnostic so it reports every wrong copy.

This does not make AMD work. XMem-backed buffers still cannot be imported on RADV. They now fail visibly instead of reading zeros. A real fix needs private (non-shared) backing for guest pages or a different import path, and is out of scope here.

Evidence

Ryzen 7 9700X iGPU (1002:13c0, RADV 25.2.8) and RTX 4080 SUPER (10de:2702, NVIDIA 570.211.01), same machine, Proton Experimental 11.0-20261014.

buffer-remap control:

Runtime AMD 1002:13c0 RTX 10de:2702
main + diagnostic copy 0: 256/256 wrong, [0]=0 expected 0x12340000; copy 1: 256/256 wrong ...; copy 2: 256/256 wrong, [0]=0 expected 0x98760000 PASS words=768/768 identical=1 replacement=1
this PR place remapped buffer failed: 0x80004001, plus the log line below PASS words=768/768 identical=1 replacement=1
TuxBox d3d12_xs: the host driver does not import section-backed guest memory: the GPU read unrelated memory after a successful import. Imports of XMem physical pages fail with E_NOTIMPL

Wine trace on AMD before the fix:

win32u_vkAllocateMemory Failed to allocate memory, res -13
vkd3d-proton:vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e.

Native Vulkan probe (VK_EXT_external_memory_host, vkAllocateMemory result). vkGetMemoryHostPointerPropertiesEXT succeeds in every case, so it cannot predict the failure.

Mapping NVIDIA RADV
anonymous private 0 0
memfd shared 0 -13
anonymous shared 0 -13

Checks

  • Rust tests, D3D12 Windows typecheck and the build pass in tuxbox.py check.
  • D3D12 regression controls on the RTX all pass: tables, heaps, placement, stream, frame, indirect, null-usage and null-disabled.
  • I did not run the guest GPU suites of tuxbox.py check (Lanes, shader translator). Proton's steam.exe aborts in lsteamclient when the Steam client is not running on this machine. The change only affects imports of section-backed memory on drivers that fail the probe, and NVIDIA passes the probe.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:6613842111 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/199). Originally posted by [smith-3](https://github.com/smith-3) on 2026-11-25T21:11:36Z. --- On RADV, every GPU import of XMem physical pages silently reads zeros. XMem pages are section views, which Wine maps as shared memory. RADV refuses shared memory as a host pointer, and vkd3d-proton then allocates unrelated memory while `OpenExistingHeapFromAddress` still succeeds. Strict mode (`TUXBOX_REQUIRE_BUFFER_IMPORT=1`) does not notice, because a CPU `Map` of the heap still returns the guest pointer. This matches the `buffer-remap` failure in #189. This PR probes once per device with a GPU copy from an imported section view. When the copy misses the canary, imports of section-backed ranges fail with `E_NOTIMPL` and a log line, instead of aliasing nothing. If the probe itself cannot run, the previous behaviour is kept. The first commit only improves the `buffer-remap` diagnostic so it reports every wrong copy. **This does not make AMD work.** XMem-backed buffers still cannot be imported on RADV. They now fail visibly instead of reading zeros. A real fix needs private (non-shared) backing for guest pages or a different import path, and is out of scope here. ### Evidence Ryzen 7 9700X iGPU (`1002:13c0`, RADV 25.2.8) and RTX 4080 SUPER (`10de:2702`, NVIDIA 570.211.01), same machine, Proton Experimental 11.0-20261014. `buffer-remap` control: | Runtime | AMD `1002:13c0` | RTX `10de:2702` | | --- | --- | --- | | main + diagnostic | `copy 0: 256/256 wrong, [0]=0 expected 0x12340000; copy 1: 256/256 wrong ...; copy 2: 256/256 wrong, [0]=0 expected 0x98760000` | `PASS words=768/768 identical=1 replacement=1` | | this PR | `place remapped buffer failed: 0x80004001`, plus the log line below | `PASS words=768/768 identical=1 replacement=1` | ``` TuxBox d3d12_xs: the host driver does not import section-backed guest memory: the GPU read unrelated memory after a successful import. Imports of XMem physical pages fail with E_NOTIMPL ``` Wine trace on AMD before the fix: ``` win32u_vkAllocateMemory Failed to allocate memory, res -13 vkd3d-proton:vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e. ``` Native Vulkan probe (`VK_EXT_external_memory_host`, `vkAllocateMemory` result). `vkGetMemoryHostPointerPropertiesEXT` succeeds in every case, so it cannot predict the failure. | Mapping | NVIDIA | RADV | | --- | --- | --- | | anonymous private | 0 | 0 | | memfd shared | 0 | -13 | | anonymous shared | 0 | -13 | ### Checks - Rust tests, D3D12 Windows typecheck and the build pass in `tuxbox.py check`. - D3D12 regression controls on the RTX all pass: tables, heaps, placement, stream, frame, indirect, null-usage and null-disabled. - I did not run the guest GPU suites of `tuxbox.py check` (Lanes, shader translator). Proton's `steam.exe` aborts in `lsteamclient` when the Steam client is not running on this machine. The change only affects imports of section-backed memory on drivers that fail the probe, and NVIDIA passes the probe. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
copilot-pull-request-reviewer[bot] commented 2026-11-25 21:11:49 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T21:11:49Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:brcly/TuxBox:review:6065046483 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/199#pullrequestreview-6065046483). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T21:11:49Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
tsunderejay commented 2026-11-25 21:23:33 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by tsunderejay on 2026-11-25T21:23:33Z.


Static review found a blocking lifetime issue: the fence is created after submission, so CreateFence/Signal/SetEventOnCompletion failure can return and unmap the section while the GPU copy is still running. Create the fence before submission and ensure every post-submit path waits (or retains the mapping/objects). Also add a bounded wait so a stuck probe cannot hang the title. The remap diagnostic counter has a separate bug: actual != expected && !wrong++ stops incrementing after the first mismatch, so it reports 1/256 instead of 256/256.

<!-- greyfinch-sync:brcly/TuxBox:comment:7175014527 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/199#issuecomment-7175014527). Originally posted by [tsunderejay](https://github.com/tsunderejay) on 2026-11-25T21:23:33Z. --- Static review found a blocking lifetime issue: the fence is created after submission, so CreateFence/Signal/SetEventOnCompletion failure can return and unmap the section while the GPU copy is still running. Create the fence before submission and ensure every post-submit path waits (or retains the mapping/objects). Also add a bounded wait so a stuck probe cannot hang the title. The remap diagnostic counter has a separate bug: `actual != expected && !wrong++` stops incrementing after the first mismatch, so it reports 1/256 instead of 256/256.
brcly commented 2026-11-26 14:42:34 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-26T14:42:34Z.


Thank you for this, @smith-3. Your approach to finding the problem, probing whether the GPU really reads imported section memory, is now in main as host_profile/section_probe.rs, which credits this PR, and you're credited as co-author of that commit (04a560c).

I'm closing this because the rest has been overtaken: #200 handles substituted imports with a memory copy, and #218 adds a way to import XMem pages through their backing. If you think refusing a substituted import is still worth having, for example as a strict mode, a small PR on top of the current probe would be welcome. The review point about creating the fence before submitting the copy would be worth keeping in mind there.

<!-- greyfinch-sync:brcly/TuxBox:comment:7195207856 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/199#issuecomment-7195207856). Originally posted by [brcly](https://github.com/brcly) on 2026-11-26T14:42:34Z. --- Thank you for this, @smith-3. Your approach to finding the problem, probing whether the GPU really reads imported section memory, is now in `main` as `host_profile/section_probe.rs`, which credits this PR, and you're credited as co-author of that commit (`04a560c`). I'm closing this because the rest has been overtaken: #200 handles substituted imports with a memory copy, and #218 adds a way to import XMem pages through their backing. If you think refusing a substituted import is still worth having, for example as a strict mode, a small PR on top of the current probe would be welcome. The review point about creating the fence before submitting the copy would be worth keeping in mind there.

Pull request closed

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!199
No description provided.