kernelx: VirtualProtect commits lazy pages in its range first #1191
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!1191
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1191"
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?
@emirduran707 on GitHub · 2026-11-24 13:03 UTC · original
emirduran707:virtualprotect-lazy-pages→main· +175 −5 · 2 files · 1 commits · openMapTitlePhysicalPages/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.github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@DavidM1911 on GitHub · 2026-11-24 13:24 UTC · original
Independent verification on current
main384f7f7(branch already contains it — clean).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.
cargo test -p xcl --lib kernelx: 33 passed, 0 failed, 1 ignored — the VirtualProtect lazy-commit change keeps the kernelx suite green.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
@JoaoPauluu on GitHub · 2026-11-24 14:34 UTC · original
A run on Linux under Wine.
Tested
x86_64-pc-windows-gnu.d0211dbas it is (based on47efa2e), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact).VirtualProtectis Wine's here, so this checks the lazy-page commit against Wine's memory manager.hle::kernelx::tests::virtual_protect_commits_lazy_pages_first: ok, no SKIPPED.Not tested
AI use
@4usphs on GitHub · 2026-11-25 11:52 UTC · original
AMD run on the exact head
d0211db(d0211db87edcb1bbbc5b68463b70c0dc31f1294c), as pushed on its base47efa2e(not merged onto currentmain), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2.Tested
XCL_TRANSLATED_CACHE=0; adapter picked withXCL_ADAPTER.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:gfx1036), driver 32.0.21045.29003: 742 passed, 0 failed, 41 ignoredSKIPPEDtests on either adapter.virtual_protect_commits_lazy_pages_firstruns and passes on both adapters.Not tested
AI use
@xpatfussy69x on GitHub · 2026-11-25 11:58 UTC · original
Test report for head
d0211dbas pushed (not merged onto currentmain) – NVIDIA, wave32.Tested
.\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignoredvirtual_protect_commits_lazy_pages_firstran and passedXCL_SAMPLE_*data set (game-data tests not run)Not tested
mainAI use
@ClosetPie107 on GitHub · 2026-11-25 12:28 UTC · original
Linux / AMD RDNA4 (RADV) test report for head
d0211dbmerged locally ontomain1a0bbe3(clean merge).Environment
experimental-11.0-20261112), vkd3d-proton v3.1 (#257+dxil-spirv53aac418), DXVKv3.1.1-209, DXC1.9.2609.5,x86_64-pc-windows-gnucross-compileTested (debug test binary under Wine,
--test-threads=1 --nocapture)hle::kernelx::tests: 40 passed, 0 failed, 1 ignored (scatter_timing), 0 skipped (1.20 s), includingvirtual_protect_commits_lazy_pages_first.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.
@emirduran707 on GitHub · 2026-11-25 23:03 UTC · original
Thanks for the thorough review @bmjask! Addressed all points in
ecac22b(rebased onto currentmaine1d84b7so Windows CI refreshes cleanly):is_current_process_handlenow matches bothGetCurrentProcess()and real handles to the current process viaCompareObjectHandles. Lazy commits now go throughVirtualAllocEx(proc_, ...)insidelazy::ensure_for_protect, so a handle withPROCESS_VM_OPERATIONcommits and succeeds while a handle lackingPROCESS_VM_OPERATIONfails withERROR_ACCESS_DENIEDwithout committing or unmarking any lazy page.ensure_for_protectnow pre-walks[addr, addr + size)withVirtualQuery(and skips whenoldis null) so if any page in the range isMEM_FREEor non-lazyMEM_RESERVE, no lazy pages are committed beforeVirtualProtect(Ex)returnsERROR_INVALID_ADDRESS.1425 passed, 2 pre-existing RX 9060 XT fuzz failed, 46 ignored; 60 s smoke1585 frames, 13931 MB peak, 0 device removals, 0 crashes):virtual_protect_ex_commits_lazy_pages_through_real_handlevirtual_protect_ex_insufficient_access_does_not_commit_lazy_pagesvirtual_protect_mixed_range_leaves_lazy_page_uncommitted@fromthemoonx on GitHub · 2026-11-24 13:27 UTC · original · edited 2026-11-26 00:07 UTC
Rerun on the new head
ecac22b(review fixes, rebased ontomaine1d84b7): passes on the RTX 3060. Each of the three new tests catches the part it covers.cargo test --workspace --no-fail-fast -- --test-threads=4,ecac22bmerged ontomain08db802(clean)SKIPPEDlinesvirtual_protect*tests alone, 30 runshle::kernelx::(46 tests),--test-threads=8, 30 runslazy::ensure_for_protectcallvirtual_protect_commits_lazy_pages_firstandvirtual_protect_ex_commits_lazy_pages_through_real_handlefailis_current_process_handleonlyproc_ == GetCurrentProcess()virtual_protect_ex_commits_lazy_pages_through_real_handlefailslazy::ensureinstead ofensure_for_protectvirtual_protect_ex_insufficient_access_does_not_commit_lazy_pagesandvirtual_protect_mixed_range_leaves_lazy_page_uncommittedfailSame machine, debug. The reports below are for older heads.
Full-suite run, to go with the
kernelxrun above.Tested
stable-x86_64-pc-windows-msvc; debugd0211db87edcb1bbbc5b68463b70c0dc31f1294c, which is on currentmain47efa2e:cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 742 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.kernelx.rsas onmainplus onlyvirtual_protect_commits_lazy_pages_first, the test fails withVirtualProtect on lazy pages,left: (0, 487), right: (1, 0): FALSE withERROR_INVALID_ADDRESS, as the description says.hle::kernelxtests (lazy pages included), 10 runs: 10 of 10 passed (32 passed, 1 ignored each)e2e, 3 runs: 3 of 3 passedNot tested
VirtualProtecton freshly mapped pages; release build.AI use
@thehollowedone on GitHub · 2026-11-24 13:18 UTC · original · edited 2026-11-26 00:24 UTC
Independent Windows check of the current
ecac22b. This supersedes my earlier real-handle finding ond0211db; the current revision includes the access-rights and mixed-range changes.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.
cargo test -p xcl --lib virtual_protect -- --nocapture --test-threads=1: 4 passed, 0 failed, 0 ignored. This includes the real current-process handle, insufficient-access/no-commit, and mixed-range/no-commit cases.cargo build --workspace: passed.cargo test --workspace --no-fail-fast -- --test-threads=4: 1,427 passed, 0 failed, 46 ignored; 25 GPU skip notices. The four focused cases also passed in this run.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.
@DavidM1911 on GitHub · 2026-11-26 03:52 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
@futurepro62 on GitHub · 2026-11-26 05:36 UTC · original
NVIDIA and AMD full-suite run, to go with the reports above by fromthemoonx, thehollowedone, since none of them covers AMD. Tested exact head
ecac22b4(on its basee1d84b7).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1415 passed, 0 failed, 44 ignored. SKIPPED (no wave64):a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,dispatch_chain_native_wave64_builds_whole,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.virtual_protect_commits_lazy_pages_first,virtual_protect_ex_commits_lazy_pages_through_real_handle,virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages,virtual_protect_mixed_range_leaves_lazy_page_uncommitted.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1426 passed, 0 failed, 46 ignored. SKIPPED:f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out tests that fail on mainb49be183too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests,const_and_null_mask_operands_agree_with_hlsl_on_the_gpuandmask_ff0_and_flbit_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
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.