eh: harden is_writable for PAGE_GUARD, multi-region spans, and lazy pages #621

Open
opened 2026-11-24 02:39:11 +00:00 by Grimkaaah · 1 comment
Grimkaaah commented 2026-11-24 02:39:11 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by Grimkaaah on 2026-11-24T02:39:11Z.


Problem

eh::is_writable (used by emulated CLZERO / ClzeroLoop) answers with a single VirtualQuery. That is wrong in four ways (originally listed as item 3 of #278; items 1–2 are on main, item 4 is #321):

  1. PAGE_GUARD. PAGE_READWRITE | PAGE_GUARD (0x104) passes & (PAGE_READWRITE | PAGE_EXECUTE_READWRITE) != 0, so the VEH can write through a guard page instead of letting the real fault happen.
  2. One region only. A ClzeroLoop can cover adjacent committed runs with different protect; one query only sees the first.
  3. Unchecked va + bytes. A wrapping end is undefined.
  4. Lazy physical pages. A page still in MEM_RESERVE (lazy map) makes is_writable false → 0xC000001D, instead of committing via lazy::ensure and zeroing.

Plan

Match the shape of dstorage::writable: checked_add → lazy::ensure → UMA coherent-window fast path → walk every VirtualQuery region covering [va, end), requiring a writable protect and no PAGE_GUARD. Unit tests with VirtualAlloc for guard, multi-region, hole, overflow, and a lazy page.

Complements #501 (sparse-window fast path); does not touch the CLWB race (#321).

Tracking

Split out of #278 item 3 so the fix can land as one small PR.

<!-- greyfinch-sync:ivall/xcl:issue:6573378648 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/626). Originally posted by [Grimkaaah](https://github.com/Grimkaaah) on 2026-11-24T02:39:11Z. --- ## Problem `eh::is_writable` (used by emulated `CLZERO` / `ClzeroLoop`) answers with a single `VirtualQuery`. That is wrong in four ways (originally listed as item 3 of #278; items 1–2 are on `main`, item 4 is #321): 1. **`PAGE_GUARD`.** `PAGE_READWRITE | PAGE_GUARD` (0x104) passes `& (PAGE_READWRITE | PAGE_EXECUTE_READWRITE) != 0`, so the VEH can write through a guard page instead of letting the real fault happen. 2. **One region only.** A `ClzeroLoop` can cover adjacent committed runs with different protect; one query only sees the first. 3. **Unchecked `va + bytes`.** A wrapping end is undefined. 4. **Lazy physical pages.** A page still in `MEM_RESERVE` (lazy map) makes `is_writable` false → `0xC000001D`, instead of committing via `lazy::ensure` and zeroing. ## Plan Match the shape of `dstorage::writable`: `checked_add` → `lazy::ensure` → UMA coherent-window fast path → walk every `VirtualQuery` region covering `[va, end)`, requiring a writable protect and **no** `PAGE_GUARD`. Unit tests with `VirtualAlloc` for guard, multi-region, hole, overflow, and a lazy page. Complements #501 (sparse-window fast path); does not touch the CLWB race (#321). ## Tracking Split out of #278 item 3 so the fix can land as one small PR.
Grimkaaah commented 2026-11-24 07:05:38 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by Grimkaaah on 2026-11-24T02:44:13Z.


Complete PR: https://github.com/ivall/xcl/pull/523 (rebased, smoke on main + head, lib tests 648 passed).

<!-- greyfinch-sync:ivall/xcl:comment:7120430882 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/issues/626#issuecomment-7120430882). Originally posted by [Grimkaaah](https://github.com/Grimkaaah) on 2026-11-24T02:44:13Z. --- Complete PR: https://github.com/ivall/xcl/pull/523 (rebased, smoke on main + head, lib tests 648 passed).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#621
No description provided.