startup: track a refused page request through the consumer view #1879

Merged
MasterDomino merged 1 commit from upstream-pr/1886 into main 2026-11-24 20:26:31 +00:00
MasterDomino commented 2026-11-24 20:10:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T20:10:39Z.


What

A source-built fixture, startup_storage_consumer_pair, that follows one refused page-destination DirectStorage request end to end (enqueue, completion status, fence, the first consumer read of its destination, and the release of its pages) next to a successful request of the same shape. This is the step asked for on #1198.

Why

Existing fixtures already cover parts of this:

  • #1664, startup_storage_refusal_order: enqueue, status and fence order for refused file-source reads into linear destinations, plus a poisoned destination.
  • #1672, startup_dstorage_destination: a refusal before any byte is written when a linear destination is not writable.
  • The dstorage case of startup_stubs (tests/startup_stub_consumer.cpp): a single short or missing-grant page request read through a mapped view, with one fill byte, no fence, no paired success and no release.

None of them pairs a success and a refusal of the same page shape in one Submit with distinct sentinels, reads the pages through the title's mapped view at each fence, and then releases and reuses them. This fixture adds that and uses the same checkpoints as #1664 (status value, fence after its own status entry, destination bytes).

Change

  • tests/startup_storage_consumer_pair.cpp (new). It loads the stand-in DLL and the xmem shim (as xmem.dll, X2W_XMEM_PERMISSIVE=1), takes two page tokens from XMemAllocatePhysicalPages, reserves a view with XMemVirtualAlloc(nullptr, 0x20000, 0x20402000, 0x21, PAGE_READWRITE) and maps the pages into it with XMemMapPhysicalPages. Every read goes through that view. Page writes go through x2w_xmem_write_physical, which the stand-in already uses.
    • One Submit: S and R, both zlib from memory, page_offset 0xF000, destination_size 0x1000 (ends exactly at the page end), one token each. S inflates to exactly 0x1000 bytes. R inflates to 0x1800 bytes and is refused as destination capacity exceeded. Each request is followed by its status entry and an EnqueueSignal fence.
    • Each page holds its own sentinel pattern before Submit. The fixture checks that the sentinels differ from each other and from both streams' bytes at every destination offset.
    • Checkpoints:
      1. Status: S S_OK, R E_FAIL.
      2. Fence order: each fence runs after its own status entry and before the next request's status entry. Positions are 1, 2 and 3.
      3. Consumer read in each fence callback and again on the test thread after both fences:
        • S's page: sentinel below 0xF000, exact inflated bytes from 0xF000.
        • R's page: every one of its 65536 bytes is still R's sentinel, and 0 bytes of R's destination equal R's stream prefix.
      4. Stand-in log: inflated for S, destination capacity exceeded for R.
      5. Release:
        • XMemMapPhysicalPages(view, 2, nullptr) unmaps and XMemFreePhysicalPages(2, …) frees; both succeed.
        • x2w_xmem_page_stats live backings drop by 2.
        • One page is allocated again and mapped at the same address (live backings +1). It reads zero-filled, so nothing of S or R carries over.
        • It gets a new sentinel, and a follow-up request of S's shape on the same queue completes S_OK with the exact bytes at its fence and after.
  • CMakeLists.txt: the test and its accept_refused_control.
  • docs/startup-runtime.md: a short entry after "DirectStorage page-request ends", with the command and what each checkpoint shows.

The stand-in (src/startup_stubs/xcrdapi.cpp) and the xmem shim are unchanged, and no outcome changes. Aggregate counters, address placement and XDsp are out of scope.

Tests

Built from upstream/main df40e4bc plus this commit. Windows 11 x64 (10.0.26300), MSVC dev preset.

cmake --preset dev -DINTAKE_PYTHON=D:/Repos/Xbox2Windows/out/pe-env/Scripts/python.exe
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_storage_consumer_pair' -V

2/2 passed: startup_storage_consumer_pair and startup_storage_consumer_pair_accept_refused_control. The main test prints:
S published its exact bytes at its fence; R reported E_FAIL and every byte of its page stayed its sentinel (no stream prefix) at its fence and after; the pages were unmapped and freed, and a follow-up of S's shape into a page allocated afterwards completed with exact bytes

ctest --preset dev --no-tests=error -R 'startup_storage|dstorage|startup_heartbeat|startup_triage' -j 4

19/19 passed.

ctest --preset dev -R '^startup_' -j 4

241 tests: 237 passed, 0 failed, 4 skipped. The skips are capability skips, not passes: startup_view_heap_hardware, startup_view_heap_warp, startup_logical_view_warp and startup_logical_view_hardware.

out/pe-env/Scripts/python.exe -B tests/docs_links_check.py      -> Checked 18 Markdown files and 376 links.
out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py   -> Checked 1327 tracked ... files: no bidirectional controls.

Negative controls

  • Registered control: startup_storage_consumer_pair_accept_refused_control (--mutate accept-refused). This consumer takes R's destination as data and expects R's stream prefix there instead of R's sentinel. The control passes only on that check's exact failure line (PASS_REGULAR_EXPRESSION, as dstorage_rfc1950_refusals_truncation_control does). Observed:
    FAIL: at R's fence: R destination taken as data differs from the stream prefix in 4096 byte(s), first at 0xf000
    FAIL: after both fences: R destination taken as data differs from the stream prefix in 4096 byte(s), first at 0xf000
    
  • Manual mutant (recorded, reverted): in execute_request, inside the decode_length > destination_capacity branch, the mutant writes the destination-sized prefix (0x1000 bytes from page_offset) through x2w_xmem_write_physical and then refuses as before. Steps: rebuild startup_stub_xcrdapi, then run ctest --preset dev --no-tests=error -R '^startup_storage_consumer_pair'. startup_storage_consumer_pair fails:
    FAIL: at R's fence: R page is not its sentinel in 4096 byte(s), first at 0xf000
    FAIL: at R's fence: R destination holds 4096 byte(s) of its stream prefix
    FAIL: after both fences: R page is not its sentinel in 4096 byte(s), first at 0xf000
    FAIL: after both fences: R destination holds 4096 byte(s) of its stream prefix
    
    The control also fails under this mutant, because R's prefix is then really there. After the revert both tests pass again.

Not covered

  • The title retest is done separately; it is not part of this PR.
  • The fixture shows what a consumer of the stand-in reads through the mapped view. It does not show what the title does with a refused request or whether it reads that destination.
  • Only memory-source zlib requests with one page token are used. Chunked file streams, BCPack and multi-page grants are covered elsewhere or not at all.

Refs #1198

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6590463734 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1886). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T20:10:39Z. --- ## What A source-built fixture, `startup_storage_consumer_pair`, that follows one refused page-destination DirectStorage request end to end (enqueue, completion status, fence, the first consumer read of its destination, and the release of its pages) next to a successful request of the same shape. This is the step asked for on #1198. ## Why Existing fixtures already cover parts of this: - #1664, `startup_storage_refusal_order`: enqueue, status and fence order for refused **file-source** reads into **linear** destinations, plus a poisoned destination. - #1672, `startup_dstorage_destination`: a refusal before any byte is written when a **linear** destination is not writable. - The `dstorage` case of `startup_stubs` (`tests/startup_stub_consumer.cpp`): a single short or missing-grant page request read through a mapped view, with one fill byte, no fence, no paired success and no release. None of them pairs a success and a refusal of the same page shape in one Submit with distinct sentinels, reads the pages through the title's mapped view at each fence, and then releases and reuses them. This fixture adds that and uses the same checkpoints as #1664 (status value, fence after its own status entry, destination bytes). ## Change - `tests/startup_storage_consumer_pair.cpp` (new). It loads the stand-in DLL and the xmem shim (as `xmem.dll`, `X2W_XMEM_PERMISSIVE=1`), takes two page tokens from `XMemAllocatePhysicalPages`, reserves a view with `XMemVirtualAlloc(nullptr, 0x20000, 0x20402000, 0x21, PAGE_READWRITE)` and maps the pages into it with `XMemMapPhysicalPages`. Every read goes through that view. Page writes go through `x2w_xmem_write_physical`, which the stand-in already uses. - One Submit: S and R, both zlib from memory, `page_offset` 0xF000, `destination_size` 0x1000 (ends exactly at the page end), one token each. S inflates to exactly 0x1000 bytes. R inflates to 0x1800 bytes and is refused as `destination capacity exceeded`. Each request is followed by its status entry and an `EnqueueSignal` fence. - Each page holds its own sentinel pattern before Submit. The fixture checks that the sentinels differ from each other and from both streams' bytes at every destination offset. - Checkpoints: 1. Status: S `S_OK`, R `E_FAIL`. 2. Fence order: each fence runs after its own status entry and before the next request's status entry. Positions are 1, 2 and 3. 3. Consumer read **in each fence callback** and again on the test thread after both fences: - S's page: sentinel below 0xF000, exact inflated bytes from 0xF000. - R's page: every one of its 65536 bytes is still R's sentinel, and 0 bytes of R's destination equal R's stream prefix. 4. Stand-in log: `inflated` for S, `destination capacity exceeded` for R. 5. Release: - `XMemMapPhysicalPages(view, 2, nullptr)` unmaps and `XMemFreePhysicalPages(2, …)` frees; both succeed. - `x2w_xmem_page_stats` live backings drop by 2. - One page is allocated again and mapped at the same address (live backings +1). It reads zero-filled, so nothing of S or R carries over. - It gets a new sentinel, and a follow-up request of S's shape on the same queue completes `S_OK` with the exact bytes at its fence and after. - `CMakeLists.txt`: the test and its `accept_refused_control`. - `docs/startup-runtime.md`: a short entry after "DirectStorage page-request ends", with the command and what each checkpoint shows. The stand-in (`src/startup_stubs/xcrdapi.cpp`) and the xmem shim are unchanged, and no outcome changes. Aggregate counters, address placement and XDsp are out of scope. ## Tests Built from upstream/main `df40e4bc` plus this commit. Windows 11 x64 (10.0.26300), MSVC dev preset. ``` cmake --preset dev -DINTAKE_PYTHON=D:/Repos/Xbox2Windows/out/pe-env/Scripts/python.exe cmake --build --preset dev ctest --preset dev --no-tests=error -R '^startup_storage_consumer_pair' -V ``` 2/2 passed: `startup_storage_consumer_pair` and `startup_storage_consumer_pair_accept_refused_control`. The main test prints: `S published its exact bytes at its fence; R reported E_FAIL and every byte of its page stayed its sentinel (no stream prefix) at its fence and after; the pages were unmapped and freed, and a follow-up of S's shape into a page allocated afterwards completed with exact bytes` ``` ctest --preset dev --no-tests=error -R 'startup_storage|dstorage|startup_heartbeat|startup_triage' -j 4 ``` 19/19 passed. ``` ctest --preset dev -R '^startup_' -j 4 ``` 241 tests: 237 passed, 0 failed, 4 skipped. The skips are capability skips, not passes: `startup_view_heap_hardware`, `startup_view_heap_warp`, `startup_logical_view_warp` and `startup_logical_view_hardware`. ``` out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Checked 18 Markdown files and 376 links. out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Checked 1327 tracked ... files: no bidirectional controls. ``` ## Negative controls - **Registered control:** `startup_storage_consumer_pair_accept_refused_control` (`--mutate accept-refused`). This consumer takes R's destination as data and expects R's stream prefix there instead of R's sentinel. The control passes only on that check's exact failure line (`PASS_REGULAR_EXPRESSION`, as `dstorage_rfc1950_refusals_truncation_control` does). Observed: ``` FAIL: at R's fence: R destination taken as data differs from the stream prefix in 4096 byte(s), first at 0xf000 FAIL: after both fences: R destination taken as data differs from the stream prefix in 4096 byte(s), first at 0xf000 ``` - **Manual mutant (recorded, reverted):** in `execute_request`, inside the `decode_length > destination_capacity` branch, the mutant writes the destination-sized prefix (0x1000 bytes from `page_offset`) through `x2w_xmem_write_physical` and then refuses as before. Steps: rebuild `startup_stub_xcrdapi`, then run `ctest --preset dev --no-tests=error -R '^startup_storage_consumer_pair'`. `startup_storage_consumer_pair` fails: ``` FAIL: at R's fence: R page is not its sentinel in 4096 byte(s), first at 0xf000 FAIL: at R's fence: R destination holds 4096 byte(s) of its stream prefix FAIL: after both fences: R page is not its sentinel in 4096 byte(s), first at 0xf000 FAIL: after both fences: R destination holds 4096 byte(s) of its stream prefix ``` The control also fails under this mutant, because R's prefix is then really there. After the revert both tests pass again. ## Not covered - The title retest is done separately; it is not part of this PR. - The fixture shows what a consumer of the stand-in reads through the mapped view. It does not show what the title does with a refused request or whether it reads that destination. - Only memory-source zlib requests with one page token are used. Chunked file streams, BCPack and multi-page grants are covered elsewhere or not at all. Refs #1198 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 21:01:08 +00:00
tedin7 commented 2026-11-24 21:01:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:25:21Z.

Review: COMMENTED


Reviewed head b5df528741ea3e0eda7d1fa20ce38899ad9c6f0a. No P1/P2 findings.

What it adds: a Windows-only fixture, startup_storage_consumer_pair, and a negative control, ..._accept_refused_control. The fixture sends two page-destination zlib requests that end at the first page's end. S completes and R is refused for capacity. Every read goes through an XMemMapPhysicalPages view, as a title would read it. It checks:

  • the status of each request (S_OK and E_FAIL);
  • fence order against the status entries, with a read inside each fence callback and another after both;
  • that R's page stays entirely its sentinel and holds no byte of its stream prefix;
  • the stand-in's log outcome for each request;
  • unmap and free, with the live page count dropping by two;
  • a zero-filled re-allocation, and a follow-up request that completes with exact bytes.

The sentinels are checked up front to differ from each other and from the data at every destination byte, so a sentinel byte can never pass as data. The CMake change only adds the target, the two tests and their properties. The control uses PASS_REGULAR_EXPRESSION on the exact failure text, so it fails for the right reason. The docs paragraph matches the fixture and says what it does not show. I saw no clean-room problem, and the diff touches no production code.

Linux commands run in a clean worktree:

  • git diff --check origin/main...HEAD -> rc 0
  • python -B tests/docs_links_check.py -> rc 0 (18 files, 376 links)
  • python -B tests/bidi_controls_check.py -> rc 0

Windows Server 2025 (MSVC 14.44, WARP), x2w_pipe.py win2025 at this exact head:

  • Debug (--preset dev): startup_storage_consumer_pair and startup_storage_consumer_pair_accept_refused_control, 2/2 passed.
  • Release /O2 (--preset release): 2/2 passed.

Mutations in src/startup_stubs/xcrdapi.cpp, applied as local patches on Win2025 and each reverted with git checkout -- .:

  1. Capacity refusal disabled -> startup_storage_consumer_pair FAILS (rc 1). The request falls to the "insufficient page grants" path, and the fixture reports R logged outcome "insufficient page grants", expected "destination capacity exceeded".
  2. The first 0x1000 inflated bytes written to R's page before the refusal, the mutant the docs describe -> startup_storage_consumer_pair FAILS (rc 1, Debug). The control also fails because its expected message no longer appears.

Notes, not blocking:

  • On early return 1 paths the fixture leaks the view and the temp log. This is harmless for a test process.

This is a review comment only, not an approval.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046803870 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1886#pullrequestreview-6046803870). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:25:21Z. **Review:** COMMENTED --- Reviewed head `b5df528741ea3e0eda7d1fa20ce38899ad9c6f0a`. No P1/P2 findings. What it adds: a Windows-only fixture, `startup_storage_consumer_pair`, and a negative control, `..._accept_refused_control`. The fixture sends two page-destination zlib requests that end at the first page's end. S completes and R is refused for capacity. Every read goes through an `XMemMapPhysicalPages` view, as a title would read it. It checks: - the status of each request (S_OK and E_FAIL); - fence order against the status entries, with a read inside each fence callback and another after both; - that R's page stays entirely its sentinel and holds no byte of its stream prefix; - the stand-in's log outcome for each request; - unmap and free, with the live page count dropping by two; - a zero-filled re-allocation, and a follow-up request that completes with exact bytes. The sentinels are checked up front to differ from each other and from the data at every destination byte, so a sentinel byte can never pass as data. The CMake change only adds the target, the two tests and their properties. The control uses `PASS_REGULAR_EXPRESSION` on the exact failure text, so it fails for the right reason. The docs paragraph matches the fixture and says what it does not show. I saw no clean-room problem, and the diff touches no production code. Linux commands run in a clean worktree: - `git diff --check origin/main...HEAD` -> rc 0 - `python -B tests/docs_links_check.py` -> rc 0 (18 files, 376 links) - `python -B tests/bidi_controls_check.py` -> rc 0 Windows Server 2025 (MSVC 14.44, WARP), `x2w_pipe.py win2025` at this exact head: - Debug (`--preset dev`): `startup_storage_consumer_pair` and `startup_storage_consumer_pair_accept_refused_control`, 2/2 passed. - Release `/O2` (`--preset release`): 2/2 passed. Mutations in `src/startup_stubs/xcrdapi.cpp`, applied as local patches on Win2025 and each reverted with `git checkout -- .`: 1. Capacity refusal disabled -> `startup_storage_consumer_pair` FAILS (rc 1). The request falls to the "insufficient page grants" path, and the fixture reports `R logged outcome "insufficient page grants", expected "destination capacity exceeded"`. 2. The first 0x1000 inflated bytes written to R's page before the refusal, the mutant the docs describe -> `startup_storage_consumer_pair` FAILS (rc 1, Debug). The control also fails because its expected message no longer appears. Notes, not blocking: - On early `return 1` paths the fixture leaks the view and the temp log. This is harmless for a test process. This is a review comment only, not an approval. AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!1879
No description provided.