d3d12: a write-back that faults does not take its tracker's lock again (RT-WRITEBACK-FAULT-RELOCK) #2418
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2418
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2418"
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?
@OreoFR on GitHub · 2026-11-27 02:52 UTC · original
OreoFR:fix/write-back-fault-relock→main· +150 −5 · 4 files · 2 commits · merged 2026-11-27 10:47 UTCClaimed in the coordination issue as: RT-WRITEBACK-FAULT-RELOCK
What and why
ShadowPages::write_back(runtime/shims/d3d12_vulkan_device.cpp) copies a window's GPU writes back to the title's pages while holding the tracker's SRW lock (#2129; #2404 made the copy 256-byte pieces). It reopens its own guard first. But the page can still be read-only because of another guard: the geometry watch, or another view's shadow over the same pages. Thememcpythen faults, andshadow_write_faultasks every tracker over the address, this one included.reopen()tooklock_again on the thread that already held it. SRW locks aren't recursive, so the title's submitting thread hung for good: the main loop froze, with no device loss and no gate wait.Seen on an RTX 4070 Laptop (NVIDIA 621.40), retail: the main loop froze at 209, 267, 309 s… in four runs. The symbolized thread dumps after each freeze show the submitting thread at:
The change:
write_backrecords its thread inwriter_while it holdslock_.reopen()andreopen_range()skip taking the lock on that thread, since they already run under it. Other threads wait on the lock as before. The docs paragraph on the write-back says so.Tested
MEASURED (n=1 each).tests/test_docs_*.pypass.ShadowPagesandshadow_write_faultsit in the anonymous namespace ofd3d12_vulkan_device.cpp. A regression test needs a title page guarded by two trackers at once, with a window write-back over it. I can add one tod3d12_title_va_testif a reviewer wants it in this PR.GPUs tested: NVIDIA GeForce RTX 4070 Laptop 8 GB, driver 621.40, Windows 11.
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: runtime only)🤖 Generated with Claude Code
@tiguan26 on GitHub · 2026-11-27 02:57 UTC · original · approved these changes
Approving
95d25843e.Read the change against the whole of
write_backand the fault handler. Both exits ofwrite_backclearwriter_before releasinglock_, and a relaxed atomic is enough here: only a thread ever stores its own id, so it always sees its latest store.shadow_write_faultcalls three things on a tracker,contains(no lock),reopenandreopen_range, and the PR covers both that lock.write_backruns from the title write-back pass undershadow_mutex, and none of the three exclusiveg_shadow_pages_locksites calls it, so the handler's shared take of that lock cannot become the same hang one level up. If the handler'sreopenchanges a page's state mid-copy,held()only becomes more cautious (that GPU result is dropped), never a stale copy.The branch sits on current main (
d1dff7949). Cross-built with clang-cl 19 + xwin, run under Wine 11.22 on llvmpipe:d3d12_title_va,d3d12_title_va_shadow,d3d12_title_window_write_back,d3d12_placed_write_back, bothd3d12_shadow_keep_refill,shadow_keepandtitle_va_aliaspass. The faulting write-back itself does not happen in those tests, so the hang is covered by your four 621.40 runs, not by these. AI-assisted (Claude Code, Claude Opus 5.5).@OreoFR on GitHub · 2026-11-27 03:32 UTC · original
Added a regression test for the faulting write-back (
0d61aa9be), the case tiguan26 pointed out the existing tests never reach:d3d12_title_window_write_back_fault(d3d12_title_va_test --window-writeback-fault).How it works: the ring is a write-watched reservation. The first submission makes its window and the tracker guards the pages. A title write then makes the first page hot, so it is writable and asked about instead of guarded. Next, a geometry watch cell over the first 64 KiB (
geometry_writes::acquire+arm, what a geometry view over the same pages arms) makes that page read-only without the tracker knowing. The next submission's write-back skips that page inreopen_locked(it is notkProtected), and its memcpy faults.shadow_write_faultreopens the cell and then callsreopen()on the tracker whose copy faulted. A watchdog thread ends the process with a FAIL line if the submission has not returned after 20 s.Results on an RTX 4070 Laptop, NVIDIA 621.40, Windows 11:
95d25843e: passes (8 of 8 runs). Every word the shader wrote reaches the title's pages (64 of 64) and the title's own word is kept.d3d12_vulkan_device.cppchange reverted locally: the submission hangs, and the watchdog fails the test at 20 s.d3d12_title_va,d3d12_title_window_write_backandd3d12_placed_write_backpass either way.AI-assisted (Claude Code, Claude Opus 5.5).
@tiguan26 on GitHub · 2026-11-27 04:52 UTC · original · approved these changes
Approving
0d61aa9be. Thanks for the test.d3d12_title_window_write_back_faultbuilds exactly the case the other tests never reached: a page the tracker treats as hot (writable, asked about) that a geometry cell then makes read-only behind its back, so the write-back'smemcpyfaults and the handler callsreopen()on the tracker whose own thread holds the lock. The watchdog turns the old hang into a FAIL line instead of a stuck run, and the checks afterwards (the GPU's words reached the page, the title's own word 1000 kept) cover the result as well as the return.The new test skips here, as it says it will: Wine has no write watching, so I could not run it, and your 621.40 runs are the evidence for the fault path. On the new head, cross-built with clang-cl 19 + xwin under Wine 11.22 on llvmpipe, the other eight title and write-back tests still pass (
d3d12_title_va,_shadow,d3d12_title_window_write_back,d3d12_placed_write_back, bothd3d12_shadow_keep_refill,shadow_keep,title_va_alias). AI-assisted (Claude Code, Claude Opus 5.5).@aslan2142 on GitHub · 2026-11-27 10:47 UTC · original
Merging.
g_shadow_pages_lockhappens undershadow_mutex, which the write-back already holds, so the handler's shared take cannot form a cycle with one device. With a second D3D12 device it could; that is a follow-up, not a blocker.main2859d0c9b+ #2418, #2440, #2432 and #2439, integrated RDNA2 GPU (RADV, Mesa 26.3.1):xdxr_build_check(a timeout under load) andxmem_no_write_watch, both flaky here.ctest: 115 of 116, the same timeout.Thanks @OreoFR, and @tiguan26 for the review.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
@OreoFR on GitHub · 2026-11-27 10:48 UTC · original
In-game A/B for @aslan2142, as asked. Two builds that differ only in this PR: plain
maind1dff7949vsmain+ #2418, with nothing else merged. Same shader pack, same settings, 11 min each, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11.mainwrite_back→ fault →reopenwaiting on the lock it holdsmain+ #2418No regression seen: no crash, no new hang, no device loss, and the run went on submitting for the whole 11 minutes.
MEASURED (n=1 each). AI-assisted (Claude Code, Claude Opus 5.5).autodefault, calibrated per driver at device creation (RT-COMPILE-GATE-AUTO) #2462