fix(libSceGnmDriver): refuse a REWIND in a submitted draw command buffer #22375
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22375"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by adam25136 on 2026-11-17T13:22:38Z.
What
On the PS4 Gnm path,
sceGnmSubmitCommandBuffersandsceGnmSubmitAndFlipCommandBuffersgo throughSubmitLocked. It merges each draw and constant command buffer into a local copy (MergeEngines), passes the copy toAgcDriverSubmitGraphics_nid_postfixand frees it on return.AGC copies the packets it is given, except at a REWIND. A REWIND's second dword is its control word: the packets after the REWIND may run once bit 31 of that word is set. At a REWIND,
copyLinkkeeps a pointer to the packets after it (submission.rewindTail = guest + cursor,Submission.cpp).executeRewindTailthen waits on the control word and reads the rest of the buffer through that pointer. On the Gnm path that pointer is into the freed copy, a use-after-free:The change:
MergeEnginesnow throwsa REWIND packet in a submitted draw command buffer(NotImplemented_nid_no_patch). This is the reason #18546 gave for refusing a REWIND in a compute ring: "the AGC driver would keep a pointer into the copy made for the submit, which is freed whensceGnmDingDongreturns". A REWIND in a buffer a compute ring calls also throws (#20384), and so does one in a constant command buffer (constant engine packet 89 is not implemented).sceGnmSubmitAndFlipCommandBuffershas already patched its flip into the title's buffer by then;copyLinkreturns at the called buffer's REWIND). On the Gnm path that would include the constant engine packetsMergeEnginesappends at the end and a flip at the end of the buffer (read from the code; a WRITE_DATA after the call was measured, below). This is separate AGC behaviour, not changed here.REWIND in a submitted draw command bufferentry under Functional.Tested
Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 (r7), CMake 4.3.1, Release, this branch on
main9c0d96916c.main's ownagc_driver_upload_cache_read_only_flush_testsdoes not build with MinGW (setenv; open #19899 fixes it), so the builds went on past it.main47b33132f9(a local test and temporary prints, not part of this PR; addresses as printed, ranges end one past the last dword):sceGnmSubmitCommandBuffers, waits 500 ms, then sets the control word to0x80000000in its own buffer. 5 s later the label is still 0. The prints show the title's buffer at0xfc00001000-0xfc0000101c,SubmitLocked's copy at0xfc40d59710-0xfc40d5972c, and AGC keeping the REWIND tail at0xfc40d59718, inside the copy, which is freed whenSubmitLockedreturns.0xfc000d2008in the title's buffer, and the label is 1 after the release.dad3ef290b7onmainc825105a77, with a temporary change to the new test): after the release, the called buffer's label is 1 and the caller's label is still 0.gnm_driver_submit_testspass:gnm_driver_packets:MergeEnginesthrows with the message above for a draw command buffer with a REWIND between two NOPs;gnm_driver_submit_wait: a draw command buffer that calls a buffer holding a REWIND and a WRITE_DATA is submitted. The label is still 0 after 200 ms, and 1 once the title sets the control word.gnm_driver_packetsfail (expected an exception). Refusing every INDIRECT_BUFFER as well makesgnm_driver_submit_waitfail (the call throws).tools/select_tests.pyselects for the 3 changed files (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), onmainand on this branch: no test fails only on the branch, and neither run skips one.performance_runner_PerformanceRunTestsfails on both: 3 of its 5 cases error, becauserun_performance_titlerefusesANYPS5_NO_SHADER_CACHE=1(clean performance capture requires enabled shader caches).VK_LAYER_KHRONOS_validation1.4.367 (throughVK_ADD_LAYER_PATH) withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,VK_LOADER_LAYERS_DISABLE=~implicit~,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1,ctest -V, onmainand on this branch.gnmpass on both.gnm_driver_submit_wait(which runs the new GPU case),gnm_driver_compute_queueandagc_driver_gds_integer_atomics64_alignment.Insert instance layer "VK_LAYER_KHRONOS_validation"lines, no "was not found" line and noVUID-message.python tools/check_conventions.py --base origin/main --title "<this title>" --body <this description>:All conventions checks passed.python tools/pr_overlap.py --branch:tests/Submit.cpp. This branch's test sits where each of them merges with it without a conflict (git merge-fileonmain's file).main, so pr_overlap exits 2. #17711'sExport.cpphunks are an include at the top and exports aftersceGnmUnmapComputeQueue, away fromMergeEngines.sceGnmSubmitAndFlipCommandBuffersitself (it reaches the sameMergeEnginesthroughSubmitLocked); any title. No title is known to hit this; it was found by reading the REWIND path.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted: Claude Code found the bug while reading the REWIND path, reproduced it with a local test, wrote the change and its tests, ran the tests, and drafted this description; separate review agents checked it.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T01:29:06Z.
Review: APPROVED
Reviewed — looks good
Nothing in the reviewed change blocks merging; the refusal targets the top-level draw-buffer REWIND path that retains a pointer into a temporary merged buffer, and the called-buffer test covers the documented exception.
What I ran
Reviewed head
b441dcb72bb2a21af3caed41e0435a31b726c4b9. No commands or tests were run. Readreview/description.md,review/commits.md,review/manifest.json,review/diff.patch,core/libs/prx/libSceGnmDriver/Export.cpp,core/libs/prx/libSceGnmDriver/tests/Submit.cpp,docs/dev/debt/changes/fix-gnm-top-level-rewind.md, and targeted AGC submission code incore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
MergeEnginesrejectsOpRewindatcore/libs/prx/libSceGnmDriver/Export.cpp:341-342;SubmitLockedbuilds merged vectors before passing them to AGC atcore/libs/prx/libSceGnmDriver/Export.cpp:381-395.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:281-289and reads the control word and tail through that pointer atcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp:700-734.core/libs/prx/libSceGnmDriver/tests/Submit.cpp:61-62andcore/libs/prx/libSceGnmDriver/tests/Submit.cpp:156-173.Not verified
The author-reported build, test suite, validation-layer run, and hardware behavior were not independently verified. The described changes in
sceGnmSubmitAndFlipCommandBuffersand title-specific behavior were not exercised here. The prepared bundle lists all three changed files as included and all three were read; excluded files: none reported.