DirectStorage: a virtual destination is written without faulting #705

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

@⁠requiemsnkrp on GitHub · 2026-11-24 03:55 UTC · original
requiemsnkrp:dstorage-destination-write → main · +90 −1 · 1 files · 1 commits · open

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. If the title unmapped the destination in that window (which spans the file read), the write faulted in the xcl-dstorage worker and ended the process. It is now written with write_own (NtWriteVirtualMemory on the process itself), the counterpart of the read_own that the page arrays already use, so the request fails with E_ACCESS_VIOLATION instead. Not WriteProcessMemory: it first queries the region, and in the 4 GiB coherent window that took 75–175 ms a call (measured in the title: 64 KiB and 8-byte writes alike, while ReadProcessMemory took 3–11 µs). A first version with it showed 0 frames in two 60 s regression runs, because the title's first streaming stalled. This is the destination side of #476; @⁠brothernog found it in the review of #561. It is independent of #509 and #561 (a different hunk of execute), branched from main 91f9a5e.

What is in it

  • crates/xcl/src/hle/dstorage.rs: write_own (NtWriteVirtualMemory, raw-dylib as the other ntdll calls), used for the virtual destination's write in execute; the writable() check at the start stays (it commits lazy pages and refuses early)
  • crates/xcl/src/hle/dstorage.rs, tests: a_destination_unmapped_under_the_worker_fails_the_request runs 20000 memory-source requests while another thread decommits and recommits the destination 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; DXC 1.9.2602.17; 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 d09f285: 693 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: 63cdc25bc0d2b59cc2af85e6e23f619dfaf72866
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1488 (PresentX 1488)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16363 MB

(main 63cdc25; this branch's base 91f9a5e differs from it by README.md only)

PR:

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

Not tested

  • whether the title unmaps a destination during a request in these 60 s (XCL logs only a sample of requests); the regression run checks that nothing else changed. #646 (a write fault in memcpy called from xcl.exe while the world streams, RTX 3060 12 GB) may be this; I could not match its xcl.exe offsets to a build, so that is a guess
  • a destination made read-only (rather than unmapped) between the check and the write: not tested
  • 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 03:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/705) `requiemsnkrp:dstorage-destination-write` → `main` · +90 −1 · 1 files · 1 commits · open `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`. If the title unmapped the destination in that window (which spans the file read), the write faulted in the `xcl-dstorage` worker and ended the process. It is now written with `write_own` (`NtWriteVirtualMemory` on the process itself), the counterpart of the `read_own` that the page arrays already use, so the request fails with `E_ACCESS_VIOLATION` instead. Not `WriteProcessMemory`: it first queries the region, and in the 4 GiB coherent window that took 75–175 ms a call (measured in the title: 64 KiB and 8-byte writes alike, while `ReadProcessMemory` took 3–11 µs). A first version with it showed 0 frames in two 60 s regression runs, because the title's first streaming stalled. This is the destination side of #476; @⁠brothernog found it in the review of #561. It is independent of #509 and #561 (a different hunk of `execute`), branched from `main` 91f9a5e. **What is in it** - `crates/xcl/src/hle/dstorage.rs`: `write_own` (`NtWriteVirtualMemory`, raw-dylib as the other ntdll calls), used for the virtual destination's write in `execute`; the `writable()` check at the start stays (it commits lazy pages and refuses early) - `crates/xcl/src/hle/dstorage.rs`, tests: `a_destination_unmapped_under_the_worker_fails_the_request` runs 20000 memory-source requests while another thread decommits and recommits the destination 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; DXC 1.9.2602.17; 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 d09f285: 693 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: 63cdc25bc0d2b59cc2af85e6e23f619dfaf72866 gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1488 (PresentX 1488) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16363 MB ``` (`main` 63cdc25; this branch's base 91f9a5e differs from it by README.md only) PR: ``` xcl-smoke v1 commit: d09f285014c6262b35f6b412d46eb4cfd70b7b2c gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 1411 (PresentX 1412) presents per 2 s (last 3): 60 60 32 device removals: 0 crashes: 0 peak commit: 17010 MB ``` **Not tested** - whether the title unmaps a destination during a request in these 60 s (XCL logs only a sample of requests); the regression run checks that nothing else changed. #646 (a write fault in `memcpy` called from `xcl.exe` while the world streams, RTX 3060 12 GB) may be this; I could not match its `xcl.exe` offsets to a build, so that is a guess - a destination made read-only (rather than unmapped) between the check and the write: not tested - 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.
`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 #476, found by brothernog in the
review of #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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:02 +00:00
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-24 04:05 UTC · original

Code audit + NVIDIA RTX 5080 test run on d09f285014c6262b35f6b412d46eb4cfd70b7b2c:

Review

Looks clean — NtWriteVirtualMemory (raw-dylib from ntdll) matches the x64 Win32 signature, checks at != 0, NT_SUCCESS (>= 0), and done == data.len(), avoiding WriteProcessMemory's expensive NtQueryVirtualMemory page-table walk while failing cleanly with E_ACCESS_VIOLATION if the title unmaps a virtual destination mid-request.

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 693 passed, 0 failed, 41 ignored.
  • New stress test hle::dstorage::tests::a_destination_unmapped_under_the_worker_fails_the_request: passed.
  • SKIPPED GPU/D3D12 tests: gpu_geometry_wave32_prefix_count_over_a_mask / gpu_wave32_program_in_wave64_hardware (no wave64), plus 2 D3D12 debug-layer tests (no d3d12SDKLayers.dll).

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

**@⁠mastrr9** on GitHub · 2026-11-24 04:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/705#issuecomment-7121701304) Code audit + NVIDIA RTX 5080 test run on `d09f285014c6262b35f6b412d46eb4cfd70b7b2c`: ### Review Looks clean — `NtWriteVirtualMemory` (`raw-dylib` from `ntdll`) matches the x64 Win32 signature, checks `at != 0`, `NT_SUCCESS` (`>= 0`), and `done == data.len()`, avoiding `WriteProcessMemory`'s expensive `NtQueryVirtualMemory` page-table walk while failing cleanly with `E_ACCESS_VIOLATION` if the title unmaps a virtual destination mid-request. ### Tested - Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), `rustc 1.100.0` (MSVC), debug build. - `cargo build --workspace && cargo test --workspace -- --test-threads=4`: **693 passed, 0 failed, 41 ignored**. - New stress test `hle::dstorage::tests::a_destination_unmapped_under_the_worker_fails_the_request`: **passed**. - `SKIPPED` GPU/D3D12 tests: `gpu_geometry_wave32_prefix_count_over_a_mask` / `gpu_wave32_program_in_wave64_hardware` (`no wave64`), plus 2 D3D12 debug-layer tests (`no d3d12SDKLayers.dll`). ### Not tested - Retail title / `scripts/smoke.ps1` run (test suite only). - AMD / Intel GPUs. *AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.*
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 04:07 UTC · original

Independent test report on d09f285:

Tested

  • Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver 616.64, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), rustc 1.100.0 (x86_64-pc-windows-gnullvm), debug build
  • Command: cargo test -p xcl --lib hle::dstorage::tests -- --nocapture
  • Result: 14 passed, 0 failed, 0 ignored in 0.19s (a_destination_unmapped_under_the_worker_fails_the_request ok)

Not tested

  • AMD / Intel GPU, retail title

AI use

  • Antigravity (Google DeepMind agent) — fetched d09f285 in a detached worktree, audited the diff, ran the test suite, and posted this report.
**@⁠lordon1a** on GitHub · 2026-11-24 04:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/705#issuecomment-7121733259) Independent test report on `d09f285`: **Tested** - Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver `616.64`, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), `rustc 1.100.0` (`x86_64-pc-windows-gnullvm`), debug build - Command: `cargo test -p xcl --lib hle::dstorage::tests -- --nocapture` - Result: **14 passed, 0 failed, 0 ignored** in `0.19s` (`a_destination_unmapped_under_the_worker_fails_the_request` ok) **Not tested** - AMD / Intel GPU, retail title **AI use** - Antigravity (Google DeepMind agent) — fetched `d09f285` in a detached worktree, audited the diff, ran the test suite, and posted this report.
Author
Owner

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

Test run of d09f285014c6262b35f6b412d46eb4cfd70b7b2c 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, native wave64), 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_destination_unmapped_under_the_worker_fails_the_request passes.

Review: Writing the destination with write_own (NtWriteVirtualMemory on the own process) turns a destination unmapped during the file read into E_ACCESS_VIOLATION for that request instead of a fault in xcl-dstorage, the write-side counterpart of #561. 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:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/705#issuecomment-7121736969) Test run of `d09f285014c6262b35f6b412d46eb4cfd70b7b2c` 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, native wave64), 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_destination_unmapped_under_the_worker_fails_the_request` passes. **Review:** Writing the destination with `write_own` (`NtWriteVirtualMemory` on the own process) turns a destination unmapped during the file read into `E_ACCESS_VIOLATION` for that request instead of a fault in `xcl-dstorage`, the write-side counterpart of #561. 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

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

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (crates/xcl/src/hle/dstorage.rs) — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 11:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/705#issuecomment-7161664676) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** (`crates/xcl/src/hle/dstorage.rs`) — needs a rebase before it can be tested.
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/705/head:github-bot/gh-705'
git switch 'github-bot/gh-705'

Merge

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