fix(guest-arena): place guest address space in the PS5 window on Linux #861

Merged
jeffrey12cali merged 5 commits from upstream-pr/861 into main 2026-10-10 10:55:28 +00:00
jeffrey12cali commented 2026-10-06 10:15:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T10:15:07Z.


What

Guest address space on Linux is placed inside the PS5 window instead of wherever the kernel's top-down mmap happens to land, so a title's allocator accepts the mapping. sceKernelAllocateDirectMemory/sceKernelMapDirectMemory with addr == NULL now return addresses in [0x2_0000_0000, 0xFC_0000_0000), which is the bound sceLibcMspaceCreate enforces.

The arena reserves the free intervals of that window up front (PROT_NONE | MAP_NORESERVE, 1 GiB chunks), so no later host mapping - driver, library, hinted mmap - can appear inside it, and commit can keep MAP_FIXED semantics, which is what committing over the arena's own reservation requires.

Also in this change, from review:

  • A reservation chunk that fails with EEXIST is recorded as occupied, so the arena cannot hand it out. Any other failure throws, with the address and the size.
  • An in-arena unmap keeps the range reserved, through the same PROT_NONE replacement that GuestArenaReset uses.
  • A partial overlap between a commit and an already-used range throws instead of being overwritten, and the unwind releases only what the failing call marked.
  • An unmodelled protection value throws.
  • The tests cover the kernel API with addr == NULL, not only the arena entry points.
  • GuestArenaReset_nid_postfix no longer releases address-space accounting on Linux (@blawesom). The Linux variant released the range in addition to resetting the memory, while the Windows variant only resets and leaves accounting to the caller. Two call sites released again after the reset, and Contains is span-based, so both released twice under two separate lock acquisitions: a thread that allocated the range in between had its entry erased and the arena handed the range out twice. Every caller already releases explicitly, so the contract is restored rather than duplicated.
  • The fixed-mapping probe test is Linux-only (@blawesom). It used mmap, PROT_READ, PROT_WRITE, MAP_FIXED_NOREPLACE and EEXIST directly, which does not compile under MinGW.

Fixes #692.

Tested

Arch Linux, kernel 7.2.8-arch1-2, GCC, Release, cmake -DBUILD_TESTING=ON: ctest 491/491 on this head, rebased onto current main. The slowest test in the suite takes 4.19 s and the two tests added here take 0.01 s each, so nothing approaches the 30 s limit.

The Windows build cannot be compiled here (no MinGW). The guard was verified by tracking preprocessor nesting: before the change the probe body and its call site are outside every __linux__ block, after it both are inside. CI has to confirm the build itself.

The new kernel-API tests were verified to fail without the change. Making ArenaAvailable() return false gives 0% tests passed, 1 tests failed, and restoring it gives 100%.

Reservation feasibility was measured before adopting it. With an unlimited address space, 1000 GiB of the window reserves in 1 GiB PROT_NONE | MAP_NORESERVE | MAP_FIXED_NOREPLACE chunks, with zero failures on kernel 7.2.8-arch1-2. Under ulimit -v 67108864 (64 GiB) the arena aborts with guest arena: cannot reserve 0x19c0000000+0x40000000 (Cannot allocate memory) instead of passing in silence, and at 128 GiB it fails at 0x29c0000000.

The reservation does not reduce allocatable device memory. A probe that reserves the same 997 GiB window and then allocates VK_MEMORY_HEAP_DEVICE_LOCAL_BIT memory gives identical totals with and without the reservation: 22 GiB before VK_ERROR_OUT_OF_DEVICE_MEMORY on an RTX 4070 Laptop, and 4 GiB on the AMD 780M, at both 1 GiB and 256 MiB step sizes. This is reported against #861's head in the discussion below.

Title evidence (PPSA28997, native Linux relink): the window placement is what the boot stands on. sceKernelGetDirectMemorySize reports 0x360000000 on both platforms, and with the window in place the bundled player/JSON chain stops rejecting the address and the title reaches on-screen video.

Independent reports on other titles:

  • @alfalfa-star, PPSA14632: sceKernelMapNamedFlexibleMemory → sceLibcMspaceCreate now lands inside [0x400000, 0xFC00000001) and Common::initialize stops failing with 0x80553504.
  • @ghreprimand, PPSA01341: guest mappings move from host addresses such as 0x7fff94400000 into 0x200000000 / 0x200300000, and the title passes the allocator fault.
  • @fisherjoey, Demon's Souls (PPSA01341 v1.07, RTX 5070 Ti): without this PR the title SIGSEGVs under _dl_init in 2 of 2 runs; with head c2e15098 it boots, plays the attract movie at about 30 fps, and exits with code 0 in 2 of 2 runs.

#1370 (partly overlapped allocations) has since merged and this head is rebased on top of it. #1360 remains an alternative to the eager reservation; I will rebase onto it or drop the reservation on the maintainer's call.

Checklist

  • Based on current main (rebased; the head is 3c54adf0)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Every test finishes well under 30 s, cold
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4757290243 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T10:15:07Z. --- ### What Guest address space on Linux is placed inside the PS5 window instead of wherever the kernel's top-down `mmap` happens to land, so a title's allocator accepts the mapping. `sceKernelAllocateDirectMemory`/`sceKernelMapDirectMemory` with `addr == NULL` now return addresses in `[0x2_0000_0000, 0xFC_0000_0000)`, which is the bound `sceLibcMspaceCreate` enforces. The arena reserves the free intervals of that window up front (`PROT_NONE | MAP_NORESERVE`, 1 GiB chunks), so no later host mapping - driver, library, hinted `mmap` - can appear inside it, and commit can keep `MAP_FIXED` semantics, which is what committing over the arena's own reservation requires. Also in this change, from review: - A reservation chunk that fails with `EEXIST` is recorded as occupied, so the arena cannot hand it out. Any other failure throws, with the address and the size. - An in-arena unmap keeps the range reserved, through the same `PROT_NONE` replacement that `GuestArenaReset` uses. - A partial overlap between a commit and an already-used range throws instead of being overwritten, and the unwind releases only what the failing call marked. - An unmodelled protection value throws. - The tests cover the kernel API with `addr == NULL`, not only the arena entry points. - `GuestArenaReset_nid_postfix` no longer releases address-space accounting on Linux (@blawesom). The Linux variant released the range in addition to resetting the memory, while the Windows variant only resets and leaves accounting to the caller. Two call sites released again after the reset, and `Contains` is span-based, so both released twice under two separate lock acquisitions: a thread that allocated the range in between had its entry erased and the arena handed the range out twice. Every caller already releases explicitly, so the contract is restored rather than duplicated. - The fixed-mapping probe test is Linux-only (@blawesom). It used `mmap`, `PROT_READ`, `PROT_WRITE`, `MAP_FIXED_NOREPLACE` and `EEXIST` directly, which does not compile under MinGW. Fixes #692. ### Tested Arch Linux, kernel 7.2.8-arch1-2, GCC, `Release`, `cmake -DBUILD_TESTING=ON`: `ctest` **491/491** on this head, rebased onto current `main`. The slowest test in the suite takes 4.19 s and the two tests added here take 0.01 s each, so nothing approaches the 30 s limit. The Windows build cannot be compiled here (no MinGW). The guard was verified by tracking preprocessor nesting: before the change the probe body and its call site are outside every `__linux__` block, after it both are inside. CI has to confirm the build itself. The new kernel-API tests were verified to fail without the change. Making `ArenaAvailable()` return false gives `0% tests passed, 1 tests failed`, and restoring it gives `100%`. Reservation feasibility was measured before adopting it. With an unlimited address space, 1000 GiB of the window reserves in 1 GiB `PROT_NONE | MAP_NORESERVE | MAP_FIXED_NOREPLACE` chunks, with zero failures on kernel 7.2.8-arch1-2. Under `ulimit -v 67108864` (64 GiB) the arena aborts with `guest arena: cannot reserve 0x19c0000000+0x40000000 (Cannot allocate memory)` instead of passing in silence, and at 128 GiB it fails at `0x29c0000000`. The reservation does not reduce allocatable device memory. A probe that reserves the same 997 GiB window and then allocates `VK_MEMORY_HEAP_DEVICE_LOCAL_BIT` memory gives identical totals with and without the reservation: 22 GiB before `VK_ERROR_OUT_OF_DEVICE_MEMORY` on an RTX 4070 Laptop, and 4 GiB on the AMD 780M, at both 1 GiB and 256 MiB step sizes. This is reported against #861's head in the discussion below. Title evidence (PPSA28997, native Linux relink): the window placement is what the boot stands on. `sceKernelGetDirectMemorySize` reports `0x360000000` on both platforms, and with the window in place the bundled player/JSON chain stops rejecting the address and the title reaches on-screen video. Independent reports on other titles: - @alfalfa-star, PPSA14632: `sceKernelMapNamedFlexibleMemory` → `sceLibcMspaceCreate` now lands inside `[0x400000, 0xFC00000001)` and `Common::initialize` stops failing with `0x80553504`. - @ghreprimand, PPSA01341: guest mappings move from host addresses such as `0x7fff94400000` into `0x200000000` / `0x200300000`, and the title passes the allocator fault. - @fisherjoey, Demon's Souls (PPSA01341 v1.07, RTX 5070 Ti): without this PR the title SIGSEGVs under `_dl_init` in 2 of 2 runs; with head `c2e15098` it boots, plays the attract movie at about 30 fps, and exits with code 0 in 2 of 2 runs. #1370 (partly overlapped allocations) has since merged and this head is rebased on top of it. #1360 remains an alternative to the eager reservation; I will rebase onto it or drop the reservation on the maintainer's call. ### Checklist - [x] Based on current `main` (rebased; the head is `3c54adf0`) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Every test finishes well under 30 s, cold - [x] Depends on: none - [x] AI-assisted: yes
alfalfa-star commented 2026-10-06 12:33:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-06T12:33:49Z.


@jeffrey12cali I don't have an arena PR in flight, so please keep #861. What I described in #692 was only a local experiment.

Tested #861 (c9ce0789) with LEGO Horizon Adventures (PPSA14632) on Linux (Arch, GCC 16.2, --to-intel), in place of that experiment. This title reaches the window through flexible memory: the bundled libSceNpCppWebApi.prx maps its 0x80000-byte heap with sceKernelMapNamedFlexibleMemory (prot 2, no address) and passes it to the bundled libc's sceLibcMspaceCreate, which only accepts [0x400000, 0xFC_0000_0001). With APS5_TRACE_MEMORY=1:

reserve    0x1000000000+0x8000000000
reserve    0x200000000+0x4000000
map anon   0x204000000+0x80000 prot=0x2
map direct 0x204080000+0x40000 ...
map direct 0x204200000+0x200000 ...

Every traced mapping is inside the window. Common::initialize no longer fails with 0x80553504, and the title runs past the online-subsystem segfault. With a separate fix for sceAudioOut2Set3DLatency(0xFF, 1) it continues to scePadReadState: invalid argument, which is unrelated. The test suite on that tree shows no new failures (only three RADV pixel tests fail, as without #861).

Edit: the first version of this comment showed a trace from a run where the patched prx in build/core/libs/libs were stale (I had built without the libs target), so it still used my local experiment. The trace above is from a rebuild with #861's libraries.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6016343509 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6016343509). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-06T12:33:49Z. --- @jeffrey12cali I don't have an arena PR in flight, so please keep #861. What I described in #692 was only a local experiment. Tested #861 (`c9ce0789`) with LEGO Horizon Adventures (PPSA14632) on Linux (Arch, GCC 16.2, `--to-intel`), in place of that experiment. This title reaches the window through flexible memory: the bundled `libSceNpCppWebApi.prx` maps its 0x80000-byte heap with `sceKernelMapNamedFlexibleMemory` (prot 2, no address) and passes it to the bundled libc's `sceLibcMspaceCreate`, which only accepts `[0x400000, 0xFC_0000_0001)`. With `APS5_TRACE_MEMORY=1`: ``` reserve 0x1000000000+0x8000000000 reserve 0x200000000+0x4000000 map anon 0x204000000+0x80000 prot=0x2 map direct 0x204080000+0x40000 ... map direct 0x204200000+0x200000 ... ``` Every traced mapping is inside the window. `Common::initialize` no longer fails with `0x80553504`, and the title runs past the online-subsystem segfault. With a separate fix for `sceAudioOut2Set3DLatency(0xFF, 1)` it continues to `scePadReadState: invalid argument`, which is unrelated. The test suite on that tree shows no new failures (only three RADV pixel tests fail, as without #861). Edit: the first version of this comment showed a trace from a run where the patched prx in `build/core/libs/libs` were stale (I had built without the `libs` target), so it still used my local experiment. The trace above is from a rebuild with #861's libraries.
jeffrey12cali commented 2026-10-06 23:09:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-06T23:09:15Z.


Thanks for testing on a second title — that is the strongest thing this PR could get, and the sceKernelMapNamedFlexibleMemory → sceLibcMspaceCreate route is a path I had not reproduced: my measurements came from sceKernelAllocateDirectMemory, same window, same [0x400000, 0xFC00000001) bound, and sceKernelGetDirectMemorySize reporting 0x360000000 on both targets.

On PPSA28997 this PR is what the boot stands on: with the window in place the title reaches on-screen video at about 60 FPS with the allocator counters matching the Windows reference built from the same commit; without it the bundled player/JSON chain asserts on the rejected address.

Good catch on the stale build/core/libs/libs trap, and worth writing down somewhere: our runner copies from exactly that directory, so a rebuild that skips the libs target silently tests the wrong binaries. If you agree it belongs in the contributor notes, I can send that as a small docs-only PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027108488 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6027108488). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-06T23:09:15Z. --- Thanks for testing on a second title — that is the strongest thing this PR could get, and the `sceKernelMapNamedFlexibleMemory` → `sceLibcMspaceCreate` route is a path I had not reproduced: my measurements came from `sceKernelAllocateDirectMemory`, same window, same `[0x400000, 0xFC00000001)` bound, and `sceKernelGetDirectMemorySize` reporting `0x360000000` on both targets. On PPSA28997 this PR is what the boot stands on: with the window in place the title reaches on-screen video at about 60 FPS with the allocator counters matching the Windows reference built from the same commit; without it the bundled player/JSON chain asserts on the rejected address. Good catch on the stale `build/core/libs/libs` trap, and worth writing down somewhere: our runner copies from exactly that directory, so a rebuild that skips the `libs` target silently tests the wrong binaries. If you agree it belongs in the contributor notes, I can send that as a small docs-only PR.
fisherjoey commented 2026-10-06 23:46:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-06T23:46:51Z.


On NVIDIA (595.91), with #861, #864 and #732 merged, Demon's Souls reaches the main loop and renders, then every vkAllocateMemory returns VK_ERROR_OUT_OF_DEVICE_MEMORY with about 14 GB of VRAM free. Without #861 it segfaults during init.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027592690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6027592690). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-06T23:46:51Z. --- On NVIDIA (595.91), with #861, #864 and #732 merged, Demon's Souls reaches the main loop and renders, then every `vkAllocateMemory` returns `VK_ERROR_OUT_OF_DEVICE_MEMORY` with about 14 GB of VRAM free. Without #861 it segfaults during init.
jeffrey12cali commented 2026-10-07 05:16:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-07T05:16:25Z.


Thank you for the data point, and sorry it is a mixed one. Reading it carefully: without #861 the title segfaults during init, and with it the title reaches the main loop and then fails at vkAllocateMemory - so this PR uncovers the NVIDIA failure rather than causing it, but that is no consolation if you want the title running, so here is what I can add.

First, a theory I tested and discarded, so nobody chases it: I suspected the arena size (sceKernelGetDirectMemorySize reports 0x360000000, 13824 MiB) of eating the card. It does not - the guest arena and direct memory are host anonymous mmap in this code path, not vkAllocateMemory-backed, so the window consumes address space and committed host pages, not VRAM. The size coincidence is still worth ruling in or out, but by the route below rather than by shrinking the arena.

What would actually pin it down:

  1. Is it literally every vkAllocateMemory, or the first large one and everything after it because the backend is wedged? "Every call fails with plenty free" usually means the memory-type/properties the backend selected are not satisfiable on that driver, not that the card is full.
  2. The failing allocationSize, memoryTypeIndex and memoryHeapIndex, plus the VkMemoryHeap sizes and flags the backend read at instance setup. If the title sizes its pools from a platform limit (the same family as 0x360000000) while ANV reports a smaller device-local heap, the request overshoots and the driver answers OUT_OF_DEVICE_MEMORY; on RADV the same request can be satisfied from a host-visible heap, which is exactly the asymmetry you would expect to see.
  3. Whether it reproduces with #861 alone, without #864/#732 - if a combination matters, I would rather know which.

I can only test on AMD here (PPSA28997 on RADV: on-screen video at ~60 FPS with every mapping inside [0x400000, 0xFC00000001) and no allocator complaints), so I cannot reproduce the NVIDIA half myself. If those numbers are cheap to grab, post them here or in a new issue and I will work out whether the fix belongs in the placement (a reservation that can dodge driver-reserved ranges) or in the memory-type selection, and send a PR either way. If you would prefer I open the follow-up issue with your configuration quoted, say the word.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6031463695 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6031463695). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-07T05:16:25Z. --- Thank you for the data point, and sorry it is a mixed one. Reading it carefully: without #861 the title segfaults during init, and with it the title reaches the main loop and then fails at `vkAllocateMemory` - so this PR uncovers the NVIDIA failure rather than causing it, but that is no consolation if you want the title running, so here is what I can add. First, a theory I tested and discarded, so nobody chases it: I suspected the arena size (`sceKernelGetDirectMemorySize` reports `0x360000000`, 13824 MiB) of eating the card. It does not - the guest arena and direct memory are host anonymous `mmap` in this code path, not `vkAllocateMemory`-backed, so the window consumes address space and committed host pages, not VRAM. The size coincidence is still worth ruling in or out, but by the route below rather than by shrinking the arena. What would actually pin it down: 1. Is it literally *every* `vkAllocateMemory`, or the first large one and everything after it because the backend is wedged? "Every call fails with plenty free" usually means the memory-type/properties the backend selected are not satisfiable on that driver, not that the card is full. 2. The failing `allocationSize`, `memoryTypeIndex` and `memoryHeapIndex`, plus the `VkMemoryHeap` sizes and flags the backend read at instance setup. If the title sizes its pools from a platform limit (the same family as `0x360000000`) while ANV reports a smaller device-local heap, the request overshoots and the driver answers `OUT_OF_DEVICE_MEMORY`; on RADV the same request can be satisfied from a host-visible heap, which is exactly the asymmetry you would expect to see. 3. Whether it reproduces with #861 alone, without #864/#732 - if a combination matters, I would rather know which. I can only test on AMD here (PPSA28997 on RADV: on-screen video at ~60 FPS with every mapping inside `[0x400000, 0xFC00000001)` and no allocator complaints), so I cannot reproduce the NVIDIA half myself. If those numbers are cheap to grab, post them here or in a new issue and I will work out whether the fix belongs in the placement (a reservation that can dodge driver-reserved ranges) or in the memory-type selection, and send a PR either way. If you would prefer I open the follow-up issue with your configuration quoted, say the word.
jeffrey12cali commented 2026-10-07 09:24:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-07T09:24:31Z.


Two corrections, then measurements from an actual NVIDIA device, because it turns out I can test this half after all.

I was wrong twice in my previous comment. I wrote that I could only test on AMD. This machine has both GPUs, and the engine has always selected the discrete one - our own startup log says Selected GPU name=NVIDIA GeForce RTX 4070 Laptop GPU vendor=0x10de, driver 615.71.09, Memory heap 0 size=8188.0 MiB flags=0x1, Memory heap 1 size=23527.8 MiB flags=0x0. So "PPSA28997 on RADV" was an assumption I never checked. Second, my size-overshoot theory does not survive contact with the device either, and I would rather say so than leave it standing.

I wrote a small probe (vkCreateInstance -> select by device name -> vkAllocateMemory at fixed sizes, once on a device-local memory type and once on a host-visible coherent type, each freed immediately) and ran it on the idle card:

single allocation device-local type host-visible type
1, 64, 1024, 2048, 4096 MiB VK_SUCCESS VK_SUCCESS
6144 MiB VK_SUCCESS VK_SUCCESS
7168 MiB VK_SUCCESS VK_SUCCESS
0x360000000 = 13824 MiB VK_ERROR_OUT_OF_DEVICE_MEMORY (expected: that heap is 8188 MiB) not cleanly measured
1 TiB not attempted VK_ERROR_OUT_OF_DEVICE_MEMORY

The two results that actually matter for your report:

  1. A rejected request does not wedge the device. Immediately after the 0x360000000 failure, a 1 MiB allocation on the same device-local type returned VK_SUCCESS; same after the 1 TiB failure on the host-visible type. So "every vkAllocateMemory fails" cannot be explained by one early oversized call poisoning the allocator on this driver family. Either every request is independently too large for the budget its type is charged against, or the memory type the backend picks is not the one it believes it chose.
  2. The host-visible heap is system RAM, and its availability is not VRAM. An earlier run of the same probe, while other processes were active (~13 GiB of 30 GiB resident), failed at 6144 MiB and above on both types; minutes later, on a quiet machine, the identical binary succeeded at those sizes. So "~14 GB free" (of VRAM) does not describe what a host-visible allocation is charged against, and a repro that depends on machine load would look exactly like a driver bug.

What I would need to go further, and I think it is enough to settle it: for the failing calls, allocationSize, memoryTypeIndex, and that type's heapIndex with the heap size and property flags; plus, if it is cheap, VK_EXT_memory_budget's budget/usage per heap at that moment. If the failing sizes cluster around one value, the title is almost certainly computing them from a platform limit - our family reports 0x360000000 (13824 MiB) for direct memory, which is suspiciously close to a "one big allocation" - and the fix belongs in the reported limit, not in the placement change.

Two control tests worth running on your side: whether the failure persists with nothing else on the GPU, and whether it moves at all when the allocation is forced onto the host-visible type.

On my side, PPSA28997 with this arena in place is unaffected - the largest GPU-side block I can observe is 3407872 bytes, so this title never approaches the sizes in question, which is why I could not feel your failure from it. Nothing here makes me think #861 causes your problem, but I now have a probe that can test your exact numbers, and I will keep it pointed at this. Say the word and I will paste the whole ~130-line file into a comment, or add it to the repo under tools/ so anyone with an affected card can run it in one command (gcc -O2 vkprobe.c -o vkprobe -lvulkan).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034988095 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6034988095). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-07T09:24:31Z. --- Two corrections, then measurements from an actual NVIDIA device, because it turns out I can test this half after all. **I was wrong twice in my previous comment.** I wrote that I could only test on AMD. This machine has both GPUs, and the engine has always selected the discrete one - our own startup log says `Selected GPU name=NVIDIA GeForce RTX 4070 Laptop GPU vendor=0x10de`, driver 615.71.09, `Memory heap 0 size=8188.0 MiB flags=0x1`, `Memory heap 1 size=23527.8 MiB flags=0x0`. So "PPSA28997 on RADV" was an assumption I never checked. Second, my size-overshoot theory does not survive contact with the device either, and I would rather say so than leave it standing. I wrote a small probe (`vkCreateInstance` -> select by device name -> `vkAllocateMemory` at fixed sizes, once on a device-local memory type and once on a host-visible coherent type, each freed immediately) and ran it on the idle card: | single allocation | device-local type | host-visible type | | --- | --- | --- | | 1, 64, 1024, 2048, 4096 MiB | `VK_SUCCESS` | `VK_SUCCESS` | | 6144 MiB | `VK_SUCCESS` | `VK_SUCCESS` | | 7168 MiB | `VK_SUCCESS` | `VK_SUCCESS` | | 0x360000000 = 13824 MiB | `VK_ERROR_OUT_OF_DEVICE_MEMORY` (expected: that heap is 8188 MiB) | not cleanly measured | | 1 TiB | not attempted | `VK_ERROR_OUT_OF_DEVICE_MEMORY` | The two results that actually matter for your report: 1. **A rejected request does not wedge the device.** Immediately after the `0x360000000` failure, a 1 MiB allocation on the same device-local type returned `VK_SUCCESS`; same after the 1 TiB failure on the host-visible type. So "every `vkAllocateMemory` fails" cannot be explained by one early oversized call poisoning the allocator on this driver family. Either every request is independently too large for the budget its type is charged against, or the memory type the backend picks is not the one it believes it chose. 2. **The host-visible heap is system RAM, and its availability is not VRAM.** An earlier run of the same probe, while other processes were active (~13 GiB of 30 GiB resident), failed at 6144 MiB and above on *both* types; minutes later, on a quiet machine, the identical binary succeeded at those sizes. So "~14 GB free" (of VRAM) does not describe what a host-visible allocation is charged against, and a repro that depends on machine load would look exactly like a driver bug. What I would need to go further, and I think it is enough to settle it: for the failing calls, `allocationSize`, `memoryTypeIndex`, and that type's `heapIndex` with the heap `size` and property flags; plus, if it is cheap, `VK_EXT_memory_budget`'s `budget`/`usage` per heap at that moment. If the failing sizes cluster around one value, the title is almost certainly computing them from a platform limit - our family reports `0x360000000` (13824 MiB) for direct memory, which is suspiciously close to a "one big allocation" - and the fix belongs in the reported limit, not in the placement change. Two control tests worth running on your side: whether the failure persists with nothing else on the GPU, and whether it moves at all when the allocation is forced onto the host-visible type. On my side, PPSA28997 with this arena in place is unaffected - the largest GPU-side block I can observe is 3407872 bytes, so this title never approaches the sizes in question, which is why I could not feel your failure from it. Nothing here makes me think #861 causes your problem, but I now have a probe that can test your exact numbers, and I will keep it pointed at this. Say the word and I will paste the whole ~130-line file into a comment, or add it to the repo under `tools/` so anyone with an affected card can run it in one command (`gcc -O2 vkprobe.c -o vkprobe -lvulkan`).
alfalfa-star commented 2026-10-07 11:04:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-07T11:04:48Z.


@jeffrey12cali Yes, please send the docs PR. The trap cost me one wrong comment here, so a line in the contributor notes would have saved it.

On the NVIDIA failure: @fisherjoey traced it in #1022, and #1051 is the fix. On NVIDIA, a refused VK_EXT_external_memory_host import of a read-only range (the relinked image's read-only sections) makes every later vkAllocateMemory on the device fail with -2. That fits "every allocation fails with 14 GB free" better than a size limit, and it would also explain why it only shows up once #861 gets the title far enough to import those ranges.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6036593607 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6036593607). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-07T11:04:48Z. --- @jeffrey12cali Yes, please send the docs PR. The trap cost me one wrong comment here, so a line in the contributor notes would have saved it. On the NVIDIA failure: @fisherjoey traced it in #1022, and #1051 is the fix. On NVIDIA, a refused `VK_EXT_external_memory_host` import of a read-only range (the relinked image's read-only sections) makes every later `vkAllocateMemory` on the device fail with -2. That fits "every allocation fails with 14 GB free" better than a size limit, and it would also explain why it only shows up once #861 gets the title far enough to import those ranges.
jeffrey12cali commented 2026-10-07 11:51:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-07T11:51:23Z.


That closes it, and #1022/#1051 explain what I could not: a refused VK_EXT_external_memory_host import of a read-only range poisoning the device allocation path is exactly the shape of "every vkAllocateMemory fails with plenty free", and your account also explains why it only surfaced once #861 got a title far enough to import those ranges at all.

For the record, the measurements I did get are consistent with that and rule the other theory out. On an idle NVIDIA device here (RTX 4070 Laptop, 6185 driver line, 8188 MiB device-local heap, 23528 MiB host heap): single vkAllocateMemory requests succeeded up to 7168 MiB and failed above the heap, and - the useful part - one rejected request did not wedge anything: the next 1 MiB allocation on the same memory type returned VK_SUCCESS, both on the device-local and on the host-visible type. So "every call fails" cannot come from an oversized allocation having been refused earlier; it needs a stateful failure like the refused import in #1022. My earlier size-overshoot guess was wrong and I have retracted it on this thread.

Docs PR for the stale build/core/libs/libs trap is on its way now - thanks for confirming where it belongs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6037308843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6037308843). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-07T11:51:23Z. --- That closes it, and #1022/#1051 explain what I could not: a refused `VK_EXT_external_memory_host` import of a read-only range poisoning the device allocation path is exactly the shape of "every `vkAllocateMemory` fails with plenty free", and your account also explains why it only surfaced once #861 got a title far enough to import those ranges at all. For the record, the measurements I did get are consistent with that and rule the other theory out. On an idle NVIDIA device here (RTX 4070 Laptop, 6185 driver line, 8188 MiB device-local heap, 23528 MiB host heap): single `vkAllocateMemory` requests succeeded up to 7168 MiB and failed above the heap, and - the useful part - **one rejected request did not wedge anything**: the next 1 MiB allocation on the same memory type returned `VK_SUCCESS`, both on the device-local and on the host-visible type. So "every call fails" cannot come from an oversized allocation having been refused earlier; it needs a stateful failure like the refused import in #1022. My earlier size-overshoot guess was wrong and I have retracted it on this thread. Docs PR for the stale `build/core/libs/libs` trap is on its way now - thanks for confirming where it belongs.
adriadam10 commented 2026-10-07 16:23:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T16:23:01Z.

Review: CHANGES_REQUESTED


Built and ran ctest on this PR merged onto current main (Linux, GCC): all green, guest_memory included. No CI ran on c9ce0789 (no checks on the head); the PR needs green CI, including the Windows/MinGW job, because the header moves the Commit/Reset declarations out of #ifdef _WIN32.

Before this can go in:

  • Code comments. GuestArena.cpp:291-297 (// PAGE_* on each case) and GuestMemory.cpp:452 (// PAGE_READWRITE). CONTRIBUTING says no code comments, and the description says there are none.
  • The TryMarkUsed result is ignored (GuestArena.cpp:318). If the range partly overlaps a used one, it returns true and the commit MAP_FIXEDs over it anyway, where MarkUsed would throw. That case should throw too. Also, on failure the catch at :322 releases the whole range, including the part the caller had already reserved with GuestArenaAllocate (the GuestHeap path).
  • MAP_FIXED on arena-chosen addresses (GuestArena.cpp:303, DirectMemory.cpp:406). The used map is seeded from /proc/self/maps once, on the first Arena() call. A host mapping created later inside the window (driver, another library, a hinted mmap) isn't in the map, so the arena can hand out its range and MAP_FIXED silently replaces it. The objection to MAP_FIXED_NOREPLACE was that it returns EEXIST on reserved space, but nothing is reserved up front anymore. For ranges the arena picked and for GuestMapNoOverwrite, MAP_FIXED_NOREPLACE turns that case into an error instead of corruption.
  • Eager reservation. You dropped the up-front PROT_NONE reservation because the kernel's top-down mmap "picks addresses just below the stack inside the range". On x86-64 with 47-bit user space, the stack and mmap_base sit near 0x7ff..., far above 0xFC_0000_0000. Could you share the failing case (kernel, ulimit -v, the /proc/self/maps at the failure)? If a MAP_NORESERVE reservation works, it also removes the seed race above.
  • Unknown protection becomes RW (GuestArena.cpp:298). Throw for values the switch doesn't model ("exact or throw").
  • Tests don't pin the fix itself. Both re-enabled checks map at fixed addresses. Nothing checks that a direct or flexible mapping with addr == NULL lands in [0x2_0000_0000, 0xFC_0000_0000), which is #692, or that munmap followed by a same-size map reuses the freed range (claimed under "Hole reuse"). Linux tests for both, plus the hinted path (addr != NULL without MAP_FIXED), would cover what the PR changes.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5445199876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#pullrequestreview-5445199876). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T16:23:01Z. **Review:** CHANGES_REQUESTED --- Built and ran ctest on this PR merged onto current `main` (Linux, GCC): all green, `guest_memory` included. No CI ran on `c9ce0789` (no checks on the head); the PR needs green CI, including the Windows/MinGW job, because the header moves the `Commit`/`Reset` declarations out of `#ifdef _WIN32`. Before this can go in: - **Code comments.** `GuestArena.cpp:291-297` (`// PAGE_*` on each case) and `GuestMemory.cpp:452` (`// PAGE_READWRITE`). CONTRIBUTING says no code comments, and the description says there are none. - **The `TryMarkUsed` result is ignored** (`GuestArena.cpp:318`). If the range partly overlaps a used one, it returns `true` and the commit `MAP_FIXED`s over it anyway, where `MarkUsed` would throw. That case should throw too. Also, on failure the `catch` at `:322` releases the whole range, including the part the caller had already reserved with `GuestArenaAllocate` (the `GuestHeap` path). - **`MAP_FIXED` on arena-chosen addresses** (`GuestArena.cpp:303`, `DirectMemory.cpp:406`). The used map is seeded from `/proc/self/maps` once, on the first `Arena()` call. A host mapping created later inside the window (driver, another library, a hinted `mmap`) isn't in the map, so the arena can hand out its range and `MAP_FIXED` silently replaces it. The objection to `MAP_FIXED_NOREPLACE` was that it returns `EEXIST` on reserved space, but nothing is reserved up front anymore. For ranges the arena picked and for `GuestMapNoOverwrite`, `MAP_FIXED_NOREPLACE` turns that case into an error instead of corruption. - **Eager reservation.** You dropped the up-front `PROT_NONE` reservation because the kernel's top-down `mmap` "picks addresses just below the stack inside the range". On x86-64 with 47-bit user space, the stack and `mmap_base` sit near `0x7ff...`, far above `0xFC_0000_0000`. Could you share the failing case (kernel, `ulimit -v`, the `/proc/self/maps` at the failure)? If a `MAP_NORESERVE` reservation works, it also removes the seed race above. - **Unknown protection becomes RW** (`GuestArena.cpp:298`). Throw for values the switch doesn't model ("exact or throw"). - **Tests don't pin the fix itself.** Both re-enabled checks map at fixed addresses. Nothing checks that a direct or flexible mapping with `addr == NULL` lands in `[0x2_0000_0000, 0xFC_0000_0000)`, which is #692, or that `munmap` followed by a same-size map reuses the freed range (claimed under "Hole reuse"). Linux tests for both, plus the hinted path (`addr != NULL` without `MAP_FIXED`), would cover what the PR changes.
jeffrey12cali commented 2026-10-07 16:46:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-07T16:46:58Z.


Thank you - the seed-race point is the important one and it changes the design, so I am taking it rather than defending it.

MAP_FIXED on arena-chosen addresses is wrong; switching to MAP_FIXED_NOREPLACE. You are right that the used map is seeded once from /proc/self/maps on the first Arena() call, so any host mapping created later inside the window - driver, another library, a hinted mmap - is invisible to the arena and MAP_FIXED silently replaces it. The original objection to MAP_FIXED_NOREPLACE was the up-front PROT_NONE reservation returning EEXIST, and that objection is gone now that nothing is reserved up front. I will use MAP_FIXED_NOREPLACE for arena-chosen ranges and for GuestMapNoOverwrite, and treat EEXIST as the retry/failure path rather than as corruption.

Eager reservation: I will re-measure and hand you the data. My note that top-down mmap picks addresses just below the stack inside the range was from a failing run, and your objection is reasonable - on 47-bit user space mmap_base sits far above 0xFC_0000_0000. I will re-test with a MAP_NORESERVE reservation and post the kernel version, ulimit -v, and the /proc/self/maps at the failure. If the reservation works, I would rather restore it, because it also removes the seed race above rather than mitigating it.

TryMarkUsed result ignored - agreed, it should throw. If the range partly overlaps a used one, returning true and then MAP_FIXED-ing over it is exactly the corruption case, and MarkUsed throws for it. I will make that path throw too. The second half of your point also stands: the catch currently releases the whole range, including the part the caller had already reserved through GuestArenaAllocate on the GuestHeap path - that has to unwind only what this call added.

Unknown protection becoming RW is wrong; it will throw. "Exact or throw" is the rule and I broke it.

Code comments removed - GuestArena.cpp:291-297 and GuestMemory.cpp:452. You are right that the description claimed there were none; that was wrong and the description will be corrected with the code.

Tests do not pin the fix - agreed, and this is the part I under-served. Both re-enabled checks map at fixed addresses, so neither would catch a regression of the actual bug. I will add Linux tests for: a direct and a flexible mapping with addr == NULL landing inside [0x2_0000_0000, 0xFC_0000_0000) (that is #692), munmap followed by a same-size map reusing the freed range (the "Hole reuse" claim, currently untested), and the hinted path (addr != NULL without MAP_FIXED) honouring or declining the hint explicitly.

CI. Noted on the missing checks for c9ce0789 and on the header moving Commit/Reset out of #ifdef _WIN32 - I will get the Windows/MinGW job green on the head before asking for another look, and will rebase onto current main as it moves.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6042551825 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6042551825). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-07T16:46:58Z. --- Thank you - the seed-race point is the important one and it changes the design, so I am taking it rather than defending it. **`MAP_FIXED` on arena-chosen addresses is wrong; switching to `MAP_FIXED_NOREPLACE`.** You are right that the used map is seeded once from `/proc/self/maps` on the first `Arena()` call, so any host mapping created later inside the window - driver, another library, a hinted `mmap` - is invisible to the arena and `MAP_FIXED` silently replaces it. The original objection to `MAP_FIXED_NOREPLACE` was the up-front `PROT_NONE` reservation returning `EEXIST`, and that objection is gone now that nothing is reserved up front. I will use `MAP_FIXED_NOREPLACE` for arena-chosen ranges and for `GuestMapNoOverwrite`, and treat `EEXIST` as the retry/failure path rather than as corruption. **Eager reservation: I will re-measure and hand you the data.** My note that top-down `mmap` picks addresses just below the stack inside the range was from a failing run, and your objection is reasonable - on 47-bit user space `mmap_base` sits far above `0xFC_0000_0000`. I will re-test with a `MAP_NORESERVE` reservation and post the kernel version, `ulimit -v`, and the `/proc/self/maps` at the failure. If the reservation works, I would rather restore it, because it also removes the seed race above rather than mitigating it. **`TryMarkUsed` result ignored - agreed, it should throw.** If the range partly overlaps a used one, returning `true` and then `MAP_FIXED`-ing over it is exactly the corruption case, and `MarkUsed` throws for it. I will make that path throw too. The second half of your point also stands: the `catch` currently releases the whole range, including the part the caller had already reserved through `GuestArenaAllocate` on the `GuestHeap` path - that has to unwind only what this call added. **Unknown protection becoming RW is wrong; it will throw.** "Exact or throw" is the rule and I broke it. **Code comments removed** - `GuestArena.cpp:291-297` and `GuestMemory.cpp:452`. You are right that the description claimed there were none; that was wrong and the description will be corrected with the code. **Tests do not pin the fix - agreed, and this is the part I under-served.** Both re-enabled checks map at fixed addresses, so neither would catch a regression of the actual bug. I will add Linux tests for: a direct and a flexible mapping with `addr == NULL` landing inside `[0x2_0000_0000, 0xFC_0000_0000)` (that is #692), `munmap` followed by a same-size map reusing the freed range (the "Hole reuse" claim, currently untested), and the hinted path (`addr != NULL` without `MAP_FIXED`) honouring or declining the hint explicitly. **CI.** Noted on the missing checks for `c9ce0789` and on the header moving `Commit`/`Reset` out of `#ifdef _WIN32` - I will get the Windows/MinGW job green on the head before asking for another look, and will rebase onto current `main` as it moves.
jeffrey12cali commented 2026-10-07 18:27:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-07T18:27:50Z.


All six points addressed; head is c4a8217c. The reservation question went better for you than for me - you were right and I was wrong, and the design changed because of it.

Eager reservation: it works, and it is now in. Measured on this box before touching the design:

kernel:      7.2.8-arch1-2
ulimit -v:   unlimited
window:      0x2_0000_0000 .. 0xFC_0000_0000
result:      1000.0 GiB reserved in 1000 x 1 GiB PROT_NONE | MAP_NORESERVE | MAP_FIXED_NOREPLACE chunks, 0 failures

So my "the kernel's top-down mmap picks addresses just below the stack inside the range" was a misattribution: what actually failed was a single mmap of the whole window, which returns EEXIST because existing host mappings intersect it. Reserving the free intervals in chunks works fine, and the arena now does exactly that in its constructor, after seeding. That removes the race you described rather than mitigating it, which is the better place to be.

Why commit still uses MAP_FIXED. I implemented your MAP_FIXED_NOREPLACE suggestion first, and it broke guest_memory with Arena mapping failed: File exists: commit legitimately replaces the arena's own PROT_NONE reservation, and NOREPLACE cannot tell that mapping from a foreign one. With the window reserved up front, no foreign mapping can exist inside it, so MAP_FIXED is correct for commit and the corruption you were protecting against is closed at the source. I would rather have it that way round anyway - the guard is now "nothing else can be in there" instead of "hope the map is up to date".

TryMarkUsed - the contract was the bug, not just the ignored result. It returned false both when the range was already fully used and when it had just marked it, so the caller could not tell those apart, and a partial overlap returned true without marking anything. Replaced with a commit-specific marker that returns whether this call inserted the range: a fully-covered range is accepted (callers pre-reserve through GuestArenaAllocate, which is what made the naive MarkUsed throw in six tests), a partial overlap throws, and the catch now releases only when this call did the marking - so the GuestHeap path's reservation is no longer unwound by someone else's failure. TryMarkUsed is deleted rather than left as a trap.

Unknown protection throws. default: no longer returns PROT_READ | PROT_WRITE.

Comments gone - the // PAGE_* cases and the // PAGE_READWRITE in the test. My description claimed there were none while the diff carried them; that was wrong and is fixed in both.

Tests now pin the change, which was the fairest criticism: three Linux cases added - unhinted placement lands inside the arena window (that is #692), a released range is handed out again for the same size (this is the "Hole reuse" claim from my description, which was previously untested - it passes, and now cannot silently regress), and the hinted path never returns below the hint and always inside the arena. Suite: 322/322 on this base.

CI / freshness, one thing I cannot fix from my side: I cannot rebase onto current main, because pushing main's commits that touch .github/workflows/conventions.yml into my fork is refused - the OAuth token has no workflow scope. This head is therefore based on 931109b3. If there is a standard way to handle that for contributor forks (web-UI sync of the fork's main, or a scoped token), tell me and I will rebase and re-run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6044227724 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6044227724). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-07T18:27:50Z. --- All six points addressed; head is `c4a8217c`. The reservation question went better for you than for me - you were right and I was wrong, and the design changed because of it. **Eager reservation: it works, and it is now in.** Measured on this box before touching the design: ``` kernel: 7.2.8-arch1-2 ulimit -v: unlimited window: 0x2_0000_0000 .. 0xFC_0000_0000 result: 1000.0 GiB reserved in 1000 x 1 GiB PROT_NONE | MAP_NORESERVE | MAP_FIXED_NOREPLACE chunks, 0 failures ``` So my "the kernel's top-down `mmap` picks addresses just below the stack inside the range" was a **misattribution**: what actually failed was a *single* `mmap` of the whole window, which returns `EEXIST` because existing host mappings intersect it. Reserving the free intervals in chunks works fine, and the arena now does exactly that in its constructor, after seeding. That removes the race you described rather than mitigating it, which is the better place to be. **Why commit still uses `MAP_FIXED`.** I implemented your `MAP_FIXED_NOREPLACE` suggestion first, and it broke `guest_memory` with `Arena mapping failed: File exists`: commit legitimately replaces the arena's *own* `PROT_NONE` reservation, and `NOREPLACE` cannot tell that mapping from a foreign one. With the window reserved up front, no foreign mapping can exist inside it, so `MAP_FIXED` is correct for commit and the corruption you were protecting against is closed at the source. I would rather have it that way round anyway - the guard is now "nothing else can be in there" instead of "hope the map is up to date". **`TryMarkUsed` - the contract was the bug, not just the ignored result.** It returned `false` both when the range was already fully used and when it had just marked it, so the caller could not tell those apart, and a partial overlap returned `true` without marking anything. Replaced with a commit-specific marker that returns whether *this call* inserted the range: a fully-covered range is accepted (callers pre-reserve through `GuestArenaAllocate`, which is what made the naive `MarkUsed` throw in six tests), a partial overlap throws, and the `catch` now releases only when this call did the marking - so the `GuestHeap` path's reservation is no longer unwound by someone else's failure. `TryMarkUsed` is deleted rather than left as a trap. **Unknown protection throws.** `default:` no longer returns `PROT_READ | PROT_WRITE`. **Comments gone** - the `// PAGE_*` cases and the `// PAGE_READWRITE` in the test. My description claimed there were none while the diff carried them; that was wrong and is fixed in both. **Tests now pin the change**, which was the fairest criticism: three Linux cases added - unhinted placement lands inside the arena window (that is #692), a released range is handed out again for the same size (this is the "Hole reuse" claim from my description, which was previously untested - it passes, and now cannot silently regress), and the hinted path never returns below the hint and always inside the arena. Suite: **322/322** on this base. **CI / freshness, one thing I cannot fix from my side:** I cannot rebase onto current `main`, because pushing `main`'s commits that touch `.github/workflows/conventions.yml` into my fork is refused - the OAuth token has no `workflow` scope. This head is therefore based on `931109b3`. If there is a standard way to handle that for contributor forks (web-UI sync of the fork's `main`, or a scoped token), tell me and I will rebase and re-run.
adriadam10 commented 2026-10-07 20:07:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T20:07:09Z.

Review: CHANGES_REQUESTED


Built and ran ctest on this head merged onto current main (Linux, GCC): 400/400, guest_memory included. Approved the pending CI runs; Linux/Windows still running. The design is fine now, but a few things need fixing before it can go in:

  • Reservation failures are ignored (GuestArena.cpp:175-182). Under ulimit -v 67108864 (64 GiB), 929 of the 992 1 GiB PROT_NONE | MAP_NORESERVE | MAP_FIXED_NOREPLACE chunks fail with ENOMEM, and guest_memory still passes. An EEXIST chunk (something mapped between reading /proc/self/maps and reserving) isn't recorded in _used either, so the arena can hand that range out later and PlaceAt/ArenaCommit will MAP_FIXED over the host mapping. A failed chunk should either go into _used/_hostRegions (for EEXIST, re-read the maps or mark the chunk) or make the arena unavailable or throw (ENOMEM). It shouldn't fall back to unreserved without anything saying so.
  • Unmap reopens the window (DirectMemory.cpp:416-417): munmap followed by ArenaForget leaves the range unreserved, so after the first unmap a host mapping can land in the window again, which is the race the description says is closed. Inside the arena, replace the range with the PROT_NONE | MAP_NORESERVE reservation, as GuestArenaReset_nid_postfix already does (GuestArena.cpp:355).
  • No test for what #692 is about: none of the new tests go through sceKernelAllocateDirectMemory + sceKernelMapDirectMemory (or sceKernelMapNamedFlexibleMemory) with addr == NULL and check that the result is in [0x2_0000_0000, 0xFC_0000_0000). They call GuestArena directly. Without the change the tests don't compile (they use GuestArenaCommit/Reset, which used to be Windows-only), so right now nothing shows the kernel-level behaviour failing on main. Please add a kernel API test for the direct and the flexible path, and ideally another that unmaps and checks the range is reserved again.
  • Minor: double blank lines at GuestArena.cpp:73 and GuestMemory.cpp:493.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5447721566 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#pullrequestreview-5447721566). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T20:07:09Z. **Review:** CHANGES_REQUESTED --- Built and ran ctest on this head merged onto current `main` (Linux, GCC): 400/400, `guest_memory` included. Approved the pending CI runs; Linux/Windows still running. The design is fine now, but a few things need fixing before it can go in: - **Reservation failures are ignored** (`GuestArena.cpp:175-182`). Under `ulimit -v 67108864` (64 GiB), 929 of the 992 1 GiB `PROT_NONE | MAP_NORESERVE | MAP_FIXED_NOREPLACE` chunks fail with `ENOMEM`, and `guest_memory` still passes. An `EEXIST` chunk (something mapped between reading `/proc/self/maps` and reserving) isn't recorded in `_used` either, so the arena can hand that range out later and `PlaceAt`/`ArenaCommit` will `MAP_FIXED` over the host mapping. A failed chunk should either go into `_used`/`_hostRegions` (for `EEXIST`, re-read the maps or mark the chunk) or make the arena unavailable or throw (`ENOMEM`). It shouldn't fall back to unreserved without anything saying so. - **`Unmap` reopens the window** (`DirectMemory.cpp:416-417`): `munmap` followed by `ArenaForget` leaves the range unreserved, so after the first unmap a host mapping can land in the window again, which is the race the description says is closed. Inside the arena, replace the range with the `PROT_NONE | MAP_NORESERVE` reservation, as `GuestArenaReset_nid_postfix` already does (`GuestArena.cpp:355`). - **No test for what #692 is about**: none of the new tests go through `sceKernelAllocateDirectMemory` + `sceKernelMapDirectMemory` (or `sceKernelMapNamedFlexibleMemory`) with `addr == NULL` and check that the result is in `[0x2_0000_0000, 0xFC_0000_0000)`. They call `GuestArena` directly. Without the change the tests don't compile (they use `GuestArenaCommit/Reset`, which used to be Windows-only), so right now nothing shows the kernel-level behaviour failing on `main`. Please add a kernel API test for the direct and the flexible path, and ideally another that unmaps and checks the range is reserved again. - Minor: double blank lines at `GuestArena.cpp:73` and `GuestMemory.cpp:493`.
jeffrey12cali commented 2026-10-08 00:45:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-08T00:45:47Z.


All four points were correct. I reproduced each one before changing anything. Head is 9bee827b, and the suite is 100% tests passed out of 322.

1. Reservation failures were ignored. Confirmed, then fixed. Your case reproduces exactly. Before the change, guest_memory passed under ulimit -v 67108864 even though most chunks cannot be reserved. Now:

ulimit -v 67108864  ->  exit 134, guest arena: cannot reserve 0x19c0000000+0x40000000 (Cannot allocate memory)
ulimit -v 134217728 ->  exit 134, cannot reserve 0x29c0000000+0x40000000
unlimited           ->  100% tests passed out of 1

The handling now splits by cause, as you proposed:

  • EEXIST means something else owns that chunk. It is recorded in _used and _hostRegions, so the arena can never hand it out.
  • Any other error throws, with the address and the size in the message. The arena no longer falls back to unreserved space in silence.

2. Unmap reopened the window. Confirmed. munmap followed by ArenaForget left the range free, so a host mapping could take it after the first unmap. In-arena unmapped ranges now go through GuestArenaReset_nid_postfix, which maps PROT_NONE over the range instead of releasing it, so the reservation survives the unmap. There is no window between munmap and re-reserve, because the replacement is a single MAP_FIXED mapping.

3. No test for the kernel-level behaviour. Confirmed, and added. Two new tests use only the kernel API:

  • CheckUnhintedKernelMappingsLandInTheWindow calls sceKernelAllocateDirectMemory plus sceKernelMapDirectMemory and sceKernelMapNamedFlexibleMemory with addr == NULL, and asserts the result is inside [0x2_0000_0000, 0xFC_0000_0000).
  • CheckUnmappedArenaRangeStaysReserved maps, unmaps, and then asserts that a hostile MAP_FIXED_NOREPLACE at that address returns EEXIST.

I verified the first one fails without the change, by making ArenaAvailable() return false and rebuilding: 0% tests passed, 1 tests failed, and 100% with it restored. Your note about compilation is still true for the older arena-level tests, which use GuestArenaCommit/GuestArenaReset and do not build on main. The two new ones do not depend on that.

4. Double blank lines removed in GuestArena.cpp and GuestMemory.cpp.

Two overlaps I should not have found last. Checking open PRs again, I see work in the same files, and I would rather raise it than let a reviewer find it:

  • #1370 (gjonn) edits DirectMemory.cpp and tests/GuestMemory.cpp and deals with partly overlapped allocations, which is the same problem as my TryMarkUsed change.
  • #1360 (TibixDev) tracks changes to mapped address ranges in GuestAllocations. That is a different answer to the same race my eager reservation closes. If #1360 lands, the reservation may be redundant, and I would drop it.

Tell me which way you want this to go. I am happy to rebase onto either, or to cut the reservation out of this PR and keep only the placement and the overlap handling.

CI and rebase. Same limit as #864: I cannot push a branch that carries main's .github/workflows/conventions.yml commits without a workflow-scoped token, so this head is based on 931109b3. You mentioned approving the pending CI runs, and I can see those. A "Sync fork" on my fork would let me rebase onto current main and re-run everything here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6049815856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6049815856). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-08T00:45:47Z. --- All four points were correct. I reproduced each one before changing anything. Head is `9bee827b`, and the suite is `100% tests passed out of 322`. **1. Reservation failures were ignored. Confirmed, then fixed.** Your case reproduces exactly. Before the change, `guest_memory` passed under `ulimit -v 67108864` even though most chunks cannot be reserved. Now: ``` ulimit -v 67108864 -> exit 134, guest arena: cannot reserve 0x19c0000000+0x40000000 (Cannot allocate memory) ulimit -v 134217728 -> exit 134, cannot reserve 0x29c0000000+0x40000000 unlimited -> 100% tests passed out of 1 ``` The handling now splits by cause, as you proposed: - `EEXIST` means something else owns that chunk. It is recorded in `_used` and `_hostRegions`, so the arena can never hand it out. - Any other error throws, with the address and the size in the message. The arena no longer falls back to unreserved space in silence. **2. `Unmap` reopened the window. Confirmed.** `munmap` followed by `ArenaForget` left the range free, so a host mapping could take it after the first unmap. In-arena unmapped ranges now go through `GuestArenaReset_nid_postfix`, which maps `PROT_NONE` over the range instead of releasing it, so the reservation survives the unmap. There is no window between `munmap` and re-reserve, because the replacement is a single `MAP_FIXED` mapping. **3. No test for the kernel-level behaviour. Confirmed, and added.** Two new tests use only the kernel API: - `CheckUnhintedKernelMappingsLandInTheWindow` calls `sceKernelAllocateDirectMemory` plus `sceKernelMapDirectMemory` and `sceKernelMapNamedFlexibleMemory` with `addr == NULL`, and asserts the result is inside `[0x2_0000_0000, 0xFC_0000_0000)`. - `CheckUnmappedArenaRangeStaysReserved` maps, unmaps, and then asserts that a hostile `MAP_FIXED_NOREPLACE` at that address returns `EEXIST`. I verified the first one fails without the change, by making `ArenaAvailable()` return false and rebuilding: `0% tests passed, 1 tests failed`, and `100%` with it restored. Your note about compilation is still true for the older arena-level tests, which use `GuestArenaCommit`/`GuestArenaReset` and do not build on `main`. The two new ones do not depend on that. **4. Double blank lines removed** in `GuestArena.cpp` and `GuestMemory.cpp`. **Two overlaps I should not have found last.** Checking open PRs again, I see work in the same files, and I would rather raise it than let a reviewer find it: - #1370 (gjonn) edits `DirectMemory.cpp` and `tests/GuestMemory.cpp` and deals with partly overlapped allocations, which is the same problem as my `TryMarkUsed` change. - #1360 (TibixDev) tracks changes to mapped address ranges in `GuestAllocations`. That is a different answer to the same race my eager reservation closes. If #1360 lands, the reservation may be redundant, and I would drop it. Tell me which way you want this to go. I am happy to rebase onto either, or to cut the reservation out of this PR and keep only the placement and the overlap handling. **CI and rebase.** Same limit as #864: I cannot push a branch that carries `main`'s `.github/workflows/conventions.yml` commits without a `workflow`-scoped token, so this head is based on `931109b3`. You mentioned approving the pending CI runs, and I can see those. A "Sync fork" on my fork would let me rebase onto current `main` and re-run everything here.
oneandonlydean commented 2026-10-08 05:12:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T05:12:40Z.


The Windows build fails on this head:

core/libs/prx/libc/src/GuestArena.cpp:8:10: fatal error: sys/mman.h: No such file or directory

Please put the new <unistd.h> / <sys/mman.h> includes, and the code that needs them, under #ifndef _WIN32.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052798253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6052798253). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T05:12:40Z. --- The Windows build fails on this head: ``` core/libs/prx/libc/src/GuestArena.cpp:8:10: fatal error: sys/mman.h: No such file or directory ``` Please put the new `<unistd.h>` / `<sys/mman.h>` includes, and the code that needs them, under `#ifndef _WIN32`.
jeffrey12cali commented 2026-10-08 11:56:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-08T11:56:22Z.


Fixed, and thank you for catching it. Head is 90172a19.

The three POSIX headers were added at the top of GuestArena.cpp outside any guard, which is exactly the reported failure:

core/libs/prx/libc/src/GuestArena.cpp:8:10: fatal error: sys/mman.h: No such file or directory

They are now inside #ifndef _WIN32, together. The code that needs them was already guarded: TryReserve, ReserveFreeRanges and the constructor call sit inside #if defined(__linux__), and MarkUsedForCommit uses only standard facilities, so it compiles on both.

How I checked it, and the limit of that check. I have no MinGW toolchain on this machine, so I could not run the Windows build. I verified the reported failure specifically, with the preprocessor:

  • g++ -E -D_WIN32 over the file: exit 0, and no request for sys/mman.h or unistd.h (previously that was the fatal error).
  • g++ -E for Linux: exit 0, headers still resolve.
  • Linux build and ctest: 100% tests passed out of 438.

So this removes the reported error, but only CI on the MinGW job can confirm the Windows compile. Please approve the run when convenient.

@ghreprimand thank you for the careful independent check on PPSA01341, and for stating its limits as clearly as the result. The mapping movement is the part this PR is about: high addresses such as 0x7fff94400000 on the base, versus 0x200000000 and 0x200300000 with the change, and the title passing the allocator-initialisation fault at RVA 0x812b49. I also take your two caveats as written: this is an early-startup result and not a playability claim, and the later fault at RVA 0x1452ee3 is a separate matter with no established cause. The userfaultfd ENOSYS skip on your kernel is worth noting for anyone else reading this thread, because it means agc_write_tracking is not evidence either way there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6059318819 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6059318819). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-08T11:56:22Z. --- Fixed, and thank you for catching it. Head is `90172a19`. The three POSIX headers were added at the top of `GuestArena.cpp` outside any guard, which is exactly the reported failure: ``` core/libs/prx/libc/src/GuestArena.cpp:8:10: fatal error: sys/mman.h: No such file or directory ``` They are now inside `#ifndef _WIN32`, together. The code that needs them was already guarded: `TryReserve`, `ReserveFreeRanges` and the constructor call sit inside `#if defined(__linux__)`, and `MarkUsedForCommit` uses only standard facilities, so it compiles on both. How I checked it, and the limit of that check. I have no MinGW toolchain on this machine, so I could not run the Windows build. I verified the reported failure specifically, with the preprocessor: - `g++ -E -D_WIN32` over the file: exit 0, and no request for `sys/mman.h` or `unistd.h` (previously that was the fatal error). - `g++ -E` for Linux: exit 0, headers still resolve. - Linux build and `ctest`: `100% tests passed out of 438`. So this removes the reported error, but only CI on the MinGW job can confirm the Windows compile. Please approve the run when convenient. @ghreprimand thank you for the careful independent check on PPSA01341, and for stating its limits as clearly as the result. The mapping movement is the part this PR is about: high addresses such as `0x7fff94400000` on the base, versus `0x200000000` and `0x200300000` with the change, and the title passing the allocator-initialisation fault at RVA `0x812b49`. I also take your two caveats as written: this is an early-startup result and not a playability claim, and the later fault at RVA `0x1452ee3` is a separate matter with no established cause. The `userfaultfd` `ENOSYS` skip on your kernel is worth noting for anyone else reading this thread, because it means `agc_write_tracking` is not evidence either way there.
blawesom commented 2026-10-08 12:29:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-08T12:29:13Z.

Review: DISMISSED


Two findings on the current head, both pre-merge. Everything else from the earlier rounds I re-verified still holds: eager reservation, the commit-specific MarkUsedForCommit, protection switch, and the new kernel-level tests all check out against the source.

1. Windows CI is red on this head: GuestMemory.cpp does not compile.

The MinGW job fails at core/libs/tests/GuestMemory.cpp:553:

error: 'PROT_READ' was not declared in this scope; did you mean 'OF_READ'?
error: 'PROT_WRITE' was not declared in this scope; did you mean 'OF_WRITE'?

Moving the #endif fence down past CheckFixedMappingsReachTheApplicationAreaEnd made CheckUnmappedArenaRangeStaysReserved compile on Windows, and it uses raw mmap / PROT_READ | PROT_WRITE / MAP_FIXED_NOREPLACE / EEXIST. The preprocessor check after the include fix covered GuestArena.cpp but not the test file. The function (and its call site in main) needs a #if defined(__linux__) guard — the hostile MAP_FIXED_NOREPLACE probe is Linux-specific anyway. The other new tests compile cross-platform, so the guard can be tight: only this one function.

2. The Linux GuestArenaReset_nid_postfix releases arena accounting internally, breaking the Reset contract every other caller follows — causing a double release (and a race) on every Linux call site.

The Windows Reset (WindowsMappings::Reset) resets memory and never touches Arena::_used; accounting is always the caller's job. That is the contract everywhere in the tree:

  • GuestHeap.cpp:171: GuestArenaReset_nid_postfix(...) then GuestArenaRelease_nid_postfix(...)
  • the Windows munmap shim in DirectMemory.cpp (~line 104): GuestArenaReset_nid_postfix(...) then arena.Release(...)
  • BdaResources.cpp and Recorder.cpp: GuestArenaReset_nid_postfix paired with GuestArenaRelease_nid_postfix

The new Linux implementation ends with Arena::Get().Release(pointer, bytes);, so on Linux every caller now releases twice:

  • Unmap (DirectMemory.cpp): GuestArenaReset releases, then ArenaForget → Contains is span-based, still true → GuestArenaRelease releases again
  • GuestHeap::release: GuestArenaReset releases, then the explicit GuestArenaRelease releases again

In the single-threaded case the second Release happens to be idempotent. But the two releases take the arena lock in separate acquisitions, so between them another thread can GuestArenaAllocate the just-freed range — and the second Release then erases the new owner's entry from _used, after which the arena hands the range out again. Guest heap frees and kernel mappings run on different threads in real titles, so this is reachable, not theoretical.

The minimal fix is to delete Arena::Get().Release(pointer, bytes); from the Linux GuestArenaReset_nid_postfix and restore the Windows contract (memory-level reset only, accounting by the caller). With that line gone, Unmap's ArenaForget stops being a redundant double release and becomes the single release it was evidently written to be, and GuestHeap::release is correct as on Windows. Note ArenaForget today is never load-bearing: on the arena path it double-releases, and on the munmap path Contains is false so it does nothing.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5456557392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#pullrequestreview-5456557392). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-08T12:29:13Z. **Review:** DISMISSED --- Two findings on the current head, both pre-merge. Everything else from the earlier rounds I re-verified still holds: eager reservation, the commit-specific `MarkUsedForCommit`, protection switch, and the new kernel-level tests all check out against the source. **1. Windows CI is red on this head: `GuestMemory.cpp` does not compile.** The MinGW job fails at `core/libs/tests/GuestMemory.cpp:553`: ``` error: 'PROT_READ' was not declared in this scope; did you mean 'OF_READ'? error: 'PROT_WRITE' was not declared in this scope; did you mean 'OF_WRITE'? ``` Moving the `#endif` fence down past `CheckFixedMappingsReachTheApplicationAreaEnd` made `CheckUnmappedArenaRangeStaysReserved` compile on Windows, and it uses raw `mmap` / `PROT_READ | PROT_WRITE` / `MAP_FIXED_NOREPLACE` / `EEXIST`. The preprocessor check after the include fix covered `GuestArena.cpp` but not the test file. The function (and its call site in `main`) needs a `#if defined(__linux__)` guard — the hostile `MAP_FIXED_NOREPLACE` probe is Linux-specific anyway. The other new tests compile cross-platform, so the guard can be tight: only this one function. **2. The Linux `GuestArenaReset_nid_postfix` releases arena accounting internally, breaking the `Reset` contract every other caller follows — causing a double release (and a race) on every Linux call site.** The Windows `Reset` (`WindowsMappings::Reset`) resets memory and never touches `Arena::_used`; accounting is always the caller's job. That is the contract everywhere in the tree: - `GuestHeap.cpp:171`: `GuestArenaReset_nid_postfix(...)` then `GuestArenaRelease_nid_postfix(...)` - the Windows `munmap` shim in `DirectMemory.cpp` (~line 104): `GuestArenaReset_nid_postfix(...)` then `arena.Release(...)` - `BdaResources.cpp` and `Recorder.cpp`: `GuestArenaReset_nid_postfix` paired with `GuestArenaRelease_nid_postfix` The new Linux implementation ends with `Arena::Get().Release(pointer, bytes);`, so on Linux every caller now releases twice: - `Unmap` (DirectMemory.cpp): `GuestArenaReset` releases, then `ArenaForget` → `Contains` is span-based, still true → `GuestArenaRelease` releases again - `GuestHeap::release`: `GuestArenaReset` releases, then the explicit `GuestArenaRelease` releases again In the single-threaded case the second `Release` happens to be idempotent. But the two releases take the arena lock in separate acquisitions, so between them another thread can `GuestArenaAllocate` the just-freed range — and the second `Release` then erases the *new* owner's entry from `_used`, after which the arena hands the range out again. Guest heap frees and kernel mappings run on different threads in real titles, so this is reachable, not theoretical. The minimal fix is to delete `Arena::Get().Release(pointer, bytes);` from the Linux `GuestArenaReset_nid_postfix` and restore the Windows contract (memory-level reset only, accounting by the caller). With that line gone, `Unmap`'s `ArenaForget` stops being a redundant double release and becomes the single release it was evidently written to be, and `GuestHeap::release` is correct as on Windows. Note `ArenaForget` today is never load-bearing: on the arena path it double-releases, and on the `munmap` path `Contains` is false so it does nothing.
jeffrey12cali commented 2026-10-08 14:31:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-08T14:31:37Z.


Both findings confirmed in the source, and both are fixed on head e0731456. Two commits, one per finding.

1. The Windows build failure was mine, and my earlier check could not have found it.

CheckUnmappedArenaRangeStaysReserved used mmap, PROT_READ, PROT_WRITE, MAP_FIXED_NOREPLACE and
EEXIST with no guard, and its call site had none either. I verified the guard by tracking conditional
nesting: before the change, the probe body (line 554) and the call (line 1167) are outside every __linux__
block; after it, both are inside one. The other PROT_READ | PROT_WRITE use in the file, line 1010, was
already guarded.

I should also correct what I said last round. I reported that I had verified the include fix with
g++ -E -D_WIN32. That check can only find preprocessor errors such as a missing header. An undeclared
identifier is a semantic error, so no amount of -E output would have shown this. The guard is what fixes
it, and only CI can confirm the build itself.

2. The double release is real, and your description of the mechanism is exact.

I confirmed each part in the source:

  • Arena::Contains compares against _base and _end only, so it stays true after the range is freed.
  • Arena::Release erases every overlapping entry in _used, under its own lock acquisition.
  • Unmap releases inside GuestArenaReset_nid_postfix and then again through ArenaForget.
  • GuestHeap::release calls GuestArenaReset_nid_postfix and then GuestArenaRelease_nid_postfix directly.

I then checked that no caller is left without a release, which is the only way your minimal fix could go
wrong. Every caller already releases explicitly: Recorder.cpp:68, DccKeysFirstWrite.cpp:107,
Srgb8ColorTarget.cpp:140 and three sites in BdaResources.cpp each follow a reset with a release, and the
Windows paths in DirectMemory.cpp release in the caller as well. So the deleted line was the only place
where the reset did the accounting itself.

ArenaForget becoming the single release on the arena path is the outcome I expected from your note.

Suite: 438 of 438 pass on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6062153869 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6062153869). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-08T14:31:37Z. --- Both findings confirmed in the source, and both are fixed on head `e0731456`. Two commits, one per finding. **1. The Windows build failure was mine, and my earlier check could not have found it.** `CheckUnmappedArenaRangeStaysReserved` used `mmap`, `PROT_READ`, `PROT_WRITE`, `MAP_FIXED_NOREPLACE` and `EEXIST` with no guard, and its call site had none either. I verified the guard by tracking conditional nesting: before the change, the probe body (line 554) and the call (line 1167) are outside every `__linux__` block; after it, both are inside one. The other `PROT_READ | PROT_WRITE` use in the file, line 1010, was already guarded. I should also correct what I said last round. I reported that I had verified the include fix with `g++ -E -D_WIN32`. That check can only find preprocessor errors such as a missing header. An undeclared identifier is a semantic error, so no amount of `-E` output would have shown this. The guard is what fixes it, and only CI can confirm the build itself. **2. The double release is real, and your description of the mechanism is exact.** I confirmed each part in the source: - `Arena::Contains` compares against `_base` and `_end` only, so it stays true after the range is freed. - `Arena::Release` erases every overlapping entry in `_used`, under its own lock acquisition. - `Unmap` releases inside `GuestArenaReset_nid_postfix` and then again through `ArenaForget`. - `GuestHeap::release` calls `GuestArenaReset_nid_postfix` and then `GuestArenaRelease_nid_postfix` directly. I then checked that no caller is left without a release, which is the only way your minimal fix could go wrong. Every caller already releases explicitly: `Recorder.cpp:68`, `DccKeysFirstWrite.cpp:107`, `Srgb8ColorTarget.cpp:140` and three sites in `BdaResources.cpp` each follow a reset with a release, and the Windows paths in `DirectMemory.cpp` release in the caller as well. So the deleted line was the only place where the reset did the accounting itself. `ArenaForget` becoming the single release on the arena path is the outcome I expected from your note. Suite: 438 of 438 pass on this head.
jeffrey12cali commented 2026-10-08 15:47:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-08T15:47:38Z.


Rebased onto current main. Head is c2e15098, three commits, base 4b005b22. The branch was mergeable=false
before this, so the stale base was not harmless after all. I had assumed a three-way merge would absorb it;
that was wrong and I am correcting it here.

The conflict, and how I resolved it. c01044ee added commit-generation and private-mapping-observer
machinery to GuestArena.cpp inside the #ifdef _WIN32 region, which also carried its own copy of the
OutsideArena helper. This branch hoists that helper out of the region so the Linux path can throw it too.
The resolution keeps both intents:

  • one OutsideArena definition, outside the region, visible to both platforms
  • GuestArenaCommitGeneration_nid_postfix and GuestArenaSetPrivateMappingObserver_nid_postfix kept
    Windows-only, in the header and in the source, matching the #ifdef _WIN32 atomics they read
  • the Windows GuestArenaCommit_nid_postfix keeps the generation and observer logic unchanged
  • the Linux GuestArenaCommit_nid_postfix and GuestArenaReset_nid_postfix are untouched by the rebase

I checked that structure with a preprocessor-nesting pass rather than by eye, because the two duplicated
function names are easy to get wrong: definitions per platform, and the new symbols inside the region in both
files.

Validation. Suite on Linux: 463 of 463. The two fixes from your review are preserved: the guarded
fixed-mapping probe and the release-contract change. What I cannot check here is the Windows build, because
the resolved code is Windows-only and this machine has no MinGW. CI has to confirm it. cmake --build build
also fails on a jpeg_turbo_external install step that wants /opt/libjpeg-turbo, which is unrelated to this
change and is why scripts/build.sh names its targets.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6063664540 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6063664540). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-08T15:47:38Z. --- Rebased onto current `main`. Head is `c2e15098`, three commits, base `4b005b22`. The branch was `mergeable=false` before this, so the stale base was not harmless after all. I had assumed a three-way merge would absorb it; that was wrong and I am correcting it here. **The conflict, and how I resolved it.** `c01044ee` added commit-generation and private-mapping-observer machinery to `GuestArena.cpp` inside the `#ifdef _WIN32` region, which also carried its own copy of the `OutsideArena` helper. This branch hoists that helper out of the region so the Linux path can throw it too. The resolution keeps both intents: - one `OutsideArena` definition, outside the region, visible to both platforms - `GuestArenaCommitGeneration_nid_postfix` and `GuestArenaSetPrivateMappingObserver_nid_postfix` kept Windows-only, in the header and in the source, matching the `#ifdef _WIN32` atomics they read - the Windows `GuestArenaCommit_nid_postfix` keeps the generation and observer logic unchanged - the Linux `GuestArenaCommit_nid_postfix` and `GuestArenaReset_nid_postfix` are untouched by the rebase I checked that structure with a preprocessor-nesting pass rather than by eye, because the two duplicated function names are easy to get wrong: definitions per platform, and the new symbols inside the region in both files. **Validation.** Suite on Linux: 463 of 463. The two fixes from your review are preserved: the guarded fixed-mapping probe and the release-contract change. What I cannot check here is the Windows build, because the resolved code is Windows-only and this machine has no MinGW. CI has to confirm it. `cmake --build build` also fails on a `jpeg_turbo_external` install step that wants `/opt/libjpeg-turbo`, which is unrelated to this change and is why `scripts/build.sh` names its targets. Written with AI assistance.
fisherjoey commented 2026-10-08 19:30:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:30:56Z.


Linux data from a retail title.

Demon's Souls (PPSA01341 v1.07), Nobara 44 (Linux 7.2), GCC 16.2.1, Release, RTX 5070 Ti (595.91.07). Same relinked binary in all runs, no env vars.

  • main 4b005b22 without this PR: SIGSEGV 4-11 s after launch, under _dl_init, before the title opens any file. The fault is a guest byte store in an init function (mov %cl,(%rdx)) to 0x7fe19adb0d96 (SEGV_MAPERR, an unmapped address up in the host mmap range). It happened in 2 of 2 runs, and in 2 more with a modified libc.
  • main 4b005b22 + this PR (head c2e15098): boots, loads /app0/packagecmdlineargs.txt (#1321 resolves the case), and plays the attract movie at about 30 fps. Closing the window exited with code 0, in 2 of 2 runs.

So on this setup the title doesn't start on Linux without this PR.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6067506013 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6067506013). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T19:30:56Z. --- Linux data from a retail title. Demon's Souls (PPSA01341 v1.07), Nobara 44 (Linux 7.2), GCC 16.2.1, Release, RTX 5070 Ti (595.91.07). Same relinked binary in all runs, no env vars. - `main` 4b005b22 without this PR: SIGSEGV 4-11 s after launch, under `_dl_init`, before the title opens any file. The fault is a guest byte store in an init function (`mov %cl,(%rdx)`) to 0x7fe19adb0d96 (`SEGV_MAPERR`, an unmapped address up in the host mmap range). It happened in 2 of 2 runs, and in 2 more with a modified libc. - `main` 4b005b22 + this PR (head c2e15098): boots, loads `/app0/packagecmdlineargs.txt` (#1321 resolves the case), and plays the attract movie at about 30 fps. Closing the window exited with code 0, in 2 of 2 runs. So on this setup the title doesn't start on Linux without this PR. AI-assisted: yes.
jeffrey12cali commented 2026-10-08 22:30:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-08T22:30:56Z.


This is the most useful report on the thread, and one part of it I can answer with a measurement.

On the reservation and VK_ERROR_OUT_OF_DEVICE_MEMORY. I tested whether the eager reservation is what
starves device allocations. The probe reserves the same window this PR uses - 0x200000000 to
0xFC00000000, 1 GiB chunks, PROT_NONE | MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED_NOREPLACE, 1000 chunks, zero failures - and then allocates VkDeviceMemory from a heap with
VK_MEMORY_HEAP_DEVICE_LOCAL_BIT until it fails, once with the reservation and once without.

device step plain with the reservation
RTX 4070 Laptop, 8188 MiB device-local heap 1 GiB 22 allocations, 22528 MiB, then -2 identical: 22, 22528 MiB, then -2
RTX 4070 Laptop 256 MiB 16 allocations, 4096 MiB, then -2 identical
AMD 780M (RADV PHOENIX), 10798 MiB device-local heap 1 GiB 4096 MiB, then -2 identical
AMD 780M 256 MiB 4096 MiB, then -2 identical

So on my hardware the reservation does not reduce how much device memory can be allocated. Note also that
NVIDIA accepted 22 GiB of device-local allocations against an 8 GiB heap before failing: the limit reached
here is not the heap size.

Two limits on that conclusion, so it is not over-read. My card is a 4070 Laptop on driver 615.71.09, not a
5070 Ti on 595.91.07. And the probe allocates unbound VkDeviceMemory, while a title binds buffers and
images and may import host memory, so this rules out "the reservation steals device memory" narrowly, not
"the reservation is unrelated to your failure".

What would help. Since the title cannot run at all without this PR on your setup, the OOM cannot be
bisected against the PR alone. Two things would settle it:

  1. The failing allocation: allocationSize, memoryTypeIndex, and that type's heap index and flags. An
    OUT_OF_DEVICE_MEMORY with 14 GiB free usually means a constrained memory type (host-visible, or a BAR
    window) rather than an exhausted heap.
  2. Whether it changes with SOS-style reservation disabled - if you can run a build where the reservation is
    skipped but the window placement is kept, that separates the two halves of this PR.

I can post the probe source if it is useful to run against your card.

Housekeeping. The branch is rebased onto current main (head 3c54adf0) and the description now carries
your result, the two fixes from @blawesom, and the measured test times. Your run was against c2e15098, so
the numbers should be re-checked against the new head if you get a chance - no rush, and thank you for the
detail either way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070360494 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6070360494). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-08T22:30:56Z. --- This is the most useful report on the thread, and one part of it I can answer with a measurement. **On the reservation and `VK_ERROR_OUT_OF_DEVICE_MEMORY`.** I tested whether the eager reservation is what starves device allocations. The probe reserves the same window this PR uses - `0x200000000` to `0xFC00000000`, 1 GiB chunks, `PROT_NONE | MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED_NOREPLACE`, 1000 chunks, zero failures - and then allocates `VkDeviceMemory` from a heap with `VK_MEMORY_HEAP_DEVICE_LOCAL_BIT` until it fails, once with the reservation and once without. | device | step | plain | with the reservation | |---|---|---|---| | RTX 4070 Laptop, 8188 MiB device-local heap | 1 GiB | 22 allocations, 22528 MiB, then `-2` | **identical**: 22, 22528 MiB, then `-2` | | RTX 4070 Laptop | 256 MiB | 16 allocations, 4096 MiB, then `-2` | **identical** | | AMD 780M (RADV PHOENIX), 10798 MiB device-local heap | 1 GiB | 4096 MiB, then `-2` | **identical** | | AMD 780M | 256 MiB | 4096 MiB, then `-2` | **identical** | So on my hardware the reservation does not reduce how much device memory can be allocated. Note also that NVIDIA accepted 22 GiB of device-local allocations against an 8 GiB heap before failing: the limit reached here is not the heap size. Two limits on that conclusion, so it is not over-read. My card is a 4070 Laptop on driver 615.71.09, not a 5070 Ti on 595.91.07. And the probe allocates unbound `VkDeviceMemory`, while a title binds buffers and images and may import host memory, so this rules out "the reservation steals device memory" narrowly, not "the reservation is unrelated to your failure". **What would help.** Since the title cannot run at all without this PR on your setup, the OOM cannot be bisected against the PR alone. Two things would settle it: 1. The failing allocation: `allocationSize`, `memoryTypeIndex`, and that type's heap index and flags. An `OUT_OF_DEVICE_MEMORY` with 14 GiB free usually means a constrained memory type (host-visible, or a BAR window) rather than an exhausted heap. 2. Whether it changes with `SOS`-style reservation disabled - if you can run a build where the reservation is skipped but the window placement is kept, that separates the two halves of this PR. I can post the probe source if it is useful to run against your card. **Housekeeping.** The branch is rebased onto current `main` (head `3c54adf0`) and the description now carries your result, the two fixes from @blawesom, and the measured test times. Your run was against `c2e15098`, so the numbers should be re-checked against the new head if you get a chance - no rush, and thank you for the detail either way.
jeffrey12cali commented 2026-10-08 22:39:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-08T22:39:59Z.


Rebased onto current main after @fisherjoey's report; head is 3c54adf0, five files. CI is now green on it,
which closes the first finding directly:

  • windows: success. The MinGW build that failed with 'PROT_READ' was not declared in this scope now
    compiles, so the __linux__ guard on the fixed-mapping probe was the right fix.
  • linux: success. Suite locally: 491 of 491.
  • conventions: success.

Two notes for whoever re-reviews. The branch was 100+ commits behind, but no commit in that range touched
GuestArena.cpp, GuestArena.hpp, GuestHeap.cpp, DirectMemory.cpp or tests/GuestMemory.cpp, so the
rebase applied without conflict. And CONTRIBUTING.md gained a rule in that range: every test must finish in
30 s on the runners, cold. The slowest test in the suite is 4.19 s, and the two tests added here take 0.01 s
each, so this head is inside it.

The second finding, the double release, is unchanged by the rebase: GuestArenaReset_nid_postfix resets only,
and each caller releases once.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070480516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6070480516). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-08T22:39:59Z. --- Rebased onto current `main` after @fisherjoey's report; head is `3c54adf0`, five files. CI is now green on it, which closes the first finding directly: - `windows`: **success**. The MinGW build that failed with `'PROT_READ' was not declared in this scope` now compiles, so the `__linux__` guard on the fixed-mapping probe was the right fix. - `linux`: **success**. Suite locally: 491 of 491. - `conventions`: **success**. Two notes for whoever re-reviews. The branch was 100+ commits behind, but no commit in that range touched `GuestArena.cpp`, `GuestArena.hpp`, `GuestHeap.cpp`, `DirectMemory.cpp` or `tests/GuestMemory.cpp`, so the rebase applied without conflict. And `CONTRIBUTING.md` gained a rule in that range: every test must finish in 30 s on the runners, cold. The slowest test in the suite is 4.19 s, and the two tests added here take 0.01 s each, so this head is inside it. The second finding, the double release, is unchanged by the rebase: `GuestArenaReset_nid_postfix` resets only, and each caller releases once.
hugodearaujo commented 2026-10-09 12:36:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-09T12:36:39Z.


Another title for this one: Hades (PPSA03355 v01.003) on Linux (Arch, GCC, RX 9070 XT).

Its bundled libc.prx creates the title's 4 GiB mspace from malloc_init: sceKernelAllocateDirectMemory(0, 0x360000000, 0x100000000, 0x200000, 0xC), then sceKernelMapDirectMemory, then sceLibcMspaceCreate. On main the mapping lands at 0x7ffef3a00000. The bundled libc's own sceLibcMspaceCreate refuses that address (its range checks shift by 40 and 43 bits), malloc_init returns 1, and libc's start-up raises:

[src/Exception.cpp:300 sceKernelDebugRaiseException] sceKernelDebugRaiseException c1=-1610481645 c2=0

(0xa0020013), followed by a crash.

With this branch (3c54adf01) merged onto current main, the raise is gone. The title creates its Vulkan device and swapchain, uploads its first textures, and stops much later on an unrelated renderer issue.

Note: on main, Hades first stops at load on the missing pthread_getname_np (#1798), so these runs include that PR as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6081020383 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6081020383). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-09T12:36:39Z. --- Another title for this one: Hades (PPSA03355 v01.003) on Linux (Arch, GCC, RX 9070 XT). Its bundled `libc.prx` creates the title's 4 GiB mspace from `malloc_init`: `sceKernelAllocateDirectMemory(0, 0x360000000, 0x100000000, 0x200000, 0xC)`, then `sceKernelMapDirectMemory`, then `sceLibcMspaceCreate`. On `main` the mapping lands at `0x7ffef3a00000`. The bundled libc's own `sceLibcMspaceCreate` refuses that address (its range checks shift by 40 and 43 bits), `malloc_init` returns 1, and libc's start-up raises: ``` [src/Exception.cpp:300 sceKernelDebugRaiseException] sceKernelDebugRaiseException c1=-1610481645 c2=0 ``` (`0xa0020013`), followed by a crash. With this branch (`3c54adf01`) merged onto current `main`, the raise is gone. The title creates its Vulkan device and swapchain, uploads its first textures, and stops much later on an unrelated renderer issue. Note: on `main`, Hades first stops at load on the missing `pthread_getname_np` (#1798), so these runs include that PR as well.
jeffrey12cali commented 2026-10-09 14:46:48 +00:00 (Migrated from github.com)

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


One more reason this PR matters on Linux, found while chasing a frame-rate problem on a title.

PageStates::initialize in libSceAgcDriver/Execution/src/GuestMemory.cpp asks GuestArenaRange for the
guest window in order to size a per-page bitmap, and describePages consults that bitmap before it queries
the kernel. Because the Arena constructor here is inside #ifdef _WIN32, on Linux the range is
base = 0 size = 0, PageSpan::allocate() fails, spanOf() always returns null, and every guest-memory
validation falls through to reading and parsing /proc/self/maps - once per loop iteration. Measured on a
retail title: 1,172,045 map parses and 64,207,427 parsed lines in one run, 50.8 % of all CPU inside
std::istream
, with the game's own code at 3 %.

Populating the span and caching the query results moved the CPU-bound frame rate from 7.40 to 60.32 FPS.
So a non-empty arena span on Linux is a precondition for that fix to do anything, which is what this PR
provides. Noting the dependency here as well, since AnyPS5#1791
and #1810 already cover the caching half: without #861 the
Linux effect of #1810 is nil, because there is nowhere to store.

Also worth knowing: PageStates::initialize only registers the ForgetPages invalidator when a span
allocated successfully, so on Linux today no page invalidation is installed at all. Making the span exist
activates it as a side effect.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083253217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6083253217). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-09T14:46:48Z. --- One more reason this PR matters on Linux, found while chasing a frame-rate problem on a title. `PageStates::initialize` in `libSceAgcDriver/Execution/src/GuestMemory.cpp` asks `GuestArenaRange` for the guest window in order to size a per-page bitmap, and `describePages` consults that bitmap before it queries the kernel. Because the `Arena` constructor here is inside `#ifdef _WIN32`, on Linux the range is `base = 0 size = 0`, `PageSpan::allocate()` fails, `spanOf()` always returns null, and **every** guest-memory validation falls through to reading and parsing `/proc/self/maps` - once per loop iteration. Measured on a retail title: 1,172,045 map parses and 64,207,427 parsed lines in one run, **50.8 % of all CPU inside `std::istream`**, with the game's own code at 3 %. Populating the span and caching the query results moved the CPU-bound frame rate from **7.40 to 60.32 FPS**. So a non-empty arena span on Linux is a precondition for that fix to do anything, which is what this PR provides. Noting the dependency here as well, since [AnyPS5#1791](https://github.com/boykopovar/AnyPS5/issues/1791) and [#1810](https://github.com/boykopovar/AnyPS5/pull/1810) already cover the caching half: without #861 the Linux effect of #1810 is nil, because there is nowhere to store. Also worth knowing: `PageStates::initialize` only registers the `ForgetPages` invalidator when a span allocated successfully, so on Linux today no page invalidation is installed at all. Making the span exist activates it as a side effect. Written with AI assistance.
hugodearaujo commented 2026-10-09 15:30:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-09T15:30:29Z.


One more title for this one: Hollow Knight: Silksong (PPSA12544) on Linux, through flexible memory this time.

The title's bundled libSceNpCppWebApi runs CppWebApi::Common::initialize when the PSN plugin starts. It calls sceKernelMapNamedFlexibleMemory, then the bundled libc's sceLibcMspaceCreate on the result. That returns NULL for the address main hands out, and the title stops:

CppWebApi::Common::initialize() failed. ret = 0x80553504

followed by an uncaught Unity.PSN.PS5.PSNException carrying 0x80553504.

Base: main d70b89989 + #1836 + #1431 + #846 + #2323. With this branch (3c54adf01) merged on top, that stop is gone and the title reaches its title menu at about 60 fps.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084008646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6084008646). Originally posted by [hugodearaujo](https://github.com/hugodearaujo) on 2026-10-09T15:30:29Z. --- One more title for this one: Hollow Knight: Silksong (PPSA12544) on Linux, through flexible memory this time. The title's bundled `libSceNpCppWebApi` runs `CppWebApi::Common::initialize` when the PSN plugin starts. It calls `sceKernelMapNamedFlexibleMemory`, then the bundled libc's `sceLibcMspaceCreate` on the result. That returns NULL for the address `main` hands out, and the title stops: ``` CppWebApi::Common::initialize() failed. ret = 0x80553504 ``` followed by an uncaught `Unity.PSN.PS5.PSNException` carrying `0x80553504`. Base: `main` `d70b89989` + #1836 + #1431 + #846 + #2323. With this branch (`3c54adf01`) merged on top, that stop is gone and the title reaches its title menu at about 60 fps.
Mouhand-Kaddo commented 2026-10-09 21:10:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-09T21:10:07Z.


Independent Windows and Arch WSL validation of head 3c54adf0195ed10b0b246a0e552d069025f9cbe5 (all three commits), cherry-picked without source edits onto main 8b393b6e. No other runtime PRs were included in these isolated suite runs.

  • Windows 11 Pro build 26300, WinLibs GCC 15.2.0, Release, RX 6900 XT / driver 32.0.21045.5002: the complete build and explicit libs target succeed. CTest: 507 passed, 1 skipped, 3 failed / 511, 36.09 s. guest_memory, fiber, and windows_exceptions pass, including the Windows compilation of the guarded mapping probe. The three failures (agc_driver_pixel_interlock, agc_driver_sdwa_float_selectors, agc_driver_sdwa_ldexp_f16) also fail after rebuilding their targets on unchanged main 8b393b6e; guest_memory passes there too.
  • Arch Linux in WSL2, kernel 6.6.87.2-microsoft-standard-WSL2, GCC 16.2.1 20260810, Release, Mesa lavapipe (software Vulkan): complete build and libs succeed. CTest: 489 passed, 27 skipped, 1 timeout / 517, 45.00 s. guest_memory and fiber pass. agc_driver_flat_store reaches the 30 s timeout both here and after rebuilding its target on unchanged main 8b393b6e. This is software-Vulkan coverage, not Linux hardware-GPU validation.

Demon's Souls startup also advances on Linux. Keeping the PR #1559 relinker conversion fixed, main runtime libraries fail during heap setup with a high host mapping around 0x7fffd4500000. Replacing only the runtime libraries with this isolated PR's build moves allocations into the console window (including 0x200000000) and passes heap setup, worker-thread creation, and Vulkan device initialization. It still stops later with a bad worker-queue pointer or a wiped saved fiber context; I am not reporting playable compatibility. PR #2054 and #2310 are absent from that Linux runtime comparison.

I have now rebased the separate integration branch onto main 4c367419 for further investigation. The suite counts above specifically describe 8b393b6e + this PR, not that newer integration branch. Testing and this report were AI-assisted.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089311714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6089311714). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-09T21:10:07Z. --- Independent Windows and Arch WSL validation of head `3c54adf0195ed10b0b246a0e552d069025f9cbe5` (all three commits), cherry-picked without source edits onto main `8b393b6e`. No other runtime PRs were included in these isolated suite runs. - Windows 11 Pro build 26300, WinLibs GCC 15.2.0, Release, RX 6900 XT / driver 32.0.21045.5002: the complete build and explicit `libs` target succeed. CTest: **507 passed, 1 skipped, 3 failed / 511**, 36.09 s. `guest_memory`, `fiber`, and `windows_exceptions` pass, including the Windows compilation of the guarded mapping probe. The three failures (`agc_driver_pixel_interlock`, `agc_driver_sdwa_float_selectors`, `agc_driver_sdwa_ldexp_f16`) also fail after rebuilding their targets on unchanged main `8b393b6e`; `guest_memory` passes there too. - Arch Linux in WSL2, kernel 6.6.87.2-microsoft-standard-WSL2, GCC 16.2.1 20260810, Release, Mesa lavapipe (software Vulkan): complete build and `libs` succeed. CTest: **489 passed, 27 skipped, 1 timeout / 517**, 45.00 s. `guest_memory` and `fiber` pass. `agc_driver_flat_store` reaches the 30 s timeout both here and after rebuilding its target on unchanged main `8b393b6e`. This is software-Vulkan coverage, not Linux hardware-GPU validation. Demon's Souls startup also advances on Linux. Keeping the PR #1559 relinker conversion fixed, main runtime libraries fail during heap setup with a high host mapping around `0x7fffd4500000`. Replacing only the runtime libraries with this isolated PR's build moves allocations into the console window (including `0x200000000`) and passes heap setup, worker-thread creation, and Vulkan device initialization. It still stops later with a bad worker-queue pointer or a wiped saved fiber context; I am not reporting playable compatibility. PR #2054 and #2310 are absent from that Linux runtime comparison. I have now rebased the separate integration branch onto main `4c367419` for further investigation. The suite counts above specifically describe `8b393b6e` + this PR, not that newer integration branch. Testing and this report were AI-assisted.
adriadam10 commented 2026-10-09 22:00:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:00:21Z.

Review: DISMISSED


Rebuilt this head merged onto current main (Linux, GCC): guest_memory passes, but guest_mlock aborts (it passes on main without this PR; patched_libraries fails here with or without it, so I'm ignoring that one).

  • guest_mlock regression. The last mlock before the abort is on the range just unmapped with sceKernelMunmap(mapped, length) (core/libs/tests/GuestMlock.cpp:112-114), which expects -1/ENOMEM. With this PR an in-arena unmap goes through GuestArenaReset and leaves the range as a PROT_NONE reservation (DirectMemory.cpp:452-455), so sceKernelMlock/sceKernelMunlock no longer see an unmapped range. The test landed with munlock; the head was green before it was on main. Please make mlock/munlock (and anything else that asks the kernel "is this mapped?") answer from the allocation registry instead of the host mapping, or otherwise restore ENOMEM for unregistered ranges, and keep guest_mlock passing.
  • Minor: Arena::PageSize() (GuestArena.cpp:222) is unused; <sstream>/<fstream> sit outside the #ifndef _WIN32 block they belong with; double blank line at core/libs/tests/GuestMemory.cpp:522.

The rest looks right to me, and the title reports in the thread (Demon's Souls, Hades, Silksong, LEGO Horizon) are good evidence for the placement. Once guest_mlock is green I expect to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5475750596 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#pullrequestreview-5475750596). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:00:21Z. **Review:** DISMISSED --- Rebuilt this head merged onto current `main` (Linux, GCC): `guest_memory` passes, but `guest_mlock` aborts (it passes on `main` without this PR; `patched_libraries` fails here with or without it, so I'm ignoring that one). - **`guest_mlock` regression.** The last `mlock` before the abort is on the range just unmapped with `sceKernelMunmap(mapped, length)` (`core/libs/tests/GuestMlock.cpp:112-114`), which expects `-1`/`ENOMEM`. With this PR an in-arena unmap goes through `GuestArenaReset` and leaves the range as a `PROT_NONE` reservation (`DirectMemory.cpp:452-455`), so `sceKernelMlock`/`sceKernelMunlock` no longer see an unmapped range. The test landed with `munlock`; the head was green before it was on `main`. Please make `mlock`/`munlock` (and anything else that asks the kernel "is this mapped?") answer from the allocation registry instead of the host mapping, or otherwise restore `ENOMEM` for unregistered ranges, and keep `guest_mlock` passing. - Minor: `Arena::PageSize()` (`GuestArena.cpp:222`) is unused; `<sstream>`/`<fstream>` sit outside the `#ifndef _WIN32` block they belong with; double blank line at `core/libs/tests/GuestMemory.cpp:522`. The rest looks right to me, and the title reports in the thread (Demon's Souls, Hades, Silksong, LEGO Horizon) are good evidence for the placement. Once `guest_mlock` is green I expect to merge.
alfalfa-star commented 2026-10-10 08:48:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-10T08:48:38Z.


On current main (6cc33583), this branch (3c54adf0) merges cleanly but breaks guest_mlock. That test came in with mlock/munlock (892aa8b5, 107860878), after this branch's base, so CI here never ran it.

  • main alone: guest_mlock passes. main + this PR: it aborts.
  • The failing check is GuestMlock.cpp:118: after sceKernelMunmap(mapped, length), munlock(mapped, page) should return -1 with ENOMEM (12), but it returns 0. The mlock check just before it (line 116) still fails with ENOMEM as expected.
  • My reading: with the arena, an unmapped guest range stays host-reserved inside the window, so the host sees the same thing as a sceKernelReserveVirtualRange reservation. The test expects munlock on a reservation to succeed (line 110) and on a freed range to fail (line 118), and those two states now look the same to the host. So sceKernelMunlock probably needs to ask the guest mapping state, as msync does with RangeMapped, rather than the host.

Setup: Linux (Arch), GCC, Release. Found while rebuilding our PPSA14632 test branch on current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095828585 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6095828585). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-10T08:48:38Z. --- On current `main` (6cc33583), this branch (3c54adf0) merges cleanly but breaks `guest_mlock`. That test came in with `mlock`/`munlock` (892aa8b5, 107860878), after this branch's base, so CI here never ran it. - `main` alone: `guest_mlock` passes. `main` + this PR: it aborts. - The failing check is `GuestMlock.cpp:118`: after `sceKernelMunmap(mapped, length)`, `munlock(mapped, page)` should return -1 with ENOMEM (12), but it returns 0. The `mlock` check just before it (line 116) still fails with ENOMEM as expected. - My reading: with the arena, an unmapped guest range stays host-reserved inside the window, so the host sees the same thing as a `sceKernelReserveVirtualRange` reservation. The test expects `munlock` on a reservation to succeed (line 110) and on a freed range to fail (line 118), and those two states now look the same to the host. So `sceKernelMunlock` probably needs to ask the guest mapping state, as `msync` does with `RangeMapped`, rather than the host. Setup: Linux (Arch), GCC, Release. Found while rebuilding our PPSA14632 test branch on current `main`.
oneandonlydean commented 2026-10-10 10:00:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T10:00:00Z.


@jeffrey12cali @adriadam10 Rebased onto current main and pushed to the branch; your three commits are unchanged apart from the test-file conflict with CheckGuestModuleImageProtection (kept under #ifdef _WIN32). Two commits on top:

  • guest_mlock: an unmapped arena range stays a PROT_NONE reservation, so host munlock succeeded on it. On Linux sceKernelMunlock now checks the guest mapping state first, the same check msync uses (RangeMapped, moved to DirectMemory.hpp as GuestRangeMapped), and returns ENOMEM for ranges that are neither mapped nor reserved. mlock already returns ENOMEM there from the host.
  • Reservation: the arena throws when /proc/self/maps can't be read or parsed, and when the kernel places a chunk somewhere other than the requested address (kernels that treat MAP_FIXED_NOREPLACE as a hint). Also removed the unused PageSize() and moved <fstream>/<sstream> into the non-Windows block.

Linux, GCC, Release: ctest 694/695 on this head, guest_mlock and guest_memory included. The one failure, agc_driver_dcc_keys_first_write, fails the same way on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096355667 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6096355667). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T10:00:00Z. --- @jeffrey12cali @adriadam10 Rebased onto current main and pushed to the branch; your three commits are unchanged apart from the test-file conflict with `CheckGuestModuleImageProtection` (kept under `#ifdef _WIN32`). Two commits on top: - `guest_mlock`: an unmapped arena range stays a `PROT_NONE` reservation, so host `munlock` succeeded on it. On Linux `sceKernelMunlock` now checks the guest mapping state first, the same check `msync` uses (`RangeMapped`, moved to `DirectMemory.hpp` as `GuestRangeMapped`), and returns `ENOMEM` for ranges that are neither mapped nor reserved. `mlock` already returns `ENOMEM` there from the host. - Reservation: the arena throws when `/proc/self/maps` can't be read or parsed, and when the kernel places a chunk somewhere other than the requested address (kernels that treat `MAP_FIXED_NOREPLACE` as a hint). Also removed the unused `PageSize()` and moved `<fstream>`/`<sstream>` into the non-Windows block. Linux, GCC, Release: ctest 694/695 on this head, `guest_mlock` and `guest_memory` included. The one failure, `agc_driver_dcc_keys_first_write`, fails the same way on main.
jeffrey12cali commented 2026-10-10 11:02:55 +00:00 (Migrated from github.com)

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


Thank you for the rebase and for fixing guest_mlock rather than asking me to. The diagnosis matches what we
assumed when we wrote the reservation: an unmapped range inside the arena stays a host reservation, so a host
munlock on it succeeds while the guest contract says ENOMEM. Checking the guest mapping state first, the
same test msync uses, is the right shape, and exporting it as GuestRangeMapped is better than a second
copy of the logic.

Two notes from the far end of this change, on the title #692 was filed for (PPSA28997):

  • That title is one of the ones that assert at start-up without the low window, so this merge is what lets it
    reach its main menu at all. It now holds 60 FPS through 15 minutes of continuous play.
  • The reservation path reads and parses /proc/self/maps to place the window. That is fine where it is,
    because it runs once at start-up. I only mention it because the same file on the per-frame path is the
    subject of #1791 and was fixed for the hot path by #157, so a reader may otherwise take the two readings to
    be the same problem.

One process note against myself: the Windows sys/mman.h failure you caught is the second portability mistake
I have shipped in this area. I now guard every Linux-only include in the same #ifndef _WIN32 block as the
code that needs it, which is also what the fork change in #1791's shape should do.

For the maintainers coordinating the queue: with #861 merged, #1810 and #2660 are no longer blocked by the
empty arena span, and the branch referenced in #1791 can now store anything on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096820023 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6096820023). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-10T11:02:55Z. --- Thank you for the rebase and for fixing `guest_mlock` rather than asking me to. The diagnosis matches what we assumed when we wrote the reservation: an unmapped range inside the arena stays a host reservation, so a host `munlock` on it succeeds while the guest contract says `ENOMEM`. Checking the guest mapping state first, the same test `msync` uses, is the right shape, and exporting it as `GuestRangeMapped` is better than a second copy of the logic. Two notes from the far end of this change, on the title #692 was filed for (`PPSA28997`): - That title is one of the ones that assert at start-up without the low window, so this merge is what lets it reach its main menu at all. It now holds 60 FPS through 15 minutes of continuous play. - The reservation path reads and parses `/proc/self/maps` to place the window. That is fine where it is, because it runs once at start-up. I only mention it because the same file on the per-frame path is the subject of #1791 and was fixed for the hot path by #157, so a reader may otherwise take the two readings to be the same problem. One process note against myself: the Windows `sys/mman.h` failure you caught is the second portability mistake I have shipped in this area. I now guard every Linux-only include in the same `#ifndef _WIN32` block as the code that needs it, which is also what the fork change in #1791's shape should do. For the maintainers coordinating the queue: with #861 merged, #1810 and #2660 are no longer blocked by the empty arena span, and the branch referenced in #1791 can now store anything on Linux.
EdouardSence commented 2026-10-10 11:36:05 +00:00 (Migrated from github.com)

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


Ratchet & Clank: Rift Apart (PPSA01474) on Linux faults about 11 s in since this merged (3 of 3 runs on b5f5362d3, gone in 2 of 2 with only this PR reverted). The trace and the placement sequence are in #2704: an address-less 64 GiB reservation is now placed at the bottom of the arena and covers the addresses the title hints for its next direct maps.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097082032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6097082032). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-10T11:36:05Z. --- Ratchet & Clank: Rift Apart (PPSA01474) on Linux faults about 11 s in since this merged (3 of 3 runs on `b5f5362d3`, gone in 2 of 2 with only this PR reverted). The trace and the placement sequence are in #2704: an address-less 64 GiB reservation is now placed at the bottom of the arena and covers the addresses the title hints for its next direct maps. *Tested and written by Claude (AI assistant) on a contributor's machine.*
jeffrey12cali commented 2026-10-11 14:46:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-11T14:46:14Z.


Author of the arena here, and the bisect is right: this is my change, not something the title was already doing.

What I got wrong. #861 places an address-less reservation at the lowest free address of the arena. For
PPSA01474 that put a 64 GiB PROT_NONE reservation directly over the addresses the title then hints for its
next two direct maps, so the non-fixed maps were relocated above it while the title went on using the hinted
address. Before the arena, the reservation went to the host's top-down area and the hints were honoured by
accident. Placing at the bottom was chosen for contiguity and was never tested against a title that hints after
reserving.

Status, for anyone reading this later. The fix is already on main: PlaceHintInReservation in
core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp (from #2667), which came through #2687; #2704 was
closed as a duplicate of it. Resolving it at map time rather than by moving the reservation is the right call,
and it is better than anything I would have proposed, because it leaves the placement policy alone.

The constraint from the other side, which the fix has to keep. PPSA28997 is a title that needs what #861
provides: with address-less mappings landing top-down it asserts at start-up, which is #692, and the low-window
arena is what lets it reach its main menu and hold 60 FPS. So the two titles pull in opposite directions - one
needs address-less reservations kept inside the low window, the other needs its hints to survive a reservation
that covers them. Honouring the hint at map time satisfies both, and I would not want a later simplification to
revert to "place address-less reservations high" just because that made the second case work.

What I can test, and what I cannot. I cannot run PPSA28997 on bare main today: our engine tree is a fork
pinned behind main, and main lacks the Umtx, Pthread and Exception shapes this title needs, plus the
bundled-libc.prx heap handshake still aborts at start-up there (see #693). So the honest test I can offer is
on our fork once it merges main: 15 minutes of scripted play with the mapping count and the start-up
milestones sampled, to confirm PlaceHintInReservation does not take the low window away from the titles that
need it. Say the word if that is worth having and I will run it and post the numbers here.

Thanks for the bisect and for writing it up with the trace - the hint= lines are what made this diagnosable
at all.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110213327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/861#issuecomment-6110213327). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-11T14:46:14Z. --- Author of the arena here, and the bisect is right: this is my change, not something the title was already doing. **What I got wrong.** #861 places an address-less reservation at the lowest free address of the arena. For `PPSA01474` that put a 64 GiB `PROT_NONE` reservation directly over the addresses the title then hints for its next two direct maps, so the non-fixed maps were relocated above it while the title went on using the hinted address. Before the arena, the reservation went to the host's top-down area and the hints were honoured by accident. Placing at the bottom was chosen for contiguity and was never tested against a title that hints after reserving. **Status, for anyone reading this later.** The fix is already on `main`: `PlaceHintInReservation` in `core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp` (from #2667), which came through #2687; #2704 was closed as a duplicate of it. Resolving it at map time rather than by moving the reservation is the right call, and it is better than anything I would have proposed, because it leaves the placement policy alone. **The constraint from the other side, which the fix has to keep.** `PPSA28997` is a title that needs what #861 provides: with address-less mappings landing top-down it asserts at start-up, which is #692, and the low-window arena is what lets it reach its main menu and hold 60 FPS. So the two titles pull in opposite directions - one needs address-less reservations kept inside the low window, the other needs its hints to survive a reservation that covers them. Honouring the hint at map time satisfies both, and I would not want a later simplification to revert to "place address-less reservations high" just because that made the second case work. **What I can test, and what I cannot.** I cannot run `PPSA28997` on bare `main` today: our engine tree is a fork pinned behind `main`, and `main` lacks the `Umtx`, `Pthread` and `Exception` shapes this title needs, plus the bundled-`libc.prx` heap handshake still aborts at start-up there (see #693). So the honest test I can offer is on our fork once it merges `main`: 15 minutes of scripted play with the mapping count and the start-up milestones sampled, to confirm `PlaceHintInReservation` does not take the low window away from the titles that need it. Say the word if that is worth having and I will run it and post the numbers here. Thanks for the bisect and for writing it up with the trace - the `hint=` lines are what made this diagnosable at all.
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!861
No description provided.