fix(agc): reject a chained INDIRECT_BUFFER that revisits a buffer of its chain #22572

Merged
Jazeupoi merged 3 commits from upstream-pr/22572 into main 2026-11-29 06:54:26 +00:00
Jazeupoi commented 2026-11-17 21:49:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-17T21:49:32Z.


What

A chained INDIRECT_BUFFER that leads back to a buffer already copied in the same chain was rejected only when the 1 << 26 word copy budget ran out. For the 4-word self-link in agc_driver that is about 16.7 million passes, and on Windows the test took 24 to 123 s (#22565).

Driver::copySegment now compares each chained target (address and size) with a marked link. The mark moves to the current link after 1, 2, 4, 8, ... links (Brent's cycle detection). A chain that revisits one of its buffers is rejected after a few passes over the loop, with a chained indirect buffer leads back to a buffer of its own chain (a jump loop). The self-link and pair checks look for that text, so they fail on main, where the loop still ends at the copy limit. It uses no memory per link, and the budget is unchanged, so long chains that end are copied as before. As discussed in #22565, this rejects the revisited link and keeps the budget.

The test adds two buffers that chain to each other next to the existing self-link check.

#22441 and #22434 add a parameter to the copyLink call in the same copySegment loop. Neither changes how a loop is detected, so whichever is merged later needs only a small rebase.

Tested

agc_driver, Release, main and this change on the same machine.

Windows 11 Pro, AMD Ryzen 5 3400G, NVIDIA GeForce RTX 2060 (driver 621.24), WinLibs GCC 15.2.0. main bef2f1f77d with #22373 merged, because the full Windows test build stops on #22358.

run 1 run 2 run 3
main 63.9 s 26.5 s 24.5 s
this change 12.4 s 12.3 s 12.4 s

macOS 27.0.1, Apple M4, MoltenVK (Vulkan SDK 1.4.363), x86-64 Release under Rosetta 2. main e798a424c7 with #17425 and #11049; Submission.cpp and Submit.cpp are the same as in bef2f1f77d.

run 1 run 2 run 3
main 21.0 s 20.9 s 21.1 s
this change 14.4 s 11.5 s 11.5 s

Validation, 3 runs of ctest -V -R '^agc_driver$' on main and on this change on each machine, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, validation layer 1.4.363. Every log shows Insert instance layer "VK_LAYER_KHRONOS_validation", none shows was not found but was requested by env var VK_INSTANCE_LAYERS, and none has a VUID- line, on main or on this change. agc_driver passed in every run. With the layer, the test took:

Windows macOS
main 27.3, 33.6 and 194.5 s 24.6, 24.0 and 21.1 s
this change 12.3, 12.4 and 12.4 s 14.8, 14.4 and 11.5 s

The tables are for 8164e0627b. ca7c91789b changes only the error text and the two checks. On the Mac: 3 runs of agc_driver passed (15.0, 11.5 and 11.4 s), and 3 validation runs passed with the layer inserted and no VUID- line. One more validation run hung at device start, in the float-controls probe, before testValidation and testChainedIndirectBuffers run. With only the new Submit.cpp on main's driver, agc_driver fails with a chained indirect buffer that links to itself was not rejected as a jump loop.

python3 tools/check_conventions.py passes.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: Fixes #22565
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 2060, driver 621.24, Windows 11 Pro; Apple M4, MoltenVK from Vulkan SDK 1.4.363, macOS 27.0.1
  • AI-assisted: yes (Claude Code)

Summary by CodeRabbit

  • Bug Fixes
    • Indirect-buffer chains that loop back to a buffer already in the chain are now rejected with a jump-loop error, including self-links and links between two buffers. The existing maximum chain-depth check remains in place.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5365608569 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22572). Originally posted by [Jazeupoi](https://github.com/Jazeupoi) on 2026-11-17T21:49:32Z. --- ### What A chained `INDIRECT_BUFFER` that leads back to a buffer already copied in the same chain was rejected only when the `1 << 26` word copy budget ran out. For the 4-word self-link in `agc_driver` that is about 16.7 million passes, and on Windows the test took 24 to 123 s (#22565). `Driver::copySegment` now compares each chained target (address and size) with a marked link. The mark moves to the current link after 1, 2, 4, 8, ... links (Brent's cycle detection). A chain that revisits one of its buffers is rejected after a few passes over the loop, with `a chained indirect buffer leads back to a buffer of its own chain (a jump loop)`. The self-link and pair checks look for that text, so they fail on `main`, where the loop still ends at the copy limit. It uses no memory per link, and the budget is unchanged, so long chains that end are copied as before. As discussed in #22565, this rejects the revisited link and keeps the budget. The test adds two buffers that chain to each other next to the existing self-link check. #22441 and #22434 add a parameter to the `copyLink` call in the same `copySegment` loop. Neither changes how a loop is detected, so whichever is merged later needs only a small rebase. ### Tested `agc_driver`, Release, `main` and this change on the same machine. **Windows 11 Pro, AMD Ryzen 5 3400G, NVIDIA GeForce RTX 2060 (driver 621.24), WinLibs GCC 15.2.0.** `main` `bef2f1f77d` with #22373 merged, because the full Windows test build stops on #22358. | | run 1 | run 2 | run 3 | |---|---|---|---| | `main` | 63.9 s | 26.5 s | 24.5 s | | this change | 12.4 s | 12.3 s | 12.4 s | **macOS 27.0.1, Apple M4, MoltenVK (Vulkan SDK 1.4.363), x86-64 Release under Rosetta 2.** `main` `e798a424c7` with #17425 and #11049; `Submission.cpp` and `Submit.cpp` are the same as in `bef2f1f77d`. | | run 1 | run 2 | run 3 | |---|---|---|---| | `main` | 21.0 s | 20.9 s | 21.1 s | | this change | 14.4 s | 11.5 s | 11.5 s | Validation, 3 runs of `ctest -V -R '^agc_driver$'` on `main` and on this change on each machine, with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, validation layer 1.4.363. Every log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"`, none shows `was not found but was requested by env var VK_INSTANCE_LAYERS`, and none has a `VUID-` line, on `main` or on this change. `agc_driver` passed in every run. With the layer, the test took: | | Windows | macOS | |---|---|---| | `main` | 27.3, 33.6 and 194.5 s | 24.6, 24.0 and 21.1 s | | this change | 12.3, 12.4 and 12.4 s | 14.8, 14.4 and 11.5 s | The tables are for `8164e0627b`. `ca7c91789b` changes only the error text and the two checks. On the Mac: 3 runs of `agc_driver` passed (15.0, 11.5 and 11.4 s), and 3 validation runs passed with the layer inserted and no `VUID-` line. One more validation run hung at device start, in the float-controls probe, before `testValidation` and `testChainedIndirectBuffers` run. With only the new `Submit.cpp` on `main`'s driver, `agc_driver` fails with `a chained indirect buffer that links to itself was not rejected as a jump loop`. `python3 tools/check_conventions.py` passes. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: Fixes #22565 - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 2060, driver 621.24, Windows 11 Pro; Apple M4, MoltenVK from Vulkan SDK 1.4.363, macOS 27.0.1 - [x] AI-assisted: yes (Claude Code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Indirect-buffer chains that loop back to a buffer already in the chain are now rejected with a jump-loop error, including self-links and links between two buffers. The existing maximum chain-depth check remains in place. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
milescoviello commented 2026-11-17 22:44:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-17T22:44:33Z.

Review: COMMENTED


I read this against main 9f75bf0be3. I didn't build it, since a title run holds the host right now.

The detection looks right to me:

  • The mark starts at the first segment, and the check runs after every chained jump, so a self-link (λ = 1) is caught on the first jump and your two-buffer pair on the third. A longer loop is caught within about two passes once the mark is inside it, which is Brent's bound.
  • It only follows chained links inside one copySegment call. A nested (non-chained) INDIRECT_BUFFER that calls the same buffer twice, for example a shared state block, still goes through copyLink's recursion with its own mark, so that legal pattern isn't touched.
  • The commands are copied from guest memory at submit time, so a chain that comes back to the same address and size within one copy can only run forever. main ended the same way, just 2^26 words later, so no chain that main copies to the end is rejected now.

One optional point: the new require says "command buffer jumps exceed the copy limit" when no limit was reached. Something like "a chained indirect buffer leads back to a buffer of its own chain (a jump loop)" would say what happened. The self-link and pair checks could then look for that text. The 2000-link chain stays the check that a long chain that ends is still copied.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5947885684 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22572#pullrequestreview-5947885684). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-17T22:44:33Z. **Review:** COMMENTED --- I read this against `main` 9f75bf0be3. I didn't build it, since a title run holds the host right now. The detection looks right to me: - The mark starts at the first segment, and the check runs after every chained jump, so a self-link (λ = 1) is caught on the first jump and your two-buffer pair on the third. A longer loop is caught within about two passes once the mark is inside it, which is Brent's bound. - It only follows chained links inside one `copySegment` call. A nested (non-chained) `INDIRECT_BUFFER` that calls the same buffer twice, for example a shared state block, still goes through `copyLink`'s recursion with its own mark, so that legal pattern isn't touched. - The commands are copied from guest memory at submit time, so a chain that comes back to the same address and size within one copy can only run forever. `main` ended the same way, just 2^26 words later, so no chain that `main` copies to the end is rejected now. One optional point: the new `require` says "command buffer jumps exceed the copy limit" when no limit was reached. Something like "a chained indirect buffer leads back to a buffer of its own chain (a jump loop)" would say what happened. The self-link and pair checks could then look for that text. The 2000-link chain stays the check that a long chain that ends is still copied.
milescoviello commented 2026-11-18 14:39:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-18T14:39:12Z.

Review: APPROVED


Re-read at ca7c91789b. The require now names the jump loop, and both the self-link and the pair checks look for that text, so they can no longer pass on main's copy-limit stop. domx4q's negative control above (this PR's test with main's Submission.cpp, failing 2 of 2) shows that. Nothing else changed since my read of 8164e0627b. Looks good to me.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5958747217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22572#pullrequestreview-5958747217). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-18T14:39:12Z. **Review:** APPROVED --- Re-read at `ca7c91789b`. The `require` now names the jump loop, and both the self-link and the pair checks look for that text, so they can no longer pass on `main`'s copy-limit stop. domx4q's negative control above (this PR's test with `main`'s `Submission.cpp`, failing 2 of 2) shows that. Nothing else changed since my read of `8164e0627b`. Looks good to me. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-20 07:36:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:36:35Z.

Review: APPROVED


Reviewed — looks good

The cycle check appears correct for chained INDIRECT_BUFFER loops, and the changed tests cover self-links, two-buffer cycles, and a long terminating chain.

What I ran

Reviewed head ca7c91789b7128674564619041e54830224ba617 using the pinned repo_read.py reader. I read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, and the relevant ranges in both changed files. No tests were run.

Results

Check Result Note
Code review passed Cycle detection and test paths inspected
Automated checks not run No commands executed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported Windows and macOS test runs and convention check were not independently verified. No other files were changed according to the manifest; both changed files were read in relevant ranges, not in full.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5989084663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22572#pullrequestreview-5989084663). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T07:36:35Z. **Review:** APPROVED --- # Reviewed — looks good The cycle check appears correct for chained INDIRECT_BUFFER loops, and the changed tests cover self-links, two-buffer cycles, and a long terminating chain. ## What I ran Reviewed head `ca7c91789b7128674564619041e54830224ba617` using the pinned `repo_read.py` reader. I read `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, and the relevant ranges in both changed files. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Cycle detection and test paths inspected | | Automated checks | not run | No commands executed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The reported Windows and macOS test runs and convention check were not independently verified. No other files were changed according to the manifest; both changed files were read in relevant ranges, not in full. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-28 13:17:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T13:17:43Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 64be018763c6ed12a84ce521e602bc8d8c2ebbad. I read the prepared description, commits, manifest, diff, and both changed files’ relevant ranges through repo_read.py; I did not run commands or tests.

Results

Check Result Note
Change review passed Cycle detection and test cases inspected
Tests not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read Submission.cpp lines 205–255 and 260–340, and Submit.cpp lines 140–190. Both files listed in the manifest as reviewed were read in the relevant ranges, but neither full file was read. Runtime behavior and author-reported test results were not independently verified. files.json was not available in the review bundle, so excluded files could not be confirmed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6097987616 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22572#pullrequestreview-6097987616). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T13:17:43Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `64be018763c6ed12a84ce521e602bc8d8c2ebbad`. I read the prepared description, commits, manifest, diff, and both changed files’ relevant ranges through `repo_read.py`; I did not run commands or tests. ## Results | Check | Result | Note | |---|---|---| | Change review | passed | Cycle detection and test cases inspected | | Tests | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read `Submission.cpp` lines 205–255 and 260–340, and `Submit.cpp` lines 140–190. Both files listed in the manifest as reviewed were read in the relevant ranges, but neither full file was read. Runtime behavior and author-reported test results were not independently verified. `files.json` was not available in the review bundle, so excluded files could not be confirmed. ## To get this to a good state Nothing is required.
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!22572
No description provided.