Skip to content

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

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
requiemsnkrp:dstorage-deferred-page-array-read
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
requiemsnkrp:dstorage-deferred-page-array-read

Conversation

@requiemsnkrp

@requiemsnkrp requiemsnkrp commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

…xcl-dev#476)

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

An array the title frees and reuses before the request's turn cannot be
told from a late fill; the title keeps it until the request is done, as
the comment now says.

The test runs 20000 requests with a deferred entry while another thread
decommits and recommits the array's page: before, the test process ended
with 0xc0000005 (5 of 5 runs); after, it passes (10 of 10).

Fixes xcl-dev#476

Assisted-by: Claude Code (Claude Opus 5.5)
Prime1997 pushed a commit to Prime1997/xcl-compat-fixes that referenced this pull request Nov 24, 2026
Port xcl-dev/xcl#509 from 3724b07170bd2ad3f689cbcfa2006a718b4443ea, including the concurrent decommit regression. Keep this integration's single-stage BCPack support.
@brothernog

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor Author

@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

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

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.

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
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)
@raylitebull

Copy link
Copy Markdown
Member

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.

@raylitebull
raylitebull merged commit db6d692 into xcl-dev:main Nov 25, 2026
4 checks passed
raylitebull added a commit to raylitebull/xcl that referenced this pull request Nov 25, 2026
…ility

- kernelx: keep plain XMemVirtualAlloc/physical fallbacks below the 40-bit VA
  ceiling via VirtualAlloc2 when available; stop large AllocateTitlePhysicalPages
  pools from stealing pre-committed coherent UMA; skip committing lazy/unmapped
  pages on read_physical_pages while ensuring lazy pages before writes; unmark
  freed lazy pages in FreeTitlePhysicalPages. (XMemIsToolsMemAvailable is
  already on main via xcl-dev#563.)
- dstorage: refresh zero or stale (freed) physical page-table entries via
  read_own (xcl-dev#476/xcl-dev#509 safe) on write/read retry; extend the parallel
  decompression pool to handle physical-page destinations and supported BCPack
  requests.
- gameinput & kbm: skip disconnected-pad XInput rumble stalls and deduplicate
  unchanged motor speeds; implement bounded reading history for GetNextReading /
  GetPreviousReading; extend XCL_PRESS_AT with triggers, sticks, LS/RS, and
  optional durations; add Z/C holdable bumper keys, require mouse capture and
  non-sizing for mouse buttons, and guard KBM mouse velocity against sub-0.5 ms
  zero-delta poll decay.
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.

DirectStorage: a deferred page-array entry is reread from title memory the title may have freed (#289)

4 participants