fix(libkernel): release flexible memory when POSIX munmap unmaps it #5267
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5267"
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 milescoviello on 2026-10-13T16:00:49Z.
What
Fixes #5260. Carries @husseinkad's fix branch from that issue (
husseinkad:fix/kernel-munmap-flexible-release,7815f5ae8, one commit), keeping the commit and its authorship. It cherry-picks onto currentmainwithout changes.The POSIX
munmapdid not give flexible memory back to the flexible-memory budget. AftersceKernelMapFlexibleMemoryand amunmapof that range,sceKernelAvailableFlexibleMemorySizestayed lower by the unmapped size. OnlysceKernelMunmapandsceKernelReleaseFlexibleMemoryreleased it. A title that maps flexible memory and frees it withmunmaptherefore leaks budget on every cycle, and later flexible maps fail once the budget runs out.munmap_nid_postfixcalledDoMunmapdirectly. It now callssceKernelMunmap, which isDoMunmapfollowed by the release of the flexible pages in the range, the same pathsceKernelReleaseFlexibleMemoryalready takes. Only ranges tracked as flexible are released, somunmapof anonymous or direct mappings changes nothing. The argument checks and theEINVALfor a failed unmap are as before.guest_memorygainsCheckPosixMunmapReleasesFlexibleMemory. It maps 64 KiB of flexible memory, unmaps the upper half and then the lower half withmunmap, and checks the available size after each step.Tested
mainand passes with the change, andguest_memory,guest_msyncandguest_mlockpass. A fuzz of 40 seeds of 300 steps each mixesmunmap,sceKernelMunmap,sceKernelReleaseFlexibleMemory, fixed flexible maps and direct maps, and checks the budget after every step. It found no mismatch with the model, and the budget returned to its start. Onmainevery seed ended with a leak.main9d0a41d5a:main'sPosixMemory.cppand the new test,guest_memoryfails atGuestMemory.cpp:128, the budget check after the firstmunmap; with the change it passes.guest_memory,guest_msyncandguest_mlockpass 20/20.guest_*tests pass in two runs.tools/check_conventions.py --base upstream/mainpasses.Not changed: as the issue notes,
DoMunmapand the budget release insceKernelMunmapare not one atomic step, which was already the case forsceKernelMunmaponmain.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:30:22Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed