DirectStorage: a deferred page-array entry is reread without faulting (#476) #509

Manually merged
github merged 1 commit from gh-pr/509/head into gh-pr/509/base 2026-11-26 04:23:56 +00:00
Owner

@⁠requiemsnkrp on GitHub · 2026-11-24 01:07 UTC · original
requiemsnkrp:dstorage-deferred-page-array-read → main · +83 −4 · 1 files · 1 commits · merged 2026-11-25 01:06 UTC

A destination page-array entry that is 0 at EnqueueRequest is read again at the request's turn (#289). That read checked readable() and then dereferenced the title's memory. If the title unmapped the array between the two, the read faulted in the xcl-dstorage worker and ended the process. It now reads with read_own (ReadProcessMemory), as the enqueue-time snapshot already does, so the request fails with E_ACCESS_VIOLATION instead. Fixes #476.

An array that is freed and reused before the request's turn cannot be told from a late fill. The title keeps it until the request is done; the comment now says so.

What is in it

  • crates/xcl/src/hle/dstorage.rs, execute: the deferred entries are read with read_own; if that read fails, the request keeps its 0 entries and fails as before
  • crates/xcl/src/hle/dstorage.rs, tests: a_deferred_page_array_unmapped_under_the_worker_fails_the_request runs 20000 requests with a deferred entry while another thread decommits and recommits the array's page

Tested

  • NVIDIA GeForce RTX 3060 12 GB, driver 621.24 (32-lane waves); AMD Ryzen 5 5600X; Windows 11 Pro 26200; Rust 1.100.0 msvc; debug for the tests, release for the regression runs
  • the new test on main 2997c9a, without the fix (5 runs, --exact): 5 × 0xc0000005 STATUS_ACCESS_VIOLATION; with the fix: 10 of 10 passed; hle::dstorage tests: 14 passed
  • cargo test --workspace -- --test-threads=4 on 3724b07: 677 passed, 0 failed, 41 ignored (main 2997c9a on the same machine: 676 passed, 0 failed, 41 ignored)
  • SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Regression run

main:

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 564 (PresentX 564)
presents per 2 s (last 3): 7 7 7
device removals: 0
crashes: 0
peak commit: 14956 MB

PR:

xcl-smoke v1
commit: 3724b07170bd2ad3f689cbcfa2006a718b4443ea
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 597 (PresentX 597)
presents per 2 s (last 3): 7 6 7
device removals: 0
crashes: 0
peak commit: 15078 MB

Not tested

  • whether the title reaches the changed path in those 60 s: none of the requests XCL logs (the first 16, then powers of two) had a physical-page destination, so the regression run checks only that nothing else changed
  • AMD / Intel GPUs; a longer run of the title

AI use

  • Claude Code with Claude Opus 5.5: wrote the change, the test and this description, and ran the tests and the regression runs on the machine above; opened at my request.
**@⁠requiemsnkrp** on GitHub · 2026-11-24 01:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/509) `requiemsnkrp:dstorage-deferred-page-array-read` → `main` · +83 −4 · 1 files · 1 commits · merged 2026-11-25 01:06 UTC A destination page-array entry that is 0 at EnqueueRequest is read again at the request's turn (#289). That read checked `readable()` and then dereferenced the title's memory. If the title unmapped the array between the two, the read faulted in the `xcl-dstorage` worker and ended the process. It now reads with `read_own` (`ReadProcessMemory`), as the enqueue-time snapshot already does, so the request fails with `E_ACCESS_VIOLATION` instead. Fixes #476. An array that is freed and reused before the request's turn cannot be told from a late fill. The title keeps it until the request is done; the comment now says so. **What is in it** - `crates/xcl/src/hle/dstorage.rs`, `execute`: the deferred entries are read with `read_own`; if that read fails, the request keeps its 0 entries and fails as before - `crates/xcl/src/hle/dstorage.rs`, tests: `a_deferred_page_array_unmapped_under_the_worker_fails_the_request` runs 20000 requests with a deferred entry while another thread decommits and recommits the array's page **Tested** - NVIDIA GeForce RTX 3060 12 GB, driver 621.24 (32-lane waves); AMD Ryzen 5 5600X; Windows 11 Pro 26200; Rust 1.100.0 msvc; debug for the tests, release for the regression runs - the new test on `main` 2997c9a, without the fix (5 runs, `--exact`): **5 × `0xc0000005 STATUS_ACCESS_VIOLATION`**; with the fix: 10 of 10 passed; `hle::dstorage` tests: 14 passed - `cargo test --workspace -- --test-threads=4` on 3724b07: 677 passed, 0 failed, 41 ignored (main 2997c9a on the same machine: 676 passed, 0 failed, 41 ignored) - SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` **Regression run** main: ``` xcl-smoke v1 commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21 gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 564 (PresentX 564) presents per 2 s (last 3): 7 7 7 device removals: 0 crashes: 0 peak commit: 14956 MB ``` PR: ``` xcl-smoke v1 commit: 3724b07170bd2ad3f689cbcfa2006a718b4443ea gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 597 (PresentX 597) presents per 2 s (last 3): 7 6 7 device removals: 0 crashes: 0 peak commit: 15078 MB ``` **Not tested** - whether the title reaches the changed path in those 60 s: none of the requests XCL logs (the first 16, then powers of two) had a physical-page destination, so the regression run checks only that nothing else changed - AMD / Intel GPUs; a longer run of the title **AI use** - Claude Code with Claude Opus 5.5: wrote the change, the test and this description, and ran the tests and the regression runs on the machine above; opened at my request.
A destination page array entry that is 0 at EnqueueRequest is read again
at the request's turn (#289). That read checked `readable()` and then
dereferenced the title's memory: an array the title unmapped between the
two faulted in the xcl-dstorage worker and ended the process. It now reads
with `read_own` (ReadProcessMemory), as the snapshot at enqueue already
does: the request fails with E_ACCESS_VIOLATION instead.

An array the title frees and reuses before the request's turn cannot be
told from a late fill; the title keeps it until the request is done, as
the comment now says.

The test runs 20000 requests with a deferred entry while another thread
decommits and recommits the array's page: before, the test process ended
with 0xc0000005 (5 of 5 runs); after, it passes (10 of 10).

Fixes #476

Assisted-by: Claude Code (Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:55 +00:00
github manually merged commit 3724b07170 into gh-pr/509/base 2026-11-26 04:23:56 +00:00
Author
Owner

@⁠brothernog on GitHub · 2026-11-24 01:42 UTC · original

Tested 3724b07 on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug:

  • a_deferred_page_array_unmapped_under_the_worker_fails_the_request: 5 of 5 passed. With only the execute hunk reverted to the old readable() + read_unaligned, 3 of 3 runs ended in 0xc0000005 STATUS_ACCESS_VIOLATION.
  • cargo test -p xcl --lib hle::dstorage: 14 passed.
  • cargo build --workspace then cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

A sibling with the same check-then-read shape is in the same function. A memory source is checked with crate::gpu::shader::readable and then copied with copy_nonoverlapping from title memory on the worker thread (dstorage.rs:801-806 on this head). If a title frees the source before the request's turn, that copy faults in xcl-dstorage just like #476 did. read_own there would turn it into E_ACCESS_VIOLATION too, whether in this PR or in a follow-up. I didn't find an open PR that covers it.

This review was AI-assisted.

**@⁠brothernog** on GitHub · 2026-11-24 01:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/509#issuecomment-7119372642) Tested `3724b07` on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug: - `a_deferred_page_array_unmapped_under_the_worker_fails_the_request`: 5 of 5 passed. With only the `execute` hunk reverted to the old `readable()` + `read_unaligned`, 3 of 3 runs ended in `0xc0000005 STATUS_ACCESS_VIOLATION`. - `cargo test -p xcl --lib hle::dstorage`: 14 passed. - `cargo build --workspace` then `cargo test --workspace --no-fail-fast -- --test-threads=4`: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. A sibling with the same check-then-read shape is in the same function. A memory source is checked with `crate::gpu::shader::readable` and then copied with `copy_nonoverlapping` from title memory on the worker thread (`dstorage.rs:801-806` on this head). If a title frees the source before the request's turn, that copy faults in `xcl-dstorage` just like #476 did. `read_own` there would turn it into `E_ACCESS_VIOLATION` too, whether in this PR or in a follow-up. I didn't find an open PR that covers it. This review was AI-assisted.
Author
Owner

@⁠requiemsnkrp on GitHub · 2026-11-24 01:50 UTC · original

@⁠brothernog thanks for the independent run, and for the memory-source copy: you were right. Same shape, same fault: the new test on main 508a0c7 ended with 0xc0000005 in 5 of 5 runs before the change and passed 10 of 10 after. I kept it out of this PR (one problem per PR) and opened #561. It is branched from main and does not depend on this one.

Written with Claude Code (Claude Opus 5.5).

**@⁠requiemsnkrp** on GitHub · 2026-11-24 01:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/509#issuecomment-7119500991) @⁠brothernog thanks for the independent run, and for the memory-source copy: you were right. Same shape, same fault: the new test on `main` 508a0c7 ended with `0xc0000005` in 5 of 5 runs before the change and passed 10 of 10 after. I kept it out of this PR (one problem per PR) and opened #561. It is branched from `main` and does not depend on this one. _Written with Claude Code (Claude Opus 5.5)._
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 04:21 UTC · original

Test run of 3724b07170bd2ad3f689cbcfa2006a718b4443ea on AMD RDNA4. I merged it onto current main f4ce27c locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 702 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 661 passed, 0 failed, 21 ignored
  • 0 SKIPPED; a_deferred_page_array_unmapped_under_the_worker_fails_the_request passes.

Review: Rereading the deferred entries with read_own (ReadProcessMemory) instead of readable() + a raw read means an array unmapped between the two no longer faults in xcl-dstorage; when the read fails the enqueue-time snapshot is used. Same pattern as #561 and #705. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

**@⁠MesshM** on GitHub · 2026-11-24 04:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/509#issuecomment-7121943292) Test run of `3724b07170bd2ad3f689cbcfa2006a718b4443ea` on AMD RDNA4. I merged it onto current `main` `f4ce27c` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **702 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 661 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `a_deferred_page_array_unmapped_under_the_worker_fails_the_request` passes. **Review:** Rereading the deferred entries with `read_own` (`ReadProcessMemory`) instead of `readable()` + a raw read means an array unmapped between the two no longer faults in `xcl-dstorage`; when the read fails the enqueue-time snapshot is used. Same pattern as #561 and #705. I found nothing to change. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 00:56 UTC · original

Diff check on 3724b07:

  • Replacing readable() + read_unaligned() with read_own() in dstorage::execute cleanly prevents access violations when a deferred (0) page-array entry is decommitted before the worker rereads it, and a_deferred_page_array_unmapped_under_the_worker_fails_the_request directly covers the race.
  • Already verified across both AMD (RX 9060 XT) and NVIDIA (RTX 3050), with PR description passing.

Next step to unblock merge: Please rebase onto current main (or push an updated commit) so CI runs Build and test (Windows, no GPU) on the head.

**@⁠raylitebull** on GitHub · 2026-11-25 00:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/509#issuecomment-7149050407) Diff check on `3724b07`: - Replacing `readable()` + `read_unaligned()` with `read_own()` in `dstorage::execute` cleanly prevents access violations when a deferred (`0`) page-array entry is decommitted before the worker rereads it, and `a_deferred_page_array_unmapped_under_the_worker_fails_the_request` directly covers the race. - Already verified across both AMD (`RX 9060 XT`) and NVIDIA (`RTX 3050`), with `PR description` passing. **Next step to unblock merge:** Please rebase onto current `main` (or push an updated commit) so CI runs `Build and test (Windows, no GPU)` on the head.
This discussion has been locked. Commenting is limited to contributors.
No description provided.