Skip to content

D3D12.X: pipeline library blob has a readable dword after its end - #2859

Open
bobosneefdev wants to merge 1 commit into
xcl-dev:amd-devfrom
bobosneefdev:pso-library-blob-end
Open

bobosneefdev wants to merge 1 commit into
xcl-dev:amd-devfrom
bobosneefdev:pso-library-blob-end

Conversation

@bobosneefdev

@bobosneefdev bobosneefdev commented Nov 26, 2026 •

Copy link
Copy Markdown

On AMD, XCL can crash at every start with 0xc0000005 in amdxc64.dll+0x176cd5 until the saved pipeline library is deleted. The driver reads a dword at blob + length in CreatePipelineLibrary (cmp dword ptr [r14], eax, with r14 = the view's address + the file's length). MappedBlob hands 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::open reads a file of such a length into memory with room after it; unit test mapped_blob_has_a_readable_dword_after_its_end (fails without the fix).

Tested

  • RX 6800 16 GB (driver 32.0.21045.29003), Ryzen 5 5600X3D, Windows 11 Pro 26200, Rust 1.98.1 MSVC.
  • 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 head 78795c74: 1642 passed, 12 failed, 27 ignored. On the unmodified base 71b8e6e0: 1640 passed, 13 failed, 27 ignored. All 12 that fail here also fail on the base; none is in pso_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).
  • Retail title, with the fix applied on c32c91a3 plus 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=0 in the environment for both.

main (e120925e):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: AMD Radeon RX 6800
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3284 (PresentX 3284)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 28469 MB

This PR's head (78795c74):

xcl-smoke v1
commit: 78795c7438b07e02651ff9ecefaaa5841a2935bd
gpu: AMD Radeon RX 6800
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3232 (PresentX 3232)
presents per 2 s (last 3): 60 60 63
device removals: 0
crashes: 0
peak commit: 13359 MB
  • The main run is on e120925e, the commit before the tip. On the tip 8b957bec the pre-launch shader preparation (xcl run: prepare shaders in the game window before title execution #2555) stopped at 23097 of 26503 records for over 26 minutes with four threads busy in amdxc64.dll, and main has no switch to leave it out, so no run of the tip finished.
  • XCL_PREPARE=0 leaves that preparation out on this PR's build; e120925e predates it and does not read the variable.

Not tested

  • NVIDIA and Intel. Whether their drivers read past the blob is unknown; the copy path is taken on any adapter.
  • Other AMD driver versions. A reviewer's RX 6800 on driver 32.0.21045.5002 does not crash with or without the fix (comment below), so the read depends on the driver version.
  • The regression run opened a 2.3 MiB library whose length is not near a page boundary, so it took the file-backed path (as its log says); it reached the title screen and does not cover the copy path. That path is covered by the unit test and the retail check above.
  • The retail check above ran on c32c91a3 with local logging in the tree, not on this exact head.

AI use

  • Claude Code with Claude Fable 5.2: found the cause, wrote the fix, the test and this description, and ran the tests.

🤖 Generated with Claude Code

@vibryxcx

Copy link
Copy Markdown

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.ps1 60 s; pso_library.rs is the same on c32c91a3 and on this PR's base 71b8e6e0)

  • I took the newest generation of my library (gen-0000005b.plib, 319,420 bytes, 4028 mod 4096) and saved a copy with 66 zero bytes added as gen-0000005c.plib: 319,486 bytes, 4094 mod 4096, the same remainder as your two crashing files.
  • I ran c32c91a3 without the fix and c32c91a3 with 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 base 71b8e6e0 the title first recompiles all 26,503 shaders, about an hour here, so I used c32c91a3, whose shader cache was warm.
build run frames crash log
without the fix 1 1358 no opened memory-mapped pipeline library gen-0000005c (0.3 MiB file-backed), then 1000+ library hits
with the fix 1 1367 no same
without the fix 2 1382 no same
with the fix 2 1293 no same

So 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 in pso_library.rs, which does not know which path MappedBlob::open took. 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 < 4 takes exactly the four remainders 4093, 4094, 4095 and 0, where the dword at blob + len would cross into the next page. view points into copy after the extend_from_slice, so it stays valid when the struct moves, and Drop skips UnmapViewOfFile for the copy path. I found no defect.

Tested

Not tested: the crash itself (it does not reproduce on this driver); the xcl-smoke pair 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.

AMD's driver reads a dword at blob + length in CreatePipelineLibrary
(amdxc64.dll+0x176cd5, `cmp dword ptr [r14], eax` with r14 = the view's
address + the file's length). MappedBlob hands it a file mapping, which
ends with the file's last page: a file that ends less than 4 bytes
before a page boundary has that dword in the unmapped page after it, and
the process dies at startup with 0xc0000005 until the file is removed.

Seen on an RX 6800 (driver 32.0.21045.29003) with two libraries, both of
a length of 4094 mod 4096 (1933310 and 3252222 bytes); the faulting
address was the first byte after the view in every one of 3 starts.

Such a file (4 lengths in 4096) is now read into memory with 4 zero
bytes after it instead of being mapped. With the fix the 1933310-byte
library opens and serves pipelines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@bobosneefdev

Copy link
Copy Markdown
Author

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 logs read into memory: the file ends at a page boundary in place of file-backed. Message only, no other change. cargo test --release -p xcl --lib pso_library on 78795c74: 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).

@bobosneefdev
bobosneefdev marked this pull request as ready for review November 26, 2026 21:26
@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the pipeline-library blob tests at 78795c74 on 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.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib pso_library -- --test-threads=1
4 passed; 0 failed; 0 ignored; 0 measured; 1677 filtered out      (exit 0)

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.dll crash 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants