casaroli opened a new pull request, #21906: URL: https://github.com/apache/nuttx/pull/21906
## Summary `pkt_close()` freed the read-ahead and error-ahead queues of a packet socket before the connection left the active list. The input path can still queue frames on the connection after that point. `pkt_free()` then released the connection with these IOBs still queued, and nothing freed them. A frame can come in at two points. With `CONFIG_NET_PKT_WRITE_BUFFERS`, `pkt_close()` waits for the write queue to drain with the device unlocked: a frame that comes in during this wait is queued, for example a sent frame that comes back on `lo`. Also, a frame can come in between `conn_dev_unlock()` and `pkt_free()`. This PR frees the queues in `pkt_free()` after `dq_rem()`, with the connection list locked, as `can_conn_uninit()`, `icmp_free()` and `udp_free()` do. `pkt_in_()` queues frames with the same lock held, so no frame can come in after that point. ## Impact Closing a packet socket no longer loses IOBs. Before, each such close made the IOB pool of the network stack smaller for good. No API change. No Documentation change (`Documentation/os/networking/pkt.rst` does not describe this). The code is the same in all build modes and on all arches. ## Testing Two test programs, each with an `ETH_P_ALL` packet socket bound to `lo` that receives IPv4 packets to 127.0.0.1. Each compares the free IOB count of `/proc/iobinfo` at the start and at the end. - `pktclose.c`: 4 rounds of open, send 2 packets, close. Case 1 at normal priority (the frames are queued before `close()`). Case 2 above the work queue priority, so `close()` waits for the write queue while the frames come back to the socket. - `pktrace.c`: open and close the socket in a loop for 3 s, while a thread at priority 200 sends a UDP datagram to 127.0.0.1 at each clock tick. A frame that comes in during `close()` is lost on master. | Configuration | master 46066440966 | this PR | |---|---|---| | qemu-armv8a:knsh (kernel), write buffers | pktclose case 2: 16 IOBs lost, FAIL | pktclose: 0 lost, PASS | | qemu-armv8a:nsh (flat), write buffers | pktclose case 2: 16 IOBs lost, FAIL | pktclose: 0 lost, PASS | | qemu-armv8a:nsh (flat), no write buffers | pktclose: PASS; pktrace: 8 IOBs lost after 136896 rounds, FAIL | pktclose: PASS; pktrace: 0 lost after 3196984 rounds, PASS | | rv-virt:knsh64 (kernel), write buffers | not run | pktclose and pktrace: PASS | ostest exits with status 0 on qemu-armv8a:knsh, on qemu-armv8a:nsh (with and without write buffers) and on rv-virt:knsh64. All runs are under QEMU (arm64 with HVF, rv-virt with TCG), one CPU. Options added to the defconfigs: NET, NET_IPv4, NET_LOOPBACK, NET_UDP, NET_ICMP, NET_PKT, NET_PKT_WRITE_BUFFERS (on or off), DEBUG_ASSERTIONS. checkpatch: `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]
