fix(libkernel): report a socket's guest send buffer size as st_blksize, as FreeBSD 11.4 does #21985

Merged
brajankw merged 1 commit from upstream-pr/21985 into main 2026-11-20 04:47:27 +00:00
brajankw commented 2026-11-17 00:45:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T00:45:21Z.


What

fstat on a guest socket filled st_blksize from the host's SO_SNDBUF, which Linux reports as twice the size that was set, and which ignores the guest's own buffer sizes (the fstat on a guest socket entry in docs/dev/debt/libkernel.md). FreeBSD 11.4's soo_stat calls pru_sense, and both pru_sense_null and uipc_sense report so_snd.sb_hiwat, the value getsockopt(SO_SNDBUF) returns.

  • GuestSockets::Stat reads st_blksize from the guest option state, under modeMutex as setsockopt and getsockopt do: 8192 for a local stream socket, 2048 for a local datagram socket, 32768 for TCP, 9216 for UDP, or what setsockopt(SO_SNDBUF) set. The same values on every host.
  • GuestSocketPair.cpp: the defaults of both ends of a stream and a datagram socketpair, of a TCP and a UDP socket, and 5000 after setsockopt(SO_SNDBUF, 5000) on one end (the other keeps 8192), through fstat and sceKernelFstat.
  • #8605 adds lines right after the getsockopt call this removes from GuestSockets::Stat; the conflict is textual, and whichever lands second needs a rebase.
  • The debt fragment drops the st_blksize clause; the rest of the entry (peer shutdown, st_size of a datagram socket, st_ino) stays open.

Tested

Linux (Debian 13, GCC 14.2.0, Release), on main 258ab7b6bd.

  • ctest -R '^guest_socket_pair$': passed.
  • Negative control: with main's Udp.cpp and this branch's test, guest_socket_pair aborts in the new CheckStatBlockSize.
  • Full ctest (5891 tests, -j 12) with this branch merged together with four unrelated fixes of mine: 5875 passed. The 16 failures are the set that fails on main in the same environment: six agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own) and ten that need a .git directory, network or a passwd entry for the user.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch: #8605 (see What). #11896, #12682, #12688, #12700 and #12965 conflict with main and could not be compared; none of their diffs touches GuestSockets::Stat.
  • Not tested on Windows or macOS. No title.

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:5348078671 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21985). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T00:45:21Z. --- ### What `fstat` on a guest socket filled `st_blksize` from the host's `SO_SNDBUF`, which Linux reports as twice the size that was set, and which ignores the guest's own buffer sizes (the `fstat on a guest socket` entry in `docs/dev/debt/libkernel.md`). FreeBSD 11.4's `soo_stat` calls `pru_sense`, and both [`pru_sense_null`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c) and [`uipc_sense`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_usrreq.c) report `so_snd.sb_hiwat`, the value `getsockopt(SO_SNDBUF)` returns. - `GuestSockets::Stat` reads `st_blksize` from the guest option state, under `modeMutex` as `setsockopt` and `getsockopt` do: 8192 for a local stream socket, 2048 for a local datagram socket, 32768 for TCP, 9216 for UDP, or what `setsockopt(SO_SNDBUF)` set. The same values on every host. - `GuestSocketPair.cpp`: the defaults of both ends of a stream and a datagram socketpair, of a TCP and a UDP socket, and 5000 after `setsockopt(SO_SNDBUF, 5000)` on one end (the other keeps 8192), through `fstat` and `sceKernelFstat`. - #8605 adds lines right after the `getsockopt` call this removes from `GuestSockets::Stat`; the conflict is textual, and whichever lands second needs a rebase. - The debt fragment drops the `st_blksize` clause; the rest of the entry (peer shutdown, `st_size` of a datagram socket, `st_ino`) stays open. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release), on `main` `258ab7b6bd`. - `ctest -R '^guest_socket_pair$'`: passed. - Negative control: with `main`'s `Udp.cpp` and this branch's test, `guest_socket_pair` aborts in the new `CheckStatBlockSize`. - Full `ctest` (5891 tests, `-j 12`) with this branch merged together with four unrelated fixes of mine: 5875 passed. The 16 failures are the set that fails on `main` in the same environment: six `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own) and ten that need a `.git` directory, network or a passwd entry for the user. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch`: #8605 (see What). #11896, #12682, #12688, #12700 and #12965 conflict with `main` and could not be compared; none of their diffs touches `GuestSockets::Stat`. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
PrivacyOnion commented 2026-11-17 00:48:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T00:48:20Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against ff941dbf41:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_socket_pair_tests built cleanly.
  • CTest (guest_socket_pair, guest_recvmsg_memory, guest_sendmsg_memory):
    1/3 Test #5393: guest_socket_pair ................   Passed    0.03 sec
    2/3 Test #5394: guest_recvmsg_memory .............   Passed    0.03 sec
    3/3 Test #5395: guest_sendmsg_memory .............   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test #5394: guest_recvmsg_memory .............   Passed    0.02 sec
    2/3 Test #5395: guest_sendmsg_memory .............   Passed    0.02 sec
    3/3 Test #5393: guest_socket_pair ................Subprocess aborted***Exception:   0.51 sec
    67% tests passed, 1 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified GuestSockets::Stat reads socket->options, socket->family, and socket->type under socket->modeMutex into sendBuffer using GuestSockets::SendBufferSize
    • Verified SendBufferSize correctly returns guest buffer sizes (8192/2048/32768/9216 or custom setsockopt value) across all supported socket families and types
    • Verified static_caststd::uint32_t(sendBuffer) assignment to status->st_blksize behaves identically on Linux (LP64) and Windows (LLP64)
    • Verified docs/dev/debt/changes/fix-libkernel-socket-stat-blksize.md accurately documents the updated st_blksize behavior without violating AGENTS.md formatting rules
    • Verified GuestSocketPair.cpp tests exercise default block sizes for stream/datagram unix pairs, TCP, UDP, and modified send buffer sizes via setsockopt and sceKernelFstat

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5930664933 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21985#pullrequestreview-5930664933). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T00:48:20Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `ff941dbf41`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_socket_pair_tests` built cleanly. - **CTest** (`guest_socket_pair`, `guest_recvmsg_memory`, `guest_sendmsg_memory`): ``` 1/3 Test #5393: guest_socket_pair ................ Passed 0.03 sec 2/3 Test #5394: guest_recvmsg_memory ............. Passed 0.03 sec 3/3 Test #5395: guest_sendmsg_memory ............. Passed 0.01 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libkernel/Socket/src/Udp.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #5394: guest_recvmsg_memory ............. Passed 0.02 sec 2/3 Test #5395: guest_sendmsg_memory ............. Passed 0.02 sec 3/3 Test #5393: guest_socket_pair ................Subprocess aborted***Exception: 0.51 sec 67% tests passed, 1 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - Verified GuestSockets::Stat reads socket->options, socket->family, and socket->type under socket->modeMutex into sendBuffer using GuestSockets::SendBufferSize - Verified SendBufferSize correctly returns guest buffer sizes (8192/2048/32768/9216 or custom setsockopt value) across all supported socket families and types - Verified static_cast<std::uint32_t>(sendBuffer) assignment to status->st_blksize behaves identically on Linux (LP64) and Windows (LLP64) - Verified docs/dev/debt/changes/fix-libkernel-socket-stat-blksize.md accurately documents the updated st_blksize behavior without violating AGENTS.md formatting rules - Verified GuestSocketPair.cpp tests exercise default block sizes for stream/datagram unix pairs, TCP, UDP, and modified send buffer sizes via setsockopt and sceKernelFstat Looks Good To Me
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!21985
No description provided.