fix(libSceGnmDriver): write draw packets through guest copies #22138
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22138"
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 domx4q on 2026-11-17T06:19:35Z.
What
The nine
libSceGnmDriverdraw writers inExport.Draw.cpp(sceGnmDrawIndex,sceGnmDrawIndexAuto,sceGnmDrawIndexOffset,sceGnmDrawIndexIndirect,sceGnmDrawIndirect,sceGnmDrawIndexIndirectMulti,sceGnmDrawIndirectMulti,sceGnmDrawIndexIndirectCountMulti,sceGnmDrawIndirectCountMulti, all_nid_disambig1) wrote their packets straight into the title's command buffer. Each writer now builds its packet in a host array and writes it withGuestCopyOut_nid_no_patch. It stores only the words main stored, so it never reads the command buffer and the NOP payload words main left alone stay untouched. Seven writers need one copy; the two count-multi writers need two (words 0-1 and 3-14), because word 2 is a NOP payload word main never wrote. An unwritable buffer returns -1, the error these writers already return for a null buffer, as in the VGT control writers (#20423). A valid buffer gets the same bytes as on main. The mode check still runs before the buffer is touched, so missing or unsupported metadata still throws before anything is written.The first revision copied the whole buffer in and out (the
WriteCommandBufferpattern oflibSceGnmDriverForNeoMode). After review it no longer reads the buffer; see the timing below.guest_pointer_audit.pylisted seven of these writers. The two count-multi writers write through a local alias, so the audit missed them, but they had the same direct writes and use the same helper now. The audit no longer lists anything inExport.Draw.cpp.No debt entry described the direct writes, so no fragment.
Overlap:
pr_overlap.py --namesfor all nine functions: main implements them inlibSceGnmDriverandlibSceGnmDriverForNeoMode, and no open PR touches them.pr_overlap.py --branch fix/gnm-draw-guest-pointers: 1775 open pull requests checked, none share files or exports.Tested
Arch Linux, GCC 16, Release. Head b062b566b1.
GuestGnmDrawWriters.cppgetsCheckUnwritable: every writer gets an unmapped buffer (0x10) and must return -1. It runs for both providers inbaseandneomode. The existing checks still pass: exact packet words, untouched NOP payload and guard words, and refusals that leave memory alone.CheckPaddingUntouched(normal provider,baseandneo): each packet is placed so the words after the last stored word sit on aPROT_NONE/PAGE_NOACCESSpage. Every writer must return 0 and store the same words as into a normal buffer. With the previous head (19c2e9afef)guest_gnm_draw_normal_baseandguest_gnm_draw_normal_neofail witha draw writer touched padding words past the ones it writes; with b062b566b1 they pass.ctest -R guest_gnm_draw: 8/8 passed.origin/mainExport.Draw.cpp,guest_gnm_draw_normal_baseandguest_gnm_draw_normal_neosegfault onCheckUnwritable. Without theGuestCopyOut, both fail on the packet check.sceKernelMapFlexibleMemory(inside the guest arena, checked withGuestArenaContains_nid_postfix) and on host memory. 5 runs each, pinned to one core, same machine (i9-14900KF). Median ns per writer call (min-max): arena: main 15.60 (11.66-17.29), previous head 36.81 (34.14-46.56), this head 28.13 (25.04-37.76). Host: main 13.70 (11.59-19.97), previous head 37.27 (33.32-43.85), this head 27.37 (23.57-31.38). WithAPS5_GUEST_COPY_SYSCALL=1(process_vm_writevfallback, not the default): main 11.88, previous head 867.65, this head 546.06. On Linux x86-64 the default path isGuestFaultCopy(rep movsbwith fault recovery), not a syscall.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -V -R '^(gnm_driver_packets|gnm_driver_submit_wait|gnm_driver_compute_queue|gnm_shader_writers|gnm_default_state_200|guest_gnm_driver|guest_gnm_driver_init_modes|guest_gnm_eq_event_type|guest_gnm_draw_.*)$': 16/16 passed. The log showsInsert instance layer "VK_LAYER_KHRONOS_validation"and nowas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-count 0, as on main (e4caa07950, first revision run).progress.py --module libSceGnmDriver: the same as the previous head andorigin/main(done 50, todo 31).check_conventions.py --base origin/main: passed.debt_fold.py --checkfails only onlibressl3-20171-inventory.md/feat-libressl3-evp-pkey-new-mac-key-v2.md, already on main, which this PR does not touch.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:49:19Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes preserve the draw packet contents while routing writes through the guest copy helper and leaving untouched padding alone; no blocking defect was found in the changed code.
What I ran
Reviewed head
5d693e7d2f674210e37864331e2954e316ab68aeand the prepared diff; no tests or builds were run. Readdescription.md,commits.md,manifest.json,diff.patch,README.md, both changed files, and theGuestCopyOut_nid_no_patchimplementation inGeneral.cpp. Both changed files listed as reviewed in the manifest were read.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported test, GPU, timing, and convention results were not independently verified. No runtime or hardware behavior was tested.
To get this to a good state
Nothing is required.