fix(libkernel): reserve the AMM virtual address ranges at the top of the guest arena #3281

Merged
oneandonlydean merged 1 commit from upstream-pr/3281 into main 2026-10-11 07:27:01 +00:00
oneandonlydean commented 2026-10-11 05:06:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T05:06:52Z.


What

Fixes #3146.

The AMM ranges (32 GiB plus the 32 GiB multimap range) were reserved address-less on first use, so since #861 they land at the lowest free address of the arena, directly after the title's last mapping. Titles keep mapping their heaps with hints just above their own mappings, and those hints now fall inside the AMM ranges. They are reserved at a fixed place instead: the last 64 GiB of the guest arena, which ends at the application map area end (0xFC_0000_0000). Maps without MAP_FIXED are placed lowest first, so neither they nor hints derived from them reach that end of the window. If the range is not free there, the reservation throws; nothing else is tried.

Where the console puts the AMM ranges is not known. ampr_emu reads them from sceKernelMapperGetParam, so they are the mapper's own ranges, not a reservation made in the title's map area. KytyPS5 puts them above the application area (0x800_0000_0000). Here every guest mapping has to be inside the arena, so the top of the arena is the place furthest from the title's own maps.

The trace in #2704 shows the same thing. The address-less 64 GiB reservation at 0x12c2600000 with alignment 0x200000 is this AMM reservation, not one the title makes. Before #861 it went to a host address (0x7ef4ffe00000) and the title's hinted maps landed on their hints. With the ranges moved, PPSA01474's heaps land on their hints again, outside the AMM ranges, whether or not #2907 promotes hints inside a reservation.

TechnicalDebt's AMM line now says where the ranges are and that the console's addresses are not known.

Tested

Linux (CachyOS, GCC), Release with BUILD_TESTING=ON, on main 06da117642:

  • New guest_ampr_markers case: the AMM ranges end at the end of the arena, and maps hinted at 4 MiB steps above an address-less map land on their hints, outside the AMM ranges. It fails on main at GuestAmpr.cpp:661 (the ranges end where the lowest free 64 GiB ends, not at the end of the arena).
  • guest_ampr_markers, guest_ampr_threads, guest_memory and the other guest_* / application_heap_* tests pass.
  • Full ctest: 751/752. The one failure, agc_driver_dcc_keys_first_write, fails the same way on main.
  • tools/check_conventions.py passes.
  • Not run on PPSA01474 here. @fma-rc, could you run the branch? With the reservation at the end of the arena it should go as far as your 0x4000000000 hint did.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01A2cY3SsTYnh4u4ZtEr2Adx

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4816732604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3281). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T05:06:52Z. --- ### What Fixes #3146. The AMM ranges (32 GiB plus the 32 GiB multimap range) were reserved address-less on first use, so since #861 they land at the lowest free address of the arena, directly after the title's last mapping. Titles keep mapping their heaps with hints just above their own mappings, and those hints now fall inside the AMM ranges. They are reserved at a fixed place instead: the last 64 GiB of the guest arena, which ends at the application map area end (`0xFC_0000_0000`). Maps without `MAP_FIXED` are placed lowest first, so neither they nor hints derived from them reach that end of the window. If the range is not free there, the reservation throws; nothing else is tried. Where the console puts the AMM ranges is not known. ampr_emu reads them from `sceKernelMapperGetParam`, so they are the mapper's own ranges, not a reservation made in the title's map area. KytyPS5 puts them above the application area (`0x800_0000_0000`). Here every guest mapping has to be inside the arena, so the top of the arena is the place furthest from the title's own maps. The trace in #2704 shows the same thing. The address-less 64 GiB reservation at `0x12c2600000` with alignment `0x200000` is this AMM reservation, not one the title makes. Before #861 it went to a host address (`0x7ef4ffe00000`) and the title's hinted maps landed on their hints. With the ranges moved, PPSA01474's heaps land on their hints again, outside the AMM ranges, whether or not #2907 promotes hints inside a reservation. TechnicalDebt's AMM line now says where the ranges are and that the console's addresses are not known. ### Tested Linux (CachyOS, GCC), Release with `BUILD_TESTING=ON`, on `main` 06da117642: - New `guest_ampr_markers` case: the AMM ranges end at the end of the arena, and maps hinted at 4 MiB steps above an address-less map land on their hints, outside the AMM ranges. It fails on `main` at `GuestAmpr.cpp:661` (the ranges end where the lowest free 64 GiB ends, not at the end of the arena). - `guest_ampr_markers`, `guest_ampr_threads`, `guest_memory` and the other `guest_*` / `application_heap_*` tests pass. - Full ctest: 751/752. The one failure, `agc_driver_dcc_keys_first_write`, fails the same way on `main`. - `tools/check_conventions.py` passes. - Not run on PPSA01474 here. @fma-rc, could you run the branch? With the reservation at the end of the arena it should go as far as your `0x4000000000` hint did. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01A2cY3SsTYnh4u4ZtEr2Adx
adriadam10 commented 2026-10-11 07:26:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:26:57Z.


Checked on Linux (GCC, Release) with the PR merged onto main: libs/libkernel ctest 94/94 green; guest_ampr_markers fails without the Apr.cpp change and passes with it. The TechnicalDebt line is accurate. Merging; @fma-rc, please confirm on PPSA01474.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106668082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3281#issuecomment-6106668082). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:26:57Z. --- Checked on Linux (GCC, Release) with the PR merged onto main: libs/libkernel ctest 94/94 green; `guest_ampr_markers` fails without the `Apr.cpp` change and passes with it. The TechnicalDebt line is accurate. Merging; @fma-rc, please confirm on PPSA01474.
fma-rc commented 2026-10-12 01:27:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-12T01:27:17Z.


Late confirmation, sorry for the gap: Ratchet & Clank (PPSA01474) on main a73a1af9c, which has this PR, no longer segfaults at 40 s. Linux, RTX 5080, two runs. Neither has a segfault; the longer one gets about 200 s in and then aborts on unmap address is not registered from the title's sceKernelMunmap, which is a different stop.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116122559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3281#issuecomment-6116122559). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-12T01:27:17Z. --- Late confirmation, sorry for the gap: Ratchet & Clank (PPSA01474) on `main` a73a1af9c, which has this PR, no longer segfaults at 40 s. Linux, RTX 5080, two runs. Neither has a segfault; the longer one gets about 200 s in and then aborts on `unmap address is not registered` from the title's `sceKernelMunmap`, which is a different stop.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3281
No description provided.