DirectStorage: commit lazy pages before reading a source or page array #2349

Open
safesearch77 wants to merge 1 commit from upstream-pr/2359 into main
safesearch77 commented 2026-11-25 16:30:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by safesearch77 on 2026-11-25T16:30:10Z.


A physical page mapped while its contents are still zero is only reserved until its first use (kernelx::lazy): a CPU access faults it in, but a kernel call fails on it. DirectStorage commits its destinations first (writable() calls lazy::ensure), but not what it reads: read_own (ReadProcessMemory) reads the source and destination page arrays, and a virtual memory source is checked with gpu::shader::readable (VirtualQuery / QueryWorkingSetEx), which sees a lazy page as reserved. A request whose page array or memory source sits in a page the title has not touched yet fails with E_ACCESS_VIOLATION (0x89240009).

This complements #561 and does not overlap it: #561 changes how the memory source is copied (read_own instead of copy_nonoverlapping, for a source unmapped under the worker). This PR commits lazy pages before the check and the read. git apply --check of #561's patch on top of this branch succeeds. The race fix and its stress test are dropped from this PR and left to #561.

What is in it

  • crates/xcl/src/hle/dstorage.rs: read_own commits the lazy pages of its range (lazy::ensure) before ReadProcessMemory, and refuses a range that wraps. The memory-source branch of execute() calls lazy::ensure before readable(). A 0-byte source is still refused, as on main.
  • crates/xcl/src/hle/dstorage.rs (tests): a_memory_source_and_page_array_in_lazy_pages_are_read. It reads a memory source that spans a committed page and a lazy::marked one (expects S_OK, [0xA5; 8] then [0; 8]), and a page array in a lazy page (snapshot_page_array gives Ok(vec![0])). On main, both reach a reserved page and fail with E_ACCESS_VIOLATION.

Tested

  • Linux host, Rust from the repo toolchain, cross-checked for x86_64-pc-windows-gnu: cargo check --workspace --tests gave 0 errors. Its 3 warnings are in d3d12x/real.rs, xgameruntime/mod.rs and d3d12x/vram.rs, are already on main, and none are in dstorage.rs.
  • git diff --check: clean. 1 file, +73 / -0.
  • The test was not run: I have no Windows machine, so I make no claim that it passes or fails.

Regression run

  • None yet. The xcl-smoke blocks (main b49be183 and this head) have to come from a Windows run before this leaves draft.

Not tested

  • cargo test on Windows, including the new test (red on main, green here), and the rest of the dstorage tests.
  • Any retail title or GPU. I have no measurement of how often a title's page arrays or memory sources sit in untouched lazy pages.
  • Composing with #561 was checked with git apply --check only. The two were not built and tested together.

AI use

  • Antigravity (Claude Opus 5.5): traced the lazy-page paths on main, wrote the change, the test and this description.
<!-- greyfinch-sync:ivall/xcl:issue:5495138484 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359). Originally posted by [safesearch77](https://github.com/safesearch77) on 2026-11-25T16:30:10Z. --- A physical page mapped while its contents are still zero is only reserved until its first use (`kernelx::lazy`): a CPU access faults it in, but a kernel call fails on it. DirectStorage commits its destinations first (`writable()` calls `lazy::ensure`), but not what it reads: `read_own` (`ReadProcessMemory`) reads the source and destination page arrays, and a virtual memory source is checked with `gpu::shader::readable` (`VirtualQuery` / `QueryWorkingSetEx`), which sees a lazy page as reserved. A request whose page array or memory source sits in a page the title has not touched yet fails with `E_ACCESS_VIOLATION` (`0x89240009`). This complements #561 and does not overlap it: #561 changes how the memory source is *copied* (`read_own` instead of `copy_nonoverlapping`, for a source unmapped under the worker). This PR commits lazy pages *before* the check and the read. `git apply --check` of #561's patch on top of this branch succeeds. The race fix and its stress test are dropped from this PR and left to #561. **What is in it** - `crates/xcl/src/hle/dstorage.rs`: `read_own` commits the lazy pages of its range (`lazy::ensure`) before `ReadProcessMemory`, and refuses a range that wraps. The memory-source branch of `execute()` calls `lazy::ensure` before `readable()`. A 0-byte source is still refused, as on main. - `crates/xcl/src/hle/dstorage.rs` (tests): `a_memory_source_and_page_array_in_lazy_pages_are_read`. It reads a memory source that spans a committed page and a `lazy::mark`ed one (expects `S_OK`, `[0xA5; 8]` then `[0; 8]`), and a page array in a lazy page (`snapshot_page_array` gives `Ok(vec![0])`). On main, both reach a reserved page and fail with `E_ACCESS_VIOLATION`. **Tested** - Linux host, Rust from the repo toolchain, cross-checked for `x86_64-pc-windows-gnu`: `cargo check --workspace --tests` gave 0 errors. Its 3 warnings are in `d3d12x/real.rs`, `xgameruntime/mod.rs` and `d3d12x/vram.rs`, are already on main, and none are in `dstorage.rs`. - `git diff --check`: clean. 1 file, +73 / -0. - The test was not run: I have no Windows machine, so I make no claim that it passes or fails. **Regression run** - None yet. The `xcl-smoke` blocks (main `b49be183` and this head) have to come from a Windows run before this leaves draft. **Not tested** - `cargo test` on Windows, including the new test (red on main, green here), and the rest of the `dstorage` tests. - Any retail title or GPU. I have no measurement of how often a title's page arrays or memory sources sit in untouched lazy pages. - Composing with #561 was checked with `git apply --check` only. The two were not built and tested together. **AI use** - Antigravity (Claude Opus 5.5): traced the lazy-page paths on main, wrote the change, the test and this description.
alexmircea1299 commented 2026-11-25 18:04:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by alexmircea1299 on 2026-11-25T17:42:36Z.


Tested commit 94fae46 on Windows:

Environment

  • OS: Windows 11
  • GPU: NVIDIA GeForce RTX 5070 (12 GB VRAM, driver 621.35, wave32)
  • DXC: 1.8.2502.11 (Windows SDK 10.0.26100.0)

Results

  • hle::dstorage tests (cargo test -p xcl --lib dstorage): 32 passed, 0 failed.
  • Full library test suite (.\scripts\test.ps1): 1201 passed, 4 failed, 26 ignored — the 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState E_OUTOFMEMORY 0x8007000E on this NVIDIA driver during the full single-process run).
  • GPU tests skipped on this adapter:
    • 13 (no wave64)
    • 3 (wave32, per-lane form: refused (unsupported V_CVT_F16_F32 / V_MUL_F16 / V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)))
    • 1 (cannot disable the driver cache (Windows Developer Mode is required): 0x887A002D)
<!-- greyfinch-sync:ivall/xcl:comment:7169888511 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#issuecomment-7169888511). Originally posted by [alexmircea1299](https://github.com/alexmircea1299) on 2026-11-25T17:42:36Z. --- Tested commit `94fae46` on Windows: ### Environment * **OS:** Windows 11 * **GPU:** NVIDIA GeForce RTX 5070 (12 GB VRAM, driver `621.35`, `wave32`) * **DXC:** `1.8.2502.11` (Windows SDK `10.0.26100.0`) ### Results * **`hle::dstorage` tests (`cargo test -p xcl --lib dstorage`):** **32 passed, 0 failed**. * **Full library test suite (`.\scripts\test.ps1`):** **1201 passed, 4 failed, 26 ignored** — the 4 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3` (`CreateComputePipelineState` `E_OUTOFMEMORY` `0x8007000E` on this NVIDIA driver during the full single-process run). * **GPU tests skipped on this adapter:** * `13` (`no wave64`) * `3` (`wave32, per-lane form: refused (unsupported V_CVT_F16_F32 / V_MUL_F16 / V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))`) * `1` (`cannot disable the driver cache (Windows Developer Mode is required): 0x887A002D`)
DavidM1911 commented 2026-11-25 19:09:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T18:37:36Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7171168816 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#issuecomment-7171168816). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T18:37:36Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
SlopTart commented 2026-11-25 19:09:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T19:06:03Z.


Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).
suite: 144/3 = the three known baseline failures on this lane (fuzz_validate_and_gpu_2 seed 1003, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed). Targeted run of the new memory-source/page-array tests: 2 passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7171819295 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#issuecomment-7171819295). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-25T19:06:03Z. --- **Tested**: current PR head merged onto current `origin/main` (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29). suite: 144/3 = the three known baseline failures on this lane (`fuzz_validate_and_gpu_2` seed 1003, `gpu_nonfused_mad_and_mac_prevent_fma_contraction`, `gpu_depth_buffer_created_for_unordered_access_is_placed`). Targeted run of the new memory-source/page-array tests: 2 passed. **Not tested**: retail titles (no title data on this lane, counts only). **AI use**: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
bmjask commented 2026-11-25 20:26:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:26:21Z.

Review: COMMENTED


No concrete code defect found. The change safely commits lazy pages before kernel reads and replaces unsafe worker-thread raw copies with ReadProcessMemory. It is not merge-ready: the current head has no Windows build/test or required smoke-pair evidence, only a failed PR-description check. Please provide those, and consider coverage for multi-page lazy sources, a real >256 MiB source, and byte-integrity assertions during the decommit race.

<!-- greyfinch-sync:ivall/xcl:review:6064470374 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#pullrequestreview-6064470374). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T20:26:21Z. **Review:** COMMENTED --- No concrete code defect found. The change safely commits lazy pages before kernel reads and replaces unsafe worker-thread raw copies with ReadProcessMemory. It is not merge-ready: the current head has no Windows build/test or required smoke-pair evidence, only a failed PR-description check. Please provide those, and consider coverage for multi-page lazy sources, a real >256 MiB source, and byte-integrity assertions during the decommit race.
throny commented 2026-11-26 03:06:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-26T02:18:18Z.


Two contributors checked independently and found that #561 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.

<!-- greyfinch-sync:ivall/xcl:comment:7180670330 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#issuecomment-7180670330). Originally posted by [throny](https://github.com/throny) on 2026-11-26T02:18:18Z. --- <!-- xcl-1607-hint:D115 --> Two contributors checked independently and found that #561 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.
upstream-sync changed title from [PR #2359] DirectStorage: read memory sources and lazy pages through read_own to [PR #2359] DirectStorage: commit lazy pages before reading a source or page array 2026-11-26 15:03:00 +00:00
safesearch77 commented 2026-11-26 15:03:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by safesearch77 on 2026-11-26T14:07:31Z.


Rebased onto b49be183 and narrowed to 520c259a (+73 / -0 in dstorage.rs), keeping only kernelx::lazy::ensure before read_own and readable() so this PR composes cleanly with #561 (git apply --check passes with zero overlap on #561's read_own copy change, re #1607 D115). Remains in Draft pending a Windows GPU suite and scripts/smoke.ps1 pair.

AI use: Antigravity (Claude Opus 5.5)

<!-- greyfinch-sync:ivall/xcl:comment:7194312386 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#issuecomment-7194312386). Originally posted by [safesearch77](https://github.com/safesearch77) on 2026-11-26T14:07:31Z. --- Rebased onto `b49be183` and narrowed to `520c259a` (`+73 / -0` in `dstorage.rs`), keeping only `kernelx::lazy::ensure` before `read_own` and `readable()` so this PR composes cleanly with #561 (`git apply --check` passes with zero overlap on #561's `read_own` copy change, re `#1607` `D115`). Remains in Draft pending a Windows GPU suite and `scripts/smoke.ps1` pair. AI use: Antigravity (Claude Opus 5.5)
github-actions[bot] commented 2026-12-01 02:34:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:34:37Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298764440 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#issuecomment-7298764440). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:34:37Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:55:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:55:16Z.


Triage (#1607) – head 520c259

#671 fixes the same problem (lazy pages under a memory source or page array fail readable / ReadProcessMemory) another way: it adds lazy::prepare_read and retries after a failed read, where this PR calls the existing lazy::ensure before checking or reading. #561 only replaces the memory-source copy with read_own, which is a different change.
Main commits lazy pages for the destination (writable) but still not in read_own or before the source readable check, so this PR is still needed.
Main now reads a memory source through cpu_range (at), not r.source. When rebasing, ensure should cover at, the address that is actually checked and read.
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:7304647959 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2359#issuecomment-7304647959). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:55:16Z. --- **Triage (#1607)** – head 520c259 #671 fixes the same problem (lazy pages under a memory source or page array fail `readable` / `ReadProcessMemory`) another way: it adds `lazy::prepare_read` and retries after a failed read, where this PR calls the existing `lazy::ensure` before checking or reading. #561 only replaces the memory-source copy with `read_own`, which is a different change. Main commits lazy pages for the destination (`writable`) but still not in `read_own` or before the source `readable` check, so this PR is still needed. Main now reads a memory source through `cpu_range` (`at`), not `r.source`. When rebasing, `ensure` should cover `at`, the address that is actually checked and read. 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/2359:upstream-pr/2359'
git switch 'upstream-pr/2359'

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/2359'
git switch 'upstream-pr/2359'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2359'
git switch 'upstream-pr/2359'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2359'
git switch 'main'
git merge --squash 'upstream-pr/2359'
git switch 'main'
git merge --ff-only 'upstream-pr/2359'
git switch 'main'
git merge 'upstream-pr/2359'
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!2349
No description provided.