DirectStorage: a virtual destination is written without faulting #700

Open
requiemsnkrp wants to merge 1 commit from upstream-pr/705 into main
requiemsnkrp commented 2026-11-24 03:55:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by requiemsnkrp on 2026-11-24T03:55:58Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6574254802 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/705). Originally posted by [requiemsnkrp](https://github.com/requiemsnkrp) on 2026-11-24T03:55:58Z. --- `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.
ethandepstein-del commented 2026-11-24 07:06:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ethandepstein-del on 2026-11-24T04:05:43Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7121701304 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/705#issuecomment-7121701304). Originally posted by [ethandepstein-del](https://github.com/ethandepstein-del) on 2026-11-24T04:05:43Z. --- 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.*
lordon1a commented 2026-11-24 07:06:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by lordon1a on 2026-11-24T04:07:48Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7121733259 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/705#issuecomment-7121733259). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T04:07:48Z. --- 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.
MesshM commented 2026-11-24 07:06:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T04:08:02Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7121736969 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/705#issuecomment-7121736969). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T04:08:02Z. --- 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.
DavidM1911 commented 2026-11-25 12:06:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T11:54:32Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7161664676 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/705#issuecomment-7161664676). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T11:54:32Z. --- 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.
Foniass commented 2026-12-01 03:58:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:58:47Z.


Triage (#1607) – head d09f285

#561 (same author) fixes the source side of the same race; this PR fixes the destination side, so they do not overlap. Main has since added write_title (NtWriteVirtualMemory) in dstorage.rs, but only for destinations in the sparse windows; other virtual destinations are still written with copy_nonoverlapping in execute, so this change is not on main.
On rebase, reuse main's write_title instead of declaring a third NtWriteVirtualMemory (main has one in dstorage.rs and one in dstorage/parallel.rs). The PR conflicts with main.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7300254662 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/705#issuecomment-7300254662). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:58:47Z. --- **Triage (#1607)** – head d09f285 #561 (same author) fixes the source side of the same race; this PR fixes the destination side, so they do not overlap. Main has since added `write_title` (NtWriteVirtualMemory) in `dstorage.rs`, but only for destinations in the sparse windows; other virtual destinations are still written with `copy_nonoverlapping` in `execute`, so this change is not on main. On rebase, reuse main's `write_title` instead of declaring a third `NtWriteVirtualMemory` (main has one in `dstorage.rs` and one in `dstorage/parallel.rs`). The PR conflicts with main. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/705:upstream-pr/705'
git switch 'upstream-pr/705'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/705'
git switch 'upstream-pr/705'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/705'
git switch 'upstream-pr/705'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/705'
git switch 'main'
git merge --squash 'upstream-pr/705'
git switch 'main'
git merge --ff-only 'upstream-pr/705'
git switch 'main'
git merge 'upstream-pr/705'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!700
No description provided.