fix(libkernel): throw on an EV_CLEAR EVFILT_WRITE knote with NOTE_LOWAT above 1 on a Linux TCP socket #9843

Merged
ebarr24 merged 6 commits from upstream-pr/9843 into main 2026-11-06 19:43:48 +00:00
ebarr24 commented 2026-10-22 17:31:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebarr24 on 2026-10-22T17:31:59Z.


What

Follow-up to #8596. nikowolf123 showed in review that an EV_CLEAR EVFILT_WRITE knote with a NOTE_LOWAT mark above 1 on a Linux TCP socket can make kevent wait forever: PollEdge disarms the EPOLLET knote while the free space is below the mark, and Linux TCP wakes EPOLLOUT only after a send or poll found the socket not writable (tcp_check_space), where FreeBSD 11's tcp_input.c calls sowwakeup on every ACK that frees send space. AddDescriptorKnote and ModifyKnote now throw NotImplemented for exactly that combination, a test requires the throw and the combinations that stay supported, and the libkernel debt entry keeps the POLLOUT gate and the stream-only write mark as open gaps.

Tested

Windows 11, MinGW-w64 GCC 15.2, Release build with tests. guest_kqueue passes with this change; the new test fails on main.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4971492690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9843). Originally posted by [ebarr24](https://github.com/ebarr24) on 2026-10-22T17:31:59Z. --- ### What Follow-up to #8596. nikowolf123 showed in review that an EV_CLEAR EVFILT_WRITE knote with a NOTE_LOWAT mark above 1 on a Linux TCP socket can make kevent wait forever: PollEdge disarms the EPOLLET knote while the free space is below the mark, and Linux TCP wakes EPOLLOUT only after a send or poll found the socket not writable (tcp_check_space), where FreeBSD 11's tcp_input.c calls sowwakeup on every ACK that frees send space. AddDescriptorKnote and ModifyKnote now throw NotImplemented for exactly that combination, a test requires the throw and the combinations that stay supported, and the libkernel debt entry keeps the POLLOUT gate and the stream-only write mark as open gaps. ### Tested Windows 11, MinGW-w64 GCC 15.2, Release build with tests. `guest_kqueue` passes with this change; the new test fails on `main`. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
harisibrar1 commented 2026-10-24 12:32:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:32:04Z.

Review: COMMENTED


Checked against main 87666fc5d6, FreeBSD 11.4 sys/kern/uipc_socket.c (filt_sowrite), FreeBSD 11.0 sys/netinet/tcp_input.c, and Linux v6.8 net/ipv4/tcp_input.c / net/core/sock.c:

  • The diagnosis holds: PollEdge disarms when SO_SNDBUF - SIOCOUTQ is below the mark while poll reported POLLOUT, so tcp_poll never set SOCK_NOSPACE and tcp_check_space never wakes the epoll edge. With a mark of 1 the knote only disarms when POLLOUT was missing, so that case is safe. Throwing also looks right to me, since Linux fixes SO_SNDLOWAT at 1 and the mark can't be handed to the host.
  • The condition is precise: guest family 2/28 plus stream, lowWater > 1, EV_CLEAR or an existing PollEdge knote. A mark of 1, no NOTE_LOWAT, Unix stream and level-triggered knotes are not affected, and UDP above 1 already throws in DescriptorLowWater.
  • On the Windows question: on main, EdgeWatch.cpp:42-43 already throws "EV_CLEAR on a socket or a pipe off Linux" for every EV_CLEAR socket knote. The new check only runs first and changes the message, so no Windows case that worked before is lost.
  • The branch now conflicts with main in docs/dev/debt/libkernel.md, because the kqueue entry was rewritten. When resolving it, the new sentence may fit better in the existing "kevent EV_CLEAR on a socket or a pipe" entry, which already cites tcp_check_space.
  • The Linux block of EdgeTriggeredTcpWriteLowWater is the only place where the new throw is the first one, and the PR was tested on Windows. Could you run guest_kqueue on a Linux host once after the rebase?

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638245123 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9843#pullrequestreview-5638245123). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:32:04Z. **Review:** COMMENTED --- Checked against main 87666fc5d6, FreeBSD 11.4 `sys/kern/uipc_socket.c` (`filt_sowrite`), FreeBSD 11.0 `sys/netinet/tcp_input.c`, and Linux v6.8 `net/ipv4/tcp_input.c` / `net/core/sock.c`: - The diagnosis holds: `PollEdge` disarms when `SO_SNDBUF - SIOCOUTQ` is below the mark while `poll` reported POLLOUT, so `tcp_poll` never set `SOCK_NOSPACE` and `tcp_check_space` never wakes the epoll edge. With a mark of 1 the knote only disarms when POLLOUT was missing, so that case is safe. Throwing also looks right to me, since Linux fixes `SO_SNDLOWAT` at 1 and the mark can't be handed to the host. - The condition is precise: guest family 2/28 plus stream, `lowWater > 1`, EV_CLEAR or an existing `PollEdge` knote. A mark of 1, no NOTE_LOWAT, Unix stream and level-triggered knotes are not affected, and UDP above 1 already throws in `DescriptorLowWater`. - On the Windows question: on main, `EdgeWatch.cpp:42-43` already throws "EV_CLEAR on a socket or a pipe off Linux" for every EV_CLEAR socket knote. The new check only runs first and changes the message, so no Windows case that worked before is lost. - The branch now conflicts with main in `docs/dev/debt/libkernel.md`, because the kqueue entry was rewritten. When resolving it, the new sentence may fit better in the existing "kevent EV_CLEAR on a socket or a pipe" entry, which already cites `tcp_check_space`. - The Linux block of `EdgeTriggeredTcpWriteLowWater` is the only place where the new throw is the first one, and the PR was tested on Windows. Could you run `guest_kqueue` on a Linux host once after the rebase? 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!9843
No description provided.