startup: read the whole destination page array when a storage request runs #1408
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1415"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-24T11:01:32Z.
Change
src/startup_stubs/xcrdapi.cpp: a DirectStorage request with page destinations (option bit 21) captured the title's page-array entries atEnqueueRequest, andrun_entryrefreshed only the entries that were still 0. The executable also replaces entries it filled earlier, between enqueue and execution. Data for those entries was written through the token captured at enqueue, into a page the title had already given to something else.run_entrynow reads every entry of the title's page array again when the request runs. A changed non-zero entry is counted, and the heartbeat reports it:docs/startup-runtime.md(DirectStorage ordering) is updated to say the whole array is re-read.Measurement
Local runs of the executable on Windows 11 26300, RX 9070 XT, release build, same switches in every run:
This is a run-time observation on one executable, not a fixture. The heartbeat counter lets another contributor see whether their title replaces entries too.
Tests
Updated for the review commit (
12864bdb): see the review reply for thedstorage-pagescases and their negative controls.ctest --test-dir out/build/check --no-tests=error -j 6(Release, Ninja, MSVC 19.50, Windows 11 26300, RX 9070 XT, debug layer off), on this branch rebased onto429a8b92:startup_*, storage and XCRDAPI test (112).dxr_placed_build_hardware,dxr_opacity_hardware,gpu_alias_lookup_writes_hardware,cpu_placed_dxr_hardwareandpixel_aot_comparisons_hardware. None of them loads the XCRDAPI stand-in, and the three that exist in an older build (before #1135) fail the same way on this adapter. The pixel comparison differs in the low mantissa bits of denormal results.cpu_exe_aot_convertpasses whenINCLUDE/LIBare set for its run-timecl.execall. It fails without them, which is a shell setup issue only.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:10:33Z.
Review: CHANGES_REQUESTED
The replacement counts and loading runs help isolate this. Please add a source-built queue test that changes a nonzero destination entry between EnqueueRequest and Submit, then checks the new page receives the data and the old page retains its sentinel. There is still a stale-write path in run_entry: if the page array or an entry cannot be read at execution, the loop can retain the old captured token. Please fail that request before writing any destination pages, and cover the failure and a following valid request. Document the caller requirement to keep the array readable and stable while the worker snapshots it.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:16:13Z.
Review: COMMENTED
Reviewed and verified at
dc16b29bed3895a675a2b1205c6423820f0ff23a:git diff --check origin/main...HEADis clean.pagesis computed instd::size_t(xcrdapi.cpp:671) andexecute_requestchecksneeded_pages > granted_pagesand zero tokens beforex2w_xmem_write_physical. However, two gaps remain (aligning with the open change request):run_entry(xcrdapi.cpp:574-580), iftitleis null orx2w_local::readable(title + i, sizeof(ULONG_PTR))returns false at execution time,entry.tokens[i]retains the stale token captured atEnqueueRequestinstead of failing the request before any destination write.EnqueueRequestandSubmit(or the unreadable-array failure + subsequent valid request).docs_links_check.py(16 Markdown files, 322 links) andbidi_controls_check.py(1181 tracked files) passed.--preset dev):ctest --preset dev -R '^(startup_stubs|startup_storage_directory_batch|startup_storage_file_range)$'3/3 passed (0.48s)./O2(--preset release): 3/3 passed (0.53s). (Note: existing tests pass, but do not yet cover mid-flight non-zero token replacement.)Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-24T11:40:51Z.
Thanks, both points are addressed in the new commit.
Stale-write path.
run_entrynow checks that the whole page array is readable before it copies it. If it is not (null pointer, or any part unreadable), the request fails withE_FAILbeforeexecute_requestruns, so no destination page is written and no token captured at enqueue is used. Otherwise the array is copied once into the entry, and the replaced and zero counters come from that copy.docs/startup-runtime.mdnow says the caller has to keep the array readable and unchanged once the request is submitted.Source-built queue test.
startup_stub_consumer dstorage-pagesruns fromstartup_stubs(tests/startup_stub_check.py). Each of three physical pages has its own view and is filled with a sentinel first.replaced: a two-page request is enqueued with{page 0, page 1}, and entry 1 is replaced with page 2 beforeSubmit. It checks that page 0 and page 2 hold the data, page 1 keeps its sentinel, and the status isS_OK.unreadable: a two-page request whose array is then madePAGE_NOACCESS, followed on the same queue by a valid one-page request into page 2. It checks that the first status is a failure, pages 0 and 1 keep their sentinel, the second status isS_OK, and page 2 holds the data.Results at
12864bdb(Release, Ninja, MSVC 19.50, Windows 11 26300, RX 9070 XT, debug layer off):ctest --test-dir out/build/check --no-tests=error -R '^startup_|storage|xcrdapi|dstorage': 105 tests, 0 failed. Four are capability skips (startup_view_heap_warp/hardware,startup_logical_view_warp/hardware), the same as before this change.startup_stubsoutput:xcrdapi.cppswapped and the new test kept:dc16b29b):unreadable: failed request hr=0x00000000, pages WRITTEN, so the test fails.main:replaced: ... new page WRONG, old page WRITTEN, so the test fails.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:03:38Z.
Review: APPROVED
Windows Release startup_stubs passed on this head. It observed a replaced nonzero token writing to the new page with the old sentinel unchanged. The unreadable-array case returns E_FAIL without changing either page, and the next request succeeds.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T14:10:12Z.
Heads-up: the page-array control this PR added is failing on current
main(a3633d4d), and because the startup stand-in checks are not in CI (#1149 is still open) it is red without anyone seeing it.Reproduction on a clean tree, no local changes:
The scenario itself prints the mismatch:
That is the
replacedcase fromdstorage_page_array_checks(): a non-zero entry is reassigned betweenEnqueueRequestandSubmit, and the expectation is that the new page receives the data while the old page keeps its sentinel. What I observe is the opposite — the old page is written — which is the exact failure mode the change inrun_entrywas meant to prevent: it re-reads the whole array at run time (std::vector<ULONG_PTR> now(title, title + entry.tokens.size())) and countstokens_replaced_after_enqueue.Two things I could not settle from the outside, so I am not proposing a fix:
run_entryrefreshesentry.tokens, but if the page-to-address resolution happens earlier (or is cached per entry), the refreshed tokens would not reach the write.startup_stubsfails the same way onorigin/maindetached, so this is not something local to a branch.store context: exit=2looks like a separate, older failure in the same test — a consumer that rejects the scenario argument — so it may just need the consumer rebuilt; I rebuilt mine and the page-array failure remained.If it helps, the reproduction is
ctest --preset dev --no-tests=error -R '^startup_stubs$' -Vaftercmake --build --preset dev --target startup_stub_consumer xg_xs d3d12_xs_shim xmem.Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T14:19:17Z.
Correction — this was my workspace, not this change. With the stand-ins rebuilt, the page-array control passes on current
main:Cause of the false alarm: my build directory held a stale
XCRDAPI.dll.ctestdoes not build anything, and I had rebuiltstartup_stub_consumer(and some shims) after syncingmainbut notstartup_stub_xcrdapi. The stale DLL still had the pre-run_entrybehaviour — pages read from the enqueue-time snapshot — which is exactly the symptom I reported: "new page WRONG, old page WRITTEN". Oncestartup_stub_xcrdapiwas rebuilt, the re-readenqueue=0x20 run=0x30is visible and the replacement lands on the new page.With the debug line I added to confirm it, the log shows the intended behaviour directly:
So: the
replacedandunreadablecases both behave as this PR intended, and I should not have reported them as failing. Sorry for the noise — the two hypotheses I offered were both wrong because the third possibility (stale artifact) never occurred to me.One thing that may still be worth acting on:
startup_stubstakes DLL paths from the build tree, so a stale shim fakes a failure exactly like a real regression. That is a sharp edge for anyone bisecting locally, but it is not this PR's problem and I am not proposing a change to the test here.I have reverted my local debug line; nothing in this PR or the tree needs changing on account of my report.