Skip to content

xmem: roll back failed physical page mapping batches - #7331

Closed
WebsiteStealer wants to merge 3 commits into
ProjectLeonida:mainfrom
WebsiteStealer:xmem/rollback-physical-maps
Closed

WebsiteStealer wants to merge 3 commits into
ProjectLeonida:mainfrom
WebsiteStealer:xmem/rollback-physical-maps

Conversation

@WebsiteStealer

Copy link
Copy Markdown

Claimed in the coordination issue as XMem physical mapping rollback.

Depends on: #6995. This is a draft stacked on that PR. The follow-up is commit 6b55bc1. The other commits in the comparison come from the dependency.

What and why

If Windows refuses a view after a physical page mapping call has already changed earlier views, restore the previous mappings and CPU page protections and return the original Windows error. Apply the same rollback to contiguous and scatter requests, including scatter requests that list an address more than once. This ports the rollback behavior we tested in WinDurango.

Tested

Windows 11 Pro build 26200, MSVC 19.50, RelWithDebInfo. Both Windows CPU tests, xmem and xmem_physical, passed. With the new test linked against #6995 alone, four rollback checks fail. With the fix, all 74 physical-page checks pass. The test uses synthetic memory, including a native placeholder replacement that forces the last mapping operation to fail. No GPU is required for these tests.

AI-assisted: yes (Codex).

Checklist

  • No game data, keys or decryption, including in logs or reports quoted here.
  • Translator contract update (no translator change).

coenflict and others added 3 commits November 23, 2026 16:48
…t startup

XMemAllocatePhysicalPages, XMemFreePhysicalPages, XMemMapPhysicalPages and
XMemMapPhysicalPagesScatter, with the shapes of the executable's call sites.
A page is a 64 KiB slot of a pagefile-backed section; a 64 KiB-page
reserve-only XMemVirtualAlloc is a placeholder reservation, and mapping a
page replaces its placeholder with a view of the slot, so one page can be
mapped at several addresses as on the console. The title's VirtualFree
releases such a reservation whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent Windows test of 6b55bc192: pass.

Setup: Windows 11 x64, MSVC 19.44.35220 (RelWithDebInfo, Windows SDK 10.0.26100.0), no game files.

  • xmem_physical_test.exe: 74 checks, 0 failed (exit 0), including contiguous and scatter host-failure rollback and per-page CPU protection restoration.

AI-assisted review/test.

@memorypressure

Copy link
Copy Markdown

FAIL-class: rebase and shrink, do not close as-is. You merged cleanly through 5cf3daf, but main's #6919 (042c5f3) landed a physical-page implementation directly inside xmem.cpp and now conflicts with this PR's parallel xmem_physical.cpp — reconfirmed against current main 9177299. The page store, map/unmap placeholders and docs section are all superseded. The one piece main lacks is your atomic rollback of failed batch maps — and main documents the opposite explicitly (xmem.cpp:560: "A failure part-way leaves the pages before it mapped"), with no test asserting either behavior. If Win32 MapUserPhysicalPages atomicity motivates the rollback, that argument belongs against #6919: rebase keeping just that diff plus xmem_test cases for both paths, or close in favor of an issue. Also: draft PR with no CI checks. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@byPreaZy

Copy link
Copy Markdown

Independent verification of the four failure invariants from #6919's review (Zunraz's test patch), built on Windows/MSVC at this head (6b55bc1).

This PR's own suite covers all four invariants explicitly and passes:

  • xmem_physical_test: 74 checks, 0 failed
  • xmem_test (this branch's copy): 116 checks, 0 failed

Invariant coverage confirmed in runtime/test/xmem_physical_test.cpp:

  1. Failed map preserves state: host-failure injection tests for both contiguous and scatter forms ("contiguous map leaves first page intact on host failure", placeholder restore) plus invalid-PFN rejection.
  2. Batch atomicity: rollback on host failure verified for contiguous and scatter.
  3. Duplicate PFN refused: "freeing one frame number twice in one call is refused" / "and frees nothing".
  4. Free unmaps every live view: "freeing unmaps the pages in every reservation" checks all three reservations (rw, alias, gpu_only) are uncommitted after XMemFreePhysicalPages, and reused pages read as zero. unmap_everywhere() in xmem_physical.cpp implements the FreeUserPhysicalPages semantic.

Comparison with the overlapping candidates, same Zunraz test patch applied on top of merged main (042c5f3):

Candidate Checks Failures
main baseline 181 4 (all invariants)
#7580 191 1 (free does not unmap live views)
#7712 207 4 (window trim only, no atomicity/free fixes)
this PR 74 own checks 0, covers all four invariants

Note: #7580 and #7712 look complementary to each other (atomicity vs window trim) but neither covers the free-unmaps-views invariant. This rewrite covers everything in one place and matches the documented FreeUserPhysicalPages behaviour. The PR is currently CONFLICTING and will need a rebase; the xmem_test.cpp on this branch predates the merged #6919 test additions.

AI-assisted review; tested with MSVC 2022 BuildTools + Ninja, no game files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants