Skip to content

DirectStorage: a memory source is copied without faulting - #561

Open
requiemsnkrp wants to merge 1 commit into
xcl-dev:mainfrom
requiemsnkrp:dstorage-memory-source-read
Open

requiemsnkrp wants to merge 1 commit into
xcl-dev:mainfrom
requiemsnkrp:dstorage-memory-source-read

Conversation

@requiemsnkrp

@requiemsnkrp requiemsnkrp commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 xcl-dev#476, found by
brothernog in the review of xcl-dev#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)
@brothernog

Copy link
Copy Markdown

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.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

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.

@jacksonslab

Copy link
Copy Markdown

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.

@upipibi upipibi mentioned this pull request Nov 24, 2026
themaoci pushed a commit to themaoci/xcl that referenced this pull request Nov 24, 2026
`execute` checks a virtual destination with `writable()` at its start,
then reads the file or copies the source and inflates it, and only then
writes the destination with `copy_nonoverlapping`. A destination the
title unmapped in that time faulted in the xcl-dstorage worker and ended
the process (the destination side of ivall#476, found by brothernog in the
review of ivall#561). It is now written with `write_own`
(NtWriteVirtualMemory on the process itself), the counterpart of the
`read_own` the page arrays use: the request fails with E_ACCESS_VIOLATION
instead. Not WriteProcessMemory: it first queries the region, which in
the 4 GiB coherent window took 75-175 ms a call (measured) and stalled the
title's first streaming (0 frames in 60 s).

The test runs 20000 requests while another thread decommits and
recommits the destination 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)
(cherry picked from commit d09f285)
@thaqiart139-alt

Copy link
Copy Markdown

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
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 gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #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.

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
`execute` checks a virtual destination with `writable()` at its start,
then reads the file or copies the source and inflates it, and only then
writes the destination with `copy_nonoverlapping`. A destination the
title unmapped in that time faulted in the xcl-dstorage worker and ended
the process (the destination side of xcl-dev#476, found by brothernog in the
review of xcl-dev#561). It is now written with `write_own`
(NtWriteVirtualMemory on the process itself), the counterpart of the
`read_own` the page arrays use: the request fails with E_ACCESS_VIOLATION
instead. Not WriteProcessMemory: it first queries the region, which in
the 4 GiB coherent window took 75-175 ms a call (measured) and stalled the
title's first streaming (0 frames in 60 s).

The test runs 20000 requests while another thread decommits and
recommits the destination 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)
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.

5 participants