kernelx: check section page liveness for DirectStorage #3075
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3075"
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 ivall/xcl. Originally posted by ZekkJJ on 2026-11-27T21:43:50Z.
Stacked on #3074 and the original section-alias stack in #2307 by @adiologydev. The focused commits are
cfe04f431eand4fdd282403. Focused diffDirectStorage rereads eligible destination page lists when a request runs. After enabling #2307, its liveness check still used the conventional page index. Valid section-backed IDs failed the check, so the worker used the old list and could write a successful request to the previous page. This follows the existing late-fill and stack snapshot contract from #1405.
What is in it
Check the section-backed page index in alias mode. Recover the individual-release bitmap from the historical section integration so freed IDs cannot pass validation while neighboring pages in the section are live.
Verify that a duplicate free leaves the neighboring allocation alive, a freed ID cannot be used for a new mapping or DirectStorage access, and an existing view retains its bytes until unmapped.
Resolve the source before unmapping the destination. Return the ordinary invalid-parameter error for a released ID and keep the old destination view intact. Serialize alias mapping and copy-back with physical-page and alias-space release so the private home view remains valid through Windows mapping and copy calls. Page-fault handlers can still acquire the state mutex.
Add deterministic cases for a source released after preflight, a multi-page rejection before the first destination changes, and duplicate releases at indices 63 and 64 in a 65-page block.
Tested
RTX 4060 Laptop GPU 8 GiB (driver
32.0.16.1656), Ryzen 7 8845HS, 16 GiB RAM, Windows 11 build 26200, Rust 1.98.1 MSVC.With
XCL_PAGE_ALIAS=1at parent785d7dc5533edc8577c9a8e8e221acd40d980d23,hle::dstorage::tests::a_destination_page_rewritten_after_enqueuefailed its 256-byte comparison. The updated page was still zero after the worker reported success.On
cfe04f431e6d9e0fdd18128064cbf546ee9fa747,cargo test -p xcl --lib hle::kernelx::alias::tests -- --test-threads=1 --nocapturegave 7 passed.cargo test -p xcl --lib hle::dstorage::tests -- --test-threads=1 --nocapturegave 19 passed, including the same byte comparison and the existing stack-snapshot assertions. Both usedXCL_PAGE_ALIAS=1, with 0 failures, ignored tests, or explicit capability skips.On review head
4fdd282403, the opt-in single-threaded alias suite passed 9 tests and DirectStorage passed 19 tests, with 0 failures, ignored tests, or explicit skips. Both new regressions passed. Only the focused library tests were rebuilt on this head.On the previous head
cfe04f431e, the clean release build passed. The complete workspace command with built fixtures reported 1,486 pass statuses, 1 failure, and 47 ignored. There were 27 explicit skip notices (21 missing wave64, 3 unsupported per-lane forms, 1 Developer Mode requirement, 1 missing heap-window capability, and 1 default-mode alias opt-in skip). The D32S8 VRAM fixture returned0x80004005in the threaded run, as it had on an initial run of the parent. It passed the isolated rerun on this head.Regression run
The Series S preflight for this review expired with 5178 MiB free RAM and 14637 MiB free commit, below the guarded thresholds of 6,600 and 18,000 MiB. The clean main release was ready for reuse. Fresh smoke blocks and the updated-head retail comparison remain pending.
The RTX 5070 Ti Prestream report is consistent with a resource field being left stale or overwritten by a wrong-page write. The reported base contains the same conventional-only liveness check, and a separate RTX 3090 capture tied stale DirectStorage page lists to garbage pointers, including the same +0x4da6315 breakpoint. The 5070 Ti run changed two switches and supplies no asset provenance or matching page history. Its cause remains unverified. Correlation would require the asset offset and expected bytes, the enqueue and execution page IDs, the selected destination and the guest's later read for that same request. RTX 5070 Ti report · RTX 3090 page history · Maintainer's alias-mode note
Not tested
AI use
Codex (GPT-6 family, exact runtime variant unavailable) recovered and isolated the correction, reproduced the failure, ran the tests, and drafted the report.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-27T21:51:20Z.
Review: COMMENTED
Reviewed the focused commit against
785d7dc5. The section lookup checks the block extent before indexing the bitmap. Under the state mutex, only the first free of each ID decrements the live count. Duplicate frees preserve neighboring IDs, and existing section views retain their backing. The nonempty DirectStorage reread predicate takes a consistent snapshot of the whole ID list.I found one mapping caller that still assumes this lookup cannot fail (inline). Separately, the existing DirectStorage copy has a lifetime limitation already acknowledged in the description. The worker rechecks IDs while resolving addresses, but the resolved home or moved-page addresses have no lifetime guard during the copy. A release or remap concurrent with an in-flight copy therefore remains outside the guarantee. A future fix would need to hold the backing mapping stable through the transfer.
I reran both test groups on Windows at
cfe04f43withXCL_PAGE_ALIAS=1and one test thread. All 26 passed (7 alias, 19 DirectStorage). The runtime log confirmed the rewritten-list path executed. That covers the duplicate-free, surviving-view and stack-snapshot cases. A useful additional bitmap edge is a 65-page block with releases on either side of indices 63 and 64. I did not run a retail title or a concurrency stress test.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-27T21:51:21Z.
Code review location:
crates/xcl/src/hle/kernelx/alias.rs; line 79Please handle a failed second lookup in
map_onebefore tearing down the destination mapping. This change makesState::pagereturnNoneimmediately for an individually released ID.mapvalidates under one lock acquisition, thenmap_onerelinquishes the old destination and callss.page(page).unwrap()under another. A concurrent release can therefore panic even while the rest of the source block remains live. The parent already had this gap on final block release. Resolving the source before changing the destination and returning the normal mapping error on a missing ID would cover this newly affected case. A regression should also assert that the old destination view stays intact on rejection.Imported from ivall/xcl. Originally posted by Lum7nt on 2026-11-27T21:54:04Z.
Native Windows 11 + NVIDIA RTX 3060 verification of PR #3075
Tested PR #3075 head
cfe04f431e6d9e0fdd18128064cbf546ee9fa747on native Windows 11 on NVIDIA RTX 3060 (12 GB, native wave32).Environment
32.0.15.8142(WDDM 3.2)rustc 1.100.0 (0ef1bc386 2026-11-09)x86_64-pc-windows-msvc, Windows SDK DXC1.8.2502.11/ dxil1.8.2502.11Test Results
XCL_PAGE_ALIAS=1):a_freed_page_id_is_rejected_while_its_neighbor_and_existing_view_survive— PASSa_page_not_from_the_title_is_refused— PASSa_page_mapped_into_two_spaces_is_one_page_and_writes_reach_both— PASSpages_read_and_written_by_number_are_the_pages_the_title_sees— PASSscatter_without_pages_unmaps_only_the_listed_aliases— PASSremapping_an_address_shows_the_new_page_and_keeps_the_old_one— PASSa_page_moved_outside_the_spaces_goes_and_comes_back_with_its_bytes— PASSResult: 7 passed; 0 failed; 0 ignored; 0 skipped (0.02s).
XCL_PAGE_ALIAS=1):a_destination_page_rewritten_after_enqueue— PASS (verified that updated destination page receives payload while previous/stale page is rejected underalias::pages_live)a_destination_page_filled_in_after_enqueue— PASSphysical_page_destinations_and_sources— PASSd3d12_resource_and_syncunderXCL_PAGE_ALIAS=1):Observations
alias::pages_livecorrectly traverses section blocks viablock.has_pageand individual-release bitmaps (b.freed), accurately identifying live section-backed page IDs for DirectStorage late-fill rereads.AI disclosure: Testing executed independently on physical hardware; report drafted with agent assistance.
Imported from ivall/xcl. Originally posted by ZekkJJ on 2026-11-27T21:59:40Z.
Code review location:
crates/xcl/src/hle/kernelx/alias.rs; line 79Addressed in
4fdd282403. It resolves the source before changing the destination and reports ERROR_INVALID_PARAMETER if the ID has been released. A separate mapping lock serializes the complete native map and move-back path with page and alias-space release. This protects the raw home view as well as the section object, while leaving STATE available to the fault handlers.The regression deterministically releases the source after preflight and checks that the destination still maps its old bytes for both a partial release and a final block release. The new 65-page test covers releases at indices 63 and 64, duplicate releases, and surviving neighbors. The opt-in run passed 9 alias tests and 19 DirectStorage tests, with no skips. Stabilizing the worker's page addresses during a concurrent DirectStorage transfer remains a separate issue.
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T16:50:13Z.
merge-check claim
head:
4fdd282403The diff of this PR contains #3074, so the check covers both. I also run the lib tests once with
XCL_PAGE_ALIAS=1.Imported from ivall/xcl. Originally posted by throny on 2026-11-28T16:54:31Z.
merge-check
base:
db3921dchead:
4fdd282403merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2169 passed, 0 failed, 48 ignored on the merge result, switch off (27 SKIPPED lines; base alone at
db3921dc: 2145 passed, 0 failed, 48 ignored, 26 SKIPPED; the extra one is this PR's scatter_without_pages_unmaps_only_the_listed_aliases, which needs the switch). AlsoXCL_PAGE_ALIAS=1 cargo test -p xcl --lib --no-fail-fast -- --test-threads=4on the same tree: 2024 passed, 11 failed, 28 ignored. The 11: two GPU tests in title_textures (gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes, gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released) and nine in hle::kernelx::tests (a_home_decommitted_in_the_same_call_is_asked_again, a_page_away_at_another_home_goes_home_with_it, a_page_away_from_home_is_committed_once, mapping_fresh_pages_does_not_query_each_page, mapping_lazy_pages_again_does_not_query_each_page, pages_mapped_again_at_another_address_keep_what_was_written, pages_mapped_again_at_the_same_address_keep_what_was_written, physical_pages_in_uma, scatter_matches_a_model_of_physical_pages). I did not sort them into "test of the other mode's internals" and "real difference"; the two that say pages keep what was written, the scatter model and the two GPU upload tests deserve the author's look.review: this diff contains #3074 and the still-open #2307, so merging it merges both. Switch off (default): by reading, behaviour is the same as main. No exception handler is installed, every branch asks the switch first, and the one changed signature (lazy::ensure) has three callers on main, all updated. One small cost remains with the switch off: lazy::commit takes the alias state lock on every lazy commit without asking the switch first. Switch on, open points: (1) the copy by page number used for DirectStorage holds no lock while a free or an unmap of the same page can run (main holds its lock across the copy); acknowledged in the thread as out of scope. (2) Only ReadFile opens guarded views before the kernel writes; other kernel read calls into a guarded view would fail. (3) While an overlapped read keeps a view open, the title's own writes to that page are not seen as dirty until the read completes. (4) The write-fault handler is first in the chain and would also take a fault the title set up itself with its own protection on a mapped view. (5) The upload of such views to the GPU is not shown: the two GPU tests above fail in this mode, as the description of #3074 says for one of them. Process: the required PR description check fails because the regression run has no xcl-smoke blocks; the PR is about 1,540 lines (about 960 without tests) and the description does not say why it cannot be split; the whole suite was not run on this head by the author (it is now, above).
performance: nothing measured by me. A tester on #3074 reports one A/B pair on an RTX 3080 with the switch on: 19-26 instead of 5-6 presents per 2 s and 20.9 instead of 33.4 GB peak commit. No translator source changes: no re-translation.
verdict: not yet: as a default-off switch the code is close (suite clean, default path unchanged by reading), but it needs the two smoke blocks, #2307 and #3074 merged first or the stack stated as one unit, and a word on the 11 tests that fail with the switch on. I will re-check a new head quickly: this stack matters for the dark picture and for memory.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by ZekkJJ on 2026-11-28T19:53:17Z.
@bmjask mind reviewing this when you get a chance? We've got independent retail validation now, with noticeable rendering and stability improvements.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T21:26:50Z.
Review of
4fdd2824(#3211 workstream B): one finding, with a regression test that fails here and passes with a one-line fix.alias::read/alias::writeresolve page addresses and then copy withoutMAPPINGS.copy_pages(alias.rs:382-406) resolves each page throughbytes_of, which takes and releasesSTATEper page, then copies with no lock held.MAPPINGSserialisesmap,freeandfree_space, but not this copy. The conventional path holdsAWAYacross both resolve and copy (read_physical_pages/write_physical_pagesin kernelx.rs), so in alias mode the guarantee is weaker than the one it replaces. Two interleavings:dstorage.rs:345,:981) resolves a page's home. The title then frees the block's last live page, andfreeunmaps and releases the home (alias.rs:216-219). The copy writes into released address space.unmap_away, which copies the page home and then decommits the away address (alias.rs:304-325). The write either faults, or lands after the copy home and is lost.Test. A
#[cfg(test)]hook runs between resolve and copy. It frees the page from another thread and asserts that the free has not completed within 1 s.4fdd2824it fails:the page's home was released while a write into it was in flight.MAPPINGStaken at the top ofcopy_pages, before resolving, it passes, and the free completes after the write. The lock order MAPPINGS → STATE is the same as inmap/free, and the fault handlers take onlySTATE.Patch (fix + test hook + test)
Tested (RTX 2070 SUPER, Windows 11, debug,
4fdd2824+ the patch above plus the test from the #2307 comment,cargo test -p xcl --lib <filter> -- --test-threads=1):hle::kernelx::: 68 passed, 0 failed, 1 ignored; SKIPPED:scatter_without_pages_unmaps_only_the_listed_aliases(XCL_PAGE_ALIAS=1 required).hle::kernelx::withXCL_PAGE_ALIAS=1: 59 passed, 9 failed, 1 ignored. The same 9 fail at4fdd2824without the patch (57 passed, 9 failed). They are conventional-path tests inkernelx::teststhat run with the alias variable set, e.g.physical_pages_in_umaandscatter_matches_a_model_of_physical_pages.hle::dstorage::withXCL_PAGE_ALIAS=1: 31 passed, 0 failed.Nit:
scatter_without_pages_unmaps_only_the_listed_aliasesskips unlessXCL_PAGE_ALIAS=1is set, and CI does not set it, so #3074's regression test does not run by default.Not tested: retail title, AMD, the race under real DirectStorage load (the test forces the order).
AI use: Claude Code (Claude Opus 5.5) did the review and wrote the test and fix; the comment was checked by @KOLESNiii before posting.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:27:08Z.
Triage (#1607) – head
4fdd282Stacked on #3074 and #2307; the own commits are
cfe04f4(section-backed liveness for DirectStorage page lists, with a per-block freed bitmap) and4fdd282(aMAPPINGSlock serializing map/copy-back with page and space release, and resolving the source before unmapping the destination). No other open PR makes these changes.The second commit is a separate change from the title (mapping serialization), so it could be its own PR. No correctness problems found in the diff.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:43:06Z.
Review (head
4fdd282, diff read, not a merge-check; conflicts with main,PR descriptionred: no smoke block on this head):copy_pages(alias.rs~382-406), reached fromdstorage.rs~345 / ~981 throughkernelx.rs~1057, finds each page's address and copies without theMAPPINGSlock that this PR takes inmap/free/free_space. So the liveness check atdstorage.rs~950 can pass, the title frees the page, and the copy writes into released memory or is lost. KOLESNiii posted a test that fails here and a one-line fix.MAPPINGSstays held while calling into D3D12.X sparse code (move_to->commit_sparse,unmap_away->sparse::decommitted). Anything there that calls back intoaliaswould deadlock.4fdd282(serialising mappings) is a separate change from what the title says.XCL_PAGE_ALIAS=1in throny's merge-check are still unanswered.kernelx.rs,kernelx/lazy.rsandvfs_hooks.rs, probably from #1221 / #1355 on main.Fine: the per-block freed bitmap can't index out of range (
Section.pages == n), duplicate frees are ignored, and the source page is now resolved before the destination is unmapped. The cost is one lock and a map lookup per page, only withXCL_PAGE_ALIAS=1. Related: #2307, #3074, #2308.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.