fix(agc): let imports that cannot write guest memory keep the watch armed #10369

Merged
krishalivaibhav merged 3 commits from upstream-pr/10369 into main 2026-10-25 17:14:07 +00:00
krishalivaibhav commented 2026-10-23 19:36:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-23T19:36:50Z.


What

Fixes #10344 (first assertion). ImportWatched opened a blanket GuestArena::HostWrite over the whole import window on macOS, because the host cannot know which pages an import will store to. Watch::BeginHostWrite then unprotects every page and marks it Written, so every block of the window read as CPU-written, including blocks the import never touched (agc_write_tracking / CheckImportWindow: "a block the import window did not touch reads as written").

This adds a trailing importMayWriteGuest parameter to ImportWatched, defaulting to true (today's behaviour). When false, the window stays write-protected during the callback, and the fault handler's record() marks only the pages that are actually stored to. Only the DMA-BUF import in GuestBufferMemory.cpp passes false: its callback creates the import in-process and never writes the range through a kernel API (analysis by MarcZX10 on #10344). The host-pointer import keeps the default true: with false there, agc_driver_depth_plane_buffer_memory failed on macOS (found and fixed by iamthehimansh, merged from krishalivaibhav/AnyPS5#2). Callbacks that can write through a kernel API (read()/recv() into the buffer, which would fault with EFAULT on a protected page) keep the default. CheckImportWindow opts out because its callback stores in-process. Non-Apple code is unchanged.

Tested

Current head 9b187f0ef (DMA-BUF site only):

  • macOS, Apple M2 Pro (iamthehimansh, on #8658's branch with the describePages one-liner): agc_write_tracking passes 3/3 and agc_driver_depth_plane_buffer_memory passes with only the DMA-BUF site opted out; with the host-pointer site also opted out, the depth-plane test failed 3/3.
  • macOS, Apple M1 Pro (maximilianfv, on mugurc's macOS series): agc_write_tracking passes the targeted CheckImportWindow check, then stops at the separate CheckUnwatchedImport issue from #8658's describePages branch (not in main; the one-line fix is in https://github.com/boykopovar/AnyPS5/pull/8658#issuecomment-6373190860). The other 25 write-watch/import tests pass with and without this PR.

Earlier two-site version 8cf0a39f8:

  • macOS, Apple M2: CheckImportWindow passes; write_watch_* (10/10) and agc_write_watch_coverage pass.
  • Windows 11, Intel Arc, GCC 15.2, Vulkan validation layers (BKlaasWerkman): 17/17 write_tracking|write_watch|host_import tests pass, as on main, with no VUID- lines; agc_driver_depth_plane_buffer_memory also passes there.

Linux: not built locally; the parameter is unused there.

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 to review; building on macOS needs the split build-fix PRs
  • Fixes: #10344 (the CheckImportWindow assertion; the CheckUnwatchedImport failure behind it is separate)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4988273125 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10369). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-23T19:36:50Z. --- ### What Fixes #10344 (first assertion). `ImportWatched` opened a blanket `GuestArena::HostWrite` over the whole import window on macOS, because the host cannot know which pages an import will store to. `Watch::BeginHostWrite` then unprotects every page and marks it `Written`, so every block of the window read as CPU-written, including blocks the import never touched (`agc_write_tracking` / `CheckImportWindow`: "a block the import window did not touch reads as written"). This adds a trailing `importMayWriteGuest` parameter to `ImportWatched`, defaulting to `true` (today's behaviour). When `false`, the window stays write-protected during the callback, and the fault handler's `record()` marks only the pages that are actually stored to. Only the DMA-BUF import in `GuestBufferMemory.cpp` passes `false`: its callback creates the import in-process and never writes the range through a kernel API (analysis by MarcZX10 on #10344). The host-pointer import keeps the default `true`: with `false` there, `agc_driver_depth_plane_buffer_memory` failed on macOS (found and fixed by iamthehimansh, merged from krishalivaibhav/AnyPS5#2). Callbacks that can write through a kernel API (read()/recv() into the buffer, which would fault with EFAULT on a protected page) keep the default. `CheckImportWindow` opts out because its callback stores in-process. Non-Apple code is unchanged. ### Tested Current head `9b187f0ef` (DMA-BUF site only): - macOS, Apple M2 Pro (iamthehimansh, on #8658's branch with the `describePages` one-liner): `agc_write_tracking` passes 3/3 and `agc_driver_depth_plane_buffer_memory` passes with only the DMA-BUF site opted out; with the host-pointer site also opted out, the depth-plane test failed 3/3. - macOS, Apple M1 Pro (maximilianfv, on mugurc's macOS series): `agc_write_tracking` passes the targeted `CheckImportWindow` check, then stops at the separate `CheckUnwatchedImport` issue from #8658's `describePages` branch (not in `main`; the one-line fix is in https://github.com/boykopovar/AnyPS5/pull/8658#issuecomment-6373190860). The other 25 write-watch/import tests pass with and without this PR. Earlier two-site version `8cf0a39f8`: - macOS, Apple M2: `CheckImportWindow` passes; `write_watch_*` (10/10) and `agc_write_watch_coverage` pass. - Windows 11, Intel Arc, GCC 15.2, Vulkan validation layers (BKlaasWerkman): 17/17 `write_tracking|write_watch|host_import` tests pass, as on `main`, with no `VUID-` lines; `agc_driver_depth_plane_buffer_memory` also passes there. Linux: not built locally; the parameter is unused there. ### 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 to review; building on macOS needs the split build-fix PRs - [x] Fixes: #10344 (the `CheckImportWindow` assertion; the `CheckUnwatchedImport` failure behind it is separate) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-23 19:38:05 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed current head 8cf0a39f86. The new trailing parameter defaults to the prior behavior, so unreviewed/other ImportWatched callbacks retain the blanket HostWrite on Apple. The two opt-outs are limited to the host-pointer and DMA-BUF Vulkan import callbacks; their bodies perform property queries/import/bind operations and do not write into the guest range. The existing CheckImportWindow fixture now opts out while retaining its writes to touched pages, covering the behavior this PR changes. The author reports that assertion passes on the M2; the later CheckUnwatchedImport failure is attributed to a separate #8658-only branch and has a separate proposed fix. I did not run the Apple-specific test locally. Hosted eligibility, conventions, intake, labels and report checks pass; product and platform jobs are skipped by path policy. git diff --check upstream/main...upstream/pr/10369 passes. I found no blocking issue in this scoped change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5633549890 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10369#pullrequestreview-5633549890). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T19:38:05Z. **Review:** APPROVED --- Reviewed current head 8cf0a39f86293f7ed7c326b6c295f240f93f6345. The new trailing parameter defaults to the prior behavior, so unreviewed/other ImportWatched callbacks retain the blanket HostWrite on Apple. The two opt-outs are limited to the host-pointer and DMA-BUF Vulkan import callbacks; their bodies perform property queries/import/bind operations and do not write into the guest range. The existing CheckImportWindow fixture now opts out while retaining its writes to touched pages, covering the behavior this PR changes. The author reports that assertion passes on the M2; the later CheckUnwatchedImport failure is attributed to a separate #8658-only branch and has a separate proposed fix. I did not run the Apple-specific test locally. Hosted eligibility, conventions, intake, labels and report checks pass; product and platform jobs are skipped by path policy. `git diff --check upstream/main...upstream/pr/10369` passes. I found no blocking issue in this scoped change.
MarcZX10 commented 2026-10-24 14:54:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T14:54:58Z.

Review: CHANGES_REQUESTED


Follow-up review of exact head 9b187f0effe9cf695ebd14b994e239b6e7dce141. The updated diff now opts out only the DMA-BUF import; the host-pointer import uses the default importMayWriteGuest=true, consistent with the macOS depth-plane regression matrix in the thread. The PR body is stale: it still says both GuestBufferMemory callers pass false. Please update the description and tested summary to record the final one-site behavior, the M2 result (the targeted CheckImportWindow assertion passes, then this macOS-series run encounters the separate #8658 CheckUnwatchedImport issue), and the Windows 17/17 Vulkan-validation run. This is needed so the review evidence describes the current head rather than the superseded two-site version. The code change itself is appropriately scoped to the dma-buf callback.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638678308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10369#pullrequestreview-5638678308). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T14:54:58Z. **Review:** CHANGES_REQUESTED --- Follow-up review of exact head `9b187f0effe9cf695ebd14b994e239b6e7dce141`. The updated diff now opts out only the DMA-BUF import; the host-pointer import uses the default `importMayWriteGuest=true`, consistent with the macOS depth-plane regression matrix in the thread. The PR body is stale: it still says both GuestBufferMemory callers pass `false`. Please update the description and tested summary to record the final one-site behavior, the M2 result (the targeted CheckImportWindow assertion passes, then this macOS-series run encounters the separate #8658 CheckUnwatchedImport issue), and the Windows 17/17 Vulkan-validation run. This is needed so the review evidence describes the current head rather than the superseded two-site version. The code change itself is appropriately scoped to the dma-buf callback.
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!10369
No description provided.