Repository navigation
common: preserve Windows fastmem protections across partial unmaps - #2361
Conversation
A partial unmap recreates the kept Windows views read-write even when the rasterizer still tracks their pages as protected. Save the protections before tearing down a view and restore them on the kept pieces before returning. Port of dzervas/Lichii@23eb549a71 by Dimitris Zervas: dzervas@23eb549 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
A partial Unmap that splits a view unmaps it whole and maps the kept parts again read-write, which wiped every write trap on them, with FRITCHII_PROTECT_UNLOCKED on or off: the page table still said RasterizerCachedMemory, so CPU writes there were missed. UnmapOnePlaceholder now reads the kept parts' committed non-read-write runs (VirtualQuery) after the first split_unmap_seq increment, while the old view is still mapped, and puts them back (VirtualProtect) after both remaps, before the sequence turns even. A locked Protect is ordered by placeholder_mutex; an unlocked one either changed the view before the read (so it is restored) or sees the sequence odd or changed and is redone under the lock after the restore, so newer flags win. Pages that are not committed (EDEN_NX2_SEC_RESERVE) are skipped, and failures are logged rather than fatal. The first 3 splits that restore anything log it, and the 10 s host protect line counts them. Adds the ported unit test. Approach of dzervas/Lichii 23eb549 by Dimitris Zervas, as ported by zortos293 in zortos293/Lichii zortos293#2361 (7f38c10), adapted: no extra protect lock (our split sequence redo covers that race and keeps the fast path lock-free), the restore after both remaps so the unmapped window stays as short as before. Review R3 should-fix 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Takes the 30 nx2 commits up to zortos293#2428, among them zortos293#2350 (the GPU render follower from zortos293#2319 is opt-in again: on Ocarina of Time it cost a cross-thread wake-up per warm draw for no overlap) and zortos293#2361 (partial unmaps keep the fastmem protections of the kept views on Windows). - shader_cache_v2 driver blobs: zortos293#2349's store finds this session's records at their file offsets; it replaces our in-memory copy (fe8ae97) of the same fix. - vk_pipeline_cache: our CanDiscardCurrentDraw (depth-only and mesh draws) asks the texture cache through the render lend like nx2's inline version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ortos293#2361 Windows fastmem partial unmaps, zortos293#2415 dma_pusher split writes, zortos293#2386 optical flow, zortos293#2425 render follower opt-in, zortos293#2435, zortos293#2436, Mod Store) into prueba Conflicts: staging pool (prewarm floor + upstream IsFree clock), rasterizer (upstream ClearImpl split; OoT camera from facts.camera keeps LICHII_OOT_ALLOW_PADDING and the LICHII_DIAG refusal log), pipeline cache (our BuiltPipeline keeps its place and takes upstream's GPURender lend for the colour-history lookup), graphics pipeline header and TickFrame (both sides). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017QULzm8uqSe8KvGLf1q689
Conflicts: - core.cpp: nx2 sets the application process before the hypervisor check; NvnHook::Install stays right before SetupForApplicationProcess. - nx2_gsv.h / nx2_present.h: the present pacing moved to Nx2PresentBookkeeping here; nx2's 240 fps cap for unpaced unlocked games (zortos293#2178) is ported into its PaceToVblank. - host_memory.cpp (Windows): nx2's partial-unmap protection fix (zortos293#2361) replaces this branch's equivalent one; Protect keeps returning whether it protected everything, and the backing views stay next to nx2's FindBackingRuns. Linux Protect drops AdjustMap as nx2 does. - renderer_vulkan.cpp: FlyHigh drains and the render lend run before the direct-mode teardown and frame pick-up. - vk_master_semaphore.cpp: nx2's submit watchdog with this branch's timeline wait. - memory.cpp, vk_rasterizer.cpp, tests: both sides kept.
…ortos293#2240) Refreshes fix/windows-backing-reserve (4e92798, last merged nx2 at 7e7bd04) on current nx2, as asked on zortos293#2240. No textual conflicts. Four files changed on both sides: src/common/host_memory.cpp (zortos293#2361, Windows fastmem protections across partial unmaps), src/tests/common/host_memory.cpp, src/tests/video_core/buffer_cache_ports.cpp and src/tests/video_core/maxwell_fast_method.cpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcHkcvCLwwzA1tzJpyBgjk Claude-Session: https://claude.ai/code/session_01RcHkcxSN7aBbebPQ17pqcF
A legal guest heap shrink or partial
UnmapPhysicalMemorycan remove part of a Windows fastmem view. Windows tears down the whole view and maps the pages it keeps as read-write. The guest page table, GPU cache counters, and armed read traps still describe those pages as protected, and the unmap path doesn’t re-arm them. A later fastmem store can bypass GPU cache invalidation, leaving a texture or buffer stale. Losing a read trap can also expose stale GPU-written data to the guest CPU.Before a partial unmap, snapshot the protection runs of the pages that will stay mapped. Restore each run immediately after remapping its piece. The single-view
Protectpath takes a shared lock so a concurrent protection change can’t get lost between the snapshot and restore. A query or restore failure stops the emulator. Guest accesses can still race the brief interval between mapping a piece read-write and restoring its protections. Full unmaps do not take the new lock, and Linux already keeps the permissions of pages outside the freed range.Port of dzervas/Lichii@23eb549a71 by Dimitris Zervas. Open Direct NVN PR #1944 contains the same source commit; this PR lets the shared-memory fix land independently. #2108 handles in-flight remap faults but does not restore protections. #2240 does not touch
UnmapOnePlaceholderorProtect; this patch applies cleanly to its current head, and its backing-commit path commits the pages before mapping them.Game-wide rendering/timing change: yes. All titles using Windows fastmem share this path, so this is an AIO candidate.
Built the Linux Release
teststarget with GCC 13. The new[host_memory]regression and all 19HostMemory:*cases passed. Both changed files passed AArch64 syntax checks. The Windows Actions job compiled both files and passed the test suite. No game was run.Summary by CodeRabbit