fix(libkernel): keep TCP_MAXSEG and the TCP keepalive options as measured on a PS5 #10327

Merged
orezraey merged 7 commits from upstream-pr/10327 into main 2026-10-24 16:52:57 +00:00
orezraey commented 2026-10-23 17:56:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T17:56:33Z.


What

The IPPROTO_TCP options TCP_MAXSEG, TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT measured on a retail PS5 (firmware 13.60) through libkernel_sys.sprx from a payload process. The source and console log are in this gist (pinet4). This branch is on top of #10320 (and so #10302), which edit the same debt entries and option state.

On an unconnected stream socket the console:

  • reads TCP_MAXSEG as 536 and fails a new segment above it (1000, 70000) or below 176 (100) with EINVAL;
  • reads TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT as 7200, 75 and 8, reads back what was set (60, 10, 3), restores the default when a keepalive time is set to 0, and stores a count of -1 as given.

AnyPS5 failed every IPPROTO_TCP option except TCP_NODELAY with ENOPROTOOPT. The four are now kept per socket with those rules, and an accepted socket takes the keepalive values from its listener, as FreeBSD 11.4's syncache_socket does. They are not applied to the host socket; that, the negotiated segment size of a connected socket, and FreeBSD's hz-based limit on the keepalive times, which was not measured, are in a new debt entry. guest_underscore_entries used TCP_MAXSEG as its example of an unsupported option, so it now uses an unknown one.

Tested

Windows 11, MinGW (winlibs).

  • guest_socket_stream_options checks the defaults, the segment limits, the keepalive read-back and the inheritance from the listener. The socket and net tests pass three runs in a row.
  • The full suite (-E "^agc_|^select_tests$") passes apart from guest_kqueue, which fails only under -j 14, as on main.
  • tools/check_conventions.py passes.
  • tools/pr_overlap.py: #7511, #8448, #8921 touch nearby lines; whichever lands second keeps both.

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
  • 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: #10320, #8448; #8448 edits the same lines too (merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4987074939 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10327). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T17:56:33Z. --- ### What The `IPPROTO_TCP` options `TCP_MAXSEG`, `TCP_KEEPIDLE`, `TCP_KEEPINTVL` and `TCP_KEEPCNT` measured on a retail PS5 (firmware 13.60) through `libkernel_sys.sprx` from a payload process. The source and console log are in [this gist](https://gist.github.com/orezraey/d9efe0da49405f19d72cb35279c0db52) (`pinet4`). This branch is on top of #10320 (and so #10302), which edit the same debt entries and option state. On an unconnected stream socket the console: - reads `TCP_MAXSEG` as 536 and fails a new segment above it (1000, 70000) or below 176 (100) with `EINVAL`; - reads `TCP_KEEPIDLE`, `TCP_KEEPINTVL` and `TCP_KEEPCNT` as 7200, 75 and 8, reads back what was set (60, 10, 3), restores the default when a keepalive time is set to 0, and stores a count of -1 as given. AnyPS5 failed every `IPPROTO_TCP` option except `TCP_NODELAY` with `ENOPROTOOPT`. The four are now kept per socket with those rules, and an accepted socket takes the keepalive values from its listener, as FreeBSD 11.4's `syncache_socket` does. They are not applied to the host socket; that, the negotiated segment size of a connected socket, and FreeBSD's `hz`-based limit on the keepalive times, which was not measured, are in a new debt entry. `guest_underscore_entries` used `TCP_MAXSEG` as its example of an unsupported option, so it now uses an unknown one. ### 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. --> Windows 11, MinGW (winlibs). - `guest_socket_stream_options` checks the defaults, the segment limits, the keepalive read-back and the inheritance from the listener. The socket and net tests pass three runs in a row. - The full suite (`-E "^agc_|^select_tests$"`) passes apart from `guest_kqueue`, which fails only under `-j 14`, as on `main`. - `tools/check_conventions.py` passes. - `tools/pr_overlap.py`: #7511, #8448, #8921 touch nearby lines; whichever lands second keeps both. ### 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) - [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: #10320, #8448; #8448 edits the same lines too (merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 05:39:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T05:39:17Z.

Review: COMMENTED


Checked against main 7c2400d29b, the pinet4/pinet6 logs in your gist, and FreeBSD 11.4 tcp_usrreq.c, tcp_subr.c and tcp_syncache.c:

  • The keepalive defaults, the 0-restores-default behaviour, the -1 count and the TCP_MAXSEG default of 536 all match pinet4, and the listener inheritance matches syncache_socket (tcp_syncache.c:944-947). Thanks for the clear debt notes.
  • pinet4 only shows TCP_MAXSEG 1000, 100 and 70000 failing; no set ever succeeded on the console. The test still asserts 175/0/-1 fail and 300 is accepted (GuestSocketStreamOptions.cpp:121,124), and the debt entry lists "below 176" among the measured behaviour. That bound and the accepted range come from FreeBSD's optval + 40 >= V_tcp_minmss (tcp_usrreq.c:1686). Could you either measure, for example, 300, 176 and 175, or move that part to the "not measured" sentence? pinet6 suggests the PS5 TCP level isn't stock 11.4 here: option 0x80 reads 0 by default and 65536 after a set of 5, where 11.4's TCP_KEEPINIT would read 75 and then 5.
  • An AF_INET6 stream socket also starts at 536 (SocketOptions.hpp:20, Udp.cpp:1127), while FreeBSD 11.4's tcp_newtcpcb uses V_tcp_v6mssdflt (1220) for INET6 (tcp_subr.c:1221-1224). So getsockopt reads 536 instead of 1220, and a set of 1000 fails. Worth either measuring or listing in the debt entry.
  • The keepalive values are kept but not applied, while SO_KEEPALIVE itself is applied on the host, so a title using short keepalive timers to detect a dead peer would wait for the host's ~2 h default. The hosts have direct equivalents (Linux TCP_KEEPIDLE/TCP_KEEPINTVL/TCP_KEEPCNT, macOS TCP_KEEPALIVE/TCP_KEEPINTVL/TCP_KEEPCNT, and MinGW's ws2ipdef.h defines TCP_KEEPIDLE/TCP_KEEPINTVL/TCP_KEEPCNT for Windows). I couldn't run this on Windows, so I haven't confirmed Winsock accepts them per socket. Would forwarding them be feasible?

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5637036175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10327#pullrequestreview-5637036175). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T05:39:17Z. **Review:** COMMENTED --- Checked against main 7c2400d29b, the pinet4/pinet6 logs in your gist, and FreeBSD 11.4 tcp_usrreq.c, tcp_subr.c and tcp_syncache.c: - The keepalive defaults, the 0-restores-default behaviour, the -1 count and the TCP_MAXSEG default of 536 all match pinet4, and the listener inheritance matches syncache_socket (tcp_syncache.c:944-947). Thanks for the clear debt notes. - pinet4 only shows TCP_MAXSEG 1000, 100 and 70000 failing; no set ever succeeded on the console. The test still asserts 175/0/-1 fail and 300 is accepted (GuestSocketStreamOptions.cpp:121,124), and the debt entry lists "below 176" among the measured behaviour. That bound and the accepted range come from FreeBSD's `optval + 40 >= V_tcp_minmss` (tcp_usrreq.c:1686). Could you either measure, for example, 300, 176 and 175, or move that part to the "not measured" sentence? pinet6 suggests the PS5 TCP level isn't stock 11.4 here: option 0x80 reads 0 by default and 65536 after a set of 5, where 11.4's TCP_KEEPINIT would read 75 and then 5. - An AF_INET6 stream socket also starts at 536 (SocketOptions.hpp:20, Udp.cpp:1127), while FreeBSD 11.4's tcp_newtcpcb uses V_tcp_v6mssdflt (1220) for INET6 (tcp_subr.c:1221-1224). So getsockopt reads 536 instead of 1220, and a set of 1000 fails. Worth either measuring or listing in the debt entry. - The keepalive values are kept but not applied, while SO_KEEPALIVE itself is applied on the host, so a title using short keepalive timers to detect a dead peer would wait for the host's ~2 h default. The hosts have direct equivalents (Linux TCP_KEEPIDLE/TCP_KEEPINTVL/TCP_KEEPCNT, macOS TCP_KEEPALIVE/TCP_KEEPINTVL/TCP_KEEPCNT, and MinGW's ws2ipdef.h defines TCP_KEEPIDLE/TCP_KEEPINTVL/TCP_KEEPCNT for Windows). I couldn't run this on Windows, so I haven't confirmed Winsock accepts them per socket. Would forwarding them be feasible? Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!10327
No description provided.