kernel: retry guest faults inside a MAP_FIXED replacement window #433
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!433
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/433/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@brandostrong on GitHub · 2026-08-31 22:16 UTC · original
brandostrong:fix/remap-window-fault-retry-v2→main· +69 −0 · 3 files · 1 commits · closed without mergingThis has some overlap with #432, though are complementary. 432 stop it from opening when no-op, this one survives it when it does open. 432 is narrower while this one is more a safety.
Summary
MAP_FIXEDreplacement is tearing down, and retry a guest fault that lands inside it once the replacement finishes.Problem
KernelMapDirectMemoryhandles a fixed map over a live range throughReplaceFixedRangeWithReserved, which doesUnmapGpuRange→Remove→UnmapBacking→ReserveFixedbefore the caller maps the new content. In that window the range is a bare reserved placeholder with no access.MAP_FIXEDreplacement is meant to be atomic — from the guest's point of view the old mapping is never withdrawn. Doing it as unmap-then-remap means another guest thread reading the range faults on memory it has every reason to believe is mapped, and the emulator then kills the process on an unhandled access violation.This is observed, not inferred. With the window instrumented, a guest thread faulted inside a block that was mid-replacement:
The fault address
0x10a7660f49is inside[0x10a7660000, +0x10000), the range being replaced.It is rare within a very common path: 1 live teardown per load against 4430 and 7039 replacements across two runs, and zero across 2634 gameplay-phase replacements. That matches where the crash was seen — during game load, not during play.
Implementation
FixedRemapGuardpublishes[addr, addr + len)to a fixed 8-slot table for the duration of the replacement, and clears it on scope exit. All publishers already holdg_memory_operation_mutex, so claiming a slot needs no extra synchronization; the slots are atomic only for the reader.WaitForFixedRemapafter the existing GPU-fault path. If the faulting address is inside a live window, it yields until the window closes and then retries the instruction; otherwise it falls straight through to the existing fatal path.SendCommandSyncand could in principle be waiting on the faulting thread. On expiry the original fatal path runs, so the worst case is the behaviour before this change.Sources
MAP_EXCLas an alias ofMAP_NO_OVERWRITE,MAP_NOSYNC,MAP_PREFAULT_READ), so FreeBSDmmap(2)is the reference for the atomicity expectation: aMAP_FIXEDmapping replaces an existing one with no intervening window.MAP_FIXED=0x10, matching the constant this path already hardcodes.Testing
1342c6f.RenderExecutorStencilBindingDiscovery, which fails identically on cleanorigin/main.origin/main, so it is not something this tree introduced.Scope
This makes the window survivable; it does not eliminate it. Making
MAP_FIXEDreplacement genuinely atomic would mean holding the old view until the new one is ready, which is a larger change to the mapping path.@brandostrong on GitHub · 2026-08-31 22:22 UTC · original
432 is enough imo in retrospect.
Pull request closed