fix(libkernel): let fixed no-overwrite mappings replace reservations #27543
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27543"
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 akkadbakkad89 on 2026-11-26T17:08:10Z.
What
Fixes the abort when a title fixed-maps with
FIXED|NO_OVERWRITE(0x90) inside its own virtual reservation — a standard arena pattern. Before this change the process died in a hoststd::runtime_errorescaping across the library boundary:The root cause is an inconsistency between the three overlap-handling stages of the fixed-map path (full analysis in the issue comments of #27525):
FixedNoOverwriteConflictdeliberately tolerates overlaps that are fully covered by reservations — correct, since reserving a span and fixed-mapping into it piecemeal is what reservations are for.RemapFixedIntoRegistereddeclines unconditionally whenNO_OVERWRITEis set.ReplaceFixedOverlapskipped the overlap unmap whenNO_OVERWRITEwas set — and then calledRequireAvailableunconditionally, which throws on any overlapping registry range, reservation or not.So for the one flag combination that the conflict stage deliberately accepts, both remediation stages declined and the availability check threw.
The fix:
ReplaceFixedOverlapnow unmaps overlapping registrations underNO_OVERWRITEwhen the overlap is fully reservation-covered (Reserved(addr, len)). Erasing a reservation overwrites no memory — a reservation is a placeholder with no content — so the no-overwrite contract is not violated. Real-memory overlaps still cannot reach here (the conflict check returns ENOMEM for anything not fully reservation-covered, and every caller checks it first), and behaviour without the flag is unchanged. The check is done insideReplaceFixedOverlapitself rather than relying only on the caller invariant, so the function is self-contained.Tested
Windows 11, Intel i7-10700, NVIDIA RTX 3070 driver 617.42, title PPSA38500 (Game bring-up discussion #27523), repeated boot runs with
APS5_TRACE_MEMORY=1:The title's watchdog still fires in these runs: workers now survive the memory system but stall on a separate, still-uninvestigated mechanism — that is the next diagnosis target and is not regressed or caused by this change (the stall frequency is unchanged from before the fix once the overlap-abort deaths are accounted for).
Known edge, pre-existing and unchanged: an overlap only partially covered by reservations is still treated as a conflict by
FixedNoOverwriteConflictand returns ENOMEM. Whether firmware is that strict for mixed coverage is unverified; no title is known to depend on it, and this PR deliberately does not widen that behaviour.Overlap scan notes: no open PR implements this behaviour. The library-splitting refactors #24322/#24917 move libkernel code between files and may textually conflict when they land, but implement no overlapping functionality.
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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T17:12:59Z.
Review: COMMENTED
Actionable comments posted: 1
357521c7-d201-413b-9025-b7330a313655Reviewing files that changed from the base of the PR and between
be2f2f3655and1755414806.core/libs/prx/libkernel/DirectMemory/DirectMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T17:39:54Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the overlap replacement logic is consistent with the reservation coverage check described in the change.
What I ran
Reviewed head
1755414806afed5b7dbefa4a131779ec5ae88c89using the prepared diff andrepo_read.py. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build, automated tests, and the reported title runs were not independently verified. Read
description.md,commits.md,manifest.json,diff.patch, and the changed function plus related overlap-handling code inDirectMemory.cpp. The full changed file was not read;files.jsonwas not available as a review document.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T17:52:08Z.
Review: COMMENTED
Actionable comments posted: 3
ba682dd0-5d36-41ba-9174-c519f639221aReviewing files that changed from the base of the PR and between
1755414806andee7431ef45.core/libs/prx/libkernel/DirectMemory/DirectMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T18:08:25Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the available code supports the stated reservation replacement behavior, but no checks were run.
What I ran
Reviewed head
ee7431ef4578174b0fb9db3fd5076add5b2f6357. Read the prepared description, commits, manifest, diff, and relevant ranges ofcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppandcore/libs/tests/GuestMemory.cpp. Checked callers and related helper definitions with repository searches. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
NO_OVERWRITEmapping into a reservation, including partial reservation coverage. The existing inspected tests cover related fixed mappings and rejection of live overlaps, but not this exact combination.Not verified
No build, test suite, or console run was performed. Only
core/libs/prx/libkernel/DirectMemory/DirectMemory.cppwas changed and included for full-text review; no files were excluded according to the manifest. The author-reported Windows runs were not independently verified.To get this to a good state
Nothing is required. Consider adding a focused regression test for the reservation plus
NO_OVERWRITEcase.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T17:43:35Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
386ae227963bd6aee76301f1e3424d1c5d317bf8by inspecting the prepared diff and relevant source ranges. No tests or builds were run.Results
Negative control
Not run.
Findings
Blocking
None.
Non-blocking
None.
Sources
The change unmaps overlapping registered ranges only when no-overwrite is absent or the requested range is fully reservation-covered; the preceding conflict checks use the same reservation condition. DirectMemory.cpp at the reviewed head.
Not verified
Runtime behavior and the author-reported Windows title runs were not independently verified. Read the changed file’s relevant ranges;
files.jsonlists one reviewed file and no exclusions.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T17:47:55Z.
Review: COMMENTED
Actionable comments posted: 2
Architecture findings (2)
Advisory architecture findings (2)
84a72e2c-583d-4d9e-aaa7-1934f6ff04fdReviewing files that changed from the base of the PR and between
ee7431ef45and386ae22796.core/libs/prx/libkernel/DirectMemory/DirectMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by GalaxyGamingFR on 2026-11-30T22:58:32Z.
Review: APPROVED
Verified on Linux (Ubuntu 26.04.1, GCC 15.2.0, Ninja, Release), with head
386ae22796merged into currentmain:ninja core/libs/prx/libkernel/all) built cleanly.ctest --test-dir core/libs/prx/libkernel) passed, 462/462. I excludedguest_pthread_mutex_contention, which times out on this slow machine with plainmaintoo.GuestMemory.cpp. It reserves 16 pages withsceKernelReserveVirtualRange, then mapsFIXED|NO_OVERWRITE(0x90) inside the reservation withsceKernelMapFlexibleMemoryandsceKernelMapDirectMemory:main, the process dies with the same host exception as #27525:CheckNoOverwriteRefusesLiveMappingand is called just before it inmain():No problems found in the change itself.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T10:15:50Z.
Review: COMMENTED
I ran guest_memory and guest_mmap_fixed_anonymous on Linux with this head. The branch builds and both existing mapping fixtures pass on Linux. Those results cover the existing mapping controls. The reported AMM overlap and the intended reservation rule remain the separate question discussed in this PR.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.