fix(agc): check a journal module's frame size before allocating it #15423

Merged
dantdmdarealguy merged 1 commit from upstream-pr/15423 into main 2026-11-07 12:39:09 +00:00
dantdmdarealguy commented 2026-11-03 07:03:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by dantdmdarealguy on 2026-11-03T07:03:08Z.


What

Since #8365 (merged 11-01 06:45Z), agc_driver_pipeline_journal has taken about 70 s on the Linux runner instead of about 8 s. In the 11-02 19:48Z run of push builds it hit ctest's 120 s timeout in six main jobs, for example job 125513256706 (main 13e95604e4):

[pipeline-journal] loaded 61 pipelines and 38 modules (1.8 MiB) from /tmp/aps5-pipeline-journal-test-2488177741/bedc564459418477/pipelines.journal in 47116 ms; the file's tail was unreadable and is dropped
...
Test #…: agc_driver_pipeline_journal ...***Timeout 120.12 sec

Cause. The journal stores a module record as identity, stage, the module's size at offset 20, then the zstd frame. expandModule resized its output buffer to that size before ZSTD_decompress looked at the frame. A record whose frame does not decode still allocated and zeroed whatever size it claimed, up to 4 GiB. The test's synthetic module records are filled with 0x5a, so each one claims 0x5a5a5a5a bytes (1.41 GiB). The eviction cases add 24 of them plus a 600 KiB filler, so every load of that journal zeroed about 1.4 GiB per record. That is where the 9.8 s, 4.3 s, 4.4 s and 5.2 s loads in the test's output go.

A first-parent bisect on lavapipe between 5f0857ee2e (2.6 s) and e6f57307fa (32 s) lands on #8365's merge 15f719a5f9 (29.8 s).

Change. expandModule now compares the frame's recorded content size (ZSTD_getFrameContentSize) with the module size before sizing the buffer. A frame that doesn't record a size, or records another one, is dropped as before, but without allocating anything. ZSTD_compress always writes the content size, so every module the journal writes still decodes: the existing test still replays its compressed modules.

Test. agc_driver_pipeline_journal_undecodable_module runs the journal test binary with --undecodable-module in its own process. It records one compute pipeline, appends a module record whose 64-byte frame claims a 1 GiB module, and opens a second device. It checks that the load keeps the recorded module, drops the bad record, and raises the process's peak resident memory (getrusage ru_maxrss, or PeakWorkingSetSize on Windows) by less than 512 MiB. On main:

AGC graphics: loading a module record whose 64-byte frame claims a 1 GiB module raised the peak resident memory by 1025 MiB

The new test joins the tests that keep the pipeline journal on (the APS5_NO_PIPELINE_JOURNAL=1 exclusion list).

Tested

Windows 11 Pro, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 5080 (driver 32.0.16.1742), WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON. Linux: Arch Linux WSL2 on the same machine, GCC 16.1.1, lavapipe (Mesa 26.1.2, Arch vulkan-swrast) with GALLIUM_OVERRIDE_CPU_CAPS=avx and ANYPS5_REQUIRE_VULKAN=1, as CI sets them.

main this PR
agc_driver_pipeline_journal_undecodable_module, lavapipe, 100 runs 100/100 fail (1025 MiB) 0/100 fail (0.10–0.13 s)
agc_driver_pipeline_journal_undecodable_module, RTX 5080, 100 runs 100/100 fail (1028 MiB) 0/100 fail
agc_driver_pipeline_journal, lavapipe, 20 runs 29.5–32.7 s 2.8–3.2 s
agc_driver_pipeline_journal, RTX 5080 21.3 s, 27.4 s 3.8–5.4 s (5 runs)

Before #8365 (3741ca9327, 5f0857ee2e) the same test took 2.3–2.9 s on lavapipe here.

  • ctest -R "pipeline_journal|pipeline_store|patched_libraries" --parallel 2: 11/11 pass on Windows. patched_libraries: 405 patched libraries loaded, 0 failed.
  • cmake --build and --target libs succeed with no warnings in the changed files. tools/check_test_registration.py and tools/check_conventions.py --base origin/main pass.
  • Validation layer, RTX 5080: ctest -V -R "^agc_driver_pipeline_journal" on main and on this PR, with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1 and the Khronos layer through VK_ADD_LAYER_PATH. Neither log has was not found but was requested by env var VK_INSTANCE_LAYERS, and each has 23 Insert instance layer "VK_LAYER_KHRONOS_validation" lines. Neither has a VUID- line. The new test fails on main there too.
  • Windows CI skips both tests (no Vulkan device), so the Linux runner is where they matter.

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: NVIDIA GeForce RTX 5080, driver 32.0.16.1742, Windows 11 Pro; lavapipe (Mesa 26.1.2) in Arch Linux WSL2
  • AI-assisted: yes, some AI assistance was used
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5133228922 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15423). Originally posted by [dantdmdarealguy](https://github.com/dantdmdarealguy) on 2026-11-03T07:03:08Z. --- ### What Since #8365 (merged 11-01 06:45Z), `agc_driver_pipeline_journal` has taken about 70 s on the Linux runner instead of about 8 s. In the 11-02 19:48Z run of push builds it hit ctest's 120 s timeout in six `main` jobs, for example job 125513256706 (`main` 13e95604e4): ``` [pipeline-journal] loaded 61 pipelines and 38 modules (1.8 MiB) from /tmp/aps5-pipeline-journal-test-2488177741/bedc564459418477/pipelines.journal in 47116 ms; the file's tail was unreadable and is dropped ... Test #…: agc_driver_pipeline_journal ...***Timeout 120.12 sec ``` **Cause.** The journal stores a module record as identity, stage, the module's size at offset 20, then the zstd frame. `expandModule` resized its output buffer to that size before `ZSTD_decompress` looked at the frame. A record whose frame does not decode still allocated and zeroed whatever size it claimed, up to 4 GiB. The test's synthetic module records are filled with `0x5a`, so each one claims 0x5a5a5a5a bytes (1.41 GiB). The eviction cases add 24 of them plus a 600 KiB filler, so every load of that journal zeroed about 1.4 GiB per record. That is where the 9.8 s, 4.3 s, 4.4 s and 5.2 s loads in the test's output go. A `first-parent` bisect on lavapipe between `5f0857ee2e` (2.6 s) and `e6f57307fa` (32 s) lands on #8365's merge `15f719a5f9` (29.8 s). **Change.** `expandModule` now compares the frame's recorded content size (`ZSTD_getFrameContentSize`) with the module size before sizing the buffer. A frame that doesn't record a size, or records another one, is dropped as before, but without allocating anything. `ZSTD_compress` always writes the content size, so every module the journal writes still decodes: the existing test still replays its compressed modules. **Test.** `agc_driver_pipeline_journal_undecodable_module` runs the journal test binary with `--undecodable-module` in its own process. It records one compute pipeline, appends a module record whose 64-byte frame claims a 1 GiB module, and opens a second device. It checks that the load keeps the recorded module, drops the bad record, and raises the process's peak resident memory (`getrusage` `ru_maxrss`, or `PeakWorkingSetSize` on Windows) by less than 512 MiB. On `main`: ``` AGC graphics: loading a module record whose 64-byte frame claims a 1 GiB module raised the peak resident memory by 1025 MiB ``` The new test joins the tests that keep the pipeline journal on (the `APS5_NO_PIPELINE_JOURNAL=1` exclusion list). ### Tested Windows 11 Pro, Intel Core i9-14900K, 128 GB RAM, NVIDIA GeForce RTX 5080 (driver 32.0.16.1742), WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`. Linux: Arch Linux WSL2 on the same machine, GCC 16.1.1, lavapipe (Mesa 26.1.2, Arch `vulkan-swrast`) with `GALLIUM_OVERRIDE_CPU_CAPS=avx` and `ANYPS5_REQUIRE_VULKAN=1`, as CI sets them. | | `main` | this PR | |---|---|---| | `agc_driver_pipeline_journal_undecodable_module`, lavapipe, 100 runs | 100/100 fail (1025 MiB) | 0/100 fail (0.10–0.13 s) | | `agc_driver_pipeline_journal_undecodable_module`, RTX 5080, 100 runs | 100/100 fail (1028 MiB) | 0/100 fail | | `agc_driver_pipeline_journal`, lavapipe, 20 runs | 29.5–32.7 s | 2.8–3.2 s | | `agc_driver_pipeline_journal`, RTX 5080 | 21.3 s, 27.4 s | 3.8–5.4 s (5 runs) | Before #8365 (`3741ca9327`, `5f0857ee2e`) the same test took 2.3–2.9 s on lavapipe here. - `ctest -R "pipeline_journal|pipeline_store|patched_libraries" --parallel 2`: 11/11 pass on Windows. `patched_libraries`: 405 patched libraries loaded, 0 failed. - `cmake --build` and `--target libs` succeed with no warnings in the changed files. `tools/check_test_registration.py` and `tools/check_conventions.py --base origin/main` pass. - **Validation layer, RTX 5080:** `ctest -V -R "^agc_driver_pipeline_journal"` on `main` and on this PR, with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1` and the Khronos layer through `VK_ADD_LAYER_PATH`. Neither log has `was not found but was requested by env var VK_INSTANCE_LAYERS`, and each has 23 `Insert instance layer "VK_LAYER_KHRONOS_validation"` lines. Neither has a `VUID-` line. The new test fails on `main` there too. - Windows CI skips both tests (no Vulkan device), so the Linux runner is where they matter. ### 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 - [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 (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: NVIDIA GeForce RTX 5080, driver 32.0.16.1742, Windows 11 Pro; lavapipe (Mesa 26.1.2) in Arch Linux WSL2 - [x] AI-assisted: yes, some AI assistance was used
MarcZX10 commented 2026-11-03 07:05:36 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

The exact-head diff checks the zstd frame content size before allocating the module buffer, and the added test covers a malformed record claiming a 1 GiB expansion; applicable hosted checks are not all complete.

What I ran

Reviewed all four changed files at head e9ac2db9475c008fc9e1440b6de8b19f42146641 against base d1ae628bc2f62459cce1e9872ba5632c938c71f2; the stack preview merges cleanly. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. No local build or CTest was run.

git diff --check d1ae628bc2f62459cce1e9872ba5632c938c71f2...e9ac2db9475c008fc9e1440b6de8b19f42146641
python3 tools/check_conventions.py --base d1ae628bc2f62459cce1e9872ba5632c938c71f2
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15423
python3 tools/pr_stack_check.py 15423 --repo boykopovar/AnyPS5
gh pr checks 15423 --repo boykopovar/AnyPS5

Results

Check Result Note
Diff and conventions passed No whitespace or convention errors.
Base merge preview passed Exact head merges cleanly into current main.
Hosted policy checks passed Intake, labels, report and eligibility completed.
Hosted build and portability not run Windows is pending; Linux was skipped by workflow filters.
Author-reported functional runs reported pass Windows and lavapipe test results are in the PR description; I did not run them.
Local build and tests not run No compilation or CTest in this review.
Optional precheck heuristics unavailable Reviewer helper scripts are absent from the isolated PR snapshot.
Full precheck results
# PR precheck report — checks failed
PR: https://github.com/boykopovar/AnyPS5/pull/15423
Head: `e9ac2db9475c008fc9e1440b6de8b19f42146641`
Base: `d1ae628bc2f62459cce1e9872ba5632c938c71f2`
Head unchanged at completion: **True**
Base unchanged at completion: **True**

diff_check: passed
conventions_and_pr_template: passed
changed_export_abi_audit: failed — tools/pr_abi_audit.py absent from isolated PR snapshot
test_quality_heuristics: failed — tools/pr_test_quality.py absent from isolated PR snapshot
live_dependency_and_mergeability_check: passed
build_dependent_cpp_tests: not applicable — no build was run
All conventions checks passed.
edge-watch  skipping
linux       skipping
register-context skipping
relinker    skipping
relinker-asan skipping
write-watch skipping
conventions pass
windows     pending
eligibility pass
intake      pass
labels      pass
library-portability pass
report      pass

Negative control

No negative control was run here because exercising the C++ regression test requires an exact-head build. The PR description reports that the new test fails on main and passes on the PR head; that is author-reported evidence, not a run performed by me.

Findings

Blocking

None found in the reviewed source and test changes.

Non-blocking

The author reports 100-run regression checks on Windows/RTX 5080 and lavapipe, plus validation-layer runs with no new VUIDs. The current hosted workflow skipped Linux and the Windows job is still pending, so those hardware and test results remain author-reported until the relevant hosted jobs complete.

Sources

Not verified

I did not compile or run CTest, the malformed-record test, Windows, a GPU, lavapipe or console behavior. Linux CI was skipped and Windows CI remained pending at the last status check. The reported performance numbers and validation-layer results were read from the PR description, not independently reproduced.

To get this to a good state

No source change is requested. Let the Windows job finish and confirm the intended Linux evidence is available through an applicable CI run; I will re-check this head and its hosted results if they change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5748321456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15423#pullrequestreview-5748321456). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-03T07:05:36Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The exact-head diff checks the zstd frame content size before allocating the module buffer, and the added test covers a malformed record claiming a 1 GiB expansion; applicable hosted checks are not all complete. ## What I ran Reviewed all four changed files at head `e9ac2db9475c008fc9e1440b6de8b19f42146641` against base `d1ae628bc2f62459cce1e9872ba5632c938c71f2`; the stack preview merges cleanly. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. No local build or CTest was run. ```sh git diff --check d1ae628bc2f62459cce1e9872ba5632c938c71f2...e9ac2db9475c008fc9e1440b6de8b19f42146641 python3 tools/check_conventions.py --base d1ae628bc2f62459cce1e9872ba5632c938c71f2 python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15423 python3 tools/pr_stack_check.py 15423 --repo boykopovar/AnyPS5 gh pr checks 15423 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | Note | |---|---|---| | Diff and conventions | passed | No whitespace or convention errors. | | Base merge preview | passed | Exact head merges cleanly into current `main`. | | Hosted policy checks | passed | Intake, labels, report and eligibility completed. | | Hosted build and portability | not run | Windows is pending; Linux was skipped by workflow filters. | | Author-reported functional runs | reported pass | Windows and lavapipe test results are in the PR description; I did not run them. | | Local build and tests | not run | No compilation or CTest in this review. | | Optional precheck heuristics | unavailable | Reviewer helper scripts are absent from the isolated PR snapshot. | <details> <summary>Full precheck results</summary> ```text # PR precheck report — checks failed PR: https://github.com/boykopovar/AnyPS5/pull/15423 Head: `e9ac2db9475c008fc9e1440b6de8b19f42146641` Base: `d1ae628bc2f62459cce1e9872ba5632c938c71f2` Head unchanged at completion: **True** Base unchanged at completion: **True** diff_check: passed conventions_and_pr_template: passed changed_export_abi_audit: failed — tools/pr_abi_audit.py absent from isolated PR snapshot test_quality_heuristics: failed — tools/pr_test_quality.py absent from isolated PR snapshot live_dependency_and_mergeability_check: passed build_dependent_cpp_tests: not applicable — no build was run ``` ```text All conventions checks passed. ``` ```text edge-watch skipping linux skipping register-context skipping relinker skipping relinker-asan skipping write-watch skipping conventions pass windows pending eligibility pass intake pass labels pass library-portability pass report pass ``` </details> ## Negative control No negative control was run here because exercising the C++ regression test requires an exact-head build. The PR description reports that the new test fails on `main` and passes on the PR head; that is author-reported evidence, not a run performed by me. ## Findings ### Blocking None found in the reviewed source and test changes. ### Non-blocking The author reports 100-run regression checks on Windows/RTX 5080 and lavapipe, plus validation-layer runs with no new VUIDs. The current hosted workflow skipped Linux and the Windows job is still pending, so those hardware and test results remain author-reported until the relevant hosted jobs complete. ## Sources - [Frame-size check at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e9ac2db9475c008fc9e1440b6de8b19f42146641/core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp#L547-L553) - [Malformed module regression test at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e9ac2db9475c008fc9e1440b6de8b19f42146641/core/libs/prx/libSceAgcDriver/tests/execution/PipelineJournal.cpp#L798-L838) - [Test registration at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e9ac2db9475c008fc9e1440b6de8b19f42146641/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_pipeline_journal_tests.cmake#L1-L9) - [AGC validation requirements at the reviewed base](https://github.com/boykopovar/AnyPS5/blob/d1ae628bc2f62459cce1e9872ba5632c938c71f2/CONTRIBUTING.md#L67-L73) ## Not verified I did not compile or run CTest, the malformed-record test, Windows, a GPU, lavapipe or console behavior. Linux CI was skipped and Windows CI remained pending at the last status check. The reported performance numbers and validation-layer results were read from the PR description, not independently reproduced. ## To get this to a good state No source change is requested. Let the Windows job finish and confirm the intended Linux evidence is available through an applicable CI run; I will re-check this head and its hosted results if they change.
MarcZX10 commented 2026-11-03 08:02:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T08:02:41Z.

Review: APPROVED


Re-checked — same head, approved

The exact-head Windows and applicable policy checks have completed successfully, and the reviewed source diff is unchanged.

What I ran

Re-checked PR #15423 at head e9ac2db9475c008fc9e1440b6de8b19f42146641 against base d1ae628bc2f62459cce1e9872ba5632c938c71f2; no new author discussion or head change was present. I refreshed the hosted checks. No local build or CTest was run; test runs described in the PR remain author-reported.

gh api repos/boykopovar/AnyPS5/pulls/15423 --jq '{state:.state,head:.head.sha,base:.base.sha}'
gh pr checks 15423 --repo boykopovar/AnyPS5

Results

Check Result Note
Reviewed source and test diff passed No blocking finding in the frame-size check or regression test.
Applicable hosted checks passed Windows and policy checks passed.
Local build and CTest not run No local compilation or test run.
Unedited hosted-check output
windows pass
conventions pass
eligibility pass
intake pass
labels pass
library-portability pass
report pass
Linux and specialized jobs skipped

Negative control

Not run locally because it requires an exact-head C++ build. The baseline-fails/change-passes runs described in the PR are author-reported, not independently reproduced.

Findings

Blocking

None found in the previously reviewed source and test changes.

Non-blocking

The local runtime tests and console behavior were not independently verified.

Sources

Not verified

I did not compile locally, run CTest, reproduce the baseline failure, independently run GPU validation, or verify console behavior.

To get this to a good state

No code change is requested. The exact-head source review and completed applicable hosted checks support approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5748832418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15423#pullrequestreview-5748832418). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-03T08:02:41Z. **Review:** APPROVED --- # Re-checked — same head, approved The exact-head Windows and applicable policy checks have completed successfully, and the reviewed source diff is unchanged. ## What I ran Re-checked PR #15423 at head `e9ac2db9475c008fc9e1440b6de8b19f42146641` against base `d1ae628bc2f62459cce1e9872ba5632c938c71f2`; no new author discussion or head change was present. I refreshed the hosted checks. No local build or CTest was run; test runs described in the PR remain author-reported. ```sh gh api repos/boykopovar/AnyPS5/pulls/15423 --jq '{state:.state,head:.head.sha,base:.base.sha}' gh pr checks 15423 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | Note | |---|---|---| | Reviewed source and test diff | passed | No blocking finding in the frame-size check or regression test. | | Applicable hosted checks | passed | Windows and policy checks passed. | | Local build and CTest | not run | No local compilation or test run. | <details> <summary>Unedited hosted-check output</summary> ```text windows pass conventions pass eligibility pass intake pass labels pass library-portability pass report pass Linux and specialized jobs skipped ``` </details> ## Negative control Not run locally because it requires an exact-head C++ build. The baseline-fails/change-passes runs described in the PR are author-reported, not independently reproduced. ## Findings ### Blocking None found in the previously reviewed source and test changes. ### Non-blocking The local runtime tests and console behavior were not independently verified. ## Sources - [Frame-size check at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e9ac2db9475c008fc9e1440b6de8b19f42146641/core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp#L547-L553) - [Malformed-module test at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/e9ac2db9475c008fc9e1440b6de8b19f42146641/core/libs/prx/libSceAgcDriver/tests/execution/PipelineJournal.cpp#L798-L838) ## Not verified I did not compile locally, run CTest, reproduce the baseline failure, independently run GPU validation, or verify console behavior. ## To get this to a good state No code change is requested. The exact-head source review and completed applicable hosted checks support approval.
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!15423
No description provided.