Repository navigation
cpu: handle reserved XMem backing during CLZERO emulation - #826
moffington wants to merge 2 commits into
Conversation
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Clean-Room Peer Review for PR #826 (cpu: handle reserved XMem backing during CLZERO emulation)
High-impact fix for emulated Zen 2 memory semantics on Intel/non-AMD host CPUs:
- First-Touch Backing Commitment:
- Implements commit_physical_page_for_write(address) in
untime/shims/xmem.cpp to dynamically commit reserved XMem scratch backing when targeted by emulated CLZERO. - Respects page protection boundaries: safely verifies AllocationProtect when State == MEM_RESERVE and delivers PAGE_GUARD violations accurately before testing writability.
- Implements commit_physical_page_for_write(address) in
- Defensive Error Handling:
- Rejects read-only views, unmapped placeholders, and inaccessible subpages with STATUS_ACCESS_VIOLATION.
- Accurately reports STATUS_GUARD_PAGE_VIOLATION on first touch of guard pages before resetting to standard write mode.
-
Concurrency & Unit Test Coverage:
untime/test/cpu_emulation_test.cpp adds est_xmem_clzero testing concurrent multi-threaded first touches on one XMem page via std::latch(2).
- Tests exact 64-byte line clearing invariance (std::memcmp against zero array).
- Clean-room verification: Zero game data, strict C++20 compliance, builds and passes on MSVC with /OPT:NOREF.
LGTM! Outstanding systems-level fix. Approved.
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Clean-room verified (zero game data). Crucial fix for Zen 2 CLZERO instruction emulation on Intel hosts touching lazily committed XMem physical memory: introduces commit_physical_page_for_write while strictly honoring PAGE_GUARD/PAGE_READONLY. Exhaustive concurrency and subpage tests in cpu_emulation_test.cpp.
|
Investigated both failed CI checks and confirmed identical failures at the PR's base (
[Baseline CI run](https://github.com/ubiquitarianism/leonida/actions/runs/45406612415) Neither failure appears to be introduced by this PR. |
2aeecd3 to
ed514a5
Compare
ed514a5 to
ffdb444
Compare
|
Rebased #826 onto On Wine 11.20, 8/8 focused tests passed, including #1499 overlaps in |
|
Rechecked mergeability against upstream I also checked the overlap with #1499. While its MSVC SEH approach addresses first-touch backing, #826 also covers the non-MSVC path. A trial merge of both PRs produces a conflict in Flagging this for merge-order coordination so we preserve the correctness guarantees and regression coverage of both changes. |
|
Investigated the Runtime workflow #1655 failures on
Mergeability check: GitHub reports |
A CLZERO emulation can encounter an XMem view whose backing is still reserved. Commit only the backing of a view that permits the attempted access, then check the faulting subpage again before writing. Keep existing XMem callers on their current commitment path.
ffdb444 to
d62aa5b
Compare
Claimed in the coordination issue as: RT-CLZERO-XMEM
What and why
Emulated CLZERO raised a false write access violation on XMem pages that were untouched or that Wine still reported as reserved after a successful CPU write. The handler now checks the exact faulting subpage, commits its XMem backing when eligible, then rechecks live protection before zeroing the cache line. Initially read-only and unrelated mappings stay reserved. Read-only, no-access, and one-shot guard protections still apply.
Tested
d0da7dadeand passed with this change, including 20 repeat runs. It covers concurrent first touches and partially committed XMem pages.d3d12_xmem_placedpassed on an NVIDIA GeForce RTX 3060 with driver 615.78.08. Stockxmemreproduced the same five Wine failures before and after: two metadata checks, one commit-accounting check, and two protection-setup checks.SEC_RESERVEand Wine’s defaultSEC_COMMITmode. Both CPU test cases passed three consecutive runs each on the rebased branch.SEC_RESERVEmode when built against the CPU-emulation header from eithermainor runtime: step try_clzero_loop by VirtualQuery regions and guard wraparound in cpu_emulation #2035.AI-assisted with OpenAI Codex.
Known limitation
The protection check and the zeroing write are separate operations, so there is no atomicity guarantee against a concurrent remap or protection change.
Overlap with other open PRs
writable()change here. Whichever lands second needs the XMem first-touch check carried intowritable_region().writable(); clang-cl keeps the check. The test entry points conflict. A clang-cl/Wine control with its SEH write helper still passed the batch checks. Native MSVC is untested.main. If its fault-ahead commit is applied to emulated writes, the adjacent-page reservation assertion may need updating; the protected-boundary and byte-preservation assertions should still hold.CI
CI pending on the rebased commit