eh: harden is_writable for PAGE_GUARD, regions, and lazy pages (#626) #518
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/523"
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?
Imported from ivall/xcl. Originally posted by Grimkaaah on 2026-11-24T01:16:49Z.
Fixes #626 (item 3 of #278:
is_writableguards). Items 1–2 are already onmain; item 4 is #321. Complements #501 (sparse-window fast path) — this PR fixes the VirtualQuery fallback that #501 still uses.Emulated
CLZERO/ClzeroLoopasked whether the destination was writable with a singleVirtualQuery. That was wrong in four ways:PAGE_GUARD.PAGE_READWRITE | PAGE_GUARD(0x104) passed& (PAGE_READWRITE | PAGE_EXECUTE_READWRITE) != 0, so the VEH would write through a guard page instead of letting the real fault happen.ClzeroLoopcan cover adjacent committed runs with different protect; one query only sees the first.va + bytes. A wrapping end was undefined.MEM_RESERVE(lazy map) madeis_writablefalse →0xC000001D, instead of committing vialazy::ensureand zeroing.What is in it
eh::is_writablenow matches the shape ofdstorage::writable:checked_add→lazy::ensure→ UMA coherent-window fast path → walk everyVirtualQueryregion covering[va, end), requiring a writable protect (READWRITE/WRITECOPY/EXECUTE_*) and noPAGE_GUARD.VirtualProtect;PAGE_NOACCESSand wrapping end; span across two differently-protected committed pages; reserved hole fails; lazy page commits throughensure; CLZERO on a guard page returns 0 without clearing the guard.Tested
rust-toolchain.toml.cargo test -p xcl --lib eh::tests -- --nocapture: 8 passed, 0 failed.cargo test -p xcl --lib -- --test-threads=4: 648 passed, 0 failed, 21 ignored; 0 GPUSKIPPED.ed2f33c.Regression run
Same title and wall time on
mainand on this PR's head (clean tree):Not tested
sparse::known_writablefast path (not onmainyet); merge order should be fine — both can sit above the VirtualQuery walk.AI use
Implemented, tested, smoke runs, and PR description with Cursor (Composer). Plan posted on #626 / #278 before landing the complete PR.
Imported from ivall/xcl. Originally posted by brothernog on 2026-11-24T01:42:47Z.
Tested
056cb61on an RTX 3050 (driver 610.88), Windows 11 Home 26300, Rust 1.100.0, debug:cargo test -p xcl --lib eh::tests: 8 passed.main'sis_writableand kept the new tests.is_writable_guards_regions_overflow_and_lazy_pagesfails at "PAGE_GUARD must not count as writable".clzero_refuses_a_guard_pagekills the test process with0x80000001(STATUS_GUARD_PAGE_VIOLATION): the old CLZERO wrote through the guard.cargo build --workspacethencargo test --workspace --no-fail-fast -- --test-threads=4: 679 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.The new
is_writablehas the same steps asdstorage::writable(checked end,lazy::ensure, coherent window, region walk withoutPAGE_GUARD), plus anext <= atguard.On the interaction with #501, which the description mentions: #501 puts
sparse::known_writablebefore this walk. On my machine its working-set check reports guarded, no-access and read-only pages as writable, details on #501. For a committed sparse-window page a title has guarded, CLZERO would then skip this PR'sPAGE_GUARDcheck. Whichever merges second may want to keep the guard check ahead of that fast path.This review was AI-assisted.
Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T02:30:16Z.
Hardware check of
056cb61ac7506e423c307832c88e009720fd2091(verified clean merge withmaincb868b2): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace -- --test-threads=4:679 passed, 0 failed, 41 ignored(GPU tests skipped on this adapter:none)cargo test -p xcl --lib eh::tests:8 passed, 0 failedRegression run
main(9ce2070):PR (
056cb61):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.Imported from ivall/xcl. Originally posted by Grimkaaah on 2026-11-24T02:44:11Z.
Rebased onto current main (
3db536e), linked to dedicated issue #626, and filled Regression run with real xcl-smoke blocks (main + headed2f33c, GTA6 60s, RX 7900 XTX).Imported from ivall/xcl. Originally posted by bunbeans2-arch on 2026-11-24T04:43:46Z.
Test report for
ed2f33c4180389ab3d926995aff111f5c987bae2on an Intel CPU without CLZERO (i9-9900K), where the emulated CLZERO path this PR changes is the one taken. The other runs here were on RDNA3 and on a Ryzen 7 9800X3D, which runs CLZERO itself.Tested
stable-x86_64-pc-windows-msvc, debug.3db536e):cargo build --workspace+cargo test --workspace -- --test-threads=4: 688 passed, 0 failed, 41 ignored, 0SKIPPED(D3D12 backend on the RX 9070 XT);eh::tests::clzero_refuses_a_guard_pageandeh::tests::is_writable_guards_regions_overflow_and_lazy_pagespass. Control,mainf4ce27c: 701 passed, 0 failed, 41 ignored.eh.rs, not part of this PR; its source is in my report on #321: https://github.com/ivall/xcl/pull/321#issuecomment-7122269978), on this PR's head merged ontomainf4ce27c(clean merge): the instructions run for real, the CPU raisesSTATUS_ILLEGAL_INSTRUCTIONandeh's handler takes it.clzeroat a line in a read-write buffer: 1 fault, that line zeroed and the bytes around it left as they were.clzero; add rax, 0x40; cmp rax, rdx; jb) over 0x400 bytes: 1 fault, the 0x400 bytes zeroed and the rest left as it was.main).Not tested
scripts/smoke.ps1run (no game files were used), a release build.main: that is the CLWB hot-patch race of #321, which this PR does not touch.AI use
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-24T10:40:22Z.
Code/CI review only (not independently runtime-tested by me): clean merge and
PR descriptiongreen (just awaiting CI workflow approval). Hardenseh::is_writableforPAGE_GUARD, multi-region spans, and lazy pages (#626). Recommend approving CI and merging, @ivall.upstream-sync referenced this pull request2026-11-24 19:06:45 +00:00
upstream-sync referenced this pull request2026-11-24 22:05:13 +00:00
upstream-sync referenced this pull request2026-11-25 03:04:25 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T13:43:25Z.
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!
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T20:25:46Z.
NVIDIA test report for
ed2f33c(head as is, base3db536e), for #1607's "one more test report" 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: 679 passed, 0 failed, 41 ignored. The end-to-end title tests pass.hle::xaudio2, because its tests fail or hang on this machine onmaintoo. The PR doesn't touch it.no wave64on this card.AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:39:38Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:39:14Z.
Triage (#1607) – head
ed2f33cNo open or merged PR makes the same change. Main's
eh::is_writablestill uses oneVirtualQuery, acceptsPAGE_READWRITE | PAGE_GUARD, addsva + bytesunchecked and does not calllazy::ensure. #501, already adapted on main asa078094, added thesparse::known_writablefast path to the same function, and #1034 also edits it. The PR conflicts with main, and the rebase must keepknown_writableahead of the new region walk. Otherwise the multi-region walk would bring back the gigabyteVirtualQuerywalks in sparse windows.No problems found in the diff.
is_writable(_, 0)now returns true where it returned false.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.