Skip to content

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

Merged
tedin7 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/storage-consumer-pair
Nov 24, 2026
Merged

tedin7 merged 1 commit into
R0Y00:mainfrom
MasterDomino:startup/storage-consumer-pair

Conversation

@MasterDomino

Copy link
Copy Markdown
Collaborator

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:

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

Add startup_storage_consumer_pair: one Submit with a matched pair of
page-destination zlib requests (page_offset 0xF000, destination_size
0x1000, ending at the first page's end). S inflates to exactly 0x1000
bytes; R inflates to 0x1800 and is refused for capacity. Each page has a
distinct sentinel, each request its status entry and fence.

The test maps the pages with XMemVirtualAlloc + XMemMapPhysicalPages
from the xmem shim (X2W_XMEM_PERMISSIVE) and reads through that view at
each fence and after both: S shows the exact bytes, every byte of R's
page stays its sentinel and none equals R's stream prefix. The pages are
then unmapped and freed, one is allocated again, and a follow-up of S's
shape on the same queue completes with exact bytes.

accept_refused_control expects R's stream prefix and must print that
check's failure. A manual mutant writing R's prefix before the refusal
fails the fixture on R's sentinel (recorded, reverted). The stand-in is
unchanged.

Refs R0Y00#1198

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tedin7
tedin7 merged commit 8a03d2a into R0Y00:main Nov 24, 2026
5 checks passed
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.

2 participants