fix(libkernel): keep the F_SETFL status flags of a socket, as FreeBSD 11.4 does #22573
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22573"
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 brajankw on 2026-11-17T21:51:04Z.
What
fcntl(F_SETFL)on a guest socket or asceNetSocketsocket failed withEOPNOTSUPPfor any bit other than the access mode andO_NONBLOCK, andF_GETFLreported onlyO_RDWRandO_NONBLOCK. In FreeBSD 11.4,kern_fcntltakes the argument'sFCNTLFLAGSbits into the file'sf_flagand drops the rest.F_GETFLreturnsOFLAGS(f_flag), the access mode asO_RDWRplus those bits.soo_ioctlaccepts theFIONBIOandFIOASYNCcalls that follow, soF_SETFLon a socket does not fail.O_APPEND,O_ASYNC,O_FSYNC,O_DIRECTand the read-ahead bit (O_CREAT), besidesO_NONBLOCK. Files, directories and pipes already take that set (SettableStatusFlagsinDescriptorControl.cpp).O_NOFOLLOWstill fails withEOPNOTSUPPand changes nothing. FreeBSD never fails it: it adds it toFCNTLFLAGSasFPOSIXSHMin a kernel built withCOMPAT_FREEBSD4toCOMPAT_FREEBSD7and drops it otherwise. The amd64GENERICconfig has those options; the console's are unknown, soO_NOFOLLOWkeeps the error a title already handles, and the debt entry records the difference.Socket/src/Udp.cpp:statusFlags, under itsmodeMutex.F_SETFLreplaces them and ignores other bits, andF_GETFLreports them afterO_RDWR;dupshares them, since the duplicate shares theSocket;acceptcopies the listener's bits, askern_accept4gives the new file the listener'sf_flagforaccept(ACCEPT4_INHERIT).libSceNet/Export.cpp: asceNetSocketsocket keeps the bits on its native handle the same way, through the status control libkernel'sfcntlcalls, andsceNetAcceptcopies them. A per-handle mutex coversF_SETFL,F_GETFLand thesceNetAcceptcopy.F_SETFLsets the host non-blocking mode on the handle it looked up, through the helpersceNetSetsockopt'sSO_NBIOnow uses, not by descriptor number again.sceNetSetsockopt'sSO_NBIO, whichsceNetIoctl(FIONBIO)and thesceNetAcceptinheritance use, now takes the same mutex. It also stores the mode on its own handle, not on whatever socket the number names when it finishes. So the host non-blocking mode,nonblockand the other bits change together, on one socket, asf_flagdoes.O_APPEND,O_FSYNC,O_DIRECTand read-ahead have no effect on a socket in FreeBSD;O_ASYNCraisesSIGIOonly for an owner, assowakeupshows. No socket here can get one:F_SETOWNfails withEINVAL,FIOSETOWNwithENOTTYandSIOCSPGRPwithEADDRNOTAVAILorENOTTY.GuestSocketDescriptorFlags.cpp:F_SETFLkeeps the five bits and ignoresO_WRONLYandO_NOCTTY. Adupshares the bits both ways,acceptcopies them, andF_SETFL 0clears them on the listener only;GuestSceNet.cpp: the same on asceNetSocketsocket and throughsceNetAccept.O_NOFOLLOWwithO_NONBLOCKfails withEOPNOTSUPPthere and leaves the flags as they were. Two threads also set different flag sets from a common start while the main thread reads them; every call must succeed, and every read and the final state must be one whole set. A third check togglesSO_NBIOfrom one thread while the main thread changes the kept bits withF_SETFL. EachF_GETFLmust show the bits just set, and on Linux and macOS the host socket'sO_NONBLOCKmust matchF_GETFLat the end;GuestKernelFcntl.cpp:sceKernelFcntlkeepsO_ASYNCand ignoresO_NOCTTY, andO_NOFOLLOWwithO_ASYNCfails withEOPNOTSUPPand sets neither.F_SETFLfails for an unknown bit are replaced:0x8000inGuestUdp.cpp(-1, #3) andGuestKernelFcntl.cpp(EOPNOTSUPP, #3078). They pinned the earlier behaviour; neither was measured, and thesceKernelFcntldebt entry listsF_SETFLas not measured on a console. The0x100check inGuestSceNet.cpp(#4924) still expectsEOPNOTSUPP.fcntlentry drops "withO_NONBLOCK", and a newF_SETFL on a socketentry states theO_NOFOLLOWerror first.ioctl(FIOASYNC)on a guest socket still fails withENOTTY, as theioctl, _ioctlentry says. #22395 changes the lines next to it, so that stays for a follow-up;O_ASYNCon a host socket that is not a guest socket still throws;O_NOFOLLOWthroughSettableStatusFlags.Tested
Linux (Debian 13, GCC 14.2.0, Release), on
main6b4e58a503, then rebased onto8dbb3bf68dfor theSO_NBIOchange; thereguest_sce_netpassed 10 of 10 repeated runs. After review,O_NOFOLLOWwent back toEOPNOTSUPP, and the branch was rebased onto6286d36449. That brings in #19824, which also changesUdp.cpp(pollon standard descriptors) and merges cleanly with this change. The 50 focused tests below pass there.guest_socket_descriptor_flags,guest_udpandguest_sce_netabort on their newF_SETFLchecks (EOPNOTSUPP). With the version that threw onO_NOFOLLOW,guest_sce_netandguest_kernel_fcntlabort on that throw.ctestover the 36 socket,fcntlandaccepttest executables (guest_socket_*,guest_net_*,guest_sce_net*,guest_tcp,guest_udp,guest_kernel_fcntl*,guest_poll,guest_curl_socketsand others, 50 tests): 49 passed;guest_socket_options_multicastskips without a network.6286d36449,guest_sce_netneeds a standard input that is not a pipe. Since #19824, itsselectcheck on descriptors 0 to 2 fails withEBADFwhen standard input is a pipe, onmaintoo. These runs use/dev/null.ctest(6040 tests,-j 12) on the first version of this branch: 6025 passed. The 15 failures also fail onmainin the same environment:.gitdirectory, network access or a passwd entry for the user:conventions_git_errors,test_script_registration,web_library_assets,title_run,title_run_identity,guest_kernel_sys_login,guest_net_ctl,guest_getloginandguest_getlogin_no_session;agc_driverGPU cases.python3 tools/check_conventions.py --base origin/main: passed, with the length warning on thefcntlentry. That entry was over 4000 characters before; this change only shortens it.python3 tools/pr_overlap.py --branchfailed closed on PRs that conflict withmain. #16826 changes the first lines ofControlSocketStatusForKernelandCheckKernelStatusFlagsforF_GETFDandF_SETFD. #12688 and #12965 change the WindowsFIONBIOline next to the changed check. #11896 changesUdp.cppforMSG_WAITALL, and #18457 edits the samefcntldebt entry forF_GETOWNon a pipe. None of them changes the status flags.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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T21:52:09Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f9985ccbb1:tools/check_conventions.pypassed.guest_kernel_fcntl_tests,guest_sce_net_tests,guest_socket_descriptor_flags_tests,guest_udp_testsbuilt cleanly.guest_sce_net,guest_socket_descriptor_flags,guest_udp,guest_kernel_fcntl):core/libs/prx/libSceNet/Export.cpp,core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T00:40:52Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: synchronize the
SO_NBIOstate updates with the new status mutex soF_GETFLandF_SETFLobserve consistent socket state.What I ran
Reviewed head
f9985ccbb12c1d0319f53f188c9257f5ed0d967fagainst the prepared diff and repository source throughrepo_read.py. No test commands were run. The author reports Linux tests and convention checks in the PR description; those results were not independently verified.Results
SO_NBIObypasses status mutexFindings
Blocking
core/libs/prx/libSceNet/Export.cpp:2133updatesNativeSocketHandle::nonblockwithoutstatusMutex, whileF_GETFLreads it under that mutex atcore/libs/prx/libSceNet/Export.cpp:1234-1236andF_SETFLchanges the host nonblocking mode and stored status flags under it atcore/libs/prx/libSceNet/Export.cpp:1234-1251. A concurrentsceNetSetsockopt(NET_SO_NBIO)andF_GETFL/F_SETFLtherefore race on the host socket state; thestd::atomiconnonblockprevents a C++ data race on that field but does not serialize the hostfcntloperation withF_SETFL. Take the status mutex around theSO_NBIOhost-mode change and state update (or otherwise coordinate it withF_SETFL).Non-blocking
None.
Not verified
manifest.jsonwere read at their changed lines; no changed file was excluded.To get this to a good state
NET_SO_NBIOupdate withstatusMutex, then rerun the relevantlibSceNetsocket status-flag tests, including the concurrency case.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T16:02:29Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes consistently retain socket status flags, synchronize the libSceNet nonblocking state, and add focused coverage; I did not run the reported checks, so approval is not justified.
What I ran
Read the prepared description, commit list, manifest, and full diff at head
fca824409d0b7fe75cf5246d284af8372d25257d, then inspected changed code and nearby context withrepo_read.py. No tests or prechecks were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read the changed regions and relevant context in
core/libs/prx/libSceNet/Export.cpp,core/libs/prx/libkernel/Socket/src/Udp.cpp,core/libs/tests/GuestKernelFcntl.cpp,core/libs/tests/GuestSceNet.cpp,core/libs/tests/GuestSocketDescriptorFlags.cpp,core/libs/tests/GuestUdp.cpp, anddocs/dev/debt/changes/fix-libkernel-socket-status-flags.md. I did not read the complete contents of the two large implementation files or the test files beyond the relevant regions. Thefiles.jsoninventory was unavailable through the reader; the manifest marks all seven changed files included with no exclusions. Tests, prechecks, Windows/macOS behavior, and console behavior were not independently verified.To get this to a good state
Nothing is required. The reported test and precheck results remain author-reported and were not independently confirmed.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T19:37:15Z.
Review: APPROVED
Reviewed — looks good
The prepared evidence supports the socket status flag change; I reviewed all seven changed files at head
3a5a64a869b91fe4de6cd3cbc54b6ea2bb79e96f, while checks were reported by the author and were not run in this review.What I ran
No commands were run. I read the prepared description, commit summary, manifest and diff, and inspected changed code and relevant callers through
repo_read.pyat the pinned head. The author reports Linux focused tests, a fullctestrun on an earlier branch revision, and convention checks; these are author-reported, not runs performed here.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run tests, build the change, or verify behavior on Windows, macOS, or console hardware. The prepared bundle excluded no changed files; all seven files listed in the manifest were read. Targeted context read included
DescriptorControl.cppandSocket.cpp.To get this to a good state
Nothing is required.