fix(libkernel): wait for the rest of a MSG_WAITALL stream receive in the guest layer #11896
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11896"
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 ionut27001 on 2026-10-27T12:09:56Z.
What
MSG_WAITALL(0x40) on a stream socket is no longer passed to the host.recv,recvfromandrecvmsgtake the first data with the existing wait (EAGAINat once on a nonblocking socket or withMSG_DONTWAIT, otherwise up toSO_RCVTIMEO), then wait for readability and receive the rest in a loop, also on a nonblocking socket and withMSG_DONTWAIT, until the request is full, the peer closes, an error occurs or no data arrives forSO_RCVTIMEO(each wait gets the whole timeout; with noSO_RCVTIMEOset the wait for the rest is unbounded, which matches v1 not returning from case c), and return the partial count. Datagram sockets keep ignoring the flag.Before, the host decided. Per the Winsock
recvdocumentation,MSG_WAITALLon a nonblocking socket or withMSG_PEEKfails withWSAEOPNOTSUPP, and a blockingMSG_DONTWAIT | MSG_WAITALLis not bounded bySO_RCVTIMEOafter the first poll. On Linux a nonblocking socket orMSG_DONTWAITreturned the queued bytes at once (tcp_recvmsgbreaks on!timeoonce data is copied), where the console waits up toSO_RCVTIMEO; a blocking receive was not bounded by the guest'sSO_RCVTIMEO, because the guest keeps that timeout in its own socket state and does not set it on the host socket. The old code was run only through the new test on Windows (see Tested), which hit ctest's 20 s limit, most likely at its first, blocking, receive; the nonblocking,MSG_PEEKandMSG_DONTWAITdescriptions above come from documentation only. Only Windows was available as a host.MSG_PEEK | MSG_WAITALLon a stream socket is now a plainMSG_PEEK(the usual wait for the first data,EAGAINwhen nonblocking with nothing queued, 0 at end of stream), and it throws when that peek gets some but fewer bytes than the request (not measured on a console except that case): it was host-dependent before (EOPNOTSUPPon Windows, a wait for the full request on Linux), and the measured result (the queued bytes repeated) is recorded in the debt entry instead of reproduced.recvmsgalready writes the passed flags tomsg_flags, which matches the measured 0x40, so it is unchanged. TheMSG_WAITALLentry indocs/dev/debt/libkernel.mdis cut to what is still open.Measured in a payload process on a PS5 (firmware 12.70), loopback TCP pair, 8-byte requests (probe p85, v2 log):
case a_blocking_split ret=8 errno=0 bytes="12345678" ms=200SHUT_WR:case b_peer_shut_first ret=3 errno=0 bytes="123" ms=0,case b_peer_shut_second ret=0 errno=0 bytes=- ms=0O_NONBLOCK,SO_RCVTIMEO1 s, 3 bytes queued:case c_nonblock_3queued ret=3 errno=0 bytes="123" ms=1000; nothing queued:case c_nonblock_empty ret=-1 errno=35 bytes=- ms=0. v1, which per the v2 probe header set noSO_RCVTIMEO, logged nothing afterc_setnonblockand has no# end probeline.case g_recvfrom_nonblock_3queued ret=3 errno=0 bytes="abc" ms=1001,case g_recvmsg_nonblock_3queued ret=3 errno=0 bytes="xyz" ms=1000,case g_recvmsg_flags value=0x40MSG_DONTWAIT | MSG_WAITALL,SO_RCVTIMEO2 s, 3 bytes queued:case d_dontwait_waitall_3queued ret=3 errno=0 bytes="123" ms=2000MSG_PEEK | MSG_WAITALL, 3 bytes queued:case e_peek_waitall_3queued ret=8 errno=0 bytes="12312312" ms=0, thencase e_plain_after_peek ret=3 errno=0 bytes="123" ms=0SO_RCVTIMEO300 ms, 3 bytes queued:case f_timeout_3queued ret=3 errno=0 bytes="123" ms=300; nothing queued:case f_timeout_empty ret=-1 errno=35 bytes=- ms=300The new test
guest_socket_wait_all(targetguest_socket_wait_all_tests) covers c, d, f, g, themsg_flagsread-back, the empty nonblockingEAGAIN,MSG_PEEK | MSG_WAITALLwith nothing queued (EAGAIN) and the deliberate throw forMSG_PEEK | MSG_WAITALLwith 3 of 8 bytes queued (the bytes stay queued) on a loopback TCP pair with a 200 msSO_RCVTIMEO; a and the first receive of b stay covered byguest_tcp. The three receives now share oneWSAEMSGSIZEmapping on Windows, which also accepts sequenced-packet sockets forrecvandrecvfromasrecvmsgalready did; Windows has noSOCK_SEQPACKETsocket (socketpairthrows), so this cannot be observed.Tested
Windows 11, WinLibs GCC 15.2.0 (Release, Ninja), commit
ef5ae8ee90on main75f3702aed:ctest -R ^guest_socket_wait_all$passed twice (about 1.5 s each).ctest -R "guest_tcp|guest_udp|socket|guest_unix|guest_net": 43 of 43 passed.Udp.cpprestored from main and rebuilt,guest_socket_wait_alltimes out (ctest's 20 s limit), most likely in the first blocking receive, where the hostMSG_WAITALLreceive is not bounded by the guest'sSO_RCVTIMEO.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)Udp.cpp; this rebases onto whichever of them land firstImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T12:22:17Z.
Review: CHANGES_REQUESTED
The Windows coverage is useful, and the core loop returns partial bytes on timeout/EOF as described. I also built the exact
Udp.cppandguest_socket_wait_all_testssource locally. The binary could not complete under QEMU because this environment's process-memory read helper fails withENOSYS(process_vm_readv failed with errno 38); I do not count that as a runtime pass. The hosted Windows test passes; Linux and macOS product tests were not run.[P1] Preserve cancellation and signal handling in the new wait loop.
WaitReadycallspoll/WSAPolldirectly, and on POSIX retriesEINTRwithout consulting the guest I/O cancellation state. When composed with open PR #11872, this is a new blocking phase after a partial receive that bypasses the cancellation-awareThreadCancel::Native/IoInterruptedpath in that PR'sWaitForTransfer. A deferred cancellation or caught signal can therefore remain stuck in the post-partialMSG_WAITALLwait. Please coordinate the stack with #11872, route this wait through its cancellation/signal machinery, and add a regression that cancels/interrupts aMSG_WAITALLreceive after its first partial bytes.[P2] Declare the overlapping PR order. The body says this conflicts with #11872 and that whichever lands second will rebase, but that is not an agreed order.
CONTRIBUTING.mdrequires contributors to agree on ordering for conflicting changes and list the dependency. Please coordinate with the #11872 author and record the agreedDepends onorder before merge.The new partial
MSG_PEEK | MSG_WAITALLpath deliberately throws when fewer bytes are queued, while the measured console repeats queued bytes. Please add a focused assertion for that explicit unsupported path so it remains a deliberate throw, or implement the measured behavior. Linux runtime validation is also still needed because this changes the POSIX receive path.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T01:56:58Z.
Review: CHANGES_REQUESTED
Thanks for the measurements and the Windows run. The change itself matches them (cases c, d, f, g in the new test), but it can't land yet:
core/libs/prx/libkernel/Socket/src/Udp.cpp:772WaitReadycallspoll/WSAPolldirectly, andReceive(Udp.cpp:844) loops on it after the first bytes. That wait can't be cancelled, interrupted by a signal or woken byclose, which is what @MarcZX10's open review asks for.MSG_WAITALLreceive after its first partial bytes (partial count still returned).Everything else (flag handling,
MSG_PEEK | MSG_WAITALLthrow, debt entry, test registration) looks fine as is.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T02:36:22Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes requested
I rechecked exact head
ef5ae8ee90against current main3a2b919816; the PR merges cleanly with main, but its declared prerequisite #11872 has since closed as superseded by #12682, and the two current heads conflict when combined.What I ran
Environment: Linux x86_64, kernel 6.1.0-54-amd64, Python 3.11.2.
I inspected the current dependency declaration, the closure note on #11872, and the changed files on both PR heads. I did not rerun the socket tests locally.
Results
Raw output
Negative control
Findings
Blocking
Non-blocking
The PR's merge preview against current main is clean, and its current hosted Windows check passes. Those checks do not resolve the stale dependency or the pairwise conflict with the replacement PR.
Sources
Not verified
I did not rerun guest_socket_wait_all_tests locally or test Linux/macOS runtime behavior. The PR's Windows check passed, but the hosted Linux and specialized jobs were skipped.
To get this to a good state
Update the dependency line to #12682 and coordinate the rebase after that replacement is ready. Then rerun guest_socket_wait_all_tests on the resulting exact head; I will repeat the merge, diff, conventions, and test checks there.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T18:13:16Z.
Review: CHANGES_REQUESTED
Still blocked on the same point, and it can't be fixed from this branch until the prerequisite lands:
core/libs/prx/libkernel/Socket/src/Udp.cpp:772WaitReadycallspoll/WSAPolldirectly andReceive(Udp.cpp:844) loops on it after the first bytes, so that wait can't be cancelled, interrupted by a signal or woken byclose.MSG_WAITALLreceive after the first partial bytes (partial count still returned). Rebase onto #12688/#12700 as well if they land first.The rest (flag handling,
MSG_PEEK | MSG_WAITALLthrow, debt entry, test registration) looks fine as is.Pull request closed