libkernel: POSIX munmap of flexible memory does not return it to the flexible budget; fix branch ready #5260
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-13T15:54:06Z.
The POSIX
munmapdoes not give flexible memory back to the flexible-memory budget. AftersceKernelMapFlexibleMemory(1 MiB)followed bymunmapof that range,sceKernelAvailableFlexibleMemorySizestays 1 MiB lower; onlysceKernelMunmap(andsceKernelReleaseFlexibleMemory) release it. A guest that maps flexible memory and unmaps it withmunmapslowly exhausts the budget and later maps fail.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/kernel-munmap-flexible-release (one commit on a recent main:
DirectMemory/PosixMemory.cppand a newCheckPosixMunmapReleasesFlexibleMemoryintests/GuestMemory.cpp).munmap_nid_postfixnow unmaps throughsceKernelMunmap, the same wrapper that already releases the budget, so no new behaviour is assumed:sceKernelMmapandsceKernelReleaseFlexibleMemoryalready reuse that path.Checks:
guest_memory,guest_msyncandguest_mlockpass.munmap,sceKernelMunmap,sceKernelReleaseFlexibleMemory, fixed flexible maps into holes and direct-memory maps, withsceKernelAvailableFlexibleMemorySizechecked after every step: 0 model mismatches, the budget never went negative or above its initial value and returned to the start at the end. A double release did not inflate the budget; partial, middle-hole and spanning unmaps released exactly the flexible pages they covered;munmapof an anonymous or direct mapping changed nothing (only ranges tracked as flexible are released). On main every fuzz seed ended with a nonzero leak (about 500 KB in the 4-thread test).check_conventions.pyis clean andpr_overlap.pyfinds no overlap.Not covered, and unchanged from main:
DoMunmapand the budget release are not atomic, so if another thread reuses the address in between, its charge can be erased (about 30% of iterations in a 4-thread test undercounted on both main'ssceKernelMunmapand the branch; the final budget was still correct); a fixed flexible map over an existing flexible range overwrites the tracked entry and under-counts the charge. Only Windows was built and run.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-13T16:00:58Z.
@husseinkad I've opened your branch as #5267, with your commit and authorship kept. It cherry-picks onto current
mainwithout changes.I added a Linux run there: Ubuntu 24.04, GCC 13.3, Release. With
main'sPosixMemory.cpp, the new check fails at the budget check after the firstmunmap; with your change it passes.guest_memory,guest_msyncandguest_mlockpass 20/20, and all 341guest_*tests pass in two runs. I'll keep it up to date withmainand answer review there.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:54:40Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. #5267 is closed for the same reason. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.