fix(libkernel): map non-fixed hints inside a reserved range in place #2907

Merged
oneandonlydean merged 1 commit from upstream-pr/2907 into main 2026-10-10 20:26:41 +00:00
oneandonlydean commented 2026-10-10 18:23:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T18:23:04Z.


What

Fixes #2687. Carry of ps54all's fix from that issue, with the race MarcZX100 found in review fixed (the reservation is now checked under the registry mutation).

A map without MAP_FIXED whose hint lies wholly inside a range still reserved by sceKernelReserveVirtualRange is placed at the hint, as a fixed map into the reservation would be. Hints outside reservations, or over a partly mapped range, stay hints.

PPSA01474 reserves 64 GiB with no address, then maps direct memory with hints inside it and no MAP_FIXED, and uses the hinted addresses. On main the maps land above the reservation and the title faults on the PROT_NONE reservation (#2704, bisected to #861):

[memory] reserve 0x12c2600000+0x1000000000 flags=0x0 align=0x200000
[memory] map direct request hint=0x12c4e00000+0x8000 flags=0x400000
[memory] map direct 0x22c2804000+0x8000 phys=0x3e3c4000 prot=0xc2 flags=0x400000 align=0x4000
SIGSEGV (SEGV_ACCERR) si_addr=0x12c4e03008

Tested

Linux (CachyOS, GCC), Release: guest_memory, guest_kernel_*, guest_access and application_heap_* pass. The new guest_memory case fails without the DirectMemory.cpp change (GuestMemory.cpp:526). tools/check_conventions.py passes. Merges cleanly with #2758, which changes where the reservation itself goes.

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:4813456481 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2907). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T18:23:04Z. --- ### What Fixes #2687. Carry of ps54all's fix from that issue, with the race MarcZX100 found in review fixed (the reservation is now checked under the registry mutation). A map without `MAP_FIXED` whose hint lies wholly inside a range still reserved by `sceKernelReserveVirtualRange` is placed at the hint, as a fixed map into the reservation would be. Hints outside reservations, or over a partly mapped range, stay hints. PPSA01474 reserves 64 GiB with no address, then maps direct memory with hints inside it and no `MAP_FIXED`, and uses the hinted addresses. On main the maps land above the reservation and the title faults on the `PROT_NONE` reservation (#2704, bisected to #861): ``` [memory] reserve 0x12c2600000+0x1000000000 flags=0x0 align=0x200000 [memory] map direct request hint=0x12c4e00000+0x8000 flags=0x400000 [memory] map direct 0x22c2804000+0x8000 phys=0x3e3c4000 prot=0xc2 flags=0x400000 align=0x4000 SIGSEGV (SEGV_ACCERR) si_addr=0x12c4e03008 ``` ### Tested Linux (CachyOS, GCC), Release: `guest_memory`, `guest_kernel_*`, `guest_access` and `application_heap_*` pass. The new `guest_memory` case fails without the `DirectMemory.cpp` change (`GuestMemory.cpp:526`). `tools/check_conventions.py` passes. Merges cleanly with #2758, which changes where the reservation itself goes. ### 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
EdouardSence commented 2026-10-10 19:43:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-10T19:43:05Z.


Tested on Ratchet & Clank: Rift Apart (PPSA01474), the title from #2704 (closed as a duplicate of #2687). On this title the PR moves the crash rather than removing it.

Setup: CachyOS (kernel 7.2.9), RX 9070 XT (RADV), Release, headless gamescope with scripted input. This PR (3444ebf5c) merged onto main 4a747c487, nothing else.

  • Without this PR: SIGSEGV (SEGV_ACCERR) about 12 s in, at the hinted address, as in #2704.
  • With this PR: that fault is gone, but 3 of 3 runs then die about 16 s in on a general protection fault (si_code 128) in sceAmprAmmCommandBufferMap, writing through base = 0xaaaaaaac00000000 read from the guest's CommandBuffer object at 0x12c5700018. The object's memory holds a repeating {0x80, 0xaaaaaaac00000000} pattern instead of a command buffer.

APS5_TRACE_MEMORY=1 shows why:

[memory] reserve 0x12c2600000+0x1000000000 flags=0x0 align=0x200000
[memory] allocate physical 0x237c00000+0xd5200000
[memory] remap fixed 0x12c4600000+0x204000 prot=0x42 phys=0x30ce00000     <- hinted map, now placed in place
[memory] remap fixed 0x12c4e00000+0x8000 prot=0xc2 phys=0x3e3c4000        <- hinted map, now placed in place
...
[memory] remap fixed 0x12c5600000+0x104000 prot=0x42 phys=0x20a2f4000     <- hinted map
...
[memory] remap fixed 0x12c56b0000+0x60000 prot=0x33 phys=0x2381e0000      <- the title filling its 64 GiB range from its 3.4 GiB pool

Of the 26 mappings that land inside the 64 GiB range, 3 pairs overlap: 0x12c56b0000+0x60000 over 0x12c5600000+0x104000, and 0x12c6170000+0x800000 over both 0x12c6200000+0x104000 and 0x12c6600000+0x4000. 0x12c5700018 sits in the first pair.

So here the title uses its address-less 64 GiB reservation as its own heap (it fills it with remap fixed from the physical block it allocated right after), and separately hints direct maps just above its previous mapping. In #2704's trace before #861, the reservation went to 0x7ef4ffe00000 and the hinted maps landed on their hints, outside it. With #861 the reservation is placed right where those hints point. With this PR the hints are honoured inside it, so both users get the same addresses.

So #2687's title wants a hint inside its own reservation honoured. This title needs its address-less reservation not to cover the addresses it hints next, and honouring the hint inside the reservation corrupts it. I don't have a PS5 placement rule to propose. Placing an address-less reservation away from the bottom of the arena, as before #861, would satisfy this title, but I haven't checked that against #2687's title.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101469482 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2907#issuecomment-6101469482). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-10T19:43:05Z. --- Tested on Ratchet & Clank: Rift Apart (PPSA01474), the title from #2704 (closed as a duplicate of #2687). On this title the PR moves the crash rather than removing it. **Setup:** CachyOS (kernel 7.2.9), RX 9070 XT (RADV), Release, headless gamescope with scripted input. This PR (`3444ebf5c`) merged onto main `4a747c487`, nothing else. - **Without this PR:** SIGSEGV (`SEGV_ACCERR`) about 12 s in, at the hinted address, as in #2704. - **With this PR:** that fault is gone, but 3 of 3 runs then die about 16 s in on a general protection fault (`si_code 128`) in `sceAmprAmmCommandBufferMap`, writing through `base = 0xaaaaaaac00000000` read from the guest's `CommandBuffer` object at `0x12c5700018`. The object's memory holds a repeating `{0x80, 0xaaaaaaac00000000}` pattern instead of a command buffer. `APS5_TRACE_MEMORY=1` shows why: ``` [memory] reserve 0x12c2600000+0x1000000000 flags=0x0 align=0x200000 [memory] allocate physical 0x237c00000+0xd5200000 [memory] remap fixed 0x12c4600000+0x204000 prot=0x42 phys=0x30ce00000 <- hinted map, now placed in place [memory] remap fixed 0x12c4e00000+0x8000 prot=0xc2 phys=0x3e3c4000 <- hinted map, now placed in place ... [memory] remap fixed 0x12c5600000+0x104000 prot=0x42 phys=0x20a2f4000 <- hinted map ... [memory] remap fixed 0x12c56b0000+0x60000 prot=0x33 phys=0x2381e0000 <- the title filling its 64 GiB range from its 3.4 GiB pool ``` Of the 26 mappings that land inside the 64 GiB range, 3 pairs overlap: `0x12c56b0000+0x60000` over `0x12c5600000+0x104000`, and `0x12c6170000+0x800000` over both `0x12c6200000+0x104000` and `0x12c6600000+0x4000`. `0x12c5700018` sits in the first pair. So here the title uses its address-less 64 GiB reservation as its own heap (it fills it with `remap fixed` from the physical block it allocated right after), and separately hints direct maps just above its previous mapping. In #2704's trace before #861, the reservation went to `0x7ef4ffe00000` and the hinted maps landed on their hints, outside it. With #861 the reservation is placed right where those hints point. With this PR the hints are honoured inside it, so both users get the same addresses. So #2687's title wants a hint inside its own reservation honoured. This title needs its address-less reservation not to cover the addresses it hints next, and honouring the hint inside the reservation corrupts it. I don't have a PS5 placement rule to propose. Placing an address-less reservation away from the bottom of the arena, as before #861, would satisfy this title, but I haven't checked that against #2687's title. *Tested and written by Claude (AI assistant) on a contributor's machine.*
screamm commented 2026-10-10 20:59:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-10T20:59:36Z.


Windows validation of the current head 3444ebf5 merged onto main 56fb1b3b.

Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including the libs target.

  • guest_memory and guest_address pass 3/3 (--repeat until-fail:3).
  • ctest -j8 -E "^agc_|video_out" passes 388/388.
  • With main's DirectMemory.cpp and this PR's test, guest_memory aborts at GuestMemory.cpp:542 (the hinted direct map lands outside the reservation), so the new case detects the previous behaviour on Windows as well.

Validation run with Claude Code assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102117957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2907#issuecomment-6102117957). Originally posted by [screamm](https://github.com/screamm) on 2026-10-10T20:59:36Z. --- Windows validation of the current head `3444ebf5` merged onto `main` `56fb1b3b`. Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including the `libs` target. - `guest_memory` and `guest_address` pass 3/3 (`--repeat until-fail:3`). - `ctest -j8 -E "^agc_|video_out"` passes 388/388. - With `main`'s `DirectMemory.cpp` and this PR's test, `guest_memory` aborts at `GuestMemory.cpp:542` (the hinted direct map lands outside the reservation), so the new case detects the previous behaviour on Windows as well. Validation run with Claude Code assistance.
EdouardSence commented 2026-10-11 13:15:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-11T13:15:56Z.


Follow-up to my report above: on main a11c8f7f, the sceAmprAmmCommandBufferMap fault at about 16 s no longer happens. Ratchet & Clank: Rift Apart (PPSA01474) runs the whole 120 s run without a fault (Linux, RX 9070 XT), so this PR is fine for it.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109417786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2907#issuecomment-6109417786). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-11T13:15:56Z. --- Follow-up to my report above: on `main` a11c8f7f, the `sceAmprAmmCommandBufferMap` fault at about 16 s no longer happens. Ratchet & Clank: Rift Apart (PPSA01474) runs the whole 120 s run without a fault (Linux, RX 9070 XT), so this PR is fine for it. *Tested and written by Claude (AI assistant) on a contributor's machine.*
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!2907
No description provided.