DirectStorage: a deferred page-array entry is reread without faulting (#476) #504

Merged
requiemsnkrp merged 1 commit from upstream-pr/509 into main 2026-11-25 01:06:08 +00:00
requiemsnkrp commented 2026-11-24 01:07:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by requiemsnkrp on 2026-11-24T01:07:06Z.


A destination page-array entry that is 0 at EnqueueRequest is read again at the request's turn (#289). That read checked readable() and then dereferenced the title's memory. If the title unmapped the array between the two, the read faulted in the xcl-dstorage worker and ended the process. It now reads with read_own (ReadProcessMemory), as the enqueue-time snapshot already does, so the request fails with E_ACCESS_VIOLATION instead. Fixes #476.

An array that is freed and reused before the request's turn cannot be told from a late fill. The title keeps it until the request is done; the comment now says so.

What is in it

  • crates/xcl/src/hle/dstorage.rs, execute: the deferred entries are read with read_own; if that read fails, the request keeps its 0 entries and fails as before
  • crates/xcl/src/hle/dstorage.rs, tests: a_deferred_page_array_unmapped_under_the_worker_fails_the_request runs 20000 requests with a deferred entry while another thread decommits and recommits the array's 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 on main 2997c9a, 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 3724b07: 677 passed, 0 failed, 41 ignored (main 2997c9a on the same machine: 676 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: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 564 (PresentX 564)
presents per 2 s (last 3): 7 7 7
device removals: 0
crashes: 0
peak commit: 14956 MB

PR:

xcl-smoke v1
commit: 3724b07170bd2ad3f689cbcfa2006a718b4443ea
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 597 (PresentX 597)
presents per 2 s (last 3): 7 6 7
device removals: 0
crashes: 0
peak commit: 15078 MB

Not tested

  • whether the title reaches the changed path in those 60 s: none of the requests XCL logs (the first 16, then powers of two) had a physical-page destination, so the regression run checks only that nothing else changed
  • AMD / Intel GPUs; a longer run of the title

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:6572253808 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/509). Originally posted by [requiemsnkrp](https://github.com/requiemsnkrp) on 2026-11-24T01:07:06Z. --- A destination page-array entry that is 0 at EnqueueRequest is read again at the request's turn (#289). That read checked `readable()` and then dereferenced the title's memory. If the title unmapped the array between the two, the read faulted in the `xcl-dstorage` worker and ended the process. It now reads with `read_own` (`ReadProcessMemory`), as the enqueue-time snapshot already does, so the request fails with `E_ACCESS_VIOLATION` instead. Fixes #476. An array that is freed and reused before the request's turn cannot be told from a late fill. The title keeps it until the request is done; the comment now says so. **What is in it** - `crates/xcl/src/hle/dstorage.rs`, `execute`: the deferred entries are read with `read_own`; if that read fails, the request keeps its 0 entries and fails as before - `crates/xcl/src/hle/dstorage.rs`, tests: `a_deferred_page_array_unmapped_under_the_worker_fails_the_request` runs 20000 requests with a deferred entry while another thread decommits and recommits the array's 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 on `main` 2997c9a, 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 3724b07: 677 passed, 0 failed, 41 ignored (main 2997c9a on the same machine: 676 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: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21 gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 564 (PresentX 564) presents per 2 s (last 3): 7 7 7 device removals: 0 crashes: 0 peak commit: 14956 MB ``` PR: ``` xcl-smoke v1 commit: 3724b07170bd2ad3f689cbcfa2006a718b4443ea gpu: NVIDIA GeForce RTX 3060 title: 2c508222 seconds: 60 exit: 0x0 frames shown: 597 (PresentX 597) presents per 2 s (last 3): 7 6 7 device removals: 0 crashes: 0 peak commit: 15078 MB ``` **Not tested** - whether the title reaches the changed path in those 60 s: none of the requests XCL logs (the first 16, then powers of two) had a physical-page destination, so the regression run checks only that nothing else changed - AMD / Intel GPUs; a longer run of the title **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.
brothernog commented 2026-11-24 07:05:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by brothernog on 2026-11-24T01:42:46Z.


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

  • a_deferred_page_array_unmapped_under_the_worker_fails_the_request: 5 of 5 passed. With only the execute hunk reverted to the old readable() + read_unaligned, 3 of 3 runs ended in 0xc0000005 STATUS_ACCESS_VIOLATION.
  • cargo test -p xcl --lib hle::dstorage: 14 passed.
  • cargo build --workspace then cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

A sibling with the same check-then-read shape is in the same function. A memory source is checked with crate::gpu::shader::readable and then copied with copy_nonoverlapping from title memory on the worker thread (dstorage.rs:801-806 on this head). If a title frees the source before the request's turn, that copy faults in xcl-dstorage just like #476 did. read_own there would turn it into E_ACCESS_VIOLATION too, whether in this PR or in a follow-up. I didn't find an open PR that covers it.

This review was AI-assisted.

<!-- greyfinch-sync:ivall/xcl:comment:7119372642 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/509#issuecomment-7119372642). Originally posted by [brothernog](https://github.com/brothernog) on 2026-11-24T01:42:46Z. --- Tested `3724b07` on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug: - `a_deferred_page_array_unmapped_under_the_worker_fails_the_request`: 5 of 5 passed. With only the `execute` hunk reverted to the old `readable()` + `read_unaligned`, 3 of 3 runs ended in `0xc0000005 STATUS_ACCESS_VIOLATION`. - `cargo test -p xcl --lib hle::dstorage`: 14 passed. - `cargo build --workspace` then `cargo test --workspace --no-fail-fast -- --test-threads=4`: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. A sibling with the same check-then-read shape is in the same function. A memory source is checked with `crate::gpu::shader::readable` and then copied with `copy_nonoverlapping` from title memory on the worker thread (`dstorage.rs:801-806` on this head). If a title frees the source before the request's turn, that copy faults in `xcl-dstorage` just like #476 did. `read_own` there would turn it into `E_ACCESS_VIOLATION` too, whether in this PR or in a follow-up. I didn't find an open PR that covers it. This review was AI-assisted.
requiemsnkrp commented 2026-11-24 07:05:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by requiemsnkrp on 2026-11-24T01:50:47Z.


@brothernog thanks for the independent run, and for the memory-source copy: you were right. Same shape, same fault: the new test on main 508a0c7 ended with 0xc0000005 in 5 of 5 runs before the change and passed 10 of 10 after. I kept it out of this PR (one problem per PR) and opened #561. It is branched from main and does not depend on this one.

Written with Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7119500991 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/509#issuecomment-7119500991). Originally posted by [requiemsnkrp](https://github.com/requiemsnkrp) on 2026-11-24T01:50:47Z. --- @brothernog thanks for the independent run, and for the memory-source copy: you were right. Same shape, same fault: the new test on `main` 508a0c7 ended with `0xc0000005` in 5 of 5 runs before the change and passed 10 of 10 after. I kept it out of this PR (one problem per PR) and opened #561. It is branched from `main` and does not depend on this one. _Written with Claude Code (Claude Opus 5.5)._
MesshM commented 2026-11-24 07:06:12 +00:00 (Migrated from github.com)

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


Test run of 3724b07170bd2ad3f689cbcfa2006a718b4443ea 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), 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_deferred_page_array_unmapped_under_the_worker_fails_the_request passes.

Review: Rereading the deferred entries with read_own (ReadProcessMemory) instead of readable() + a raw read means an array unmapped between the two no longer faults in xcl-dstorage; when the read fails the enqueue-time snapshot is used. Same pattern as #561 and #705. 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:7121943292 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/509#issuecomment-7121943292). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T04:21:26Z. --- Test run of `3724b07170bd2ad3f689cbcfa2006a718b4443ea` 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), 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_deferred_page_array_unmapped_under_the_worker_fails_the_request` passes. **Review:** Rereading the deferred entries with `read_own` (`ReadProcessMemory`) instead of `readable()` + a raw read means an array unmapped between the two no longer faults in `xcl-dstorage`; when the read fails the enqueue-time snapshot is used. Same pattern as #561 and #705. 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.
upstream-sync closed this pull request 2026-11-25 01:08:36 +00:00
raylitebull commented 2026-11-25 01:10:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T00:56:46Z.


Diff check on 3724b07:

  • Replacing readable() + read_unaligned() with read_own() in dstorage::execute cleanly prevents access violations when a deferred (0) page-array entry is decommitted before the worker rereads it, and a_deferred_page_array_unmapped_under_the_worker_fails_the_request directly covers the race.
  • Already verified across both AMD (RX 9060 XT) and NVIDIA (RTX 3050), with PR description passing.

Next step to unblock merge: Please rebase onto current main (or push an updated commit) so CI runs Build and test (Windows, no GPU) on the head.

<!-- greyfinch-sync:ivall/xcl:comment:7149050407 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/509#issuecomment-7149050407). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-25T00:56:46Z. --- Diff check on `3724b07`: - Replacing `readable()` + `read_unaligned()` with `read_own()` in `dstorage::execute` cleanly prevents access violations when a deferred (`0`) page-array entry is decommitted before the worker rereads it, and `a_deferred_page_array_unmapped_under_the_worker_fails_the_request` directly covers the race. - Already verified across both AMD (`RX 9060 XT`) and NVIDIA (`RTX 3050`), with `PR description` passing. **Next step to unblock merge:** Please rebase onto current `main` (or push an updated commit) so CI runs `Build and test (Windows, no GPU)` on the head.
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!504
No description provided.