Skip to content

fix(libkernel): query non-readable live mappings - #1929

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
MarcZX10:fix/virtualquery-partial-unmap
Oct 10, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
MarcZX10:fix/virtualquery-partial-unmap

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1894.

What

This PR carries the live-mapping extent fix from #1731 (the original commit author is preserved), adds support for querying live ranges whose registry protection is PROT_NONE, and includes the direct-mmap partial-unmap regression test contributed in #2267. The test commit retains Saranxzi as its author. sceKernelVirtualQuery must report current mapped extents after partial unmaps and still find non-readable mappings; GPU consumers continue using the existing readable-only lease.

Without the full-range snapshot, guest_ampr_markers fails when querying AMPR protection on a mapped range. The regression checks a PROT_NONE mapping and verifies the registered extent and protection. A debug assertion makes explicit that the full-range lease is address-ordered before the coalescing scan relies on that invariant.

Tested

Current head e06c459534fec70b5738d55392794fa963421024 is rebased linearly onto upstream main at e51d4e1f21280da4529dc7fe3a3d50d7d7dbc3ec. The complete source diff remains limited to four files.

  • Linux x86-64, GCC 12.2, Release: built guest_memory_tests; guest_memory passed (1/1) on this head, exercising flexible-range splits, PROT_NONE, and direct mmap after partial unmap.
  • Windows 11 Pro 25H2, RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0, Release: guest_memory passed and full CTest passed (510/510) on pre-rebase commit 099b8cf0 cherry-picked onto main d70b8998 (report); this predates the additional direct-mmap test. Saranxzi separately reported the direct-mmap regression passing on Windows and Linux on fix(libkernel): report live mapping bounds in sceKernelVirtualQuery after partial unmap #2267 head 8073bda, not on this combined head.
  • python3 tools/check_conventions.py --base upstream/main and git diff --check upstream/main...HEAD pass.
  • An earlier fork Build stopped at the unrelated missing SPIRV-Headers include in agc_shader_fusion_tests; fix(tests): add SPIRV-Headers to the tests that include VulkanTestDevice.hpp #2099 fixed that dependency. Eligibility, Conventions, report, and all three relinker jobs pass on this head. The automated PR workflow skipped the full Linux and Windows Build jobs; an authorized collaborator must start Build for those under ci(build): require manual full builds and auto-test relinker for contr #2113.
  • No console hardware was available.

Checklist

  • Based on current main; overlap with fix(libkernel): report live mapping bounds in sceKernelVirtualQuery after partial unmap #2267 is disclosed, and its direct-mmap regression test is included here with original author attribution; coordination with its author is pending
  • One topic: report live guest mapping extents after partial unmaps and for non-readable ranges
  • No code comments except technical debt comments; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behavior, not title-specific
  • Depends on: none
  • AI-assisted: yes

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The PR is based on current upstream main (f145139676a48306681d3a4d5fabf83938759daf), and the focused Linux guest_memory test plus conventions pass locally. No upstream checks are reported for head 493000d5787aff60a8fe6a892cb81da1e79c1e13. CONTRIBUTING says fork workflows marked action_required need maintainer approval; could an authorized maintainer approve Build and Conventions for this head?

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 493000d to 6e5bb47 Compare October 9, 2026 00:34
@MarcZX10

MarcZX10 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

#1929 now stacks on the exact current #1731 commit 1a301c48a74f879ac3136745056edd8b7bf04403 and contains the distinct follow-up for mapped, non-readable ranges. Fork Build 37868880231 passed on the identical source tree: Linux 497/497, Windows 488/488, and relinker CTests on Ubuntu, Windows and macOS. Exact-head Build 37870858453 is queued. Upstream still reports no checks; under CONTRIBUTING's fork workflow policy, could an authorized maintainer approve Build and Conventions for this head?

@klosixgaming-arch klosixgaming-arch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix for a real bug: after a partial munmap, sceKernelVirtualQuery was reporting the full allocation range instead of the live sub-range. The new logic coalesces contiguous sub-ranges (same allocationAddress, adjacent addresses) in both directions, so a query inside a fragmented allocation reports the correct live extent and a query in the unmapped hole returns EACCES. The test CheckVirtualQueryAfterPartialUnmap covers the merged range, the hole, the findNext flag, and the post-unmap state — exactly the regression this fixes.

Minor: the bidirectional merge walks the lease and assumes it is ordered by address; if that invariant is ever relaxed, the coalescing would silently under-merge. An assert (or a one-line note) that the lease is address-ordered would make the assumption explicit.

Written with AI assistance.

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 6e5bb47 to 9f25043 Compare October 9, 2026 00:52
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The lease is address-ordered by construction: the registry stores ranges in std::map keyed by address, and both lease functions append them in map iteration order. The updated all-range snapshot preserves the same ordering, so the adjacent-range merge walks stable address order.

@MarcZX10

MarcZX10 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

@klosixgaming-arch #1929 now stacks on the exact current #1731 commit and its source tree is unchanged from the fully green fork Build 37868880231. Linux CTest 497/497, Windows CTest 488/488, and all relinker jobs passed. Exact-head Build 37870858453 is running; please re-review the current head after it completes.

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 9f25043 to 6db0682 Compare October 9, 2026 01:15
@MarcZX10 MarcZX10 changed the title fix(libkernel): query live ranges after partial unmap fix(libkernel): query non-readable live mappings Oct 9, 2026
@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 6db0682 to ee68f67 Compare October 9, 2026 01:39
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The exact current heads are #1731 1a301c4 and this PR ee68f67. Upstream Actions created Build and Conventions runs for both fork heads, but all are action_required; this token has pull-only access on boykopovar/AnyPS5, so I cannot approve those workflows. The same source tree was already validated in our fork Build (Linux CTest 497/497, Windows 488/488, relinker CTests on Ubuntu/Windows/macOS), and #1731 has been approved after full review. Could an authorized maintainer approve the upstream fork workflows? The exact-head runs are Build 37870860630 and Conventions 37870893265 for this PR; #1731 Build 37870628828 and Conventions 37870628839.

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Updated head: rebased the #1731 shared patch plus this follow-up onto current upstream main 25f1008; pushed 4ff734c0. On Linux x86_64/GCC 12.2 Release, rebuilt both focused test binaries; guest_memory and guest_ampr_markers pass (2/2). Conventions and diff checks pass. Fork Build 37902960354 is running on this head.

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 4ff734c to 8a222b6 Compare October 9, 2026 08:19
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased the fully reviewed three-commit diff onto current upstream main 6cc0503d and pushed head 8a222b65. The focused Linux guest_memory and guest_ampr_markers tests both pass (2/2); conventions and git diff --check pass. Fork Build 37904356054 is running on the exact new head. The updated PR description records the previous head’s unrelated missing SPIRV-Headers build dependency and points to #2093.

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Build 37904356054 completed: Linux and Windows fail only while compiling agc_shader_fusion_tests, with VulkanTestDevice.hpp missing spirv/unified1/spirv.hpp; the Ubuntu, Windows and macOS relinker jobs pass. I checked both job logs. This matches #2093’s missing SPIRV-Headers target dependency, and the PR description now records that result. The focused tests on this head pass.

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 8a222b6 to 103e97f Compare October 9, 2026 09:20
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Updated to current upstream main d9484c71; the four-file diff is unchanged. The PR body now fills Depends on: none, and exact-head Conventions passes. The focused Linux tests passed on the immediately preceding head, whose source diff is identical. The earlier full Build failed at the missing SPIRV-Headers include; #2099 is now in this base and fixes that dependency. Could an upstream collaborator run the full Build for current PR head 103e97ff under the #2113 policy?

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@klosixgaming-arch Your review observation about address ordering is now explicit in this head via the std::is_sorted assertion; the lease is populated from the address-keyed registry map. The PR is rebased to current main and Conventions passes. Please re-review head 103e97ff when convenient. The older full Build hit the header dependency fixed in #2099; an upstream collaborator can now run the manual full Build for this PR under #2113.

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch 6 times, most recently from 8134a0e to 099b8cf Compare October 9, 2026 10:10
@rmz-24

rmz-24 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build plus libs. 099b8cf cherry-picked onto current main d70b899 (applies cleanly).

  • guest_memory passes.
  • Full ctest: 510/510.

AI-assisted: yes

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the Windows report. It tests the exact PR commit 099b8cf0 cherry-picked onto current main d70b8998; the full Windows CTest (510/510) passes, so that closes the Windows validation gap for this source. The upstream PR head still has only Conventions; Linux and the relinker matrix are not yet recorded on this exact head. Could an authorized collaborator run Build and the reviewer recheck the updated address-order assertion?

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 099b8cf to 83983e3 Compare October 9, 2026 19:08
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased the existing PR linearly onto current main (ae3d5f95) at head 83983e3c. The full diff remains the same four files, including the address-order assertion requested in review. On this head, Linux guest_memory_tests builds and guest_memory passes (1/1); local and GitHub Conventions pass. The prior Windows report is preserved in the description and labeled as pre-rebase evidence.\n\nCould a collaborator with write access run the required upstream Build and relinker matrix on this current PR head under #2113?

@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 83983e3 to 14d150b Compare October 9, 2026 19:54
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Updated head and validation

I rebased the existing branch linearly onto upstream main at 8b393b6e and pushed head 14d150b5. The complete diff remains the same four files, including the reviewer-requested lease-order assertion. On this head, Linux guest_memory_tests builds and guest_memory passes (1/1); local Conventions and git diff --check pass. The Windows 510/510 result remains labeled as pre-rebase evidence in the description.

Could the reviewer recheck the assertion on this current head, and could a collaborator with write access run Actions → Build for PR #1929? The required upstream Linux/Windows and relinker matrix has not run for this head.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1324 core/libs/prx/libc/include/GuestAllocations.hpp L38
core/libs/prx/libc/src/GuestAllocations.cpp L436
#1360 core/libs/prx/libc/include/GuestAllocations.hpp L38
core/libs/prx/libc/src/GuestAllocations.cpp L436
#1803 core/libs/tests/GuestMemory.cpp L1082-1084

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The overlap scan flagged #2267. I reviewed both diffs: the sceKernelVirtualQuery bound change (allocationAddress/allocationBytes to live range address/bytes) is shared. This PR additionally acquires non-readable ranges and tests mprotect/unmap-split flexible mappings; #2267 contributes a direct mmap partial-unmap regression. I posted a coordination note there; no dependency is implied, but please resolve the shared implementation and preserve the direct-mmap test contribution before merging.

praveenkumarappu and others added 4 commits October 9, 2026 22:10
Use the current registered range after protection splits and partial unmaps, including FIND_NEXT lookups. Add a regression covering extents, protection and surviving contents.

AI-assisted: yes
Carry over the direct mmap regression from PR boykopovar#2267. The live-extent implementation is already present in the preceding commits.
@MarcZX10
MarcZX10 force-pushed the fix/virtualquery-partial-unmap branch from 14d150b to e06c459 Compare October 9, 2026 22:14
@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

I rebased the existing branch onto current main (e51d4e1f) and carried over the direct-mmap partial-unmap regression from #2267 in commit e06c4595, retaining Saranxzi as the commit author. The combined guest_memory test now covers flexible-range splits, non-readable mappings, and a direct mmap hole/find-next query. Linux Release build and CTest pass (1/1); conventions and diff checks pass. The Windows results from the earlier heads remain labeled as such, and this exact combined head still needs the collaborator-only upstream Build/relinker matrix.

@MarcZX10

MarcZX10 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The latest overlap scan also flags #1324 and #1360 in GuestAllocations.hpp/.cpp. I reviewed those diffs against this PR; the shared files hold separate APIs and behavior:

Change Purpose
#1929 GuestAllocationsAcquireAll_nid_postfix includes non-readable live ranges so sceKernelVirtualQuery can report PROT_NONE mappings.
#1324 / #1360 GuestAllocationsAcquireRange_nid_no_patch and bounded mapping updates/history optimize AGC import lookup and cache validation. #1360 explicitly depends on #1324.

I found no duplicate behavior or dependency between these changes. The additions can coexist; the overlap is at the header/implementation files and may need a small insertion-hunk resolution when branches are combined. The separate direct-mmap test from #2267 is already preserved here with Saranxzi's authorship.

oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 10, 2026
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 10, 2026
@oneandonlydean
oneandonlydean merged commit b860fa0 into boykopovar:main Oct 10, 2026
9 of 11 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
…rtial-unmap

fix(libkernel): query non-readable live mappings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sceKernelVirtualQuery reports the whole mapping after a partial munmap

6 participants