Skip to content

xmem: map physical pages without a cache modifier in the view protection - #7492

Open
hcristosm wants to merge 2 commits into
ItsNotRexed:mainfrom
hcristosm:fix/xmem-view-writecombine
Open

hcristosm wants to merge 2 commits into
ItsNotRexed:mainfrom
hcristosm:fix/xmem-view-writecombine

Conversation

@hcristosm

@hcristosm hcristosm commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue: #7333 (new RT-5 item, no ID). Fixes a bug that came into main with #6919.

AI-assisted (Claude).

What and why

Three of the retail executable's five physical-page windows (the MEM_REPLACE_PLACEHOLDER windows carved out of
the placeholder) carry 0x400 next to PAGE_READWRITE in their protection word. host_protect drops only the
PAGE_GRAPHICS_* range (0x800..0x40000), so 0x400, which is PAGE_WRITECOMBINE on the PC, stays in the
window's protection. map_page then calls MapViewOfFile3(..., MEM_REPLACE_PLACEHOLDER, PAGE_READWRITE | PAGE_WRITECOMBINE, ...), which fails with ERROR_INVALID_PARAMETER. The first
XMemMapPhysicalPages into such a window returns NULL; the title unmaps everything, its descriptor-heap setup
returns false and it asserts. The two windows without 0x400 mapped fine.

view_protect now drops PAGE_WRITECOMBINE and PAGE_NOCACHE (a view takes no cache modifier); PAGE_GUARD, an
access alarm rather than a cache modifier, is kept as the window has it.
The window's own recorded protection is unchanged.

Note for #7218, which reads PAGE_WRITECOMBINE back with VirtualQuery as a write-combine hint: with this change
the mapped pages no longer report it, so that hint would have to come from the window's recorded protection instead.

Tests

On native Windows MapViewOfFile3 accepts the bit and the view comes out write-combined (Protect = 0x404), which
#7218's import of the slot-133 pages refuses; with this change it imports them (RX 9070 XT, AMD Windows driver, tested
in the comments here by @jimokulou2-ops). Wine 11.18 refuses PAGE_NOCACHE with error 87 as well (comment here).

Three of the retail executable's five physical-page windows carry 0x400
(PAGE_WRITECOMBINE on the PC) next to PAGE_READWRITE. host_protect drops only the
PAGE_GRAPHICS_* range, so map_page passed PAGE_READWRITE | PAGE_WRITECOMBINE to
MapViewOfFile3, which refuses it with ERROR_INVALID_PARAMETER: the first
XMemMapPhysicalPages into such a window failed and the title's descriptor-heap
setup returned false.

view_protect now drops PAGE_WRITECOMBINE, PAGE_NOCACHE and PAGE_GUARD.
xmem_test maps a page into a window reserved with that protection.

AI-assisted.
@jtrudeau1530

Copy link
Copy Markdown

Code read of 7e8e3c1, plus related local diagnostic evidence; this is not a test of this PR head.

Our Wine 11.18 / RX 7900 XT (RADV Mesa 26.2.3), clang-cl 23.1.6 + xwin integration reproduced the section-view failure. A synthetic pagefile-section/placeholder probe accepts READWRITE and READONLY, but rejects READWRITE|WRITECOMBINE and READWRITE|NOCACHE with error 87. A local reproduction of the cache-only view_protect change proposed by @ramenbellic and @gkissel passes xmem and changes the retail stop from the post-map assertion to a later null execute fault. Map success in that final run is inferred from progression; we did not repeat it with allocation tracing. Native Windows was not tested. The original proposal and implementation are here and here; we have not executed gkissel's exact commit or its added tests.

One scope concern in view_protect: PAGE_GUARD is not a caching modifier. Microsoft documents it as a one-time access alarm. Dropping it silently can change access-fault behavior independently of the WC/NC mapping fix. Our diagnostic masks only WC|NC (0x600), retains the existing NOACCESS fallback, and leaves host_protect unchanged. Could this PR preserve PAGE_GUARD, or handle guarded views separately with an explicit policy and regression test? The added test currently covers WC, not guard semantics or NOCACHE.

Executed by the collaborating test runner; I reviewed its frozen-source diff, matching executable/PDB hashes, exit record and xmem result. No raw game logs or inputs shared. AI-assisted.

@jimokulou2-ops

Copy link
Copy Markdown

Tested 7e8e3c1db with the retail executable (own 1.0.2.1 copy) on AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32029.2010 (26.11.2), Windows 11 Pro 26300, MSVC 19.44 RelWithDebInfo, LEONIDA_D3D12=vulkan: pass, it is what lets #7218 import the slot-133 pages on this card.

Base: main@51e7c9dc8 + #6919 36936f3bf + #4313 (rebased, IAmNotSiob:tls-4313-rebased bd71d37b7) + #6582 (IAmNotSiob:xerr-check b928f0290) + #4348 45c39cf6f + #7078 3ace9869d + #6954 72ab7623e + #2490 5be2fd287 + #7183 e7b3fade2 + #7218 c3fe82529.

Not checked: whether GPU reads of that buffer see the title's writes (no draw is reached yet), and the runtime's unit tests on this exact stack.

No game data: only flag values, sizes and counts.

AI-assisted (Claude Code).

…s are dropped

PAGE_GUARD is an access alarm, not a cache modifier (review on ItsNotRexed#7492). The comment
also says what the write-combine bit does on Windows, where the view is created
write-combined and ItsNotRexed#7218's import of those pages refuses it.
@hcristosm

Copy link
Copy Markdown
Author

Thanks both.

AI-assisted.

@jtrudeau1530

Copy link
Copy Markdown

Code read of 954fcb1: the PAGE_GUARD scope concern from my earlier review is addressed. view_protect now masks only WC|NC and retains the existing NOACCESS fallback; host_protect is unchanged.

This is source review, not an exact-head test. Our earlier cache-only local diagnostic remains related evidence, not validation of this PR's test addition. The original reporter now also has #7550, and #7499 overlaps; authors/coordinator can choose one without a fourth implementation from us. AI-assisted.

@SkillIssueXO

Copy link
Copy Markdown

Independent native Windows A/B of 954fcb106 against its upstream base 37f2151. Windows 11 build 26300, LLVM-MinGW Clang 23.1.6, CPU-only synthetic tests.

xmem_test passed 180/180 in all three runs on this head. The same test linked with the base shim failed exactly one check in each run, the plain read/write protection of the mapped write-combine window. For libc++ only, the test copy used path.c_str() in its two ifstream calls. Both shim trees were unmodified.

A separate probe allocated and mapped one 64 KiB page for each case through the registered XMem exports. All maps succeeded. VirtualQuery().Protect returned these values.

Window protection Base 37f2151 PR 954fcb106
PAGE_READWRITE 0x004 0x004
PAGE_READWRITE | PAGE_WRITECOMBINE 0x404 0x004
PAGE_READWRITE | PAGE_NOCACHE 0x204 0x004
PAGE_READWRITE | PAGE_GUARD 0x104 0x104

I queried the guard view without touching it. This confirms the latest head's cache-only change on native Windows. No game files or Vulkan import were used. AI-assisted testing (Codex).

@gkissel

gkissel commented Nov 23, 2026

Copy link
Copy Markdown

Independent confirmation under Wine 11.21 (Linux, clang-cl + xwin, GTX 1650 Mobile), retail 1.0.2.1 (own copy). Outcomes only. I'd found the same thing and opened #7852, now closed as a duplicate of this one.

  • In the boot (main + open PRs), the first XMemMapPhysicalPages into the descriptor pool failed with ERROR_INVALID_PARAMETER (87) on page 0, with view protection 0x404. With view_protect dropping PAGE_WRITECOMBINE | PAGE_NOCACHE, the run goes past the pool.
  • A synthetic test with the pool's measured shape gives the same result on current main under Wine 11.21: page 0 of 752 failed to map, error 87 before the change, xmem_test: OK after. The shape: 185 MiB placeholder, five MEM_REPLACE_PLACEHOLDER | MEM_PHYSICAL | MEM_LARGE_PAGES windows with PAGE_READWRITE | PAGE_WRITECOMBINE, 0x2c60 + 0x5c80 pages, and 0x2f0 mapped in one call.

AI-assisted (Claude Code). No game files here.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 954fcb106 merged into main dde82f27e on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: pass.

  • ctest -R "xmem|tiny_game" --output-on-failure: 100% passed out of 11 (xmem and the run_tiny_game* tests). Native Windows only; the Wine behaviour the PR targets was not exercised.

AI-assisted (Claude Code).

@ramenbellic

Copy link
Copy Markdown

Tested 954fcb10 under Wine: Proton Experimental (wine 11), clang-cl 23.1.6 + xwin cross-build, RTX 3070. xmem_test: OK (180 checks).

On the retail boot (own 1.0.2.1 copy, outcomes only), the same view_protect change lets all five XMemMapPhysicalPages calls succeed on Wine (752, 1600, 160, 16 and 432 pages). Without it, the first map into the 0x2404 window fails with ERROR_INVALID_PARAMETER and the device init asserts.

I opened #7550 for the same fix without seeing this one; it is closed in favour of this PR, and its test adds nothing this one lacks.

AI-assisted (Claude Code); outcomes only, no game data.

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Carrying over a measurement from #7550, which was closed as a duplicate of this PR, because it is a native-Windows reason for the same view_protect change: #7550 (comment)

In short (Windows 11, RTX 5060 Ti, retail 1.0.2.1 boot with #7218): without the change, the slot-133 buffer's pages are PAGE_READWRITE | PAGE_WRITECOMBINE. create_host_buffer refuses them on purpose, so the title's writes never reach the GPU buffer. With the same change on top, the import succeeds and the boot reaches the same next stop. @tibzejoker has added this dependency to #7218's description. AI-assisted (Claude Code).

@AwkGrep256

Copy link
Copy Markdown
Contributor

Tested 954fcb1 on Linux/Wine 11.22 (CachyOS, RX 9070 XT/RADV 26.3.1, own 1.0.2.1 copy, merged into tibzejoker:rt5-integration + #7673 + #7417): pass, and it's what unblocks Linux.

Without it, the title's descriptor-heap allocator calls XMemMapPhysicalPages on 752 pages into a window whose view protection is 0x404 (PAGE_READWRITE | PAGE_WRITECOMBINE); Wine's MapViewOfFile3(MEM_REPLACE_PLACEHOLDER) fails it with ERROR_INVALID_PARAMETER, so graphics init returns false right after XboxIDXGIDevice::GetAdapter (1,181 D3D12 calls). With this PR every map succeeds and the run goes on to 2,262 calls (stub pipelines, root signatures, the first DirectStorage queue) before the next, unrelated stops. Details: #7599. AI-assisted.

@dracbat

dracbat commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A data point from a Windows retail boot. RX 5700 (RDNA1), AMD driver 32.0.21045.29003, own 1.0.2.1 copy, a local stack with #7218 (a3eae95) and this PR.

This PR's view_protect covers mapped views. But the slot-133 buffers that #7218 tries to import live in memory the title commits directly through XMemVirtualAlloc, and host_protect keeps the cache modifier there. I added a local log to #7218's create_host_buffer. It refused both buffers it saw, at 460,800 bytes and at 16 bytes, with page state MEM_COMMIT and protect 0x404 (PAGE_READWRITE | PAGE_WRITECOMBINE).

The same strip in host_protect fixes it: p & ~(kPageGraphicsMask | PAGE_WRITECOMBINE | PAGE_NOCACHE). With that, the next run had 0 import refusals, and #7218 imported every slot-133 buffer, using the RX 5700's VK_EXT_external_memory_host (minImportedHostPointerAlignment 0x1000). The boot runs its frame loop with PresentX succeeding, but the frames are still black. As expected, the UI's textures are still ordinary textures, not on the title's pages.

So this PR could cover host_protect as well. Otherwise #7218 falls back for every directly committed range on Windows.

AI-assisted (Claude Code).

@thedarkcr0w

Copy link
Copy Markdown

Tested on the retail boot, together with #7218 (and #8225 for the comparison). Own 1.0.2.1 copy, Windows 11, NVIDIA GeForce RTX 4090 (driver 32.0.16.1062), LEONIDA_D3D12=vulkan, MSVC 2022 RelWithDebInfo; local integration of main with the boot-chain PRs (#4313, #6582, #4348, #6953, #7075, #7066, #7218, #7235, #8225 among them).

slot 133's buffer on the title's pages
without this PR import refused (the write-combined windows fail #7218's VirtualQuery check), E_NOTIMPL; #8225's shadow copy takes over
with this PR imported: one buffer of 0xae00000 bytes at the title's VA (LEONIDA_ARENA_LOG: "title-placed buffer VA ... + 0xae00000 (outside the arena)"), no shadow

So on this driver the whole 174 MiB range imports once the views carry no cache modifier; the ~64 MiB host-import budget #8166 measured on an RTX 3070 Ti does not show up on the 4090. The boot continues to the same later stop either way. As your description says, #7218's write-combine hint then has to come from the window's recorded protection, not from VirtualQuery.

AI-assisted (Claude Code).

@miguelsilva5989

Copy link
Copy Markdown

Tested head 954fcb1 on CachyOS with Wine 11.22 and a Clang 23.1.5 / MinGW build. The PR's synthetic xmem_test failed when linked against the base XMem implementation: the physical page would not map into a window reserved with PAGE_WRITECOMBINE. With the patched implementation, all 180 checks passed, including the read-write view and its contents.

Both builds used the same fixture, with only two ifstream arguments changed to .c_str() in scratch for MinGW compatibility. No title files were used. AI-assisted verification.

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.