kernelx: catch CPU writes to the views of physical pages, page by page #2294
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2294
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2294"
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?
@adiologydev on GitHub · 2026-11-25 12:45 UTC · original
adiologydev:kernelx/page-guards→main· +800 −11 · 7 files · 3 commits · openStacked 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, #1905);main568e7dbfails 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
@nnonno91 on GitHub · 2026-11-25 14:56 UTC · original
Independent native Windows verification of
d660e3070bef6e3ae095393dc134ecd517ab4a35, including a real file read across two guarded pages.Tested
cargo test --locked -p xcl --lib hle::kernelx::guards -- --nocapture --test-threads=4in three separate processes. Each gave 8 passed, 0 failed, 0 ignored and no skips. The eight-thread write check and simulated pending-overlapped check passed each time.std::fs::File::read_exactto read a 16-byte file across the boundary of two committed pages while their destination views were held open. A second view of the same pages immediately read back all 16 bytes. After the open guard was dropped and dirty pages were collected, all four views were reported and guarded again.cargo test --locked -p xcl --lib hle::kernelx::guards::tests::local_file_read_across_two_guarded_pages -- --exact --nocapture --test-threads=1gave 1 passed, 0 failed, 0 ignored and no skips. The temporary test was removed.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.
@oni-swr on GitHub · 2026-11-25 16:05 UTC · original
amd-win test report for head
d660e3070bef6e3ae095393dc134ecd517ab4a35(exact PR head, not a merge; its merge-base withmainis568e7db7).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
cargo test -p xcl --lib kernelx::guards: 8 passed, 0 failedcargo test -p xcl --lib kernelx::sections: 7 passed, 0 failedcargo test -p xcl --lib kernelx::: 53 passed, 0 failed, 1 ignoredFull suite:
cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 1168 passed, 1 failed, 46 ignored.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 722: res[30] = 0x1, CPU 0x7fffffff). It fails the same way on the merge-base568e7db7(1 failed, same seed and message), so it is not caused by this PR.f16_programs_on_the_gpuandf32_programs_on_the_gpu(several forms, "unsupported V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32"),heap_window_out_of_memory_falls_back_to_the_switch_form("no heap windows").Regression run (retail title, 60 s,
scripts/smoke.ps1 -Seconds 60, release builds of568e7db7and of the PR head; one run each, so run-to-run noise applies). These are not pastedxcl-smokeblocks: the script stamps the checkout's HEAD, and I ran both binaries from one checkout, so I quote the numbers instead.568e7db7(main)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).
@safesearch77 on GitHub · 2026-11-25 16:30 UTC · original
Reviewed
d660e30(#2294, stacked on#2293) againstmain(0829441). Clean design usingOpenedpins for kernel writes where user-mode VEH won't fire — caught two subtlePAGE_READONLYraces in the callers whenXCL_PAGE_ALIAS=1is turned on in#2307:dstorage/parallel.rsNtWriteVirtualMemoryrace (0x89240009E_ACCESS_VIOLATION):dstorage::writable(p, n),let _open = lazy::ensure(p, n);dropsOpenedbeforewritablereturns. That works for serialexecute()'s user-modecopy_nonoverlapping, butPipeline::retire_one(parallel.rs:465, 488) writes file-backed zlib requests via the kernel syscallNtWriteVirtualMemory.ExecuteCommandLists->title_textures::refresh_once->guards::take_dirtybetweenwritable(at, n)returning andwrite_destination(at, ...),take_dirtyre-armsPAGE_READONLYonat, causingNtWriteVirtualMemoryto fail in the kernel (0x89240009) without invokingguards::handler. ReturningOpenedfromwritableand holding it acrosswrite_destinationcloses that window.d3d12x/cpu_writes.rssilently droppingWrite32/64BitValueBottomOfPipeXon re-guarded views:cpu_writes::writable(va, bytes)callslazy::ensureat enqueue time, butwrite_now(va, words)(cpu_writes.rs:92-107) andu64_writable_now(va)(cpu_writes.rs:110-126) run later on thexcl-cpu-writesworker after GPU fence completion and checkVirtualQueryforPAGE_READWRITE | PAGE_EXECUTE_READWRITEwithout callinglazy::ensurebefore executing the atomic store.take_dirtyre-protected the view toPAGE_READONLYwhile GPU work was in flight,write_now/write_u64_now/max_u64_nowseePAGE_READONLYand return early without writing the bottom-of-pipe fence value (never reaching the store that would fault intoguards::handler). Holdinglet _open = lazy::ensure(va, bytes);insidewrite_nowandu64_writable_nowfixes this too.AI use: Antigravity (Gemini 4 Carbon) helped trace
Openedlifetimes acrossdstorage/parallel.rsandcpu_writes.rs; verified against the source by me.@upipibi on GitHub · 2026-11-25 17:07 UTC · original
NVIDIA test report for
d660e30(head as is, base568e7db; stacked on #2293), for #1607's NVIDIA list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, aftercargo build --workspace:cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2: 1160 passed, 0 failed, 46 ignored. The end-to-end title tests pass.main0829441on the same machine, same command: 1263 passed, 0 failed, 46 ignored (the PR's base is older, so it has fewer tests).hle::xaudio2, because its tests fail or hang on this machine onmaintoo. The PR doesn't touch it.no wave64on this card, 3 f16/f32 forms the per-lane path refuses, 1 no heap windows, and 1 PSO measurement that needs Developer Mode to turn the driver cache off.AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
@DavidM1911 on GitHub · 2026-11-25 17:29 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
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.