perf(libc): copy checked guest bytes without a syscall on Linux x86-64 #21156

Merged
milescoviello merged 2 commits from upstream-pr/21156 into main 2026-11-17 03:19:58 +00:00
milescoviello commented 2026-11-15 21:30:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-15T21:30:51Z.


What

On Linux x86-64, GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch now copy with a rep movsb whose faults the copy itself handles, instead of a process_vm_readv/process_vm_writev system call. A checked 8-byte copy goes from about 327 ns to about 6 ns. This removes the cost that has kept checked copies out of per-element paths: #20589, #20600, #20588, and #20682's Json2 Value(const char*) going from 136 to 511 ns.

This uses the same technique as the kernel's copy_from_user exception table. AnyPS5 already uses it on Windows: #14799 added GuardedCopy/GuardedCopyAvx2 to GuestArena.cpp for committed guest reads. Those are assembly loads at known labels; the first thing ReportCrash's vectored handler does is call GuestArenaRecoverRead_nid_no_patch, which moves Rip to GuardedReadFailed. This PR brings the same scheme to Linux, for every checked copy:

  • GuestFaultCopyBytes (new, src/specifics/linux/GuestFaultCopy.cpp) is mov %rdx, %rcx; rep movsb; mov %rcx, %rax; ret. It returns the number of bytes it did not copy.
  • A SIGSEGV/SIGBUS handler is installed once, on the first checked copy. When a kernel-raised fault's REG_RIP is exactly the rep movsb, the handler moves REG_RIP to the next instruction and returns. rcx still holds the bytes left, so the copy returns non-zero and the caller returns false, as it does today on EFAULT.
  • Any other fault goes to the handler that was installed before, unchanged: the handler is called, or SIG_DFL is restored and the fault re-raised (the same chaining as CrashReport.cpp).
  • CrashReport.cpp's OnFatalSignal makes the same check first, so a copy fault never prints a crash report, whichever handler was installed first.

Handler order: libc's crash report is installed when libc loads, so the copy handler, installed later, runs first and chains to it. libkernel's DeliverFault (installed when a title registers an exception handler) runs before both. It sends a fault whose rip isn't in guest code to the previous handler, and libc.prx isn't guest code, so copy faults still reach the copy handler. libkernel's Signals.cpp also changes the host SIGSEGV disposition, with std::signal, when a title registers or resets a SIGSEGV handler (Install, ResetToDefault). After each change it now calls GuestFaultCopyReinstall_nid_no_patch(), which puts the copy handler back in front and chains it to the new disposition: the guest's Dispatch, SIG_DFL or SIG_IGN. The previous dispositions are kept in two slots, swapped once the new one is written, so a fault handler never reads one that's being rewritten. The copy handler is installed with SA_NODEFER, but it keeps the previous disposition's sa_mask, and a guest handler installed through std::signal blocks SIGSEGV in that mask. So a copy that faults inside the guest's own SIGSEGV handler does not resolve: the fault stays fatal there, where main's process_vm_readv returns false. The reinstall after a guest registration takes over SIGSEGV only, the signal libkernel replaced: SIGBUS keeps the chain it had, so a DeliverFault that already chains to the copy handler is never saved as that handler's previous. A raised SIGSEGV that the guest ignores (SIG_IGN) is ignored, as ChainFault does, instead of reaching the SIG_DFL fallback. The install takes no lock, because it can run inside a signal handler: a guest handler registered with SA_RESETHAND resets SIGSEGV from Dispatch. One thread installs at a time, set by an atomic owner thread id, and a nested call on that thread asks the outer install to run once more instead of waiting on itself. Besides these, the only host sigaction callers for SIGSEGV/SIGBUS in core are the crash report and DeliverFault (git grep -n "sigaction(\|std::signal(" -- core, tests aside; the write watch's handler is macOS-only). A guest's sigprocmask is emulated in libkernel and never blocks the host's SIGSEGV.

Unchanged:

  • The null and wrap checks; GuestArenaPrepareHostRead_nid_no_patch before reads; the GuestArena::HostWrite bracket around writes.
  • errno: the copy never touches it, so nothing needs saving.
  • Guest writes stay tracked. On Linux the write watch uses userfaultfd async write-protect, which the kernel resolves for a plain host store just as it does for process_vm_writev's page walk.
  • GuestCopyInUnsynced_nid_no_patch and the per-page reads in CopyGuestString_nid_no_patch go through the same CopyGuestBytes, so they get the new path too.
  • Windows (VirtualQuery + memcpy), macOS (mach_vm_*), Linux on other CPUs, and GuestWritable_nid_no_patch keep their current code.

APS5_GUEST_COPY_SYSCALL=1 keeps the system-call path; it is read once, on the first copy. The test that blocks process_vm_readv with seccomp to pin the throw on a non-EFAULT failure (guest_output_pointer_fault) now runs that check only on that path, in a new guest_output_pointer_fault_syscall registration. The rest of that test runs on both paths.

Measured at this PR's head a889c2afab (the patch as tested, before the one-line test change in f5c078a51f), with a release build on an i7-13700K (Ubuntu 26.04.1, kernel 7.0, GCC 15.2). Pinned to one core, best of 7 rounds of 1M calls (20k for 64 KiB). The cells are the two values from two runs of the benchmark in one logged job:

copy system call (APS5_GUEST_COPY_SYSCALL=1) this PR
8 B in / out 323-325 / 320-326 ns 6.2 / 8.4 ns
64 B in / out 321-327 / 325-327 ns 6.2 / 8.3-8.4 ns
4 KiB in / out 387-388 / 385-389 ns 21.0-21.4 / 22.0-22.1 ns
64 KiB in / out 1912-1937 / 1953-1962 ns 900-901 / 898-916 ns
8 B from or to an unmapped page 265 / 263-264 ns 1026-1027 / 1025-1027 ns

A failed copy costs more, about 1 µs for the signal round trip, but that only happens on a bad pointer, where today's alternative is a host crash or an error return. strace -c on guest_fault_copy_tests at the same head shows no process_vm_readv or process_vm_writev calls on the new path, against 160,035 and 80,035 with APS5_GUEST_COPY_SYSCALL=1.

Draft, for discussion: the signal-handler approach is the part to agree on before I go further. If this goes in, the cost note in #20691 changes to cover Windows and the fallback only, and I'll update whichever of the two lands second. Possible follow-ups:

  • Windows GuestCopyIn_nid_no_patch through #14799's GuardedCopy and GuestArenaRecoverRead_nid_no_patch (with a guarded store for GuestCopyOut_nid_no_patch), in place of ReadProcessMemory and VirtualQuery per call;
  • GuestWritable_nid_no_patch as a probe through the same handler.

Tested

Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, -DBUILD_TESTING=ON, i7-13700K.

  • New guest_fault_copy (this path) and guest_fault_copy_syscall (APS5_GUEST_COPY_SYSCALL=1) run the same checks:
    • copies of 1 to 65536 bytes at four alignments, both ways;
    • false with errno kept for 0x10, a non-canonical address (0x8000000000000000, a #GP rather than a page fault), a PROT_NONE page, a span running into it, and a write to a read-only page, which still reads back;
    • 4 threads × 20,000 rounds of good and faulting copies;
    • a handler installed before the first copy still gets a fault outside the copy, in a forked child;
    • a handler installed after it, chaining to the previous one, sees the copy faults and the copies still return false.
    • after a guest registers a SIGSEGV handler through sigaction_nid_postfix (a plain handler, an SA_SIGINFO one, SIG_IGN, a reset to the default, and an SA_RESETHAND handler run once by a raised SIGSEGV, so the reset happens in signal context), copies from and to 0x10 still return false. Negative control: without the two GuestFaultCopyReinstall_nid_no_patch() calls, the plain-handler child loops on the fault until its 10 s alarm;
    • zero-length copies from and to 0x10 return true.
    • after a guest registers SIG_IGN for SIGSEGV, a raised SIGSEGV is ignored and the child exits 0. Negative control, at fa9ec0d269's GuestFaultCopy.cpp: the child is killed (check failed at line 45);
    • with a libkernel exception handler registered after the first copy and then a guest SIGSEGV sigaction, a raised SIGBUS kills the child with SIGBUS. Negative control, with only the SIG_IGN fix and the reinstall of both signals: the child loops between the copy handler and DeliverFault until its 10 s alarm (check failed at line 129).
  • guest_output_pointer_fault and the new guest_output_pointer_fault_syscall: pass.
  • tools/check_conventions.py passes on the branch and this body.
  • At head 33364ad1eb: guest_fault_copy and guest_fault_copy_syscall pass, 3 runs of 3.
  • At fa9ec0d269: the 10 copy, fault and signal registrations (guest_fault_copy, guest_output_pointer_fault, guest_fstat_fault, each with its _syscall twin, guest_signal_handler_mask, guest_sigvec, guest_kernel_sig_pending) pass, 3 runs of 3. Without the reinstall in ResetToDefault, guest_fault_copy aborts. guest_umtx_op passes 5 of 5 on each copy path.
  • Full Linux suite at fa9ec0d269 (ctest -j4): 5761 passed, 59 skipped, 1 failed, of 5821. The failure is agc_driver_image_table_packed_guards, described below. In that run 22 display tests (guest_video_out_*, agc_driver_gcn_display_present*, video_out_hdr_present) skipped because the shell had no display. Rerun on the desktop session, all 22 pass; they're counted as passed here.
  • Full Linux suite at 8b3b02c012 (ctest -j4): 5760 passed, 59 skipped, 2 failed, of 5821. agc_driver_image_table_packed_guards is the failure described below, and guest_umtx_op aborted once under the -j4 load without captured output. At a889c2afab, before the signal-registration change, it was 5759 passed, 59 skipped, 2 failed, of 5820:
    • guest_fstat_fault had a second seccomp check of the same kind as guest_output_pointer_fault's: it blocks process_vm_writev and expects GuestCopyOut_nid_no_patch to throw. f5c078a51f runs it only with APS5_GUEST_COPY_SYSCALL=1, in a new guest_fstat_fault_syscall registration. Both registrations pass, and no other test blocks those system calls (grep -rln "SYS_process_vm_" core/libs/tests).
    • agc_driver_image_table_packed_guards (unrecoverable packed table format was not poisoned) fails in the same way with APS5_GUEST_COPY_SYSCALL=1 on the same build, two runs each way, so it isn't from this change.
  • Title pair: MGS4 Act 1, main b2779012ae against this patch on it (557565b461), A B A B A B. The result is 39.7 fps on main against 40.25 fps here, inside the spread; details in the comment below. Expected, since that scene is bound by queue worker 0x0, not by guest copies.
  • Trace capture: MGS4 Act 1 from the same save, APS5_TRACE_SECONDS=300:30, on main e4caa07950 (A1) and on this head fa9ec0d269 merged onto it (c5ada12bb1, B2 and B4).
    • Mean frame time was 23.27 ms on main, against 22.26 and 21.40 ms here.
    • That is one main run against two, and MGS4 varies 2 to 3.5 % from run to run, so I read it as neutral, like the A/B above.
    • The second main run (A3) crashed at 157 s (EXIT-139) on the unchanged main build. Its core wasn't kept.
    • Traces: release pr21156-mgs4-trace-e4caa07950. performance_compare.py and trace_digest.py output is in the comment below.
    • Summary lines, main A1 then this PR B2:
{"commit":"e4caa07950f8","dirty":false,"env":{"APS5_EBOOT":"<path>","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"300:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-43-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA18194","title":"METAL GEAR SOLID 4: Guns of the Patriots - Master Collection Version","content_version":"01.004.003","resolution":"3840x2160","window":{"spec":"seconds 300:30","first_present":15681,"ms":30013.319},"presents":1290,"frame_ms":{"p50":22.921,"p90":24.375,"p99":28.442,"max":36.144},"gpu_busy_ms_per_present":7.746,"worker_busy_pct":{"queue worker 0x0":97.239},"phase_totals_ms":{"Driver.Completion":2.341,"Driver.Dispatch":16.053,"Driver.Draw":22123.243,"Driver.Draw.device_setup":1091.949,"Driver.Draw.draw_enqueued":3831.482,"Driver.Draw.post_compile_prepare":375.568,"Driver.Draw.prepare":1879.113,"Driver.Draw.shader_compile_and_link":14539.047,"Driver.EndSubmission":2.767,"Driver.Packet":29179.332,"Driver.Packet.device_lock":357.714,"Driver.Packet.dispatch":28.161,"Driver.Packet.draw":22372.190,"Driver.Packet.execute":975.970,"Driver.Packet.flip_flush":20.078,"Driver.Packet.flush_between_packets":738.739,"Driver.Packet.memory_wait":0.403,"Driver.Packet.pipeline_drain":406.965,"Driver.Packet.pipeline_prepare":503.888,"Driver.Packet.prepare_memory":3413.287,"Driver.Packet.rendering_wait":1.148,"Driver.Present":1900.409,"Driver.Present.acquire_image":42.364,"Driver.Present.device_setup":0.741,"Driver.Present.gpu_mutex_wait":10.014,"Driver.Present.inflight_wait":3.680,"Driver.Present.present_display_buffer":72.561,"Driver.Present.queue_present":103.380,"Driver.Present.release_and_callback":1.214,"Driver.Present.render_fence_wait":1663.679,"Driver.Present.resize":1.471,"Driver.Present.validate":0.522,"Driver.Suspend":0.229,"GpuMutex.wait.copy":19.877,"GpuMutex.wait.draw":68.675,"GpuMutex.wait.end":0.244,"GpuMutex.wait.fill":10.401,"GpuMutex.wait.flush":22.600,"GpuMutex.wait.label":2361.792,"GpuMutex.wait.present":8.113,"GpuMutex.wait.wait":3.744,"Graphics.Draw":14653.915,"Graphics.Draw.draw_and_resource_release":10413.247,"Graphics.Draw.index_upload":395.786,"Graphics.Draw.validate":1554.450,"Graphics.Draw.vertex_upload":2124.777,"Graphics.DrawWithRecipe":1707.339,"Graphics.DrawWithRecipe.draw_and_resource_release":1182.503,"Graphics.DrawWithRecipe.index_upload":100.959,"Graphics.DrawWithRecipe.validate":79.586,"Graphics.DrawWithRecipe.vertex_upload":313.946,"Recorder.Reap":154.944,"Recorder.Submit":349.072,"Recorder.WaitSerial":1782.330,"Resources.Complete":449.924,"Resources.Prepare":141.200,"Shader.DrawStage":9971.849,"Shader.DrawStage.capture_resources":5014.203,"Shader.DrawStage.materialize":2988.521,"Shader.DrawStage.prepared_invocation":1798.329,"Shader.ResolveAbi":1352.795,"Shader.ResolveGraphicsAbi":336.895,"Shader.ResolveGraphicsStagesAbi":783.638,"VideoOut.Flip":1962.869,"VideoOut.Flip.completion_mutex_wait":1.136,"VideoOut.Flip.config_mutex_wait":0.162,"VideoOut.Flip.frame_limit":0.945,"VideoOut.Flip.notify_game":15.101,"VideoOut.Flip.present":1905.010,"VideoOut.Flip.validate":1.413,"VideoOut.Flip.vblank_wait":1.024,"VideoOut.Flip.window_prepare":1.673,"VideoOut.Flip.window_title":35.727,"VideoOut.Readiness":1.883,"VideoOut.Readiness.locks_validate":0.942,"Vulkan.Acquire":40.087,"Vulkan.Acquire.acquire_fence_wait":5.551,"Vulkan.Acquire.acquire_image":25.459,"Vulkan.Acquire.fence_reset":8.432,"Vulkan.Acquire.retired_swapchains":0.374,"Vulkan.DrawFromRecipe":1759.899,"Vulkan.Present":47.292,"Vulkan.Present.command_record_scale":20.489,"Vulkan.Present.pixel_upload":20.894,"Vulkan.Present.queue_submit":5.050,"Vulkan.QueuePresent":101.860,"Vulkan.QueuePresent.queue_present":100.949,"Vulkan.Retire":1663.468,"Vulkan.Retire.wait":1656.891},"top_phases_ms_per_frame":{"Driver.Packet":22.620,"Driver.Packet.draw":17.343,"Driver.Draw":17.150,"Graphics.Draw":11.360,"Driver.Draw.shader_compile_and_link":11.271,"Graphics.Draw.draw_and_resource_release":8.072,"Shader.DrawStage":7.730,"Shader.DrawStage.capture_resources":3.887},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":4198,"Graphics.Barrier.dcc-clear":10320,"Graphics.Barrier.dcc-keys":10276,"Graphics.Barrier.draw":105021,"Graphics.Barrier.fill":6836,"Graphics.Barrier.label-run":203368,"Graphics.Barrier.present-blit":5160,"Graphics.Barrier.storage-writeback":16885,"Graphics.BarrierMerged.copy":962,"Graphics.BarrierMerged.fill":3484,"Graphics.BarrierMerged.label-run":4,"Graphics.BarrierMerged.storage-writeback":3811,"Graphics.RenderPass":68783,"Graphics.RenderPass.Close.command":17748,"Graphics.RenderPass.Close.image":26346,"Graphics.RenderPass.Close.key":13444,"Graphics.RenderPass.Close.label":4,"Graphics.RenderPass.Close.new-batch":11241,"Graphics.RenderPass.Continued":1715287},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":15.661,"events_lost":239186,"totals_full":false}},"trace":"aps5-trace-e4caa07950f8-3.json.gz"}
{"commit":"c5ada12bb185","dirty":false,"env":{"APS5_EBOOT":"<path>","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"300:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-43-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA18194","title":"METAL GEAR SOLID 4: Guns of the Patriots - Master Collection Version","content_version":"01.004.003","resolution":"3840x2160","window":{"spec":"seconds 300:30","first_present":15757,"ms":30003.772},"presents":1348,"frame_ms":{"p50":22.010,"p90":22.964,"p99":26.702,"max":38.640},"gpu_busy_ms_per_present":7.526,"worker_busy_pct":{"queue worker 0x0":97.134},"phase_totals_ms":{"Driver.Completion":2.571,"Driver.Dispatch":15.852,"Driver.Draw":21964.398,"Driver.Draw.device_setup":1144.774,"Driver.Draw.draw_enqueued":3743.674,"Driver.Draw.post_compile_prepare":383.505,"Driver.Draw.prepare":1817.289,"Driver.Draw.shader_compile_and_link":14450.428,"Driver.EndSubmission":2.747,"Driver.Packet":29138.427,"Driver.Packet.device_lock":376.238,"Driver.Packet.dispatch":24.799,"Driver.Packet.draw":22211.444,"Driver.Packet.execute":1021.103,"Driver.Packet.flip_flush":20.169,"Driver.Packet.flush_between_packets":762.788,"Driver.Packet.memory_wait":0.500,"Driver.Packet.pipeline_drain":419.278,"Driver.Packet.pipeline_prepare":522.241,"Driver.Packet.prepare_memory":3410.814,"Driver.Packet.rendering_wait":0.979,"Driver.Present":1883.847,"Driver.Present.acquire_image":44.487,"Driver.Present.device_setup":0.746,"Driver.Present.gpu_mutex_wait":10.007,"Driver.Present.inflight_wait":2.844,"Driver.Present.present_display_buffer":74.940,"Driver.Present.queue_present":109.710,"Driver.Present.release_and_callback":1.367,"Driver.Present.render_fence_wait":1636.876,"Driver.Present.resize":1.515,"Driver.Present.validate":0.533,"Driver.Suspend":0.238,"GpuMutex.wait.copy":25.133,"GpuMutex.wait.draw":59.229,"GpuMutex.wait.end":0.010,"GpuMutex.wait.fill":13.723,"GpuMutex.wait.flush":21.852,"GpuMutex.wait.label":2337.612,"GpuMutex.wait.present":8.070,"GpuMutex.wait.wait":3.613,"Graphics.Draw":14347.075,"Graphics.Draw.draw_and_resource_release":10367.731,"Graphics.Draw.index_upload":390.525,"Graphics.Draw.validate":1589.748,"Graphics.Draw.vertex_upload":1832.960,"Graphics.DrawWithRecipe":1971.734,"Graphics.DrawWithRecipe.draw_and_resource_release":1495.216,"Graphics.DrawWithRecipe.index_upload":117.488,"Graphics.DrawWithRecipe.validate":97.120,"Graphics.DrawWithRecipe.vertex_upload":225.798,"Recorder.Reap":160.233,"Recorder.Submit":346.696,"Recorder.WaitSerial":1778.263,"Resources.Complete":485.434,"Resources.Prepare":144.752,"Shader.DrawStage":10031.319,"Shader.DrawStage.capture_resources":5041.763,"Shader.DrawStage.materialize":3024.400,"Shader.DrawStage.prepared_invocation":1795.893,"Shader.ResolveAbi":1321.886,"Shader.ResolveGraphicsAbi":350.983,"Shader.ResolveGraphicsStagesAbi":740.596,"VideoOut.Flip":1952.412,"VideoOut.Flip.completion_mutex_wait":1.354,"VideoOut.Flip.config_mutex_wait":0.162,"VideoOut.Flip.frame_limit":0.939,"VideoOut.Flip.notify_game":16.373,"VideoOut.Flip.present":1889.744,"VideoOut.Flip.validate":1.337,"VideoOut.Flip.vblank_wait":0.986,"VideoOut.Flip.window_prepare":1.730,"VideoOut.Flip.window_title":38.034,"VideoOut.Readiness":1.956,"VideoOut.Readiness.locks_validate":0.948,"Vulkan.Acquire":41.596,"Vulkan.Acquire.acquire_fence_wait":5.933,"Vulkan.Acquire.acquire_image":26.085,"Vulkan.Acquire.fence_reset":8.797,"Vulkan.Acquire.retired_swapchains":0.458,"Vulkan.DrawFromRecipe":2034.597,"Vulkan.Present":47.917,"Vulkan.Present.command_record_scale":21.339,"Vulkan.Present.pixel_upload":20.640,"Vulkan.Present.queue_submit":5.137,"Vulkan.QueuePresent":107.939,"Vulkan.QueuePresent.queue_present":106.768,"Vulkan.Retire":1636.625,"Vulkan.Retire.wait":1629.620},"top_phases_ms_per_frame":{"Driver.Packet":21.616,"Driver.Packet.draw":16.477,"Driver.Draw":16.294,"Driver.Draw.shader_compile_and_link":10.720,"Graphics.Draw":10.643,"Graphics.Draw.draw_and_resource_release":7.691,"Shader.DrawStage":7.442,"Shader.DrawStage.capture_resources":3.740},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":4492,"Graphics.Barrier.dcc-clear":10784,"Graphics.Barrier.dcc-keys":10266,"Graphics.Barrier.draw":109292,"Graphics.Barrier.fill":7415,"Graphics.Barrier.label-run":212314,"Graphics.Barrier.present-blit":5392,"Graphics.Barrier.storage-writeback":17553,"Graphics.BarrierMerged.copy":900,"Graphics.BarrierMerged.fill":3367,"Graphics.BarrierMerged.label-run":1,"Graphics.BarrierMerged.storage-writeback":4020,"Graphics.RenderPass":71425,"Graphics.RenderPass.Close.command":17848,"Graphics.RenderPass.Close.image":27905,"Graphics.RenderPass.Close.key":13997,"Graphics.RenderPass.Close.label":1,"Graphics.RenderPass.Close.new-batch":11674,"Graphics.RenderPass.Continued":1791511},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":18.747,"events_lost":163181,"totals_full":false}},"trace":"aps5-trace-c5ada12bb185-3.json.gz"}

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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5327401021 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21156). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-15T21:30:51Z. --- ### What On Linux x86-64, `GuestCopyIn_nid_no_patch` and `GuestCopyOut_nid_no_patch` now copy with a `rep movsb` whose faults the copy itself handles, instead of a `process_vm_readv`/`process_vm_writev` system call. A checked 8-byte copy goes from about 327 ns to about 6 ns. This removes the cost that has kept checked copies out of per-element paths: #20589, #20600, #20588, and #20682's Json2 `Value(const char*)` going from 136 to 511 ns. This uses the same technique as the kernel's `copy_from_user` exception table. AnyPS5 already uses it on Windows: #14799 added `GuardedCopy`/`GuardedCopyAvx2` to `GuestArena.cpp` for committed guest reads. Those are assembly loads at known labels; the first thing `ReportCrash`'s vectored handler does is call `GuestArenaRecoverRead_nid_no_patch`, which moves `Rip` to `GuardedReadFailed`. This PR brings the same scheme to Linux, for every checked copy: - `GuestFaultCopyBytes` (new, `src/specifics/linux/GuestFaultCopy.cpp`) is `mov %rdx, %rcx; rep movsb; mov %rcx, %rax; ret`. It returns the number of bytes it did not copy. - A SIGSEGV/SIGBUS handler is installed once, on the first checked copy. When a kernel-raised fault's `REG_RIP` is exactly the `rep movsb`, the handler moves `REG_RIP` to the next instruction and returns. `rcx` still holds the bytes left, so the copy returns non-zero and the caller returns `false`, as it does today on `EFAULT`. - Any other fault goes to the handler that was installed before, unchanged: the handler is called, or `SIG_DFL` is restored and the fault re-raised (the same chaining as `CrashReport.cpp`). - `CrashReport.cpp`'s `OnFatalSignal` makes the same check first, so a copy fault never prints a crash report, whichever handler was installed first. Handler order: libc's crash report is installed when libc loads, so the copy handler, installed later, runs first and chains to it. libkernel's `DeliverFault` (installed when a title registers an exception handler) runs before both. It sends a fault whose `rip` isn't in guest code to the previous handler, and libc.prx isn't guest code, so copy faults still reach the copy handler. libkernel's `Signals.cpp` also changes the host SIGSEGV disposition, with `std::signal`, when a title registers or resets a SIGSEGV handler (`Install`, `ResetToDefault`). After each change it now calls `GuestFaultCopyReinstall_nid_no_patch()`, which puts the copy handler back in front and chains it to the new disposition: the guest's `Dispatch`, `SIG_DFL` or `SIG_IGN`. The previous dispositions are kept in two slots, swapped once the new one is written, so a fault handler never reads one that's being rewritten. The copy handler is installed with `SA_NODEFER`, but it keeps the previous disposition's `sa_mask`, and a guest handler installed through `std::signal` blocks SIGSEGV in that mask. So a copy that faults inside the guest's own SIGSEGV handler does not resolve: the fault stays fatal there, where `main`'s `process_vm_readv` returns `false`. The reinstall after a guest registration takes over SIGSEGV only, the signal libkernel replaced: SIGBUS keeps the chain it had, so a `DeliverFault` that already chains to the copy handler is never saved as that handler's previous. A raised SIGSEGV that the guest ignores (`SIG_IGN`) is ignored, as `ChainFault` does, instead of reaching the `SIG_DFL` fallback. The install takes no lock, because it can run inside a signal handler: a guest handler registered with `SA_RESETHAND` resets SIGSEGV from `Dispatch`. One thread installs at a time, set by an atomic owner thread id, and a nested call on that thread asks the outer install to run once more instead of waiting on itself. Besides these, the only host `sigaction` callers for SIGSEGV/SIGBUS in `core` are the crash report and `DeliverFault` (`git grep -n "sigaction(\|std::signal(" -- core`, tests aside; the write watch's handler is macOS-only). A guest's `sigprocmask` is emulated in libkernel and never blocks the host's SIGSEGV. Unchanged: - The null and wrap checks; `GuestArenaPrepareHostRead_nid_no_patch` before reads; the `GuestArena::HostWrite` bracket around writes. - `errno`: the copy never touches it, so nothing needs saving. - Guest writes stay tracked. On Linux the write watch uses userfaultfd async write-protect, which the kernel resolves for a plain host store just as it does for `process_vm_writev`'s page walk. - `GuestCopyInUnsynced_nid_no_patch` and the per-page reads in `CopyGuestString_nid_no_patch` go through the same `CopyGuestBytes`, so they get the new path too. - Windows (`VirtualQuery` + `memcpy`), macOS (`mach_vm_*`), Linux on other CPUs, and `GuestWritable_nid_no_patch` keep their current code. `APS5_GUEST_COPY_SYSCALL=1` keeps the system-call path; it is read once, on the first copy. The test that blocks `process_vm_readv` with seccomp to pin the throw on a non-`EFAULT` failure (`guest_output_pointer_fault`) now runs that check only on that path, in a new `guest_output_pointer_fault_syscall` registration. The rest of that test runs on both paths. Measured at this PR's head `a889c2afab` (the patch as tested, before the one-line test change in `f5c078a51f`), with a release build on an i7-13700K (Ubuntu 26.04.1, kernel 7.0, GCC 15.2). Pinned to one core, best of 7 rounds of 1M calls (20k for 64 KiB). The cells are the two values from two runs of the benchmark in one logged job: | copy | system call (`APS5_GUEST_COPY_SYSCALL=1`) | this PR | |---|---|---| | 8 B in / out | 323-325 / 320-326 ns | 6.2 / 8.4 ns | | 64 B in / out | 321-327 / 325-327 ns | 6.2 / 8.3-8.4 ns | | 4 KiB in / out | 387-388 / 385-389 ns | 21.0-21.4 / 22.0-22.1 ns | | 64 KiB in / out | 1912-1937 / 1953-1962 ns | 900-901 / 898-916 ns | | 8 B from or to an unmapped page | 265 / 263-264 ns | 1026-1027 / 1025-1027 ns | A failed copy costs more, about 1 µs for the signal round trip, but that only happens on a bad pointer, where today's alternative is a host crash or an error return. `strace -c` on `guest_fault_copy_tests` at the same head shows no `process_vm_readv` or `process_vm_writev` calls on the new path, against 160,035 and 80,035 with `APS5_GUEST_COPY_SYSCALL=1`. Draft, for discussion: the signal-handler approach is the part to agree on before I go further. If this goes in, the cost note in #20691 changes to cover Windows and the fallback only, and I'll update whichever of the two lands second. Possible follow-ups: - Windows `GuestCopyIn_nid_no_patch` through #14799's `GuardedCopy` and `GuestArenaRecoverRead_nid_no_patch` (with a guarded store for `GuestCopyOut_nid_no_patch`), in place of `ReadProcessMemory` and `VirtualQuery` per call; - `GuestWritable_nid_no_patch` as a probe through the same handler. ### Tested Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release, `-DBUILD_TESTING=ON`, i7-13700K. - New `guest_fault_copy` (this path) and `guest_fault_copy_syscall` (`APS5_GUEST_COPY_SYSCALL=1`) run the same checks: - copies of 1 to 65536 bytes at four alignments, both ways; - `false` with `errno` kept for `0x10`, a non-canonical address (`0x8000000000000000`, a #GP rather than a page fault), a `PROT_NONE` page, a span running into it, and a write to a read-only page, which still reads back; - 4 threads × 20,000 rounds of good and faulting copies; - a handler installed before the first copy still gets a fault outside the copy, in a forked child; - a handler installed after it, chaining to the previous one, sees the copy faults and the copies still return `false`. - after a guest registers a SIGSEGV handler through `sigaction_nid_postfix` (a plain handler, an `SA_SIGINFO` one, `SIG_IGN`, a reset to the default, and an `SA_RESETHAND` handler run once by a raised SIGSEGV, so the reset happens in signal context), copies from and to `0x10` still return `false`. Negative control: without the two `GuestFaultCopyReinstall_nid_no_patch()` calls, the plain-handler child loops on the fault until its 10 s alarm; - zero-length copies from and to `0x10` return `true`. - after a guest registers `SIG_IGN` for SIGSEGV, a raised SIGSEGV is ignored and the child exits 0. Negative control, at `fa9ec0d269`'s `GuestFaultCopy.cpp`: the child is killed (`check failed at line 45`); - with a libkernel exception handler registered after the first copy and then a guest SIGSEGV `sigaction`, a raised SIGBUS kills the child with SIGBUS. Negative control, with only the `SIG_IGN` fix and the reinstall of both signals: the child loops between the copy handler and `DeliverFault` until its 10 s alarm (`check failed at line 129`). - `guest_output_pointer_fault` and the new `guest_output_pointer_fault_syscall`: pass. - `tools/check_conventions.py` passes on the branch and this body. - At head `33364ad1eb`: `guest_fault_copy` and `guest_fault_copy_syscall` pass, 3 runs of 3. - At `fa9ec0d269`: the 10 copy, fault and signal registrations (`guest_fault_copy`, `guest_output_pointer_fault`, `guest_fstat_fault`, each with its `_syscall` twin, `guest_signal_handler_mask`, `guest_sigvec`, `guest_kernel_sig_pending`) pass, 3 runs of 3. Without the reinstall in `ResetToDefault`, `guest_fault_copy` aborts. `guest_umtx_op` passes 5 of 5 on each copy path. - Full Linux suite at `fa9ec0d269` (`ctest -j4`): 5761 passed, 59 skipped, 1 failed, of 5821. The failure is `agc_driver_image_table_packed_guards`, described below. In that run 22 display tests (`guest_video_out_*`, `agc_driver_gcn_display_present*`, `video_out_hdr_present`) skipped because the shell had no display. Rerun on the desktop session, all 22 pass; they're counted as passed here. - Full Linux suite at `8b3b02c012` (`ctest -j4`): 5760 passed, 59 skipped, 2 failed, of 5821. `agc_driver_image_table_packed_guards` is the failure described below, and `guest_umtx_op` aborted once under the `-j4` load without captured output. At `a889c2afab`, before the signal-registration change, it was 5759 passed, 59 skipped, 2 failed, of 5820: - `guest_fstat_fault` had a second seccomp check of the same kind as `guest_output_pointer_fault`'s: it blocks `process_vm_writev` and expects `GuestCopyOut_nid_no_patch` to throw. `f5c078a51f` runs it only with `APS5_GUEST_COPY_SYSCALL=1`, in a new `guest_fstat_fault_syscall` registration. Both registrations pass, and no other test blocks those system calls (`grep -rln "SYS_process_vm_" core/libs/tests`). - `agc_driver_image_table_packed_guards` (`unrecoverable packed table format was not poisoned`) fails in the same way with `APS5_GUEST_COPY_SYSCALL=1` on the same build, two runs each way, so it isn't from this change. - Title pair: MGS4 Act 1, `main` `b2779012ae` against this patch on it (`557565b461`), A B A B A B. The result is 39.7 fps on `main` against 40.25 fps here, inside the spread; details in the comment below. Expected, since that scene is bound by queue worker 0x0, not by guest copies. - Trace capture: MGS4 Act 1 from the same save, `APS5_TRACE_SECONDS=300:30`, on `main` `e4caa07950` (A1) and on this head `fa9ec0d269` merged onto it (`c5ada12bb1`, B2 and B4). - Mean frame time was 23.27 ms on `main`, against 22.26 and 21.40 ms here. - That is one `main` run against two, and MGS4 varies 2 to 3.5 % from run to run, so I read it as neutral, like the A/B above. - The second `main` run (A3) crashed at 157 s (`EXIT-139`) on the unchanged `main` build. Its core wasn't kept. - Traces: [release `pr21156-mgs4-trace-e4caa07950`](https://github.com/milescoviello/AnyPS5/releases/tag/pr21156-mgs4-trace-e4caa07950). `performance_compare.py` and `trace_digest.py` output is in the comment below. - Summary lines, `main` A1 then this PR B2: ```json {"commit":"e4caa07950f8","dirty":false,"env":{"APS5_EBOOT":"<path>","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"300:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-43-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA18194","title":"METAL GEAR SOLID 4: Guns of the Patriots - Master Collection Version","content_version":"01.004.003","resolution":"3840x2160","window":{"spec":"seconds 300:30","first_present":15681,"ms":30013.319},"presents":1290,"frame_ms":{"p50":22.921,"p90":24.375,"p99":28.442,"max":36.144},"gpu_busy_ms_per_present":7.746,"worker_busy_pct":{"queue worker 0x0":97.239},"phase_totals_ms":{"Driver.Completion":2.341,"Driver.Dispatch":16.053,"Driver.Draw":22123.243,"Driver.Draw.device_setup":1091.949,"Driver.Draw.draw_enqueued":3831.482,"Driver.Draw.post_compile_prepare":375.568,"Driver.Draw.prepare":1879.113,"Driver.Draw.shader_compile_and_link":14539.047,"Driver.EndSubmission":2.767,"Driver.Packet":29179.332,"Driver.Packet.device_lock":357.714,"Driver.Packet.dispatch":28.161,"Driver.Packet.draw":22372.190,"Driver.Packet.execute":975.970,"Driver.Packet.flip_flush":20.078,"Driver.Packet.flush_between_packets":738.739,"Driver.Packet.memory_wait":0.403,"Driver.Packet.pipeline_drain":406.965,"Driver.Packet.pipeline_prepare":503.888,"Driver.Packet.prepare_memory":3413.287,"Driver.Packet.rendering_wait":1.148,"Driver.Present":1900.409,"Driver.Present.acquire_image":42.364,"Driver.Present.device_setup":0.741,"Driver.Present.gpu_mutex_wait":10.014,"Driver.Present.inflight_wait":3.680,"Driver.Present.present_display_buffer":72.561,"Driver.Present.queue_present":103.380,"Driver.Present.release_and_callback":1.214,"Driver.Present.render_fence_wait":1663.679,"Driver.Present.resize":1.471,"Driver.Present.validate":0.522,"Driver.Suspend":0.229,"GpuMutex.wait.copy":19.877,"GpuMutex.wait.draw":68.675,"GpuMutex.wait.end":0.244,"GpuMutex.wait.fill":10.401,"GpuMutex.wait.flush":22.600,"GpuMutex.wait.label":2361.792,"GpuMutex.wait.present":8.113,"GpuMutex.wait.wait":3.744,"Graphics.Draw":14653.915,"Graphics.Draw.draw_and_resource_release":10413.247,"Graphics.Draw.index_upload":395.786,"Graphics.Draw.validate":1554.450,"Graphics.Draw.vertex_upload":2124.777,"Graphics.DrawWithRecipe":1707.339,"Graphics.DrawWithRecipe.draw_and_resource_release":1182.503,"Graphics.DrawWithRecipe.index_upload":100.959,"Graphics.DrawWithRecipe.validate":79.586,"Graphics.DrawWithRecipe.vertex_upload":313.946,"Recorder.Reap":154.944,"Recorder.Submit":349.072,"Recorder.WaitSerial":1782.330,"Resources.Complete":449.924,"Resources.Prepare":141.200,"Shader.DrawStage":9971.849,"Shader.DrawStage.capture_resources":5014.203,"Shader.DrawStage.materialize":2988.521,"Shader.DrawStage.prepared_invocation":1798.329,"Shader.ResolveAbi":1352.795,"Shader.ResolveGraphicsAbi":336.895,"Shader.ResolveGraphicsStagesAbi":783.638,"VideoOut.Flip":1962.869,"VideoOut.Flip.completion_mutex_wait":1.136,"VideoOut.Flip.config_mutex_wait":0.162,"VideoOut.Flip.frame_limit":0.945,"VideoOut.Flip.notify_game":15.101,"VideoOut.Flip.present":1905.010,"VideoOut.Flip.validate":1.413,"VideoOut.Flip.vblank_wait":1.024,"VideoOut.Flip.window_prepare":1.673,"VideoOut.Flip.window_title":35.727,"VideoOut.Readiness":1.883,"VideoOut.Readiness.locks_validate":0.942,"Vulkan.Acquire":40.087,"Vulkan.Acquire.acquire_fence_wait":5.551,"Vulkan.Acquire.acquire_image":25.459,"Vulkan.Acquire.fence_reset":8.432,"Vulkan.Acquire.retired_swapchains":0.374,"Vulkan.DrawFromRecipe":1759.899,"Vulkan.Present":47.292,"Vulkan.Present.command_record_scale":20.489,"Vulkan.Present.pixel_upload":20.894,"Vulkan.Present.queue_submit":5.050,"Vulkan.QueuePresent":101.860,"Vulkan.QueuePresent.queue_present":100.949,"Vulkan.Retire":1663.468,"Vulkan.Retire.wait":1656.891},"top_phases_ms_per_frame":{"Driver.Packet":22.620,"Driver.Packet.draw":17.343,"Driver.Draw":17.150,"Graphics.Draw":11.360,"Driver.Draw.shader_compile_and_link":11.271,"Graphics.Draw.draw_and_resource_release":8.072,"Shader.DrawStage":7.730,"Shader.DrawStage.capture_resources":3.887},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":4198,"Graphics.Barrier.dcc-clear":10320,"Graphics.Barrier.dcc-keys":10276,"Graphics.Barrier.draw":105021,"Graphics.Barrier.fill":6836,"Graphics.Barrier.label-run":203368,"Graphics.Barrier.present-blit":5160,"Graphics.Barrier.storage-writeback":16885,"Graphics.BarrierMerged.copy":962,"Graphics.BarrierMerged.fill":3484,"Graphics.BarrierMerged.label-run":4,"Graphics.BarrierMerged.storage-writeback":3811,"Graphics.RenderPass":68783,"Graphics.RenderPass.Close.command":17748,"Graphics.RenderPass.Close.image":26346,"Graphics.RenderPass.Close.key":13444,"Graphics.RenderPass.Close.label":4,"Graphics.RenderPass.Close.new-batch":11241,"Graphics.RenderPass.Continued":1715287},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":15.661,"events_lost":239186,"totals_full":false}},"trace":"aps5-trace-e4caa07950f8-3.json.gz"} ``` ```json {"commit":"c5ada12bb185","dirty":false,"env":{"APS5_EBOOT":"<path>","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"300:30","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 4070 Ti","driver":"NVIDIA 615.71.09","os":"Linux 7.0.0-43-generic","cpu":"13th Gen Intel(R) Core(TM) i7-13700K","cpu_threads":24,"memory_mib":30993,"title_id":"PPSA18194","title":"METAL GEAR SOLID 4: Guns of the Patriots - Master Collection Version","content_version":"01.004.003","resolution":"3840x2160","window":{"spec":"seconds 300:30","first_present":15757,"ms":30003.772},"presents":1348,"frame_ms":{"p50":22.010,"p90":22.964,"p99":26.702,"max":38.640},"gpu_busy_ms_per_present":7.526,"worker_busy_pct":{"queue worker 0x0":97.134},"phase_totals_ms":{"Driver.Completion":2.571,"Driver.Dispatch":15.852,"Driver.Draw":21964.398,"Driver.Draw.device_setup":1144.774,"Driver.Draw.draw_enqueued":3743.674,"Driver.Draw.post_compile_prepare":383.505,"Driver.Draw.prepare":1817.289,"Driver.Draw.shader_compile_and_link":14450.428,"Driver.EndSubmission":2.747,"Driver.Packet":29138.427,"Driver.Packet.device_lock":376.238,"Driver.Packet.dispatch":24.799,"Driver.Packet.draw":22211.444,"Driver.Packet.execute":1021.103,"Driver.Packet.flip_flush":20.169,"Driver.Packet.flush_between_packets":762.788,"Driver.Packet.memory_wait":0.500,"Driver.Packet.pipeline_drain":419.278,"Driver.Packet.pipeline_prepare":522.241,"Driver.Packet.prepare_memory":3410.814,"Driver.Packet.rendering_wait":0.979,"Driver.Present":1883.847,"Driver.Present.acquire_image":44.487,"Driver.Present.device_setup":0.746,"Driver.Present.gpu_mutex_wait":10.007,"Driver.Present.inflight_wait":2.844,"Driver.Present.present_display_buffer":74.940,"Driver.Present.queue_present":109.710,"Driver.Present.release_and_callback":1.367,"Driver.Present.render_fence_wait":1636.876,"Driver.Present.resize":1.515,"Driver.Present.validate":0.533,"Driver.Suspend":0.238,"GpuMutex.wait.copy":25.133,"GpuMutex.wait.draw":59.229,"GpuMutex.wait.end":0.010,"GpuMutex.wait.fill":13.723,"GpuMutex.wait.flush":21.852,"GpuMutex.wait.label":2337.612,"GpuMutex.wait.present":8.070,"GpuMutex.wait.wait":3.613,"Graphics.Draw":14347.075,"Graphics.Draw.draw_and_resource_release":10367.731,"Graphics.Draw.index_upload":390.525,"Graphics.Draw.validate":1589.748,"Graphics.Draw.vertex_upload":1832.960,"Graphics.DrawWithRecipe":1971.734,"Graphics.DrawWithRecipe.draw_and_resource_release":1495.216,"Graphics.DrawWithRecipe.index_upload":117.488,"Graphics.DrawWithRecipe.validate":97.120,"Graphics.DrawWithRecipe.vertex_upload":225.798,"Recorder.Reap":160.233,"Recorder.Submit":346.696,"Recorder.WaitSerial":1778.263,"Resources.Complete":485.434,"Resources.Prepare":144.752,"Shader.DrawStage":10031.319,"Shader.DrawStage.capture_resources":5041.763,"Shader.DrawStage.materialize":3024.400,"Shader.DrawStage.prepared_invocation":1795.893,"Shader.ResolveAbi":1321.886,"Shader.ResolveGraphicsAbi":350.983,"Shader.ResolveGraphicsStagesAbi":740.596,"VideoOut.Flip":1952.412,"VideoOut.Flip.completion_mutex_wait":1.354,"VideoOut.Flip.config_mutex_wait":0.162,"VideoOut.Flip.frame_limit":0.939,"VideoOut.Flip.notify_game":16.373,"VideoOut.Flip.present":1889.744,"VideoOut.Flip.validate":1.337,"VideoOut.Flip.vblank_wait":0.986,"VideoOut.Flip.window_prepare":1.730,"VideoOut.Flip.window_title":38.034,"VideoOut.Readiness":1.956,"VideoOut.Readiness.locks_validate":0.948,"Vulkan.Acquire":41.596,"Vulkan.Acquire.acquire_fence_wait":5.933,"Vulkan.Acquire.acquire_image":26.085,"Vulkan.Acquire.fence_reset":8.797,"Vulkan.Acquire.retired_swapchains":0.458,"Vulkan.DrawFromRecipe":2034.597,"Vulkan.Present":47.917,"Vulkan.Present.command_record_scale":21.339,"Vulkan.Present.pixel_upload":20.640,"Vulkan.Present.queue_submit":5.137,"Vulkan.QueuePresent":107.939,"Vulkan.QueuePresent.queue_present":106.768,"Vulkan.Retire":1636.625,"Vulkan.Retire.wait":1629.620},"top_phases_ms_per_frame":{"Driver.Packet":21.616,"Driver.Packet.draw":16.477,"Driver.Draw":16.294,"Driver.Draw.shader_compile_and_link":10.720,"Graphics.Draw":10.643,"Graphics.Draw.draw_and_resource_release":7.691,"Shader.DrawStage":7.442,"Shader.DrawStage.capture_resources":3.740},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":4492,"Graphics.Barrier.dcc-clear":10784,"Graphics.Barrier.dcc-keys":10266,"Graphics.Barrier.draw":109292,"Graphics.Barrier.fill":7415,"Graphics.Barrier.label-run":212314,"Graphics.Barrier.present-blit":5392,"Graphics.Barrier.storage-writeback":17553,"Graphics.BarrierMerged.copy":900,"Graphics.BarrierMerged.fill":3367,"Graphics.BarrierMerged.label-run":1,"Graphics.BarrierMerged.storage-writeback":4020,"Graphics.RenderPass":71425,"Graphics.RenderPass.Close.command":17848,"Graphics.RenderPass.Close.image":27905,"Graphics.RenderPass.Close.key":13997,"Graphics.RenderPass.Close.label":1,"Graphics.RenderPass.Close.new-batch":11674,"Graphics.RenderPass.Continued":1791511},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":18.747,"events_lost":163181,"totals_full":false}},"trace":"aps5-trace-c5ada12bb185-3.json.gz"} ``` ### 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](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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-16 06:08:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T06:08:25Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: preserve the existing SIGSEGV/SIGBUS handler chain when guest fault delivery and write-watch handlers are installed after the copy handler.

What I ran

Inspected the prepared diff and the changed implementation, call sites, signal-handler callers, and tests at head 557565b46194084e43021894b38b45c9efe03af0. No commands or tests were run; the run environment provides the review reader only. No merged-preview check was run.

Results

Check Result Note
Diff and source review passed Changed code and relevant callers inspected
Automated tests not run Author reports targeted tests; full suite pending
Build and title runs not run Not performed on this head

Findings

Blocking

  • core/libs/prx/libc/src/specifics/linux/GuestFaultCopy.cpp:168 — the copy handler replaces the current SIGSEGV/SIGBUS handler and saves it for chaining. Later, GuestWriteWatch::Watch() replaces those handlers and saves OnCopyFault as its predecessor. Its fault handler delegates ordinary faults to that predecessor, but OnCopyFault chains to the handler captured when the copy handler was installed, skipping any handler installed in between. If libkernel's DeliverFault is installed after the first checked copy, it is lost from the chain for faults that reach write-watch first; guest exception delivery can therefore be bypassed. Preserve a chain that accounts for handlers installed both before and after the copy handler, or coordinate the handler installation order. The PR's stated claim that handler order is safe does not cover this ordering.

Non-blocking

None.

Sources

Not verified

No tests, build, full Linux suite, title runs, or physical-console behavior were verified. Author-reported test and benchmark results were not run by this review. Read all changed files listed in the manifest; no files were excluded by rule.

To get this to a good state

Update signal-handler chaining so handlers installed after the copy handler remain in the chain even when write-watch wraps them; then rerun the targeted copy and guest exception tests and the full Linux suite on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5915711931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21156#pullrequestreview-5915711931). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T06:08:25Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: preserve the existing SIGSEGV/SIGBUS handler chain when guest fault delivery and write-watch handlers are installed after the copy handler. ## What I ran Inspected the prepared diff and the changed implementation, call sites, signal-handler callers, and tests at head `557565b46194084e43021894b38b45c9efe03af0`. No commands or tests were run; the run environment provides the review reader only. No merged-preview check was run. ## Results | Check | Result | Note | |---|---|---| | Diff and source review | passed | Changed code and relevant callers inspected | | Automated tests | not run | Author reports targeted tests; full suite pending | | Build and title runs | not run | Not performed on this head | ## Findings ### Blocking - `core/libs/prx/libc/src/specifics/linux/GuestFaultCopy.cpp:168` — the copy handler replaces the current SIGSEGV/SIGBUS handler and saves it for chaining. Later, `GuestWriteWatch::Watch()` replaces those handlers and saves `OnCopyFault` as its predecessor. Its fault handler delegates ordinary faults to that predecessor, but `OnCopyFault` chains to the handler captured when the copy handler was installed, skipping any handler installed in between. If libkernel's `DeliverFault` is installed after the first checked copy, it is lost from the chain for faults that reach write-watch first; guest exception delivery can therefore be bypassed. Preserve a chain that accounts for handlers installed both before and after the copy handler, or coordinate the handler installation order. The PR's stated claim that handler order is safe does not cover this ordering. ### Non-blocking None. ## Sources - [GuestFaultCopy.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/557565b46194084e43021894b38b45c9efe03af0/core/libs/prx/libc/src/specifics/linux/GuestFaultCopy.cpp) - [GuestWriteWatch.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/557565b46194084e43021894b38b45c9efe03af0/core/libs/prx/libc/src/GuestWriteWatch.cpp) - [Exception.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/557565b46194084e43021894b38b45c9efe03af0/core/libs/prx/libkernel/System/src/Exception.cpp) ## Not verified No tests, build, full Linux suite, title runs, or physical-console behavior were verified. Author-reported test and benchmark results were not run by this review. Read all changed files listed in the manifest; no files were excluded by rule. ## To get this to a good state Update signal-handler chaining so handlers installed after the copy handler remain in the chain even when write-watch wraps them; then rerun the targeted copy and guest exception tests and the full Linux suite on the updated head.
MarcZX10 commented 2026-11-16 12:05:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T12:05:18Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks this; the points below are optional.

What I ran

Reviewed head fa9ec0d26942fcc018a0e34083405d57a4bfc8fa using the prepared diff and pinned reader. No test or build commands were run.

Results

Check Result Note
Changed code review passed All 13 changed files appear in the diff.
Build and tests not run Results in the description are author-reported.

Findings

Blocking

None.

Non-blocking

None.

Sources

  • PR description and prepared diff
  • Changed files reviewed: core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/General.hpp, core/libs/prx/libc/include/specifics/linux/GuestFaultCopy.hpp, core/libs/prx/libc/src/General.cpp, core/libs/prx/libc/src/specifics/linux/CrashReport.cpp, core/libs/prx/libc/src/specifics/linux/GuestFaultCopy.cpp, core/libs/prx/libc/tests/cmake/guest_fault_copy.cmake, core/libs/prx/libkernel/CMakeLists.txt, core/libs/prx/libkernel/System/src/Signals.cpp, core/libs/tests/GuestFaultCopy.cpp, core/libs/tests/GuestFstatFault.cpp, core/libs/tests/GuestOutputPointerFault.cpp, and docs/dev/ENVIRONMENT.md.

Not verified

Builds and tests were not run. The test results and measurements in the description are author-reported. The review bundle lists all 13 changed files as included; no changed files were excluded.

To get this to a good state

Nothing is required. Optionally, run the Linux build and tests on this head to independently confirm the reported results.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5919666579 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21156#pullrequestreview-5919666579). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T12:05:18Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks this; the points below are optional. ## What I ran Reviewed head `fa9ec0d26942fcc018a0e34083405d57a4bfc8fa` using the prepared diff and pinned reader. No test or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All 13 changed files appear in the diff. | | Build and tests | not run | Results in the description are author-reported. | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [PR description and prepared diff](https://github.com/boykopovar/AnyPS5/commit/fa9ec0d26942fcc018a0e34083405d57a4bfc8fa) - Changed files reviewed: `core/libs/prx/libc/CMakeLists.txt`, `core/libs/prx/libc/include/General.hpp`, `core/libs/prx/libc/include/specifics/linux/GuestFaultCopy.hpp`, `core/libs/prx/libc/src/General.cpp`, `core/libs/prx/libc/src/specifics/linux/CrashReport.cpp`, `core/libs/prx/libc/src/specifics/linux/GuestFaultCopy.cpp`, `core/libs/prx/libc/tests/cmake/guest_fault_copy.cmake`, `core/libs/prx/libkernel/CMakeLists.txt`, `core/libs/prx/libkernel/System/src/Signals.cpp`, `core/libs/tests/GuestFaultCopy.cpp`, `core/libs/tests/GuestFstatFault.cpp`, `core/libs/tests/GuestOutputPointerFault.cpp`, and `docs/dev/ENVIRONMENT.md`. ## Not verified Builds and tests were not run. The test results and measurements in the description are author-reported. The review bundle lists all 13 changed files as included; no changed files were excluded. ## To get this to a good state Nothing is required. Optionally, run the Linux build and tests on this head to independently confirm the reported results.
MarcZX10 commented 2026-11-16 15:15:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T15:15:42Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change based on the code reviewed; the reported test runs were supplied by the author and were not run here.

What I ran

Reviewed head 33364ad1ebffdf867ac414d34f56ed1c9f9170f0 using the prepared diff and repo_read.py reader tools. No build or tests were run. The description reports Linux test runs, including copy-path tests at this head; these are author supplied.

Results

Check Result Note
Diff and changed code passed All 13 changed files were included and read
Build and tests here not run No shell execution available
Author-reported Linux tests not run Reported passing; not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

No changed file was excluded: files.json reports no excluded files. The provided prepared diff, manifest, description, and commits were read; all 13 files marked reviewed were read. Runtime behavior, builds, and tests were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5922372209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21156#pullrequestreview-5922372209). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T15:15:42Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change based on the code reviewed; the reported test runs were supplied by the author and were not run here. ## What I ran Reviewed head `33364ad1ebffdf867ac414d34f56ed1c9f9170f0` using the prepared diff and `repo_read.py` reader tools. No build or tests were run. The description reports Linux test runs, including copy-path tests at this head; these are author supplied. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | All 13 changed files were included and read | | Build and tests here | not run | No shell execution available | | Author-reported Linux tests | not run | Reported passing; not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No changed file was excluded: `files.json` reports no excluded files. The provided prepared diff, manifest, description, and commits were read; all 13 files marked `reviewed` were read. Runtime behavior, builds, and tests were not independently verified. ## 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!21156
No description provided.