Repository navigation
kernelx: catch CPU writes to the views of physical pages, page by page - #2294
adiologydev wants to merge 3 commits into
Conversation
…addresses On the console a physical page mapped at several addresses is one page. XCL keeps a page at one address at a time and copies it when the title maps it elsewhere (`move_away`), so the other addresses go stale; a retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). `kernelx::sections` is the base for real aliasing: a block of physical pages is one pagefile-backed SEC_RESERVE section, and a page is mapped as a view of its 64 KiB slice into a placeholder (MapViewOfFile3 with MEM_REPLACE_PLACEHOLDER). Every view of a slice is the same memory and a page takes commit once, when it is committed through any view. Unmapping leaves a placeholder for the next view. Ordinary reserved memory (write-watched if asked) can replace part of a placeholder and go back to one. Nothing calls it yet. Measured in a standalone program on Windows 11 26200 over 200 000 pages: map 2.2 us, unmap 2.75 us, commit 0.9 us a page. GetWriteWatch refuses a range that holds a view (error 87), and one call cannot span two neighbouring reservations either.
The upload of title memory to video memory (`d3d12x::sparse`) and the textures kept in step with title memory learn what the CPU wrote from the write watch, and a view of a section (`kernelx::sections`) cannot be write-watched: GetWriteWatch refuses any range that holds one. `kernelx::guards` keeps the views of a physical page read-only. The first write through any of them faults; a vectored handler makes that view writable, notes the page and lets the write go on. `take_dirty` hands over the pages of every view of each page written – a write through one view is a write to all of them – and guards those views again before their bytes are read, so a later write is caught again and an earlier one is in what is read. Kernel calls do not fault into the handler, they fail: `lazy::ensure`, which XCL already calls before a kernel call or its own code writes title memory, opens the guards there first and counts the write. A view committed by the lazy handler is writable and counts as written. Both take no lock until a view has been watched. Nothing watches a view yet.
… fault A guarded view of a physical page (`kernelx::guards`) is read-only until it is written. Code of XCL's own that writes there faults into the guard and goes on, but a kernel call does not fault: ReadFile into such a view fails. `lazy::ensure` opened the views first, yet the submit thread's `take_dirty` could guard them again before the write – between DirectStorage's check of its destination and the copy, or before the kernel wrote a ReadFile buffer. `guards::open` now returns `Opened`, which keeps its views writable until it is dropped; `take_dirty` uploads a pinned view but does not guard it again, and the end of the write counts as a write. `lazy::ensure` returns it and its callers hold it across their write: the routed ReadFile for a synchronous read, and the destination checks of DirectStorage and the CPU-side bottom-of-pipe writes. An overlapped ReadFile writes after the call returns: its views stay open until its OVERLAPPED is no longer STATUS_PENDING, which `take_dirty` reads without faulting (the title may free it once done). A retail title reads 271 MB that way into the CPU view of its 24 GB reservation 8.5 s after start. `guards::written` counts a page as written through all its views when XCL writes it by page number. Nothing watches a view yet, so nothing changes without views.
|
Independent native Windows verification of Tested
Not tested Real overlapped file I/O, GPU uploads, a retail title, Wine and the full workspace suite. AI use OpenAI Codex (GPT-6.2 Sol) added the temporary file-read check, ran the tests and wrote this report. |
…sing stack) Integrates upstream PR stack xcl-dev#2293 -> xcl-dev#2294 -> xcl-dev#2307 -> xcl-dev#2308 (opt-in real section-slice physical page aliasing across virtual views via XCL_PAGE_ALIAS=1).
|
amd-win test report for head Hardware: AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 26200, Rust 1.100.0, debug for tests, release for the smoke runs. Focused tests
Full suite:
Regression run (retail title, 60 s,
PR head is 96 % of main's frames, and its peak commit is 96 % of main's. Not tested: NVIDIA, wave32-only GPUs, runs longer than 60 s, any title other than the one above. The smoke run reaches the title's world load, and I did not check whether it exercises the new write-watch path specifically. AI use: this report was run and written by Claude Code (Claude Sonnet 5.5). |
|
Reviewed
AI use: Antigravity (Gemini 4 Carbon) helped trace |
|
NVIDIA test report for
AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
Stacked on #2293; only the top two commits (
6602a70,d660e30) belong here. Second part of the plan on #1031.The upload of title memory to video memory (
d3d12x::sparse) andtitle_textureslearn what the CPU wrote from the write watch, and a view of a section cannot be write-watched. This keeps the views of a physical page read-only and catches the first write through any of them, so a write through one view is uploaded at all of them. Nothing watches a view yet.What is in it
6602a70crates/xcl/src/hle/kernelx/guards.rs(new):watch(page, view)guards a view; a vectored handler opens a written view and notes its page;take_dirtyhands over the 4 KiB pages of every view of each page written and guards them again before their bytes are read;forget,committed(a view the lazy handler committed counts as written). A write to a view not committed yet is left to the lazy handler (claimed here it would fault again for ever – a test calls the handler with that fault).lazy::commitandlazy::ensurecall it; both take no lock until a view is watched.d660e30guards.rs,lazy.rs,vfs_hooks.rs,dstorage.rs,d3d12x/cpu_writes.rs: a kernel call does not fault into the handler, it fails – soguards::openreturnsOpened, which keeps its views writable until dropped (take_dirtyuploads a pinned view without guarding it again), andlazy::ensurereturns it to its callers, which hold it across their write. An overlappedReadFilewrites after the call returns: its views stay open until its OVERLAPPED is no longerSTATUS_PENDING(read withReadProcessMemory: the title may free it once done). A retail title reads 271 MB that way into the CPU view of its 24 GB reservation 8.5 s after start.guards::writtencounts a page written by page number.guards.rs, among them 8 threads writing 64 guarded pages at once.Tested
XCL_DXC_DIR), debug tests, release runs.cargo test --workspace -- --test-threads=4ond660e30: 1109 passed, 4 failed, 26 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(CreateComputePipelineState→E_OUTOFMEMORYon this card, DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905);main568e7db fails the same 4 here (1094 passed, 4 failed, 26 ignored). SKIPPED (23, the same onmain): 20 need 64-lane waves ("no wave64"), 3 per-lane f16 refusals inlower_dxil::tests::{f16,f32}_programs_on_the_gpu.cargo test -p xcl --lib kernelx::repeat existing races thatmainhas too (gpu_visible_fallback_memory_is_write_watched,virtual_free_ex_and_sparse_validation,a_page_whose_move_fails_stays_mapped_where_it_was; 3 failures in 40 runs ofmain568e7db).Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 60, no input,mainfirst, same machine (each run'sxcl.exebuilt from a clean checkout of its commit):Not tested
AI use