Repository navigation
kernelx: VirtualProtect commits lazy pages in its range first - #1191
emirduran707 wants to merge 1 commit into
Conversation
|
Independent Windows check of the current Tested: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (driver 621.35), Rust 1.99.1 MSVC, debug, DXC 1.8.2502.11.
The test worktree was clean at the exact PR head. Not tested: my own retail smoke run, foreign-process handles, AMD hardware, or Wine. The author supplied paired main/head smoke blocks in the PR description; I did not independently reproduce those. AI use: Codex (GPT-6.2 Sol) reviewed the diff, ran the tests on this machine, and drafted this report. AI-assisted. |
|
Independent verification on current Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
AI use: test runs by Devin (Cognition, SWE-2); no code changes. |
|
Rerun on the new head
Same machine, debug. The reports below are for older heads. Full-suite run, to go with the Tested
Not tested
AI use
|
|
A run on Linux under Wine. Tested
Not tested
AI use
|
, xcl-dev#1142, xcl-dev#1150, xcl-dev#1156, xcl-dev#1182, xcl-dev#1191, xcl-dev#1195, xcl-dev#1221 Integrate 10 high-impact open upstream PRs on top of upstream/main (930e8b4): - xcl-dev#1182: share video memory across render targets aliased onto one physical page (~1.85-2.1 GB VRAM saved) - xcl-dev#1142: declare tiled texture pools texture-only (D3D12_HEAP_FLAG_DENY_BUFFERS) for vkd3d-proton - xcl-dev#1097: report process memory under Wine via PagefileUsage fallback - xcl-dev#1078: bound BCPack record scratch memory to 2 KiB stack batches - xcl-dev#1150: convert console clear-value formats in CreatePlacedResource - xcl-dev#1156: release the interface returned by QueryInterface in class_for - xcl-dev#1139: check pointer alignment in is_adopted before dereferencing - xcl-dev#1195: skip ExecuteIndirect dispatch of untranslated console compute pipelines - xcl-dev#1191: VirtualProtect commits lazy pages in its range first - xcl-dev#1221: unmark lazy away mappings in FreeTitlePhysicalPages Assisted-by: Antigravity (Google DeepMind)
…ll#1221, and updated Linux PRs Update fork README for upstream/main 930e8b4 (BCPack BC1-BC7, XCL_PSO_WAIT_MS, low-VA ASLR < 2^40, alloc_pool, sparse tile parking/pool reuse, direct page moves, write-watch merge), newly integrated PRs (ivall#1078, ivall#1097, ivall#1139, ivall#1142, ivall#1150, ivall#1156, ivall#1182, ivall#1191, ivall#1195, ivall#1221), and updated Linux PRs (ivall#867, ivall#871, ivall#877). Assisted-by: Antigravity (Google DeepMind)
|
AMD run on the exact head Tested
Not tested
AI use
|
|
Test report for head Tested
Not tested
AI use
|
|
Linux / AMD RDNA4 (RADV) test report for head Environment
Tested (debug test binary under Wine,
Not tested: full workspace suite, retail title run, native Windows. AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report. |
d0211db to
c3ff67b
Compare
bmjask
left a comment
There was a problem hiding this comment.
P1 VirtualProtectEx scope bug: lazy::ensure runs only for proc_ == GetCurrentProcess(), so a real handle opened on current process is rejected despite same identity (Windows reproduction returns ERROR_INVALID_ADDRESS; CompareObjectHandles recognizes it). Use robust same-process handle identity and commit through supplied handle respecting access; add real-handle success plus insufficient-access/no-side-effect coverage. Also decide/test whether ensure-before-VirtualProtect validation may commit lazy pages even when mixed range validation ultimately fails. Current Windows check fails and needs refresh.
Physical pages mapped into the title's own reservation are left reserved until first touched (lazy::mark in map_pages); the fault handler commits them on a CPU access, but kernel calls do not fault, they fail. Windows' VirtualProtect fails when any page of the range is not committed, so a title that maps pages and changes their protection before touching them got FALSE with ERROR_INVALID_ADDRESS (487), where the non-lazy path (and the console) succeeds. VirtualProtect now commits the lazy pages of the range first with lazy::ensure, as the file and DirectStorage paths already do; VirtualProtectEx does the same when the handle is the current process. The new test reserves two 64 KiB pages, marks them lazy and protects them read-only: before the fix it got (0, 487), now it succeeds, returns PAGE_READWRITE as the old protection and the pages read as zeros. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c3ff67b to
ecac22b
Compare
|
Thanks for the thorough review @bmjask! Addressed all points in
|
|
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
Thanks! — Devin |
|
NVIDIA and AMD full-suite run, to go with the reports above by fromthemoonx, thehollowedone, since none of them covers AMD. Tested exact head Tested
Not tested
AI use
|
gut0to
left a comment
There was a problem hiding this comment.
AI-assisted review: I inspected this change and its added tests; I did not run the test suite. I found one edge case where the preflight can still leave side effects after VirtualProtect fails.
| if seg_end <= cur { | ||
| return; | ||
| } | ||
| if mbi.State == MEM_COMMIT { |
There was a problem hiding this comment.
Could the preflight also verify that every region in the requested range has the same AllocationBase? VirtualProtect fails with ERROR_INVALID_ADDRESS when a range spans two adjacent but separately reserved regions. If both regions are marked lazy, this loop currently commits each page and removes its lazy mark before the native VirtualProtect call fails, so the failed operation changes both reservations. A focused test with two adjacent reservations could assert the call fails and both pages remain reserved/lazy. AI-assisted review; I inspected the diff and tests but did not run them.
MapTitlePhysicalPages/XMemMapPhysicalPagesmap fresh pages into a title's own reservation lazily: the page stays reserved (lazy::mark) until it is first touched. A title that maps pages and callsVirtualProtecton them before touching them got FALSE withERROR_INVALID_ADDRESS(487). Windows'VirtualProtectfails when any page in the range is not committed. On the console the pages are mapped, and XCL's non-lazy path for the same call commits them, so there the call succeeds.lazy.rsitself notes that kernel calls fail on lazy pages and that buffers passed to them are committed first (ensure). TheVirtualProtectwrapper did not do that.VirtualProtect, andVirtualProtectExfor the current process (matching both the pseudo-handle and real current-process handles viaCompareObjectHandles), now calllazy::ensure_for_protecton the range first:[addr, addr + size)is either alreadyMEM_COMMITor marked lazy (MEM_RESERVEinLAZY) before committing any lazy page, so a mixed range containing an uncommitted non-lazy or free page failsVirtualProtectwithERROR_INVALID_ADDRESSand leaves lazy pages uncommitted and still marked lazy.VirtualAllocEx, so a real handle lackingPROCESS_VM_OPERATIONfails withERROR_ACCESS_DENIEDwithout committing or unmarking any lazy page.oldis null.What is in it
crates/xcl/src/hle/kernelx/lazy.rs:ensure_for_protect(proc_, p, len).crates/xcl/src/hle/kernelx.rs:is_current_process_handle,VirtualProtect,VirtualProtectEx; four unit tests:virtual_protect_commits_lazy_pages_firstvirtual_protect_ex_commits_lazy_pages_through_real_handle(real handle opened with onlyPROCESS_VM_OPERATION)virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages(real handle opened with onlyPROCESS_QUERY_LIMITED_INFORMATION->ERROR_ACCESS_DENIED, page staysMEM_RESERVEand still lazy)virtual_protect_mixed_range_leaves_lazy_page_uncommitted(lazy page + plainMEM_RESERVEpage ->ERROR_INVALID_ADDRESS, lazy page staysMEM_RESERVEand still lazy)#1034 adds a different line at the top of
VirtualProtect; the two changes are independent (a rebase keeps both lines).Tested
cargo test --workspace --no-fail-fast -- --test-threads=4onecac22b(rebased ontomaine1d84b7):1425 passed, 2 failed, 46 ignored; 8 SKIPPED(6 inlower_dxil::tests::{f16,f32}_programs_on_the_gpu;heap_window_out_of_memory_falls_back_to_the_switch_form;pso_measurement_compiles_an_exact_synthetic_record)hle::kernelx::tests::virtual_protect*tests pass.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 722 andfuzz_validate_and_gpu_3seed 1599) fail identically on unmodifiedmainon this GPU.Regression run
main (
08db8020):this PR (
ecac22b):Not tested
AI use
maine1d84b7, addressed the P1 review (CompareObjectHandlesreal-handle identity, committing throughVirtualAllocExto respect handle access rights, pre-validating mixed ranges to avoid partial commits, and adding the 3 new regression tests), reran the full workspace suite and 60 s smoke test, and updated this description.