All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v6 0/2] vsock/bpf: fix recvmsg deadlock and zero-length, OOB, errqueue reads
@ 2026-11-14 11:59 ` Jerome Mohm
  0 siblings, 0 replies; 8+ messages in thread
From: Jerome Mohm via B4 Relay @ 2026-11-14 11:59 UTC (permalink / raw)
  To: Stefano Garzarella, Bobby Eshleman, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Michael S. Tsirkin,
	Alexei Starovoitov
  Cc: Michal Luczaj, virtualization, netdev, linux-kernel, bpf, stable,
	Jerome Mohm

On a vsock socket in a sockmap, a blocking recv() deadlocks with the
virtio delivery worker and stops all vsock rx on that worker, and
zero-length, MSG_OOB and MSG_ERRQUEUE reads spin with the lock held,
wait, or consume stream bytes. Both come from the commit that added
sockmap support. Patch 1 hands those reads to __vsock_recvmsg(), and
patch 2 releases the lock around the wait and makes the wait loop.

The deadlock and the MSG_ERRQUEUE case were found with the help of
Anthropic's Claude, with Stefano adding the stream-byte part; the other
cases come from the netdev Sashiko reviews and Alexei. The reproducers
are available on request.

Changes in v6:
- Split into two patches, the zero-length, MSG_OOB and MSG_ERRQUEUE
  early return first, as Stefano preferred; the deadlock fix does not
  need it. This is the reverse of the v3 and v4 order, and 2/2 no
  longer argues for one patch.
- 2/2: check the transport in the wait loop before the data, so a
  reader that wakes after a failed connect() has dropped the transport
  no longer calls the data check, which warns (netdev Sashiko review).
  I check the transport instead of swapping the two tests because
  hv_sock reports the peer's FIN from its has_data() callback. The
  WARN_ON_ONCE() at the top of vsock_bpf_recvmsg() is unchanged.
- 2/2: reword the comment above vsock_rx_done() (Sashiko).
- 2/2: leave Sashiko's signal-and-timeout point as is: such a reader
  gets -EAGAIN where a native one gets -EINTR (see my v5 reply).
- Rebase onto current net.
- Link to v5: https://patch.msgid.link/20261109-kbh3-1-022-fix-v2-v5-1-4d9af04f0fad@eldare.de

Changes in v5: one patch on Alexei's approach, falling back to
__vsock_recvmsg() instead of copying its return values, which also
replaced the v4 comments; covers the Sashiko review of v4; don't cite
the selftests as coverage of the wait (Alexei).
Changes in v4: comments, one data <= 0 check and message changes
(Stefano); rebase; retest with a new dataless-wakeup reproducer.
Changes in v3: split into two patches after Michal's note; end the
wait after a reset read with SO_ERROR, and MSG_OOB returns -EOPNOTSUPP
(Sashiko).
Changes in v2: loop in the wait and stop on sk_err and peer shutdown,
len == 0 guard (Sashiko); MSG_ERRQUEUE to the native path.

Not tested: the lost-transport case and SHUT_RD with a pending socket
error (both checked in the code only), transports other than
virtio-vsock (PCI) and vsock-loopback, more than one run per
reproducer, a sockmap delete while a reader sleeps, the signal and
timeout case above, the vmtest.sh ns_* tests, W=1 builds beyond
vsock_bpf.o, the selftests on patch 1 alone, and anything after the
rebase: the runs were on the previous net head, and the rebase leaves
vsock_bpf.c unchanged.
Still left for separate patches, as in v5: data that sits only in
psock->ingress_skb (the loop can now reach that case after a wakeup
without data), and READ_ONCE()/WRITE_ONCE() for the lockless accesses.

---
Jerome Mohm (2):
      vsock/bpf: fix zero-length, MSG_OOB and MSG_ERRQUEUE reads
      vsock/bpf: release sock lock while waiting for data in recvmsg

 net/vmw_vsock/vsock_bpf.c | 45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)
---
base-commit: ead6fa9a0ab194f02a2f36d634b193e9c5f9a1c6
change-id: 20261001-kbh3-1-022-fix-v2-e3f14290641a

Best regards,
--  
Jerome Mohm <jrmmhm.kernel@eldare.de>



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-14 12:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 11:59 [PATCH net v6 0/2] vsock/bpf: fix recvmsg deadlock and zero-length, OOB, errqueue reads Jerome Mohm via B4 Relay
2026-11-14 11:59 ` Jerome Mohm
2026-11-14 11:59 ` [PATCH net v6 1/2] vsock/bpf: fix zero-length, MSG_OOB and MSG_ERRQUEUE reads Jerome Mohm via B4 Relay
2026-11-14 11:59   ` Jerome Mohm
2026-11-14 12:24   ` sashiko-bot
2026-11-14 11:59 ` [PATCH net v6 2/2] vsock/bpf: release sock lock while waiting for data in recvmsg Jerome Mohm via B4 Relay
2026-11-14 11:59   ` Jerome Mohm
2026-11-14 12:24   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.