Memory: crash reports list XCL's own last writes to the registers' pages #3629
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3629"
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 ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T01:06:09Z.
(Edited: head
1890e2bf1, rebased with #3627's commit onmain395405e4c; this commit unchanged.)(Edited: head
105765416: an overlapped ReadFile is logged before its OVERLAPPED is used for another read, while it still holds its own result, or with the bytes asked for when the caller has reset it (second reviews). Onmain38ad22da.)Stacked on #3628 (
xcl-run/crash-report-regions), itself on #3627; only the top commit belongs here.A title can find its own heap overwritten (a pool block header holding float data) and fault long after the write. Nothing said whether XCL wrote there: page copies in kernelx, DirectStorage data, file reads into title buffers, texture downloads, sparse copies back and the writes made after the GPU all land in the title's memory without a trace. XCL now keeps its last 16,384 such writes in a ring without a lock, and an unhandled exception lists the ones that overlap each 64 KiB page of title memory a register points into, newest first, with their reason, age and thread. It is on without a switch.
What is in it
hle/write_log.rs(new):record(why, start, len),overlapping,writers_of; oldest overwritten first. A write takes a slot only from an older one and not while another is written there, so a slot's fields are always one write's.writers_oflists the newest 32 writes per range and counts the rest.recordcalls where XCL writes title memory:kernelx.rs(page maps, moves, copies home, the zeroing decommit in a committed window, DirectStorage writes by page number),dstorage.rsanddstorage/parallel.rs,d3d12x/file_reads.rs(ReadFileinto graphics memory once it finishes, with the bytes read; an overlapped read that failed or was given up is not recorded),title_textures.rs(texture downloads),sparse.rs(copy back, immediates),cpu_writes.rs(labels, fences, 64-bit values),frame.rs(the frame index).eh.rs: the lines per register page in the crash report.Measured under Wine: a record cost 70 ns on one thread, and 19-25 ns of wall time per record with 8 threads recording at once (2 M records, 3 runs); a query that matched all 16,384 kept writes 0.35-0.47 ms.
Tested
105765416: Under Wine on Mesa's CPU Vulkan driver, release, 1 run:file_reads write_log window_stats11 passed, 0 failed;cargo test --lib -- window_stats file_reads write_log shader_mem console_heap eh::at the top of the stack (#3642,f1ae90ebb): 62 passed, 0 failed.a_reused_overlapped_logs_each_read_at_its_own_bufferfailed without the fix.5653fd69, with an earlier version of this PR's commit, before the second review's fixes):cargo test --workspace -- --test-threads=4, 2,931 passed, 0 failed, 51 ignored, 1 run; 28SKIPPEDlines (wave64 tests: no wave64 on this card; heap-window tests withoutXCL_HEAP_WINDOWS=1; no D3D12 debug layer). The stack's GPU tests (gpu_mem_stats_*, the writer and geometry-pass tests) ran and passed.x86_64-pc-windows-gnu, release. Tests under Wine on Mesa's CPU Vulkan driver (no card).cargo check -p xcl --release --target x86_64-pc-windows-gnu, with and without--tests: no errors, no new warnings.cargo test -p xcl --release --target x86_64-pc-windows-gnu --lib -- --test-threads=8 kernelx dstorage cpu_writes hle::d3d12x::frame eh:: write_log window_stats file_reads: 151 passed, 0 failed, 1 ignored in 2 of 3 runs; in the thirdframe::tests::origin_events_issue_tokens_and_flips_have_statisticsfailed once and passed on its own.write_logtests: overlap order, the ring keeping the last writes, a slot taken by a newer write or being written left alone, and a range listing its newest writes and counting the rest.file_reads::a_finished_read_is_a_known_writechecks the bytes recorded for a plain and an overlapped read, and that a failed overlapped read records nothing.Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
AI use
main.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T01:12:23Z.
Review (head
b8e0e3e6, diff read, not a merge-check; draft, checks red):why.record(hle/write_log.rs~49-57) writeswhyandwhy_lenas two relaxed stores guarded only byseq. If a writer is preempted after itsfetch_addwhile 16,384 more records arrive, the writer that wraps onto the same slot publishes itsseq, and the stalled writer's field stores land after it. A reader inoverlapping(~86) can then see a matchingseqwithwhyfrom one write andwhy_lenfrom the other and pass them tofrom_raw_parts+from_utf8_unchecked: UB inside the crash handler. Storing the reason as one word (an index into a reason table, or a&'static strpointer) removes the tear, and the writer should give up the slot ifseqchanged under it.ReadFileis logged for every caller and before the read. The kernelbaseReadFile/ReadFileExhooks (vfs_hooks.rs~558, ~574) record every read in the process with the requested size before the call, so failed or short reads are logged as full writes, and reads into memory the report never queries (title_regioncovers only windows, pair views and graphics reservations) push out the title-memory writes the report is for. Recording after the read, with the bytes read and only for a title-region destination, avoids both.eh.rs~123 logs every kept write overlapping each register's 64 KiB page; labels, fences and the frame index are rewritten to the same few addresses, so one register can print up to 16,384 lines. A cap of a few dozen newest lines per page plus a count of the rest keeps it readable.the_ring_keeps_the_last_writes(~124) recordsKEEP + 5entries into the same staticRINGthatwrites_are_found_by_overlap_newest_firstuses; run in parallel, it can push outfirst/second/besidebefore the other test asserts. Other tests that reachmap_pages,write_physical_pagesand thedstoragepaths now record into it too.Fine: the record points sit right before the copies in
kernelx,dstorage,sparse,cpu_writes,frameandtitle_textureswith the right addresses and lengths; the reader'sseq/ fence pattern is right with one writer per slot; the stack is declared. Thexcl-smokeblocks are still owed (the reasonPR descriptionis red).AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T02:55:49Z.
Thanks. Fixed at
666ed738e: a write takes its slot only from an older one and not while another is being written there; ReadFile is recorded after the read, with the bytes read, for graphics memory only (ReadFileEx is no longer recorded, since its bytes are known only at completion); a page lists its newest 32 writes and counts the rest; each test has its own ring. The record re-timed at 70 ns on one thread, 19–25 ns with 8 (in the commit message).AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T03:00:50Z.
Follow-up review (head
666ed738, sinceb8e0e3e6, diff read, not a merge-check; draft, checks red):why/why_lenin the crash handler: fixed.Ring::write(hle/write_log.rs~75-87) claims a slot with acompare_exchangetoBUSYonly if itsseqis not newer than this write, so a stalled writer fails the exchange; the reader skipsBUSYslots and rechecksseqafter the acquire fence (~93-103).a_slot_taken_by_a_newer_write_or_being_written_is_left_alonecovers both cases.ReadFilelogged for every caller and before the read: mostly fixed. The record moved tofile_reads::returned(hle/d3d12x/file_reads.rs~41): after the call, only for a destination in graphics memory, with the bytes read. The overlapped path (~60) still records the requestedp.len, including a read that completed with an error or was dropped afterGIVE_UP, and only at the next look that callstake_finished, so a crash before that look misses it.ReadFileExis no longer recorded.writers_of(~115) lists the newest 32 writes per page and thenand N older writes, with a test.write_logtests build their ownRing.New:
vfs_hooks.rs(ReadFile,ReadFileEx) as record points, gives the old costs (66 ns, 18 ns, 11 µs) where the commit message now says 70 ns, 19-25 ns and 0.35-0.47 ms, and says "the two new tests" (now four plus thefile_readsassertion). Thexcl-smokeblocks are still owed (the reasonPR descriptionis red).AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T03:36:41Z.
Fixed at
53f2c1fd: the overlapped path records the bytes the read returned, and nothing for a failed or given-up read; the test covers both. The description is rewritten to match the commit (record points, costs, tests). The smoke blocks are for the previous head and run again for this one.AI use: Claude Code (Claude Opus 5.5) made the fixes and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T03:39:58Z.
Follow-up review (head
53f2c1fd, since666ed738, diff read, not a merge-check; draft, checks red):ReadFile(overlapped) recorded with the requested length, even on failure: fixed.take_finished(file_reads.rs~56-62) now records only a read whose status is 0, with the bytes fromInternalHighcapped at the request, and records nothing for a failed read or one dropped afterGIVE_UP; the test covers a failed read and a short one (0x1800 of 0x2000).vfs_hooks.rs(ReadFile,ReadFileEx) and the old costs.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:47:25Z.
Follow-up review (head
f95a41f5, since53f2c1fd, diff read, not a merge-check; checks red):git range-diffshows the own commit identical to the previous one; this push only rebases the stack onto the currentmain.New: none.
AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T16:34:47Z.
Code review location:
crates/xcl/src/hle/d3d12x/file_reads.rs; line 62Could this pending request be correlated with an operation generation instead of only the
OVERLAPPED*address? The entry remains inPENDINGuntil this poll. If the caller reuses a completedOVERLAPPEDfor another read first, this stale entry sees the new status andInternalHigh, then records the new byte count at the previousp.at, creating a false crash-report attribution. Could the old entry be removed or replaced when the pointer is reused, with a test that reuses oneOVERLAPPEDbeforetake_finished? AI-assisted review (model: GPT-6); I traced the request identity from enqueue through completion.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T16:34:47Z.
Review: COMMENTED
AI-assisted review (model: GPT-6). I traced the pending overlapped-read record through completion polling.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:46:58Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:47:08Z.
Code review location:
crates/xcl/src/hle/d3d12x/file_reads.rs; line 62Right: a caller that reused a finished OVERLAPPED before the next look made the old entry read the new read's status and byte count. The ReadFile hook now calls
file_reads::reusing(ov)before the call (vfs_hooks.rs). That takes any entry on that OVERLAPPED while it still holds the earlier read's result, so each read is logged at its own buffer with its own bytes.a_reused_overlapped_logs_each_read_at_its_own_bufferreuses one OVERLAPPED beforetake_finished. Without the fix the first buffer got the second read's 0x400 bytes; with it, 1 run each under Wine, it passed. Head69ccace1.AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T20:56:33Z.
Follow-up review of
69ccace1, sincef95a41f5(code reading only, not a merge-check;PR descriptionred) · 1 medium, 1 nitIn short: The PR keeps XCL's last 16,384 writes into title memory in a lock-free ring and lists the ones on each register's 64 KiB page in the crash report. Since
f95a41f5the only change to the PR's own commit is the overlappedReadFilepath:hk_read_filenow callsfile_reads::reusingbefore eachReadFile, so a pending read on the sameOVERLAPPEDis logged before the next one overwrites its result. Nothing blocks on correctness, but the new path drops the record when the caller has reset theOVERLAPPED. Thexcl-smokeblock still namesf95a41f5, which is whyPR descriptionis red.Medium
A reset
OVERLAPPEDdrops the earlier read from the log.reusing(file_reads.rs~49-58, called fromvfs_hooks.rs~559 beforeorig) readsInternal/InternalHighafter the caller has prepared the struct for the next read.OVERLAPPEDbefore each request.finish(~77-78) then sees status 0 withInternalHigh0 and records length 0, andRing::recordreturns early. A read that landed in graphics memory is missing from the crash report.Fix: on the reuse path, record the requested
p.lenwhen the struct no longer holds a result, with a reason saying the length is not known, and add that case toa_reused_overlapped_logs_each_read_at_its_own_buffer.ReadFileExandWriteFileon the sameOVERLAPPEDstill log the other call's byte count throughtake_finished; at least say so in the module doc.Nit
5653fd69"carries this PR's commit unchanged". That head has nofile_reads::reusing, so it carries the previous version.Checked and fine
why/why_lenin the crash handler. A slot is claimed withcompare_exchangetoBUSY, and the reader skipsBUSYand rechecksseq(write_log.rs~74-103).ReadFilewas logged for every caller and before the read. It is now recorded after the call, only for graphics memory, with the bytes read.writers_oflists the newest 32 and counts the rest, with a test.Ring.reusingtakes onlyPENDING, in the same lock order astake_finished, and costs one atomic load when nothing is pending.a_reused_overlapped_logs_each_read_at_its_own_bufferfails against the previoustake_finished.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T21:32:29Z.
10576541: on the reuse path, 0 bytes logs the length asked for, asReadFile (overlapped; its OVERLAPPED was reset: the bytes asked for).a_reused_overlapped_logs_each_read_at_its_own_buffernow covers a reset OVERLAPPED too, and failed without the fix. The module doc says only ReadFile is followed, so a ReadFileEx or WriteFile on the same OVERLAPPED before the look gives the read its result.5653fd69had an earlier version of this commit. A whole-suite run at the stack's new top is queued on Windows, and its counts go in when it ends.AI use: Claude Code (Claude Opus 5.5) made the changes and wrote this reply.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:34:05Z.
Follow-up review of
10576541, since69ccace1(code reading only, not a merge-check;PR descriptionred) · no new findingsIn short: This push fixes the reset-
OVERLAPPEDpoint from my last review. When the earlier read's struct was reset before reuse (status 0, no byte count), the read is now logged with the bytes it asked for, under a reason that says so. The module doc now says that onlyReadFileis followed. Tested now says which earlier version the GPU run was made on. The smoke block namesf95a41f5(PR descriptionis red).Checked and fine
OVERLAPPEDdropped the read from the log.finishnow recordsp.lenas "ReadFile (overlapped; its OVERLAPPED was reset: the bytes asked for)" when the read is done but the struct holds 0 bytes.a_reused_overlapped_logs_each_read_at_its_own_buffercovers it with a struct zeroed before reuse.ReadFileEx/WriteFileon the sameOVERLAPPEDare now named in the module doc.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T02:34:31Z.
Follow-up review of
1890e2bf, since10576541(code reading only, not a merge-check) · no new findingsIn short: This push only rebases the stack onto
main. This PR's own commit is identical (git range-diff); the only change underneath is #3627 followingmain's newUploadCopyjobs. Nothing new, and nothing blocks it.Checked and fine
Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.