docs(libkernel): record select limits as measured on a PS5 #10310

Merged
orezraey merged 5 commits from upstream-pr/10310 into main 2026-10-26 16:19:30 +00:00
orezraey commented 2026-10-23 17:18:58 +00:00 (Migrated from github.com)

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


What

select 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 (pselect). The debt entry said the console's answer for a timeout outside the host clock's range was unknown.

The console:

  • accepts a timeout of INT32_MAX, 2^32 and INT64_MAX seconds (on a descriptor that is already ready, so the wait itself was not observed), and fails a negative tv_sec or tv_usec and a tv_usec of 1000000 or more with EINVAL, as AnyPS5 does;
  • leaves the timeout unchanged and fails a negative nfds with EINVAL, as AnyPS5 does;
  • clears a set descriptor at nfds when the timeout expires with nothing ready (nfds 16, descriptor 16), as FreeBSD writes back whole 64-bit fd_mask words, as AnyPS5 does since #10777. With nfds 0 the bit stays set on both;
  • accepts an nfds of 1025, where AnyPS5 fails any nfds above 1024 with EINVAL, and fails with EBADF when a bit above its last open descriptor is set (measured with nfds 1000 and descriptor 999, where AnyPS5 also fails EBADF), as FreeBSD 11.4's select_check_badfd does. The probe's sets hold 1024 bits, so the results at nfds 1025 and 65536 depend on the bytes past them.

Only the debt entry changes: the last difference touches how far the guest's descriptor tables reach (files may go past the 1024 sockets), so it is recorded for a separate change.

Tested

Not tested: documentation only (head 59d248674f, which merges current main 14c99b52ac with #10501's pselect entry; the entry's "where AnyPS5 keeps it" clause was dropped earlier). tools/check_conventions.py passes.

  • The debt entry is 963 characters.
  • tools/check_conventions.py passes.
  • tools/pr_overlap.py: #9389, #10162 edit nearby libkernel.md 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: #9389, #10162 (merge order only: they edit the same lines; this PR is refreshed after them)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4986610971 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10310). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T17:18:58Z. --- ### What `select` 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/7006c6d29c4543bc8f48b7de8c19b661) (`pselect`). The debt entry said the console's answer for a timeout outside the host clock's range was unknown. The console: - accepts a timeout of `INT32_MAX`, 2^32 and `INT64_MAX` seconds (on a descriptor that is already ready, so the wait itself was not observed), and fails a negative `tv_sec` or `tv_usec` and a `tv_usec` of 1000000 or more with `EINVAL`, as AnyPS5 does; - leaves the timeout unchanged and fails a negative `nfds` with `EINVAL`, as AnyPS5 does; - clears a set descriptor at `nfds` when the timeout expires with nothing ready (`nfds` 16, descriptor 16), as FreeBSD writes back whole 64-bit `fd_mask` words, as AnyPS5 does since #10777. With `nfds` 0 the bit stays set on both; - accepts an `nfds` of 1025, where AnyPS5 fails any `nfds` above 1024 with `EINVAL`, and fails with `EBADF` when a bit above its last open descriptor is set (measured with `nfds` 1000 and descriptor 999, where AnyPS5 also fails `EBADF`), as FreeBSD 11.4's `select_check_badfd` does. The probe's sets hold 1024 bits, so the results at `nfds` 1025 and 65536 depend on the bytes past them. Only the debt entry changes: the last difference touches how far the guest's descriptor tables reach (files may go past the 1024 sockets), so it is recorded for a separate change. ### 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. --> Not tested: documentation only (head `59d248674f`, which merges current `main` `14c99b52ac` with #10501's `pselect` entry; the entry's "where AnyPS5 keeps it" clause was dropped earlier). `tools/check_conventions.py` passes. - The debt entry is 963 characters. - `tools/check_conventions.py` passes. - `tools/pr_overlap.py`: #9389, #10162 edit nearby `libkernel.md` 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: #9389, #10162 (merge order only: they edit the same lines; this PR is refreshed after them) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-24 15:44:39 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Checked against main c9b75825f3 and the linked gist (pselect.c / pselect.log), plus Socket.cpp and SocketSelectDeadline.hpp on main:

  • The numbers in the new debt line match the log, and main's validation at Socket.cpp:189 matches the "as here" parts. The branch still merges cleanly with main.
  • One case in the log differs from AnyPS5, though the description says it matches. In nfds_below_fd (nfds 16, fd 16 set, timeout 0) the console returned 0 with the bit cleared (bit=0). Main returns 0 and leaves bit 16 set, because the timeout path (Socket.cpp:319-325) clears only the requested descriptors, all below nfds. FreeBSD's kern_select seems to copy out whole fd_mask words, which would explain it (and why nfds_0_ready left the bit alone). Could this go into the entry, or into a follow-up?
  • Small wording point: the EBADF was measured with nfds 1000 and fd 999, where AnyPS5 also gives EBADF; as written it reads like an nfds > 1024 result. Maybe "accepted 1025, and, like FreeBSD 11.4's select_check_badfd, fails EBADF for a set bit above the last open descriptor (measured with nfds 1000)".
  • Probe note: the sets are uint64_t set[16], so with nfds 1025 or 65536 the kernel reads bits past the array. "No EINVAL at 1025" stands, but the 1025 return of 1 and the 65536 EBADF depend on whatever stack bytes follow the array, so a re-probe with larger sets would pin them down.
  • Optional: how long the console actually waits on an out-of-range timeout is still unmeasured; keeping a plain "unknown" sentence would leave that open question visible.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638830298 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10310#pullrequestreview-5638830298). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T15:44:39Z. **Review:** COMMENTED --- Checked against main c9b75825f3 and the linked gist (`pselect.c` / `pselect.log`), plus `Socket.cpp` and `SocketSelectDeadline.hpp` on main: - The numbers in the new debt line match the log, and main's validation at `Socket.cpp:189` matches the "as here" parts. The branch still merges cleanly with main. - One case in the log differs from AnyPS5, though the description says it matches. In `nfds_below_fd` (`nfds` 16, fd 16 set, timeout 0) the console returned 0 with the bit cleared (`bit=0`). Main returns 0 and leaves bit 16 set, because the timeout path (`Socket.cpp:319-325`) clears only the requested descriptors, all below `nfds`. FreeBSD's `kern_select` seems to copy out whole `fd_mask` words, which would explain it (and why `nfds_0_ready` left the bit alone). Could this go into the entry, or into a follow-up? - Small wording point: the `EBADF` was measured with `nfds` 1000 and fd 999, where AnyPS5 also gives `EBADF`; as written it reads like an `nfds > 1024` result. Maybe "accepted 1025, and, like FreeBSD 11.4's `select_check_badfd`, fails `EBADF` for a set bit above the last open descriptor (measured with `nfds` 1000)". - Probe note: the sets are `uint64_t set[16]`, so with `nfds` 1025 or 65536 the kernel reads bits past the array. "No `EINVAL` at 1025" stands, but the 1025 return of 1 and the 65536 `EBADF` depend on whatever stack bytes follow the array, so a re-probe with larger sets would pin them down. - Optional: how long the console actually waits on an out-of-range timeout is still unmeasured; keeping a plain "unknown" sentence would leave that open question visible. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
harisibrar1 commented 2026-10-24 16:37:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T16:37:23Z.

Review: APPROVED


Re-checked head 9dd91b6f23 against main feb5059ac4:

  • The entry now records the nfds_below_fd difference (the console cleared descriptor 16 with nfds 16 on an expired timeout, where AnyPS5 keeps it; nfds 0 leaves it in both), which matches the log and main's timeout path in Socket.cpp.
  • The EBADF clause now says it was measured with nfds 1000, the probe caveat about 1024-bit sets at nfds 1025/65536 is there, and the unknown wait for a saturated timeout is stated plainly.
  • It still merges cleanly into main. Thanks, LGTM.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638985728 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10310#pullrequestreview-5638985728). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T16:37:23Z. **Review:** APPROVED --- Re-checked head 9dd91b6f23 against main feb5059ac4: - The entry now records the `nfds_below_fd` difference (the console cleared descriptor 16 with `nfds` 16 on an expired timeout, where AnyPS5 keeps it; `nfds` 0 leaves it in both), which matches the log and main's timeout path in `Socket.cpp`. - The `EBADF` clause now says it was measured with `nfds` 1000, the probe caveat about 1024-bit sets at `nfds` 1025/65536 is there, and the unknown wait for a saturated timeout is stated plainly. - It still merges cleanly into main. Thanks, LGTM. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-10-24 21:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:14:21Z.

Review: DISMISSED


The PS5 measurements and the limits of the probe are recorded carefully, and the earlier review verified the updated wording against the console log. Before merge, the branch still needs the declared integration work: #9389 and #10162 remain open, and this PR is based on f57e4ef, 7,503 commits behind current main. docs/dev/debt/libkernel.md has also changed repeatedly since that base. Please refresh after the two documented merge-order dependencies land, resolve the current-main debt-file edits while preserving this select result, and rerun the conventions/overlap checks on the final head. As a documentation-only PR, no runtime test is needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5640056238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10310#pullrequestreview-5640056238). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T21:14:21Z. **Review:** DISMISSED --- The PS5 measurements and the limits of the probe are recorded carefully, and the earlier review verified the updated wording against the console log. Before merge, the branch still needs the declared integration work: #9389 and #10162 remain open, and this PR is based on `f57e4ef`, 7,503 commits behind current `main`. `docs/dev/debt/libkernel.md` has also changed repeatedly since that base. Please refresh after the two documented merge-order dependencies land, resolve the current-main debt-file edits while preserving this `select` result, and rerun the conventions/overlap checks on the final head. As a documentation-only PR, no runtime test is needed.
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!10310
No description provided.