fix(agc): describe the pages after a gap in a Linux host page query #442

Merged
oneandonlydean merged 1 commit from upstream-pr/442 into main 2026-10-03 22:32:42 +00:00
oneandonlydean commented 2026-10-03 07:35:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-03T07:35:10Z.


What

On Linux, a host page query that no cached page table covers walks /proc/self/maps line by line (describePages). When the cursor sat in a gap between two mappings, no line contained it, so the scan read the whole file and then reported the rest of the range as unmapped, including mapped pages after the gap. CommittedRanges and Accessible then gave a wrong answer for any range that starts in, or crosses, an unmapped hole.

The scan now stops at the first mapping above the cursor, reports the gap up to it as inaccessible and continues from there, which is what the VirtualQuery path already does with a free region. A range with no mapping above it is still reported unmapped to its end, as before.

It is also a speed fix: PPSA21564 queries near-null addresses (0x18, 0x30, 0x58) about 1500 times a second during resource capture, and each of those queries parsed every line of the maps file (about 5700 lines on my machine, mostly NVIDIA mappings) before giving up. That was about 220 us per query instead of 32.

#157 (where I offered this as a follow-up) rewrites this loop around a cached snapshot of the maps, but keeps the same behaviour: when findRegion misses, it emits {cursor, end, false, false} for the rest of the range. If #157 lands first I'll rebase this onto it; the fix there is the same few lines.

Tested

  • Linux (CachyOS, x86-64): full build with BUILD_TESTING=ON and ctest pass.
  • New RunUnmappedGapTests in agc_driver_graphics_tests (GuestAllocations.cpp, Linux only): maps three host pages, unmaps the middle one, and checks that CommittedRanges returns the first and third pages, that a query starting in the gap returns the third page, that Accessible refuses the whole block but accepts the third page, and that a near-null address is inaccessible. Against main's GuestMemory.cpp it fails with "the pages after an unmapped gap in host memory were not described".
  • PPSA21564: the change has been on my integration branch since 2026-10-01 through repeated passes of my visual regression check (checkpoint frames, flicker, shimmer, video tearing, FPS).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4724926501 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/442). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-03T07:35:10Z. --- ### What On Linux, a host page query that no cached page table covers walks `/proc/self/maps` line by line (`describePages`). When the cursor sat in a gap between two mappings, no line contained it, so the scan read the whole file and then reported the rest of the range as unmapped, including mapped pages after the gap. `CommittedRanges` and `Accessible` then gave a wrong answer for any range that starts in, or crosses, an unmapped hole. The scan now stops at the first mapping above the cursor, reports the gap up to it as inaccessible and continues from there, which is what the `VirtualQuery` path already does with a free region. A range with no mapping above it is still reported unmapped to its end, as before. It is also a speed fix: PPSA21564 queries near-null addresses (0x18, 0x30, 0x58) about 1500 times a second during resource capture, and each of those queries parsed every line of the maps file (about 5700 lines on my machine, mostly NVIDIA mappings) before giving up. That was about 220 us per query instead of 32. #157 (where I offered this as a follow-up) rewrites this loop around a cached snapshot of the maps, but keeps the same behaviour: when `findRegion` misses, it emits `{cursor, end, false, false}` for the rest of the range. If #157 lands first I'll rebase this onto it; the fix there is the same few lines. ### Tested - Linux (CachyOS, x86-64): full build with `BUILD_TESTING=ON` and `ctest` pass. - New `RunUnmappedGapTests` in `agc_driver_graphics_tests` (`GuestAllocations.cpp`, Linux only): maps three host pages, unmaps the middle one, and checks that `CommittedRanges` returns the first and third pages, that a query starting in the gap returns the third page, that `Accessible` refuses the whole block but accepts the third page, and that a near-null address is inaccessible. Against main's `GuestMemory.cpp` it fails with "the pages after an unmapped gap in host memory were not described". - PPSA21564: the change has been on my integration branch since 2026-10-01 through repeated passes of my visual regression check (checkpoint frames, flicker, shimmer, video tearing, FPS). ### 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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!442
No description provided.