Thread (12 messages) 12 messages, 3 authors, 3d ago

Re: [PATCH v4 0/2] bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup

From: Jiayuan Chen <jiayuan.chen@linux.dev>
Date: 2026-07-16 01:30:50
Also in: bpf, sashiko-reviews

On 7/16/26 5:35 AM, Nnamdi Onyeyiri wrote:
Spurious wakeups in tcp_msg_wait_data() isn't being handled by
tcp_bpf_recvmsg() and tcp_bpf_recvmsg_parser(), leading to unexpected
EAGAIN errors returned by recvfrom()/recv().  Adding handling for the
wakeup and a selftest.

This issue was first discovered in an application that adds sockets to
a sockmap as a way to view the received data.  No redirects or any
other operations are performed.

Sashiko has noted a few other pre-existing issues in the same area
(https://patch.msgid.link/20260714205118.17DB11F000E9@smtp.kernel.org)
that can lead to EAGAIN in tcp_bpf_recvmsg() and
tcp_bpf_recvmsg_parser().  A local run of Sashiko also identified a
potential issue in tcp_bpf_recvmsg() handling zero-data FIN packets when
the MSG_PEEK flag is set.  To prevent this patchset from growing too
large, I intend to submit follow up patches to address these once this
one has been accepted.

Changes in v2:
- In tcp_bpf_recvmsg, handle signals and the socket closing in the loop.
- Fix spurious wakeups when SO_RCVTIMEO has been set on the socket.
- Link to v1: https://patch.msgid.link/ak_rR-Skd8Mvn4mH@localhost.localdomain

Changes in v3:
- Added the sockmap_recvfrom selftest.
- Link to v2: https://patch.msgid.link/alFRK66z45eDNZA7@localhost.localdomain

Changes in v4:
- Fix potential data loss in tcp_bpf_recvmsg() when a FIN or RST has
   been received.
- Check the return code of pthread_create() in the selftest.
- Fix race caused by using EXPECT macros in a thread in selftest.
- Link to v3: https://patch.msgid.link/20260714203927.32289-1-nnamdio@gmail.com
Please do not send a patch by replying to an old thread.

Signed-off-by: Nnamdi Onyeyiri <redacted>
---
Nnamdi Onyeyiri (2):
   bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup
   bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup

Please use a commit subject like "selftests/bpf: add selftest xxx" for 
the selftest patch.


  net/ipv4/tcp_bpf.c                            |  69 +++-
  tools/testing/selftests/net/.gitignore        |   2 +
  tools/testing/selftests/net/Makefile          |   5 +
  .../selftests/net/sockmap_recvfrom.bpf.c      |  31 ++
  .../testing/selftests/net/sockmap_recvfrom.c  | 299 ++++++++++++++++++

Please use existing test frameworks such as sockmap_basic.c or 
sockmap_strp.c.

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help