Skip to content

net/arp,icmpv6: Avoid blocking and allocations on non-blocking TX. - #22749

Open
mohitgurav20 wants to merge 1 commit into
apache:masterfrom
mohitgurav20:fix/nonblock-arp-ndp
Open

mohitgurav20 wants to merge 1 commit into
apache:masterfrom
mohitgurav20:fix/nonblock-arp-ndp

Conversation

@mohitgurav20

@mohitgurav20 mohitgurav20 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On the TX path, arp_send() and icmpv6_neighbor() allocate state/callback and semaphore objects before checking the ARP/Neighbor table, and block in a retry loop even when the socket is O_NONBLOCK or MSG_DONTWAIT is set.
  • Add arp_send_nonblock() (net/arp/arp_send.c) and icmpv6_neighbor_nonblock() (net/icmpv6/icmpv6_neighbor.c) which take netdev_lock(dev) and check arp_find() / neighbor_lookup() up front, returning OK immediately with zero allocations on a cache hit.
  • When nonblock is true and the entry is missing:
    • With CONFIG_NET_ARP_SEND_QUEUE=y, arp_send_nonblock() returns OK so arp_out() queues the packet and sends the ARP request.
    • Otherwise, it kicks off a one-shot asynchronous request (non-blocking mempool_allocate(..., 0) + arp_update(dev, ipaddr, NULL, 0) -EINPROGRESS guard for IPv4; heap-allocated async state freed on completion or NETDEV_DOWN for IPv6) and returns -EAGAIN.
  • Keep arp_send() and icmpv6_neighbor() as blocking wrappers so existing non-socket callers (tcp_conn.c, tcp_sendfile.c, arp_acd.c, icmpv6_autoconfig.c, icmpv6_sendmsg.c) are unaffected.
  • Update tcp_send_buffered.c, tcp_send_unbuffered.c, udp_sendto_buffered.c, and udp_sendto_unbuffered.c to evaluate nonblock before L2 resolution and call the non-blocking variants.
  • Related NuttX Issue: [BUG] net: O_NONBLOCK and MSG_DONTWAIT block synchronously on ARP/NDP resolution, and TX hot-path repeats allocation on cache hit #22596

Impact

  • Is new feature added? Is existing feature changed? YES - non-blocking (O_NONBLOCK / MSG_DONTWAIT) TCP and UDP sends no longer block waiting on ARP/NDP retries.
  • Impact on user (will user need to adapt to change)? YES - on a cold ARP/NDP cache, non-blocking sends now return -1 (errno = EAGAIN) immediately instead of blocking 100ms+ and failing with EHOSTUNREACH (or queue and return the byte count when CONFIG_NET_ARP_SEND_QUEUE=y).
  • Impact on build (will build process change)? NO.
  • Impact on hardware (will arch(s) / board(s) / driver(s) change)? NO.
  • Impact on documentation (is update required / provided)? NO.
  • Impact on security (any sort of implications)? NO.
  • Impact on compatibility (backward/forward/interoperability)? NO (existing arp_send() and icmpv6_neighbor() signatures are preserved).

Testing

  • Build Host(s): Windows 11 / WSL Ubuntu, x86_64, riscv-none-elf-gcc 13.2.0
  • Target(s): riscv64, rv-virt:netnsh64 (qemu-system-riscv64)
  • Style check: ./tools/checkpatch.sh -f on all 8 modified files passed with no errors.
  • Note: CONFIG_TESTING_OSTEST was disabled locally due to an apps/ version mismatch on work_queue_run. Since rv-virt:netnsh64 has CONFIG_NET_IPv6 disabled by default, IPv4 was runtime-tested in QEMU for both CONFIG_NET_ARP_SEND_QUEUE=n and CONFIG_NET_ARP_SEND_QUEUE=y, while icmpv6_neighbor_nonblock() is verified by inspection. Could maintainers confirm whether these QEMU logs are acceptable?

Testing logs before change (unmodified master, CONFIG_NET_ARP_SEND_QUEUE=n):

nsh> hello
IPv4 MSG_DONTWAIT: ret=-1 errno=113 elapsed=117 ms
IPv4 O_NONBLOCK: ret=-1 errno=113 elapsed=116 ms

Testing logs after change (CONFIG_NET_ARP_SEND_QUEUE=n):

nsh> hello
IPv4 MSG_DONTWAIT: ret=-1 errno=11 elapsed=4 ms
IPv4 O_NONBLOCK: ret=-1 errno=11 elapsed=0 ms

Testing logs after change (CONFIG_NET_ARP_SEND_QUEUE=y, CONFIG_DRIVERS_VIRTIO_NET_BUFNUM=8):

nsh> hello
IPv4 MSG_DONTWAIT: ret=5 errno=0 elapsed=5 ms
IPv4 O_NONBLOCK: ret=5 errno=0 elapsed=0 ms

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is ready for review and can be safely merged into a codebase.
  • My PR is still work in progress (not ready for review).

arp_send() and icmpv6_neighbor() previously allocated mempool/callback
and semaphore resources before checking the ARP/Neighbor tables, and
blocked synchronously even for O_NONBLOCK or MSG_DONTWAIT sends.

* Add arp_send_nonblock() and icmpv6_neighbor_nonblock() with a
  fast-path table lookup under netdev_lock(dev) before allocating
  any state or callback.
* When nonblock is true and the entry is missing, return OK when
  CONFIG_NET_ARP_SEND_QUEUE is enabled (letting arp_out() queue the
  packet), or trigger a one-shot asynchronous request and return -EAGAIN.
* Keep arp_send() and icmpv6_neighbor() as blocking wrappers for
  existing non-socket callers.
* Update tcp_send_buffered.c, tcp_send_unbuffered.c,
  udp_sendto_buffered.c, and udp_sendto_unbuffered.c to pass nonblock.

Assisted-by: Antigravity:gemini-4-hydrogen-medium
Signed-off-by: mohitgurav20 <mohitgurav20@gmail.com>
@mohitgurav20

Copy link
Copy Markdown
Contributor Author

@xiaoxiang781216 @jerpelea reviewer pls feel free to to request the changes and guide me thorugh this issue .

@github-actions github-actions Bot added Area: Networking Effects networking subsystem Size: M The size of the change in this PR is medium labels Dec 2, 2026
@mohitgurav20

Copy link
Copy Markdown
Contributor Author

The failed jobs hit ghcr.io Docker Login / Docker Pull EOF/401 errors before the build step ,could a maintainer please re-run the failed CI jobs?

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Networking Effects networking subsystem Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants