fix(libkernel): report is_committed from sceKernelVirtualQuery only for direct memory, as a PS5 does #22013

Merged
brajankw merged 1 commit from upstream-pr/22013 into main 2026-11-29 10:12:21 +00:00
brajankw commented 2026-11-17 01:32:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T01:32:38Z.


What

sceKernelVirtualQuery set is_committed for every registered or host-queried range. A PS5 payload (firmware 13.590.001) reports it only for direct memory, and 0 for flexible memory whether touched or not, stacks, images and reservations (the sceKernelVirtualQuery size and flags entry in docs/dev/debt/libkernel.md, which left it because mincore read the field).

  • QueryVirtualRange sets is_committed only for a direct mapping; host-queried memory (stacks, the title's own heap) now reports 0 too.
  • mincore was the only reader: it used is_committed to tell a mapping from a reservation. It now asks GuestReservation directly, so every mapped page is still resident and a reserved page is not.
  • GuestMemory.cpp: flexible pages and a stack address report is_committed 0; the 72-byte wire layout's flag byte is 0x01 (flexible) for flexible memory; mincore over a direct page followed by a reserved one gives 1, 0, also after the direct page is set to protection 0, which still reports is_committed; pages of the registered main image (a static global and a function) report neither committed, flexible nor direct. The existing mincore checks on anonymous mmap memory still expect 1.
  • The debt fragment drops the is_committed gap from the entry and notes that pooled memory was not measured.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head 8f161a08b2, rebased onto main 11c9e7764e without conflicts. The runs after the first two bullets are from the earlier head on main ab5089590a.

  • At 8f161a08b2, merged with #22046 and #22049 onto main 11c9e7764e: ctest -R '^(guest_sysarch|guest_memory|guest_mmap_fixed_anonymous|guest_virtual_query_arguments|np_uds_events|guest_np_uds_.*|guest_np_trophy_.*)$': 16 passed, and guest_mmap_executable skipped itself (exit 77) in this environment. This head adds Helldiverr's two pins.
  • Mutations: the registry branch reporting is_committed for anything not flexible fails guest_memory at the new image check; mincore treating protection 0 as not resident fails it at the new protection-0 check.
  • ctest -R '^guest_memory$': passed.
  • Negative control: with main's Export.cpp and PosixMemory.cpp and this branch's test, guest_memory fails at the first flexible-memory is_committed check.
  • Full ctest (5893 tests, -j 12) with this branch merged together with my other three branches of this batch: 5877 passed. The 16 failures are the set that fails on main in the same environment: six agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own) and ten that need a .git directory, network or a passwd entry for the user.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch at 8f161a08b2: no conflicting pull request. #18190 and #21569, which conflict with main, share Export.cpp, PosixMemory.cpp or GuestMemory.cpp and could not be compared; #18190 only renames mincore's export (a textual conflict, not a behaviour one), and #21569 changes neither is_committed nor mincore.
  • Not tested on Windows or macOS. No title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5348643636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22013). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T01:32:38Z. --- ### What `sceKernelVirtualQuery` set `is_committed` for every registered or host-queried range. A PS5 payload (firmware 13.590.001) reports it only for direct memory, and 0 for flexible memory whether touched or not, stacks, images and reservations (the `sceKernelVirtualQuery size and flags` entry in `docs/dev/debt/libkernel.md`, which left it because `mincore` read the field). - `QueryVirtualRange` sets `is_committed` only for a direct mapping; host-queried memory (stacks, the title's own heap) now reports 0 too. - `mincore` was the only reader: it used `is_committed` to tell a mapping from a reservation. It now asks `GuestReservation` directly, so every mapped page is still resident and a reserved page is not. - `GuestMemory.cpp`: flexible pages and a stack address report `is_committed` 0; the 72-byte wire layout's flag byte is `0x01` (flexible) for flexible memory; `mincore` over a direct page followed by a reserved one gives `1, 0`, also after the direct page is set to protection 0, which still reports `is_committed`; pages of the registered main image (a static global and a function) report neither committed, flexible nor direct. The existing `mincore` checks on anonymous `mmap` memory still expect 1. - The debt fragment drops the `is_committed` gap from the entry and notes that pooled memory was not measured. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release). Head `8f161a08b2`, rebased onto `main` `11c9e7764e` without conflicts. The runs after the first two bullets are from the earlier head on `main` `ab5089590a`. - At `8f161a08b2`, merged with #22046 and #22049 onto `main` `11c9e7764e`: `ctest -R '^(guest_sysarch|guest_memory|guest_mmap_fixed_anonymous|guest_virtual_query_arguments|np_uds_events|guest_np_uds_.*|guest_np_trophy_.*)$'`: 16 passed, and `guest_mmap_executable` skipped itself (exit 77) in this environment. This head adds Helldiverr's two pins. - Mutations: the registry branch reporting `is_committed` for anything not flexible fails `guest_memory` at the new image check; `mincore` treating protection 0 as not resident fails it at the new protection-0 check. - `ctest -R '^guest_memory$'`: passed. - Negative control: with `main`'s `Export.cpp` and `PosixMemory.cpp` and this branch's test, `guest_memory` fails at the first flexible-memory `is_committed` check. - Full `ctest` (5893 tests, `-j 12`) with this branch merged together with my other three branches of this batch: 5877 passed. The 16 failures are the set that fails on `main` in the same environment: six `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own) and ten that need a `.git` directory, network or a passwd entry for the user. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch` at `8f161a08b2`: no conflicting pull request. #18190 and #21569, which conflict with `main`, share `Export.cpp`, `PosixMemory.cpp` or `GuestMemory.cpp` and could not be compared; #18190 only renames `mincore`'s export (a textual conflict, not a behaviour one), and #21569 changes neither `is_committed` nor `mincore`. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 01:35:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T01:35:54Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b56a3a67ac:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_memory_tests built cleanly.
  • CTest (guest_memory, guest_mmap_fixed_anonymous, guest_mmap_executable):
    1/3 Test #5420: guest_mmap_executable ............   Passed    0.04 sec
    2/3 Test #5419: guest_mmap_fixed_anonymous .......   Passed    0.03 sec
    3/3 Test #5418: guest_memory .....................   Passed    4.82 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test #5420: guest_mmap_executable ............   Passed    0.03 sec
    2/3 Test #5419: guest_mmap_fixed_anonymous .......   Passed    0.03 sec
    3/3 Test #5418: guest_memory .....................Subprocess aborted***Exception:   0.61 sec
    67% tests passed, 1 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in Export.cpp:QueryVirtualRange that info->is_committed is correctly set to 1u for direct memory mappings and 0u for flexible/host/other ranges, adhering to real PS5 firmware measurements.
    • Verified in PosixMemory.cpp:mincore_nid_postfix that residency is determined by GuestReservation(pageCursor, &reservedStart, &reservedEnd), reporting resident (1) for mapped non-reserved pages and non-resident (0) for reservations.
    • Verified GuestReservation usage and pointer arguments (&reservedStart, &reservedEnd) against DirectMemory.hpp declaration.
    • Verified debt fragment docs/dev/debt/changes/fix-libkernel-virtual-query-committed-direct-only.md matches AGENTS.md conventions and documentation guidelines.
    • Verified test cases in GuestMemory.cpp for wire layout flags, flexible memory query, stack address query, and mincore over direct+reserved ranges.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5931182449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22013#pullrequestreview-5931182449). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T01:35:54Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b56a3a67ac`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_memory_tests` built cleanly. - **CTest** (`guest_memory`, `guest_mmap_fixed_anonymous`, `guest_mmap_executable`): ``` 1/3 Test #5420: guest_mmap_executable ............ Passed 0.04 sec 2/3 Test #5419: guest_mmap_fixed_anonymous ....... Passed 0.03 sec 3/3 Test #5418: guest_memory ..................... Passed 4.82 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libkernel/DirectMemory/Export.cpp`, `core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #5420: guest_mmap_executable ............ Passed 0.03 sec 2/3 Test #5419: guest_mmap_fixed_anonymous ....... Passed 0.03 sec 3/3 Test #5418: guest_memory .....................Subprocess aborted***Exception: 0.61 sec 67% tests passed, 1 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in Export.cpp:QueryVirtualRange that info->is_committed is correctly set to 1u for direct memory mappings and 0u for flexible/host/other ranges, adhering to real PS5 firmware measurements. - Verified in PosixMemory.cpp:mincore_nid_postfix that residency is determined by GuestReservation(pageCursor, &reservedStart, &reservedEnd), reporting resident (1) for mapped non-reserved pages and non-resident (0) for reservations. - Verified GuestReservation usage and pointer arguments (&reservedStart, &reservedEnd) against DirectMemory.hpp declaration. - Verified debt fragment docs/dev/debt/changes/fix-libkernel-virtual-query-committed-direct-only.md matches AGENTS.md conventions and documentation guidelines. - Verified test cases in GuestMemory.cpp for wire layout flags, flexible memory query, stack address query, and mincore over direct+reserved ranges. Looks Good To Me
MarcZX10 commented 2026-11-23 03:58:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T03:58:07Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected code implements the reported direct-memory-only is_committed behavior and checks reservations directly in mincore.

What I ran

Reviewed head b56a3a67ac1125908dd341621250c28c23578a5d. No commands or tests were run in this review; repo_read.py was used to inspect the prepared diff and targeted source ranges. The description reports Linux checks, which were not run by me.

Results

Check Result Note
Diff and targeted source review passed Four changed files inspected
Tests in this review not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full text of all four changed files was read, as shown in manifest.json. The behavior of the PS5 payload, title process, pooled memory, Windows and macOS, and author-reported test results were not independently verified. Excluded files: none are listed in the prepared manifest; files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016394613 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22013#pullrequestreview-6016394613). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T03:58:07Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected code implements the reported direct-memory-only `is_committed` behavior and checks reservations directly in `mincore`. ## What I ran Reviewed head `b56a3a67ac1125908dd341621250c28c23578a5d`. No commands or tests were run in this review; `repo_read.py` was used to inspect the prepared diff and targeted source ranges. The description reports Linux checks, which were not run by me. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Four changed files inspected | | Tests in this review | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full text of all four changed files was read, as shown in `manifest.json`. The behavior of the PS5 payload, title process, pooled memory, Windows and macOS, and author-reported test results were not independently verified. Excluded files: none are listed in the prepared manifest; `files.json` was not available through the reader. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 11:35:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T11:35:53Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed implementation and focused regression checks support the reported is_committed behavior.

What I ran

Read the prepared diff and relevant changed code at head 8f161a08b244649aff5725ca22a64dceb40be8c2, plus GuestReservation and its callers. No commands or tests were run; repo_read.py was unavailable as a runnable command in this interface.

Results

Check Result Note
Source review passed Four changed files read
Tests not run Test results in the PR description are author reported
Full file coverage passed All files listed as reviewed were read

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently. Windows and macOS behavior and console behavior were not verified. Read: core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp, core/libs/tests/GuestMemory.cpp, and docs/dev/debt/changes/fix-libkernel-virtual-query-committed-direct-only.md. The manifest lists all four as included; no changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6056880728 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22013#pullrequestreview-6056880728). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T11:35:53Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed implementation and focused regression checks support the reported `is_committed` behavior. ## What I ran Read the prepared diff and relevant changed code at head `8f161a08b244649aff5725ca22a64dceb40be8c2`, plus `GuestReservation` and its callers. No commands or tests were run; `repo_read.py` was unavailable as a runnable command in this interface. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Four changed files read | | Tests | not run | Test results in the PR description are author reported | | Full file coverage | passed | All files listed as reviewed were read | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run independently. Windows and macOS behavior and console behavior were not verified. Read: `core/libs/prx/libkernel/DirectMemory/Export.cpp`, `core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp`, `core/libs/tests/GuestMemory.cpp`, and `docs/dev/debt/changes/fix-libkernel-virtual-query-committed-direct-only.md`. The manifest lists all four as included; no changed files were excluded. ## To get this to a good state Nothing is required.
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!22013
No description provided.