Skip to content

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

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

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

Conversation

@bobosneefdev

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 83b95c4f: 1643 passed, 11 failed, 27 ignored. On the unmodified base 71b8e6e0: 1640 passed, 13 failed, 27 ignored. All 11 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

  • In progress (scripts/smoke.ps1, 120 s, main 8b957bec and this PR's head). The two xcl-smoke blocks will be pasted here when they finish.

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.
  • 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).

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.

2 participants