DirectStorage: a memory source is copied without faulting #561

Open
github-bot wants to merge 1 commit from github-bot/gh-561 into main AGit
Owner

@⁠requiemsnkrp on GitHub · 2026-11-24 01:50 UTC · original
requiemsnkrp:dstorage-memory-source-read → main · +73 −2 · 1 files · 1 commits · open

A memory-source DirectStorage request's source was checked with readable() and then copied with copy_nonoverlapping on the xcl-dstorage worker at the request's turn. If the title unmapped the source between the two, the copy faulted in the worker and ended the process. It is now copied with read_own (ReadProcessMemory), as the page arrays are, so the request fails with E_ACCESS_VIOLATION instead. This is the source side of #476; @⁠brothernog found it while reviewing #509. It is independent of #509: a different hunk of execute, branched from main 508a0c7.

What is in it

  • crates/xcl/src/hle/dstorage.rs, execute: the memory source is copied with read_own after the existing readable() check, which stays for the cheap refusals (empty or oversized sources)
  • crates/xcl/src/hle/dstorage.rs, tests: a_memory_source_unmapped_under_the_worker_fails_the_request runs 20000 memory-source requests while another thread decommits and recommits the source 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 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 c65cf2e: 681 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: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1384 (PresentX 1384)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14486 MB

PR:

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

Not tested

  • whether the title uses memory-source requests in those 60 s (XCL logs only a sample of requests); the regression run checks that nothing else changed
  • the full suite on main 508a0c7 without the change on this machine (the count above is for the PR head only)
  • AMD / Intel GPUs

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:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/561) `requiemsnkrp:dstorage-memory-source-read` → `main` · +73 −2 · 1 files · 1 commits · open A memory-source DirectStorage request's source was checked with `readable()` and then copied with `copy_nonoverlapping` on the `xcl-dstorage` worker at the request's turn. If the title unmapped the source between the two, the copy faulted in the worker and ended the process. It is now copied with `read_own` (`ReadProcessMemory`), as the page arrays are, so the request fails with `E_ACCESS_VIOLATION` instead. This is the source side of #476; @⁠brothernog found it while reviewing #509. It is independent of #509: a different hunk of `execute`, branched from `main` 508a0c7. **What is in it** - `crates/xcl/src/hle/dstorage.rs`, `execute`: the memory source is copied with `read_own` after the existing `readable()` check, which stays for the cheap refusals (empty or oversized sources) - `crates/xcl/src/hle/dstorage.rs`, tests: `a_memory_source_unmapped_under_the_worker_fails_the_request` runs 20000 memory-source requests while another thread decommits and recommits the source 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 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 c65cf2e: 681 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: 508a0c74d7c0625d6d2de8d24494e69dc2e1926f gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1384 (PresentX 1384) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14486 MB ``` PR: ``` xcl-smoke v1 commit: c65cf2ef9a9ecb7d7673b93b8d210dfb979be8d8 gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1444 (PresentX 1444) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14612 MB ``` **Not tested** - whether the title uses memory-source requests in those 60 s (XCL logs only a sample of requests); the regression run checks that nothing else changed - the full suite on `main` 508a0c7 without the change on this machine (the count above is for the PR head only) - AMD / Intel GPUs **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 memory-source request's source was checked with `readable()` and then
copied with `copy_nonoverlapping` on the xcl-dstorage worker, at the
request's turn: a source the title unmapped between the two faulted in
the worker and ended the process (the source side of #476, found by
brothernog in the review of #509). It is now copied with `read_own`
(ReadProcessMemory), as the page arrays are: the request fails with
E_ACCESS_VIOLATION instead.

The test runs 20000 memory-source requests while another thread
decommits and recommits the source page: before, the test process ended
with 0xc0000005 (5 of 5 runs); after, it passes (10 of 10).

Assisted-by: Claude Code (Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:25:43 +00:00
Author
Owner

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

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

  • a_memory_source_unmapped_under_the_worker_fails_the_request (--exact): 3 of 3 passed. With only the execute hunk put back to copy_nonoverlapping, 3 of 3 runs ended in 0xc0000005 STATUS_ACCESS_VIOLATION.
  • cargo test -p xcl --lib hle::dstorage: 14 passed.

Thanks for picking this up. One more of the same shape, on the destination side (read only, not run): execute checks a virtual destination with writable() at its start (dstorage.rs:790 on this head), then reads the file or copies the source and decompresses, and only then writes with copy_nonoverlapping (:854). The window there is longer than the source's, since it spans the file read. A destination the title decommits in that time would fault in xcl-dstorage the same way. WriteProcessMemory on the current process would be the write-side counterpart of read_own. Probably a separate PR, if it is worth doing.

This review was AI-assisted.

**@⁠brothernog** on GitHub · 2026-11-24 01:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/561#issuecomment-7119579309) Tested `c65cf2e` on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug: - `a_memory_source_unmapped_under_the_worker_fails_the_request` (`--exact`): 3 of 3 passed. With only the `execute` hunk put back to `copy_nonoverlapping`, 3 of 3 runs ended in `0xc0000005 STATUS_ACCESS_VIOLATION`. - `cargo test -p xcl --lib hle::dstorage`: 14 passed. Thanks for picking this up. One more of the same shape, on the destination side (read only, not run): `execute` checks a virtual destination with `writable()` at its start (`dstorage.rs:790` on this head), then reads the file or copies the source and decompresses, and only then writes with `copy_nonoverlapping` (`:854`). The window there is longer than the source's, since it spans the file read. A destination the title decommits in that time would fault in `xcl-dstorage` the same way. `WriteProcessMemory` on the current process would be the write-side counterpart of `read_own`. Probably a separate PR, if it is worth doing. This review was AI-assisted.
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 03:12 UTC · original

Test run of c65cf2ef9a9ecb7d7673b93b8d210dfb979be8d8 on AMD RDNA4. I merged it onto current main dd2ae9a 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: 691 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 651 passed, 0 failed, 21 ignored
  • 0 SKIPPED; a_memory_source_unmapped_under_the_worker_fails_the_request passes (20 000 requests against a page decommitted and committed in a loop, no crash).

Review: Copying the source with read_own turns a source unmapped between the check and the copy into E_ACCESS_VIOLATION for that request, as the page arrays already do, instead of a fault in xcl-dstorage. 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 03:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/561#issuecomment-7120866671) Test run of `c65cf2ef9a9ecb7d7673b93b8d210dfb979be8d8` on AMD RDNA4. I merged it onto current `main` `dd2ae9a` 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: **691 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 651 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `a_memory_source_unmapped_under_the_worker_fails_the_request` passes (20 000 requests against a page decommitted and committed in a loop, no crash). **Review:** Copying the source with `read_own` turns a source unmapped between the check and the copy into `E_ACCESS_VIOLATION` for that request, as the page arrays already do, instead of a fault in `xcl-dstorage`. 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

@⁠jacksonslab on GitHub · 2026-11-24 03:23 UTC · original

Tested the same change on a retail title (Windows 11, RTX 4070 SUPER 12 GB, i7-14700K, NVIDIA driver current as of this week), applied on top of main 508a0c7 plus #533/#549/#567/#572/#551/#454.

Before: the process ended with an access violation inside VCRUNTIME140!memcpy called from the xcl-dstorage worker, ~80 s in, during a burst of several thousand DirectStorage requests per 2 s while the title streams its world.

After replacing the copy_nonoverlapping of the memory source with read_own (identical to this PR) — together with the same treatment for the deferred page-array read (#509) and #454 for title textures — that crash is gone; the run continued past 140 s and DirectStorage reported 0 failed requests over the run.

Note: tested with a local equivalent of this patch, not this exact branch.

**@⁠jacksonslab** on GitHub · 2026-11-24 03:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/561#issuecomment-7121050384) Tested the same change on a retail title (Windows 11, RTX 4070 SUPER 12 GB, i7-14700K, NVIDIA driver current as of this week), applied on top of main 508a0c7 plus #533/#549/#567/#572/#551/#454. Before: the process ended with an access violation inside `VCRUNTIME140!memcpy` called from the `xcl-dstorage` worker, ~80 s in, during a burst of several thousand DirectStorage requests per 2 s while the title streams its world. After replacing the `copy_nonoverlapping` of the memory source with `read_own` (identical to this PR) — together with the same treatment for the deferred page-array read (#509) and #454 for title textures — that crash is gone; the run continued past 140 s and DirectStorage reported 0 failed requests over the run. Note: tested with a local equivalent of this patch, not this exact branch.
Author
Owner

@⁠thaqiart139-alt on GitHub · 2026-11-24 22:48 UTC · original

Test report for this PR's head c65cf2e, merged into main 689f2db (no conflicts), on AMD RDNA2 with native 64-lane waves and on a 32-lane NVIDIA card.

Tested

  • GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), chosen with XCL_ADAPTER.
  • System: 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17.
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
main 689f2db with this PR
RTX 5070 971 passed, 4 failed, 45 ignored 972 passed, 4 failed, 45 ignored
Radeon iGPU 974 passed, 1 failed, 45 ignored 975 passed, 1 failed, 45 ignored
  • This PR adds no failure. The failures are the same on main, from #1679's new fuzz tests, and both are already reported on #1679:
    • RTX 5070: fuzz_validate_and_gpu_0 to _3 (CreateComputePipelineState: 0x8007000E)
    • iGPU: fuzz_validate_and_gpu_1 (seed 540: res[833] = 0x7, CPU 0x6)
  • This PR's new tests pass on both GPUs: a_memory_source_unmapped_under_the_worker_fails_the_request.
  • This includes the full suite on main without the change on the same machine, which the description lists as not tested, and an AMD GPU.
SKIPPED tests (the same on main and with this PR)
  • RTX 5070:
    • no wave64:
      • gpu::recomp::lower::tests: a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu
      • gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu, and the wave64 cases of its f16 / f32 / f64 / integer_programs_on_the_gpu
      • gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
    • the wave32 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused ("its #1426 semantics differ from the console's")
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is off)
  • Radeon iGPU:
    • no mesh shaders: gpu::dxil::geometry_tests::gpu_geometry_direct_records, emitted_ms_primitive_attribute_reaches_the_pixel_shader, emitted_ms_ps_draw_a_triangle, gpu_geometry_mode_es_gs_strip, gpu_geometry_mode_es_gs_strip_with_branches, gpu_mesh_mode_two_passes
    • the wave32 and wave64 per-lane cases of lower_dxil's f16 arithmetic, f16 packed and f32 conversions: refused, as above
    • heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off)

Not tested

  • a title run (whether a title uses memory-source requests); other GPUs; Linux / Wine.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.
**@⁠thaqiart139-alt** on GitHub · 2026-11-24 22:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/561#issuecomment-7146675948) Test report for this PR's head `c65cf2e`, merged into `main` `689f2db` (no conflicts), on AMD RDNA2 with native 64-lane waves and on a 32-lane NVIDIA card. **Tested** - GPUs: AMD Radeon(TM) Graphics, the RDNA2 iGPU of a Ryzen 7 7800X3D (native wave64, driver 32.0.21045.29003), and NVIDIA GeForce RTX 5070 (driver 32.0.16.2101), chosen with `XCL_ADAPTER`. - System: 32 GB, Windows 11 Home build 26300, Rust 1.100.0, debug, DXC 1.9.2602.17. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: | | `main` `689f2db` | with this PR | |---|---|---| | RTX 5070 | 971 passed, 4 failed, 45 ignored | 972 passed, 4 failed, 45 ignored | | Radeon iGPU | 974 passed, 1 failed, 45 ignored | 975 passed, 1 failed, 45 ignored | - This PR adds no failure. The failures are the same on `main`, from #1679's new fuzz tests, and both are already reported on #1679: - RTX 5070: `fuzz_validate_and_gpu_0` to `_3` (`CreateComputePipelineState`: `0x8007000E`) - iGPU: `fuzz_validate_and_gpu_1` (`seed 540: res[833] = 0x7, CPU 0x6`) - This PR's new tests pass on both GPUs: `a_memory_source_unmapped_under_the_worker_fails_the_request`. - This includes the full suite on `main` without the change on the same machine, which the description lists as not tested, and an AMD GPU. <details><summary>SKIPPED tests (the same on <code>main</code> and with this PR)</summary> - **RTX 5070:** - no wave64: - `gpu::recomp::lower::tests`: `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu` - `gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu`, and the wave64 cases of its `f16` / `f32` / `f64` / `integer_programs_on_the_gpu` - `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` - the wave32 per-lane cases of `lower_dxil`'s f16 arithmetic, f16 packed and f32 conversions: refused ("its #1426 semantics differ from the console's") - `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - `pso_measurement_compiles_an_exact_synthetic_record` (Windows Developer Mode is off) - **Radeon iGPU:** - no mesh shaders: `gpu::dxil::geometry_tests::gpu_geometry_direct_records`, `emitted_ms_primitive_attribute_reaches_the_pixel_shader`, `emitted_ms_ps_draw_a_triangle`, `gpu_geometry_mode_es_gs_strip`, `gpu_geometry_mode_es_gs_strip_with_branches`, `gpu_mesh_mode_two_passes` - the wave32 and wave64 per-lane cases of `lower_dxil`'s f16 arithmetic, f16 packed and f32 conversions: refused, as above - `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode is off) </details> **Not tested** - a title run (whether a title uses memory-source requests); other GPUs; Linux / Wine. **AI use** - Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 13:30 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/561#issuecomment-7163876979) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Author
Owner

@⁠throny on GitHub · 2026-11-26 02:18 UTC · original

Two contributors checked independently and found that #2359 solves the same problem in a different way: #1607, group D115. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-26 02:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/561#issuecomment-7180669913) <!-- xcl-1607-hint:D115 --> Two contributors checked independently and found that #2359 solves the same problem in a different way: #1607, group D115. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/dstorage.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/561/head:github-bot/gh-561'
git switch 'github-bot/gh-561'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-561'
git switch 'github-bot/gh-561'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-561'
git switch 'github-bot/gh-561'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-561'
git switch 'main'
git merge --squash 'github-bot/gh-561'
git switch 'main'
git merge --ff-only 'github-bot/gh-561'
git switch 'main'
git merge 'github-bot/gh-561'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.