kernel: skip a fixed map that already matches the mapped range #432
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!432
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/432/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:07 UTC · original
brandostrong:fix/map-fixed-noop→main· +64 −0 · 2 files · 1 commits · closed without mergingThis fixed a game-load crash that was reported by multiple people, happened intermittently, like 10% of the time, but it was a reliable cause.
Summary
MAP_FIXEDdirect map requests exactly the mapping that is already there, return success without touching it.Problem
KernelMapDirectMemoryhandles a fixed map over a live range by falling through toReplaceFixedRangeWithReserved, which doesUnmapGpuRange→Remove→UnmapBacking→ReserveFixedbefore the caller maps the new content. For the duration of that sequence the address range is reserved and inaccessible.MAP_FIXEDreplacement is supposed to be atomic — there should be no window in which the address is unmapped. Doing it as unmap-then-remap means a guest thread reading the range concurrently can fault on memory the guest has every reason to believe is mapped, because from its point of view nothing was ever unmapped.The case that makes this worth fixing is that the replacement is frequently a no-op: the game re-maps a range with the same address, length, physical offset and protection it already has. The teardown destroys a live mapping only to rebuild an identical one, so the window is opened for no benefit at all.
Implementation
Directrange covering exactly[addr, addr + len), with the same physical offset and protection, and with the backing still present.OK.MAP_NO_OVERWRITEhandling, so a caller that asked to fail on an existing mapping still getsENOMEMrather than success.Sources
MAP_FIXED=0x10andMAP_NO_OVERWRITE=0x80, matching the constants this function already hardcodes.MAP_EXCLis documented as an alias ofMAP_NO_OVERWRITE, "for MAP_FIXED, fail if address is used", which is why the new check is placed after that test and not before it.mmap(2)is the reference for the atomicity expectation above: aMAP_FIXEDmapping replaces any existing mapping without an intervening window.Testing
1342c6f.RenderExecutorStencilBindingDiscovery, which fails identically on cleanorigin/main, so this adds no new failure.FixedMapOverIdenticalRangeIsNoOpis a real regression test, not a contract test — it fails onorigin/mainand passes with the change, verified by reverting the source hunk and rebuilding:It maps a named direct range, re-maps it fixed with identical parameters, and checks the range survived: bounds, physical offset, protection, type, contents, and the range name. The name is what discriminates — the replacement path re-adds the range with an empty name, so a surviving name proves no teardown happened.
Scope
This removes the window for the identical-remap case, which is the one observed in practice. It does not make
MAP_FIXEDreplacement atomic in general; a fixed map that changes the mapping still tears down and rebuilds.@Nmzik on GitHub · 2026-09-24 17:24 UTC · original
Should be fixed by now. Re open if still is
0382d0ca58Pull request closed