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! |
|
Independent desktop NVIDIA verification of PR #2294 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib hle::kernelx::guards:: -- --test-threads=1 --nocapture (3 consecutive runs) |
8 passed; 0 failed; 0 ignored; 1131 filtered out × 3 (0.00s × 3, 0 skipped: a_forgotten_view_is_no_longer_reported, a_view_committed_later_counts_as_written, a_write_through_one_view_reports_every_view_of_the_page, a_write_to_a_view_not_committed_yet_is_left_to_the_next_handler, open_makes_views_writable_for_a_kernel_call_and_counts_the_write, steps_of_4_kib_cover_the_view, views_an_overlapped_read_writes_stay_open_until_it_is_done, writes_from_many_threads_are_all_caught_and_kept) |
cargo test --release -p xcl --lib hle::kernelx:: -- --test-threads=1 (3 consecutive runs) |
53 passed; 0 failed; 1 ignored; 1085 filtered out × 3 (1.16s, 1.15s, 1.14s, 0 skipped; includes all 8 guards::tests and all 7 stacked sections::tests) |
cargo build --release -p xcl |
Clean build (1m 18s, exit 0, 0 new warnings in non-test build; cargo test emits 1 new unused_assignments warning in #[cfg(test)]: crates/xcl/src/hle/kernelx/guards.rs:366:9 ov[0] = 0) |
Paired quiet 60 s retail smoke (title: 29640639)
Exact parent & merge-base (568e7db7729c8fa6c8f0f4b32d798faaf11462bb, cached baseline on the same machine):
xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14527 MB
PR #2294 (d660e3070bef6e3ae095393dc134ecd517ab4a35):
xcl-smoke v1
commit: d660e3070bef6e3ae095393dc134ecd517ab4a35
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1554 (PresentX 1554)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14500 MB
Limits of coverage
- Page-by-page VEH write-catching across aliased views, kernel-call/overlapped-read
open/open_until_donewindows, multi-threaded concurrent faults, and uncommitted-page fallthrough were directly verified on Windows 11 via all 8 newhle::kernelx::guards::tests(3/3,0skipped) andhle::kernelx::(53/53× 3). - Full runtime
XCL_PAGE_ALIAS=1activation is wired in stacked PR kernelx: XCL_PAGE_ALIAS=1 shows a physical page at every address it is mapped at #2307, so this 60 s retail smoke confirms default-path non-regression ontitle: 29640639(single-run frame/commit delta reflects normal startup variance, not this PR).
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
… stand down, and the log says which is at work Lab port of the upstream alias stack (xcl-dev#2293, xcl-dev#2294, xcl-dev#2307, xcl-dev#2308, xcl-dev#3074, xcl-dev#3075). The lab's two stopgaps for a physical page at more than one address keep the page at ONE address and move it (bring_page / bring_range, XCL_PAGE_BRING) or its video memory (sparse::share_page, XCL_PAGE_SHARE=1). With real aliases a page is at every address the title mapped it at, outside the sparse windows, and an address it is not at was unmapped by the title: both stand down when XCL_PAGE_ALIAS=1. With the switch not set they are as they were. One line at start-up (the first time the switch is asked) names which of the three is at work; with aliases, a line at the first view and at each power of two from 1024 on says how many pages are shown at how many addresses and how many of them at more than one (guards::view_counts). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Stacked on #2293 (only AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
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