Repository navigation
d3d12: a write-back that faults does not take its tracker's lock again (RT-WRITEBACK-FAULT-RELOCK) - #2418
Conversation
…n in the fault handler ShadowPages::write_back copies a window's GPU writes back to the title's pages under the tracker's SRW lock (ProjectLeonida#2129, and the 256-byte pieces of ProjectLeonida#2404). It reopens its own guard first, but the page can still be read-only because of another guard (the geometry watch, another view's shadow). The copy then faults, shadow_write_fault asks every tracker over the address, and this one's reopen() took lock_ again on the thread that already held it. SRW locks are not recursive, so the title's submitting thread hung for good: on an RTX 4070 Laptop (NVIDIA 621.40) the main loop froze at 209-309 s with no device loss, and the thread dumps showed the submitting thread inside write_back -> (fault) -> shadow_write_fault -> reopen, waiting on the SRW lock, in four runs. write_back records its thread in writer_ while it holds lock_; reopen() and reopen_range() skip taking the lock on that thread (they run under it). Other threads still wait on the lock as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tiguan26
left a comment
There was a problem hiding this comment.
Approving 95d2584.
Read the change against the whole of write_back and the fault handler. Both exits of write_back clear writer_ before releasing lock_, and a relaxed atomic is enough here: only a thread ever stores its own id, so it always sees its latest store. shadow_write_fault calls three things on a tracker, contains (no lock), reopen and reopen_range, and the PR covers both that lock. write_back runs from the title write-back pass under shadow_mutex, and none of the three exclusive g_shadow_pages_lock sites calls it, so the handler's shared take of that lock cannot become the same hang one level up. If the handler's reopen changes 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 (d1dff79). 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, both d3d12_shadow_keep_refill, shadow_keep and title_va_alias pass. 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).
…eturns (ProjectLeonida#2418) d3d12_title_window_write_back_fault (d3d12_title_va_test --window-writeback-fault) makes the write-back's copy fault on a page the tracker did not protect itself, the case review asked for: the ring is write-watched, a title write makes its first page hot (writable, asked about rather than guarded), and a geometry watch cell over the first 64 KiB, what a geometry view over the same pages arms, makes that page read-only behind the tracker's back. The next submission's write-back faults there; the handler reopens the cell and asks every tracker over the address, the writing one too. Without 95d2584 that tracker took its own SRW lock again on the thread that held it and the submission never returned: a watchdog thread ends the process with a FAIL line after 20 s. With it the submission returns and the GPU's words, and the title's own word, are in the pages. RTX 4070 Laptop, NVIDIA 621.40, Windows 11: passes (8 of 8 runs) with the fix; with the fix's d3d12_vulkan_device.cpp change reverted locally it fails at the watchdog. d3d12_title_va, d3d12_title_window_write_back and d3d12_placed_write_back pass either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Added a regression test for the faulting write-back (0d61aa9), the case tiguan26 pointed out the existing tests never reach: 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 ( Results on an RTX 4070 Laptop, NVIDIA 621.40, Windows 11:
AI-assisted (Claude Code, Claude Opus 5.5). |
tiguan26
left a comment
There was a problem hiding this comment.
Approving 0d61aa9. Thanks for the test.
d3d12_title_window_write_back_fault builds 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's memcpy faults and the handler calls reopen() 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, both d3d12_shadow_keep_refill, shadow_keep, title_va_alias). AI-assisted (Claude Code, Claude Opus 5.5).
|
Merging.
Thanks @OreoFR, and @tiguan26 for the review. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) |
|
In-game A/B for @aslan2142, as asked. Two builds that differ only in this PR: plain
No regression seen: no crash, no new hang, no device loss, and the run went on submitting for the whole 11 minutes. |
… still go back (RT-WRITEBACK-TILE-REOPEN) ShadowPages::write_back decided page by page, inside its loop, whether a page's GPU result goes back. A copy that faults on another guard (a geometry watch cell) makes the handler reopen the whole 64 KiB tile on the write-back's own thread (reopen_range, under the lock #2418 lets it reuse), which clears kClean and kProtected there. The runs after it in the tile then read as written by the title: their GPU results were dropped from a batch already taken off the queue, and the next forward copy put the title's older bytes over them. The decision is now taken for every page of the range before the first copy, into a host-heap vector the tracker keeps. A page the title wrote before the write-back (not guarded and not clean after the asking) is still held, so the title's words win as before. Test: d3d12_title_window_write_back_fault_tile (d3d12_title_va_test --window-writeback-fault-tile), the #2418 fault case with a second dispatch on the third page of the tile and a title write on the second. Found by DadaCap's review of #2418. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed 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