D3D12.X: pipeline library blob has a readable dword after its end #2859
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2859
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2859"
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?
@bobosneefdev on GitHub · 2026-11-26 19:21 UTC · original
bobosneefdev:pso-library-blob-end→amd-dev· +39 −3 · 1 files · 1 commits · openOn AMD, XCL can crash at every start with
0xc0000005inamdxc64.dll+0x176cd5until the saved pipeline library is deleted. The driver reads a dword at blob + length inCreatePipelineLibrary(cmp dword ptr [r14], eax, withr14= the view's address + the file's length).MappedBlobhands it a file mapping, which ends with the file's last page, so a file that ends less than 4 bytes before a page boundary has that dword in the unmapped page after it.Seen with two libraries, 1933310 and 3252222 bytes, both 4094 mod 4096. In 3 of 3 crashing starts the faulting address was the first byte after the view. Such a file (4 lengths in 4096) is now read into memory with 4 zero bytes after it instead of being mapped.
This corrects my earlier reading in #2619, where I put the crash down to the memory-window layout.
What is in it
crates/xcl/src/hle/d3d12x/pso_library.rs:MappedBlob::openreads a file of such a length into memory with room after it; unit testmapped_blob_has_a_readable_dword_after_its_end(fails without the fix).Tested
cargo test --release -p xcl --lib pso_library: 4 passed, 0 failed. With the new branch disabled, the new test fails.cargo test --workspace -- --test-threads=4(debug) on this PR's head78795c74: 1642 passed, 12 failed, 27 ignored. On the unmodified base71b8e6e0: 1640 passed, 13 failed, 27 ignored. All 12 that fail here also fail on the base; none is inpso_library.rs.SKIPPED:gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu, 4 forms (f16 arithmetic and f16 packed, wave32 and wave64, per-lane form: refused as unsupported).c32c91a3plus local logging: the 1933310-byte library that crashed 3 starts opened, served over 1000 pipelines, and 7 newer generations were saved.Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 120, same title, same machine,XCL_PREPARE=0in the environment for both.main(e120925e):This PR's head (
78795c74):mainrun is one120925e, the commit before the tip. On the tip8b957becthe pre-launch shader preparation (#2555) stopped at 23097 of 26503 records for over 26 minutes with four threads busy inamdxc64.dll, andmainhas no switch to leave it out, so no run of the tip finished.XCL_PREPARE=0leaves that preparation out on this PR's build;e120925epredates it and does not read the variable.Not tested
c32c91a3with local logging in the tree, not on this exact head.AI use
🤖 Generated with Claude Code
@vibryxcx on GitHub · 2026-11-26 20:12 UTC · original · edited 2026-11-27 02:48 UTC
Same card, different driver. On an RX 6800 with driver 32.0.21045.5002 (yours is 32.0.21045.29003), a pipeline library that ends 2 bytes before a page boundary does not crash without the fix. Both builds open it as a file mapping and use it. This fills in one line of Not tested ("Other AMD driver versions"): the read past the end, or the fault from it, seems to depend on the driver version. The fix does no harm on this driver either.
Repro (retail title, release builds,
scripts/smoke.ps160 s;pso_library.rsis the same onc32c91a3and on this PR's base71b8e6e0)gen-0000005b.plib, 319,420 bytes, 4028 mod 4096) and saved a copy with 66 zero bytes added asgen-0000005c.plib: 319,486 bytes, 4094 mod 4096, the same remainder as your two crashing files.c32c91a3without the fix andc32c91a3with this PR's commit cherry-picked on top (no conflict), twice each and alternating, restoring the padded file before every run. On this head's own base71b8e6e0the title first recompiles all 26,503 shaders, about an hour here, so I usedc32c91a3, whose shader cache was warm.opened memory-mapped pipeline library gen-0000005c (0.3 MiB file-backed), then 1000+ library hitsSo on this driver the 4-byte read past the view, if it happens at all, does not fault. One run per remainder: I did not try 4093, 4095 or 0 mod 4096.
Small note on the log. With the fix, a file in the copy path still logs
opened memory-mapped pipeline library … file-backed, because that message is printed by the caller inpso_library.rs, which does not know which pathMappedBlob::opentook. A user reading a log to tell whether the workaround was used cannot tell from this line. It is a message only, with no behaviour change.Diff review. I read the whole diff. The length check
(4096 - len % 4096) % 4096 < 4takes exactly the four remainders 4093, 4094, 4095 and 0, where the dword atblob + lenwould cross into the next page.viewpoints intocopyafter theextend_from_slice, so it stays valid when the struct moves, andDropskipsUnmapViewOfFilefor the copy path. I found no defect.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), debug. Head83b95c4fand base71b8e6e0in their own worktrees, no uncommitted changes.cargo test -p xcl --lib -- --test-threads=1 --skip placed_title_textures_share_vram_and_preserve_pixels --skip d32s8_targets_take_their_own_size_of_video_memoryon head: 1640 passed, 12 failed, 27 ignored, 2 filtered out. These two tests hang or abort inside the full run onamd-dev(#2757, #2842), and both pass alone on base and on head.pso_library::tests: all 4 pass, the newmapped_blob_has_a_readable_dword_after_its_endincluded.--exact) on base71b8e6e0and on head: the same 10 fail on both, the same set as onb5c0275fandc32c91a3.two_pass_binds_set_the_shared_view_heapandgpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_releasedpass alone on both: they fail only inside the full run (the second is flaky, see #2842). No failure comes from this PR.f16_programs_on_the_gpuonly (#1426).Not tested: the crash itself (it does not reproduce on this driver); the
xcl-smokepair on this exact head and its base (both need the full shader recompile first); NVIDIA / Intel; other remainders.AI use: Claude Code (Claude Opus 5.5) read the diff, built the trees, made the padded library, ran the tests and game runs, and wrote this comment. Every number comes from those runs on the hardware above.
Update for head
78795c74: the log line now readsread into memory: the file ends at a page boundarywhen the copy path is taken, which settles the note above.cargo test -p xcl --lib -- pso_library --test-threads=1on this head, same RX 6800: 4 passed, 0 failed. I did not rerun the title, because the code path is unchanged apart from the message. Also,amd-devbf7c82eealready has its own version of this change as39440cd("give mapped pipeline library blobs a readable tail").83b95c4f73to78795c7438@bobosneefdev on GitHub · 2026-11-26 20:25 UTC · original
Thanks for the run on 32.0.21045.5002 and for reading the diff. Good to know the fault depends on the driver version; I will add your result to the description.
The log note is fixed in
78795c74(amended, force-pushed): a library taken through the copy path now logsread into memory: the file ends at a page boundaryin place offile-backed. Message only, no other change.cargo test --release -p xcl --lib pso_libraryon78795c74: 4 passed, 0 failed. The full suite and the regression runs on the new head are running; I will update the description with them.Written with Claude Code (Claude Fable 5.2).
@Aniseto on GitHub · 2026-11-26 21:37 UTC · original
Ran the pipeline-library blob tests at
78795c74on an NVIDIA Blackwell desktop part:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.
All four tests pass, including
mapped_blob_has_a_readable_dword_after_its_end. They are CPU-side file/mapping tests; no AMD driver is involved and no D3D12 pipeline library was created on this adapter. The thread's runs are on RX 6800 with two driver versions, where the crash is driver-specific; this adds a Windows MSVC run on an NVIDIA card, with no claim that the AMD fault path was exercised here.Not tested: the AMD
amdxc64.dllcrash path, a paired smoke run, the full workspace suite, release profile, AMD and Intel GPUs, native wave64 hosts, Wine, game data.AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
@ettehn on GitHub · 2026-11-27 03:48 UTC · original
The padded-copy branch at
78795c74has the sameMappedBlobimplementation as currentamd-devbf7c82ee(the port in39440cd). On Windows 11 build 26200 / Rust 1.97.1 MSVC, I checked the private memory it retains while the blob is live.fs::readfills the vector, then appending four bytes doubles its capacity. For synthetic files of 64 MiB minus 0, 1, 2, or 3 bytes, opening the blob increased process private bytes by 128.26 MiB. Reserving exactlylen+4up front and reading from the already-open handle reduced that to 64.13 MiB. Three fresh processes per variant reproduced those values. The-4file stayed mapped in both (~0.125 MiB private delta).The tested replacement for the copy setup was:
All 15 lengths per run preserved the logical size and last payload byte, exposed four zero bytes at the end, and kept the same mapped-vs-copied split. The odd lengths also keep the original handle through the read. This is a source-extracted Windows file/memory test using synthetic payloads, with no D3D12 driver or title run.
OpenAI Codex assisted with verification.
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.