fix(ampr): preserve pooled pages across AMM remaps #3902

Merged
MarcZX10 merged 4 commits from upstream-pr/3902 into main 2026-10-13 10:25:37 +00:00
MarcZX10 commented 2026-10-11 19:01:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T19:01:24Z.


What

Prevents AMM from returning pooled physical pages while another virtual mapping still references them, and reserves remap targets before releasing their old pages. Adds regression tests for alias remaps and pool exhaustion, including reusing a page after its final alias is unmapped. Updates the AMM ownership debt note.

This carries the two AMM ownership fixes from #3321. The four commits retain their original authorship, including the restored alias regression test.

Tested

  • The author reports Windows MinGW-w64 GCC 15.2.0 checks on base ee4962190 plus these four commits: full default build, libs, six selected AMPR/AMM/guest-memory tests, conventions and whitespace checks passed. Their four-way control matrix reports each regression fails on the pinned base and passes with both fixes. These results are not from the current rebased head.
  • Current rebased head: git diff --check upstream/main...HEAD passed. No build or runtime tests were run after the latest rebase onto main fc1f063f5.

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 under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821530537 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T19:01:24Z. --- ### What Prevents AMM from returning pooled physical pages while another virtual mapping still references them, and reserves remap targets before releasing their old pages. Adds regression tests for alias remaps and pool exhaustion, including reusing a page after its final alias is unmapped. Updates the AMM ownership debt note. This carries the two AMM ownership fixes from #3321. The four commits retain their original authorship, including the restored alias regression test. ### Tested - The author reports Windows MinGW-w64 GCC 15.2.0 checks on base `ee4962190` plus these four commits: full default build, `libs`, six selected AMPR/AMM/guest-memory tests, conventions and whitespace checks passed. Their four-way control matrix reports each regression fails on the pinned base and passes with both fixes. These results are not from the current rebased head. - Current rebased head: `git diff --check upstream/main...HEAD` passed. No build or runtime tests were run after the latest rebase onto `main` `fc1f063f5`. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-11 23:18:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:18:35Z.


Conflicts with main in core/libs/tests/GuestAmpr.cpp; please rebase. Does TestAmmMapFailureKeepsPoolOwnership fail on main, and which test fails without 69b970e14 (the alias-remap commit)? The description lists five cases and the diff adds one test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115020575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6115020575). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:18:35Z. --- Conflicts with main in `core/libs/tests/GuestAmpr.cpp`; please rebase. Does `TestAmmMapFailureKeepsPoolOwnership` fail on main, and which test fails without 69b970e14 (the alias-remap commit)? The description lists five cases and the diff adds one test.
cookie42073-cmd commented 2026-10-12 17:10:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-12T17:10:45Z.


Hi, I'm Blazing Cook. I checked both questions and found a lost test in the carried series: 78d196d15 replaced TestAmmRemapKeepsPoolReferences and its call with TestAmmMapFailureKeepsPoolOwnership. The alias regression is still missing at the rebased head 29f9bb19.

Thanks for the rebase. I put a single test-restoration commit on top of your new head: 1c1e4f4d, branch. It adds the original alias regression and its invocation alongside the pool-exhaustion test. You can cherry-pick that commit into this PR; the existing authorship stays intact.

Yes, TestAmmMapFailureKeepsPoolOwnership fails on the pinned main runtime. I also ran each regression in a fresh process with the same executable while rebuilding only the production variants:

Production code Alias regression Map pool-exhaustion regression
Pinned main 2a5eca11c Fails Fails
Alias fix only Passes Fails
Map reservation fix only Fails Passes
Both fixes Passes Passes

Without the alias fix, the alias regression fails at Require(rejected) because another allocation succeeds while the physical page is still in use. Without the map reservation fix, the other regression fails at the protection check after the oversized allocation: the old target remains mapped. With the fixes, both pass and the existing AMPR tests still pass together.

The map test exercises pool exhaustion, not an injected host mapping failure. It does not establish console rollback semantics. The restored alias test covers remapping onto an existing alias, self/overlapping remaps, exhaustion while an alias survives, and reuse after releasing the last alias. That is the coverage the description should refer to.

Windows, MinGW-w64 GCC 15.2.0: full default build plus libs, six selected AMPR/AMM/guest-memory checks, conventions and whitespace checks passed. No title run or Linux result is claimed for this update.

Please also remove Closes #3321: this PR covers two items from that larger report. We already have Ratchet & Clank memory-placement evidence in #2704 and #3146; there is no need to resend it. Those reports do not show either ownership failure tested here. If someone encounters one of these failures in a title, the useful evidence is the title ID/version, exact AnyPS5 commit and patch stack, pool size, physical page, and map/remap/unmap sequence around the stop, with matching before/after logs for the isolated fix. Logs or a small redistributable repro are enough for this request; I am not asking for a game dump.

AI-assisted with Codex; the source variants, failure locations and saved hashes were independently reviewed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6128992780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6128992780). Originally posted by [cookie42073-cmd](https://github.com/cookie42073-cmd) on 2026-10-12T17:10:45Z. --- Hi, I'm Blazing Cook. I checked both questions and found a lost test in the carried series: `78d196d15` replaced `TestAmmRemapKeepsPoolReferences` and its call with `TestAmmMapFailureKeepsPoolOwnership`. The alias regression is still missing at the rebased head `29f9bb19`. Thanks for the rebase. I put a single test-restoration commit on top of your new head: [1c1e4f4d](https://github.com/cookie42073-cmd/AnyPS5/commit/1c1e4f4d23c7a1f17968ea2a589b3a7afa402483), [branch](https://github.com/cookie42073-cmd/AnyPS5/tree/fix/amm-restore-alias-regression-20261012). It adds the original alias regression and its invocation alongside the pool-exhaustion test. You can cherry-pick that commit into this PR; the existing authorship stays intact. Yes, `TestAmmMapFailureKeepsPoolOwnership` fails on the pinned main runtime. I also ran each regression in a fresh process with the same executable while rebuilding only the production variants: | Production code | Alias regression | Map pool-exhaustion regression | |---|---|---| | Pinned main `2a5eca11c` | Fails | Fails | | Alias fix only | Passes | Fails | | Map reservation fix only | Fails | Passes | | Both fixes | Passes | Passes | Without the alias fix, the alias regression fails at `Require(rejected)` because another allocation succeeds while the physical page is still in use. Without the map reservation fix, the other regression fails at the protection check after the oversized allocation: the old target remains mapped. With the fixes, both pass and the existing AMPR tests still pass together. The map test exercises **pool exhaustion**, not an injected host mapping failure. It does not establish console rollback semantics. The restored alias test covers remapping onto an existing alias, self/overlapping remaps, exhaustion while an alias survives, and reuse after releasing the last alias. That is the coverage the description should refer to. Windows, MinGW-w64 GCC 15.2.0: full default build plus `libs`, six selected AMPR/AMM/guest-memory checks, conventions and whitespace checks passed. No title run or Linux result is claimed for this update. Please also remove `Closes #3321`: this PR covers two items from that larger report. We already have Ratchet & Clank memory-placement evidence in [#2704](https://github.com/boykopovar/AnyPS5/issues/2704) and [#3146](https://github.com/boykopovar/AnyPS5/issues/3146); there is no need to resend it. Those reports do not show either ownership failure tested here. If someone encounters one of these failures in a title, the useful evidence is the title ID/version, exact AnyPS5 commit and patch stack, pool size, physical page, and map/remap/unmap sequence around the stop, with matching before/after logs for the isolated fix. Logs or a small redistributable repro are enough for this request; I am not asking for a game dump. AI-assisted with Codex; the source variants, failure locations and saved hashes were independently reviewed.
MarcZX10 commented 2026-10-12 19:43:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:43:38Z.


Thanks for checking the rebased head and for separating the two regressions with the control matrix. The restored alias test is missing from the current PR head, and I agree the map test demonstrates pool exhaustion rather than an injected host mapping failure. I have not applied your offered commit yet; I will review it before updating the branch and narrowing the description.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131395978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6131395978). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:43:38Z. --- Thanks for checking the rebased head and for separating the two regressions with the control matrix. The restored alias test is missing from the current PR head, and I agree the map test demonstrates pool exhaustion rather than an injected host mapping failure. I have not applied your offered commit yet; I will review it before updating the branch and narrowing the description.
MarcZX10 commented 2026-10-12 19:50:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:50:53Z.


I reviewed Blazing Cook’s offered commit 1c1e4f4d. It restores the missing alias-remap regression and its invocation, and the author supplied a control matrix showing each ownership fix fails without its corresponding test. The commit is based on the prior head 29f9bb19, so it needs to be carried onto the current head d75176d.

The overlap check now flags #4207 in GuestAmpr.cpp; the changes are functionally independent, but the test insertions need coordination. @xXPBSXx, would you prefer #3902’s test restoration to land first, or #4207? Whichever lands second can rebase the test-file change. I’ll hold off pushing the offered commit until we agree on the order.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131506434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6131506434). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:50:53Z. --- I reviewed Blazing Cook’s offered commit `1c1e4f4d`. It restores the missing alias-remap regression and its invocation, and the author supplied a control matrix showing each ownership fix fails without its corresponding test. The commit is based on the prior head `29f9bb19`, so it needs to be carried onto the current head `d75176d`. The overlap check now flags #4207 in `GuestAmpr.cpp`; the changes are functionally independent, but the test insertions need coordination. @xXPBSXx, would you prefer #3902’s test restoration to land first, or #4207? Whichever lands second can rebase the test-file change. I’ll hold off pushing the offered commit until we agree on the order.
cookie42073-cmd commented 2026-10-12 22:28:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-12T22:28:34Z.


Hi, I'm Blazing Cook. Since #4207 has merged, I rebased the carried series at d75176d43 onto upstream ee4962190 and restored the missing alias regression alongside the pool-exhaustion test. TestAmmUsageStats is preserved, so the overlapping test insertions are resolved.

The updated branch ends at 4cbda1fb3. The three carried commits retain their original authors, including Marc's follow-up. The fourth commit restores the test. All upstream AMPR test calls are preserved.

I reran the checks on Windows with MinGW-w64 GCC 15.2.0: full default build, libs, all six selected AMPR/AMM/guest-memory tests, conventions and whitespace checks passed. The same probe executable was used for each test across all four production variants:

Production code Alias regression Pool-exhaustion regression
Pinned main ee4962190 Fails Fails
Alias fix only Passes Fails
Map reservation fix only Fails Passes
Both fixes Passes Passes

The negative runs fail at the intended assertions: Require(rejected) at GuestAmpr.cpp:1051 and the old-target protection check at :1102. The final source was restored and rebuilt before the six tests ran.

The pool-exhaustion test does not exercise the host mapping catch path or establish console rollback behavior. This update has no title run or Linux result. The existing Ratchet logs are already linked above; they do not demonstrate these ownership failures.

This branch also merges cleanly with later upstream 43e3a70f8; the runtime results above are specifically for ee4962190 plus the four commits. Please keep both regressions when updating this PR and keep its scope to items 3 and 9 of #3321.

AI-assisted with Codex. A separate review checked the preserved tests, source variants, expected failures, hashes and final results.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6133808913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6133808913). Originally posted by [cookie42073-cmd](https://github.com/cookie42073-cmd) on 2026-10-12T22:28:34Z. --- Hi, I'm Blazing Cook. Since #4207 has merged, I rebased the carried series at `d75176d43` onto upstream `ee4962190` and restored the missing alias regression alongside the pool-exhaustion test. `TestAmmUsageStats` is preserved, so the overlapping test insertions are resolved. The updated [branch](https://github.com/cookie42073-cmd/AnyPS5/tree/fix/amm-current-main-20261012) ends at [4cbda1fb3](https://github.com/cookie42073-cmd/AnyPS5/commit/4cbda1fb3e8cdfdd8b19619296ee1c8ce4a9183a). The three carried commits retain their original authors, including Marc's follow-up. The fourth commit restores the test. All upstream AMPR test calls are preserved. I reran the checks on Windows with MinGW-w64 GCC 15.2.0: full default build, `libs`, all six selected AMPR/AMM/guest-memory tests, conventions and whitespace checks passed. The same probe executable was used for each test across all four production variants: | Production code | Alias regression | Pool-exhaustion regression | |---|---|---| | Pinned main `ee4962190` | Fails | Fails | | Alias fix only | Passes | Fails | | Map reservation fix only | Fails | Passes | | Both fixes | Passes | Passes | The negative runs fail at the intended assertions: `Require(rejected)` at GuestAmpr.cpp:1051 and the old-target protection check at :1102. The final source was restored and rebuilt before the six tests ran. The pool-exhaustion test does not exercise the host mapping catch path or establish console rollback behavior. This update has no title run or Linux result. The existing Ratchet logs are already linked [above](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6128992780); they do not demonstrate these ownership failures. This branch also merges cleanly with later upstream `43e3a70f8`; the runtime results above are specifically for `ee4962190` plus the four commits. Please keep both regressions when updating this PR and keep its scope to items 3 and 9 of #3321. AI-assisted with Codex. A separate review checked the preserved tests, source variants, expected failures, hashes and final results.
MarcZX10 commented 2026-10-13 07:12:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:12:03Z.


Thanks for restoring the alias-remap regression and rerunning the four-way control matrix on Windows. The current PR head still does not include commit 4cbda1fb3. I have not applied it yet; I will check that the offered test patch matches the current PR tree and then either carry it with your authorship preserved or report any issue I find.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140318191 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6140318191). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:12:03Z. --- Thanks for restoring the alias-remap regression and rerunning the four-way control matrix on Windows. The current PR head still does not include commit 4cbda1fb3. I have not applied it yet; I will check that the offered test patch matches the current PR tree and then either carry it with your authorship preserved or report any issue I find.
MarcZX10 commented 2026-10-13 07:43:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:43:22Z.


Rebased the four-commit series onto current main (6d7b87370), preserving the original authors of all four commits, including the restored alias regression. The branch now includes both TestAmmRemapKeepsPoolReferences and TestAmmMapFailureKeepsPoolOwnership, alongside TestAmmUsageStats.

The supplied Windows control matrix is useful evidence for the earlier base ee4962190: each regression fails without its corresponding fix and both pass together. I updated the description to identify that base and to make clear the rebased head has not been rerun. git diff --check passes on the rebased patch; I have not run a build or runtime test after the rebase. The description now says this PR carries two items from #3321 rather than closing the larger report.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140793285 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6140793285). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:43:22Z. --- Rebased the four-commit series onto current `main` (`6d7b87370`), preserving the original authors of all four commits, including the restored alias regression. The branch now includes both `TestAmmRemapKeepsPoolReferences` and `TestAmmMapFailureKeepsPoolOwnership`, alongside `TestAmmUsageStats`. The supplied Windows control matrix is useful evidence for the earlier base `ee4962190`: each regression fails without its corresponding fix and both pass together. I updated the description to identify that base and to make clear the rebased head has not been rerun. `git diff --check` passes on the rebased patch; I have not run a build or runtime test after the rebase. The description now says this PR carries two items from #3321 rather than closing the larger report.
adriadam10 commented 2026-10-13 09:48:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:48:35Z.


Read through the ownership changes (page references held across remap, target reserved before old pages are released, per-run _addPage in _mapPages), the two regression tests and the debt note; they are consistent with each other and with the description. Merging once the full Build (linux and windows) is green on this head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142869248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3902#issuecomment-6142869248). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T09:48:35Z. --- Read through the ownership changes (page references held across remap, target reserved before old pages are released, per-run `_addPage` in `_mapPages`), the two regression tests and the debt note; they are consistent with each other and with the description. Merging once the full Build (linux and windows) is green on this head.
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!3902
No description provided.