libkernel: non-fixed map hints inside a sceKernelReserveVirtualRange range are placed elsewhere #2687

Closed
opened 2026-10-10 10:56:07 +00:00 by ps54all · 2 comments
ps54all commented 2026-10-10 10:56:07 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-10T10:56:07Z.


PPSA01474 (Ratchet & Clank: Rift Apart) reserves 64 GiB with sceKernelReserveVirtualRange (0x12c3000000+0x1000000000) and then maps its heaps inside that range with a hint and no MAP_FIXED (0x1307000000+0x204000, prot 0x42, flags NO_COALESCE). The hint is not honoured: the range is mapped past the end of the reservation (0x22c3100000), the title keeps using 0x1307000000, and sceAmprCommandBufferSetBuffer faults writing a command buffer object at 0x1307200000.

Cause: DoMapDirect and DoMapAnon treat any address without MAP_FIXED as a pure hint, even when the whole range is still reserved.

Fix: ps54all/AnyPS5:fix/libkernel-reserved-range-hint (one commit, fd39361b, on main a29ef592). A non-fixed hint that lies wholly inside a still-reserved range is placed there, as a fixed map into the reservation would be; other hints are unchanged. Includes a guest_memory case that fails without the change, and a TechnicalDebt line (the behaviour comes from the title, not a console measurement). Details and test results: #2667 (closed by the intake pause).

Happy for anyone with intake access to carry it.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5790568375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2687). Originally posted by [ps54all](https://github.com/ps54all) on 2026-10-10T10:56:07Z. --- PPSA01474 (Ratchet & Clank: Rift Apart) reserves 64 GiB with `sceKernelReserveVirtualRange` (`0x12c3000000+0x1000000000`) and then maps its heaps inside that range with a hint and no `MAP_FIXED` (`0x1307000000+0x204000`, prot 0x42, flags `NO_COALESCE`). The hint is not honoured: the range is mapped past the end of the reservation (`0x22c3100000`), the title keeps using `0x1307000000`, and `sceAmprCommandBufferSetBuffer` faults writing a command buffer object at `0x1307200000`. **Cause:** `DoMapDirect` and `DoMapAnon` treat any address without `MAP_FIXED` as a pure hint, even when the whole range is still reserved. **Fix:** [`ps54all/AnyPS5:fix/libkernel-reserved-range-hint`](https://github.com/ps54all/AnyPS5/tree/fix/libkernel-reserved-range-hint) (one commit, `fd39361b`, on `main` `a29ef592`). A non-fixed hint that lies wholly inside a still-reserved range is placed there, as a fixed map into the reservation would be; other hints are unchanged. Includes a `guest_memory` case that fails without the change, and a TechnicalDebt line (the behaviour comes from the title, not a console measurement). Details and test results: #2667 (closed by the intake pause). Happy for anyone with intake access to carry it. Written with AI assistance.
MarcZX10 commented 2026-10-10 11:59:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T11:59:02Z.


Concurrency review note for the proposed hint promotion

I reviewed the PlaceHintInReservation change from #2667 against current main. One race may make the hint fixed after its reservation is gone:

Step Mapping thread Concurrent thread
1 Reserved(addr, len) returns true and PlaceHintInReservation adds MAP_FIXED
2 Acquires GuestAllocations::Mutation, releases/unmaps the reservation, then releases the range
3 A new mapping takes the now-free address
4 Acquires Mutation with the stale MAP_FIXED flag; ReplaceFixedOverlap can unmap the new mapping

DoReserveVirtual and UnmapRegistered update the reservation map while holding GuestAllocations::Mutation. Could PlaceHintInReservation be called after constructing the Mutation in both DoMapDirect and DoMapAnon, before FixedNoOverwriteConflict and ReplaceFixedOverlap? That would make the reservation check and map operation share the registry mutation lock, following the existing mutation-then-reservation-lock order.

The added guest_memory case checks the serial behavior; it would not catch this interleaving. I have not run this branch or reproduced the race, so this is a source-level concurrency concern for review rather than a confirmed runtime failure.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097255435 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2687#issuecomment-6097255435). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T11:59:02Z. --- ### Concurrency review note for the proposed hint promotion I reviewed the `PlaceHintInReservation` change from #2667 against current `main`. One race may make the hint fixed after its reservation is gone: | Step | Mapping thread | Concurrent thread | |---|---|---| | 1 | `Reserved(addr, len)` returns true and `PlaceHintInReservation` adds `MAP_FIXED` | | | 2 | | Acquires `GuestAllocations::Mutation`, releases/unmaps the reservation, then releases the range | | 3 | | A new mapping takes the now-free address | | 4 | Acquires `Mutation` with the stale `MAP_FIXED` flag; `ReplaceFixedOverlap` can unmap the new mapping | | `DoReserveVirtual` and `UnmapRegistered` update the reservation map while holding `GuestAllocations::Mutation`. Could `PlaceHintInReservation` be called after constructing the `Mutation` in both `DoMapDirect` and `DoMapAnon`, before `FixedNoOverwriteConflict` and `ReplaceFixedOverlap`? That would make the reservation check and map operation share the registry mutation lock, following the existing mutation-then-reservation-lock order. The added `guest_memory` case checks the serial behavior; it would not catch this interleaving. I have not run this branch or reproduced the race, so this is a source-level concurrency concern for review rather than a confirmed runtime failure.
ps54all commented 2026-10-10 14:09:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-10T14:09:46Z.


Thanks, that interleaving is real: the reservation check ran before the registry mutation was taken. Fixed on the branch: PlaceHintInReservation now runs after GuestAllocations::Mutation is constructed in both DoMapDirect and DoMapAnon, so the check and the map share the mutation, as FixedNoOverwriteConflict already does (g_reservationLock stays a leaf lock under it). Branch fix/libkernel-reserved-range-hint is rebased onto current main (head 987be674). The serial guest_memory case still passes; like you, I have no deterministic test for the race itself.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6098345115 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2687#issuecomment-6098345115). Originally posted by [ps54all](https://github.com/ps54all) on 2026-10-10T14:09:46Z. --- Thanks, that interleaving is real: the reservation check ran before the registry mutation was taken. Fixed on the branch: `PlaceHintInReservation` now runs after `GuestAllocations::Mutation` is constructed in both `DoMapDirect` and `DoMapAnon`, so the check and the map share the mutation, as `FixedNoOverwriteConflict` already does (`g_reservationLock` stays a leaf lock under it). Branch [`fix/libkernel-reserved-range-hint`](https://github.com/ps54all/AnyPS5/tree/fix/libkernel-reserved-range-hint) is rebased onto current `main` (head `987be674`). The serial `guest_memory` case still passes; like you, I have no deterministic test for the race itself. Written with AI assistance.
Sign in to join this conversation.
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#2687
No description provided.