fix(agc): check the guest address of ordered memory waits #16200

Open
MarcZX10 wants to merge 2 commits from upstream-pr/16200 into main
MarcZX10 commented 2026-11-05 20:40:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-05T20:40:13Z.


What

  • Defect: on the pipelined path, a WAIT_REG_MEM / WAIT_REG_MEM_64 packet that finds the draw pipeline busy reads its awaited guest address directly (Pm4::WaitSatisfiedUnchecked, OwnStoreRejects) without GuestMemory::CheckRange. An unmapped address faults the host instead of giving the guest-visible error that the other wait paths give.
  • Fix: validate the awaited range with GuestMemory::CheckRange before the direct read, unless the range overlaps a queued write (the same condition that already gates the read).
  • Commit: fix(agc): check the guest address of ordered memory waits.
  • Test: not added in this PR. A regression test needs a busy draw pipeline and a fault-reporting path that were not read in detail.

Tested

  • Not run yet. Build and ctest for libSceAgcDriver are queued, not yet run.
  • Checks run: tools/check_conventions.py --base upstream/main (passed), git diff --check upstream/main.

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 (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:5178379950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16200). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-05T20:40:13Z. --- ### What - Defect: on the pipelined path, a `WAIT_REG_MEM` / `WAIT_REG_MEM_64` packet that finds the draw pipeline busy reads its awaited guest address directly (`Pm4::WaitSatisfiedUnchecked`, `OwnStoreRejects`) without `GuestMemory::CheckRange`. An unmapped address faults the host instead of giving the guest-visible error that the other wait paths give. - Fix: validate the awaited range with `GuestMemory::CheckRange` before the direct read, unless the range overlaps a queued write (the same condition that already gates the read). - Commit: `fix(agc): check the guest address of ordered memory waits`. - Test: not added in this PR. A regression test needs a busy draw pipeline and a fault-reporting path that were not read in detail. ### Tested - Not run yet. Build and ctest for `libSceAgcDriver` are queued, not yet run. - Checks run: `tools/check_conventions.py --base upstream/main` (passed), `git diff --check upstream/main`. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.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
adriadam10 commented 2026-11-10 06:38:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-10T06:38:40Z.

Review: CHANGES_REQUESTED


The change itself looks right: PacketExecution.cpp:327-329 now calls GuestMemory::CheckRange before the direct read, the same check the keepsDrawPipeline path already does at line 99, and it is skipped when the range overlaps a queued write.

One thing is missing:

  • No test. The PR body says a regression test needs a busy draw pipeline and was not written. Please add one that submits a WAIT_REG_MEM / WAIT_REG_MEM_64 on an unmapped address while the draw pipeline is busy and checks the guest-visible error instead of a host fault, so it fails on main and passes here. If that can't be built from the existing driver tests, show the failing log on main and the fixed one.

Also note #16897 edits the adjacent line 326; whichever lands second needs a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5837756294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16200#pullrequestreview-5837756294). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-11-10T06:38:40Z. **Review:** CHANGES_REQUESTED --- The change itself looks right: `PacketExecution.cpp:327-329` now calls `GuestMemory::CheckRange` before the direct read, the same check the `keepsDrawPipeline` path already does at line 99, and it is skipped when the range overlaps a queued write. One thing is missing: - No test. The PR body says a regression test needs a busy draw pipeline and was not written. Please add one that submits a `WAIT_REG_MEM` / `WAIT_REG_MEM_64` on an unmapped address while the draw pipeline is busy and checks the guest-visible error instead of a host fault, so it fails on `main` and passes here. If that can't be built from the existing driver tests, show the failing log on `main` and the fixed one. Also note #16897 edits the adjacent line 326; whichever lands second needs a rebase.
ligmaSec commented 2026-12-03 22:37:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:37:31Z.

Review: COMMENTED


The trial merge onto c1601e56d5 was clean. The new validation runs before the unchecked ordered-wait read, and the queued-write path still defers the read as before. Please keep explicit coverage for both waiter widths and confirm the valid queued-write case still proceeds normally. My review is source-based.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179841169 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16200#pullrequestreview-6179841169). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:37:31Z. **Review:** COMMENTED --- The trial merge onto `c1601e56d5` was clean. The new validation runs before the unchecked ordered-wait read, and the queued-write path still defers the read as before. Please keep explicit coverage for both waiter widths and confirm the valid queued-write case still proceeds normally. My review is source-based. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/16200:upstream-pr/16200'
git switch 'upstream-pr/16200'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/16200'
git switch 'upstream-pr/16200'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/16200'
git switch 'upstream-pr/16200'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/16200'
git switch 'main'
git merge --squash 'upstream-pr/16200'
git switch 'main'
git merge --ff-only 'upstream-pr/16200'
git switch 'main'
git merge 'upstream-pr/16200'
git push origin 'main'
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!16200
No description provided.