casaroli opened a new pull request, #21531: URL: https://github.com/apache/nuttx/pull/21531
## Summary A TCP socket has `CONFIG_NET_TCP_NPOLLWAITERS` poll waiters (default 2). When all are in use, `tcp_pollsetup()` calls `DEBUGPANIC()`. With `CONFIG_DEBUG_ASSERTIONS`, a user program can stop the system: a third `poll()` or a third epoll set on one socket is a kernel panic. ``` dump_assert_info: Assertion failed panic: at file: tcp/tcp_netpoll.c:234 task: tcppollwait ``` The UDP, ICMP, ICMPv6, packet and usrsock sockets return `ENOMEM` in this case. This PR makes TCP do the same, with a warning, and adds a help text to `NET_TCP_NPOLLWAITERS` that describes the limit. ## Impact Only builds with `CONFIG_DEBUG_ASSERTIONS`: the call now fails with `ENOMEM` and the system continues. Without assertions the behaviour does not change (`DEBUGPANIC()` was empty). `poll()` reports the failure as `POLLERR` in `revents`, and `epoll_ctl()` returns `ENOMEM`. Common network code, so all architectures and build modes. No flat-build API change. No Documentation change: `Documentation/` does not name `NET_TCP_NPOLLWAITERS`; the new Kconfig help describes it. ## Testing Test program, on a listening TCP socket with the default of 2 poll waiters: 2 threads wait in `poll()`, and one more `poll()` must return `POLLERR`. When the threads end, `poll()` must work again. Then 2 epoll sets take the waiters, and a third `epoll_ctl(EPOLL_CTL_ADD)` must fail with `ENOMEM`. It is not in apps; a regression guard would need an apps PR. | Config | master 43f7f34b995 | this branch | |---|---|---| | `qemu-armv8a:nsh` (flat), HVF | panic at `tcp/tcp_netpoll.c:234` | 5 PASS; ostest status 0 | | `qemu-armv8a:knsh` (kernel), HVF | panic at `tcp/tcp_netpoll.c:234` | 5 PASS; ostest status 0 | | `mps2-an500:knsh` (protected), TCG | panic at `tcp/tcp_netpoll.c:234` | 5 PASS; ostest status 0 | This branch, the same in all three: ``` tcppollwait: poll ret 1 revents 0x8 errno 0 PASS tcppollwait: after ret 0 revents 0x0 PASS tcppollwait: epoll0 ret 0 errno 0 PASS tcppollwait: epoll1 ret 0 errno 0 PASS tcppollwait: epoll2 ret -1 errno 12 PASS ``` Options: `NET`, `NET_IPv4`, `NET_TCP`, `NETDEV_LATEINIT`, `NET_SOCKOPTS`, `DEBUG_FEATURES`, `DEBUG_ASSERTIONS`. `mps2-an500:knsh` also has `TLS_LOG2_MAXSTACK=15`, for the stack of the test. Not run: a build without `DEBUG_ASSERTIONS`, and a real network device (the test uses no traffic). Compilers: aarch64 GCC 14.2, arm-none-eabi GCC 15.3. `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
