Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable
@ 2026-12-03 18:49 Andrew Stellman
  0 siblings, 0 replies; only message in thread
From: Andrew Stellman @ 2026-12-03 18:49 UTC (permalink / raw)
  To: Stefano Garzarella, Stefan Hajnoczi
  Cc: Bobby Eshleman, Michael S. Tsirkin, Jason Wang,
	Eugenio Pérez, Xuan Zhuo, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	virtualization, kvm, netdev, linux-kernel

From: Andrew Stellman <astellman@stellman-greene.com>

For SOCK_SEQPACKET, virtio_transport_notify_poll_in() and
vsock_data_ready() check the number of queued bytes, so poll reports
the socket readable and blocked poll and epoll waiters are woken before
the packet carrying EOM has arrived, while a nonblocking recv still
fails with -EAGAIN. Check for a complete message instead in both
places. SO_RCVLOWAT then no longer affects SEQPACKET poll results or
data-ready wakeups.

Fixes: 9ac841f5e9f2 ("virtio/vsock: rest of SOCK_SEQPACKET support")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v2: Also skip the data-ready wakeup for an incomplete SEQPACKET
message, as Bobby Eshleman suggested, and drop the comment from v1.
v1: https://lore.kernel.org/all/20261202181307.73934-1-bugs@stellman-greene.com/

Tested on net 90ae4042bd9f (7.4.0-rc4) in an arm64 QEMU guest with KASAN
and vsock loopback: with a test-only three-second gap before EOM, poll
and epoll reported readable while recv failed with EAGAIN in 12/12
samples on plain net and 0/12 with the patch; with SO_RCVLOWAT=4096,
a blocked poll or epoll woke for a complete 26-byte message with the
patch and stayed blocked until the test's timeout on plain net; and
vsock_test ran IDs 0-43 on both local peers, with both exiting 0.

Found with Quality Playbook
(https://github.com/andrewstellman/quality-playbook) running Claude
Opus 5; the fix was drafted with OpenAI GPT-6 (Codex).

A reproducer is available on request.

 net/vmw_vsock/af_vsock.c                | 3 ++-
 net/vmw_vsock/virtio_transport_common.c | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 1d7d53542724..d403d3226ef8 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1117,9 +1117,10 @@ EXPORT_SYMBOL_GPL(vsock_stream_has_space);
 
 void vsock_data_ready(struct sock *sk)
 {
+	int target = sk->sk_type == SOCK_SEQPACKET ? 1 : sk->sk_rcvlowat;
 	struct vsock_sock *vsk = vsock_sk(sk);
 
-	if (vsock_stream_has_data(vsk) >= sk->sk_rcvlowat ||
+	if (vsock_connectible_has_data(vsk) >= target ||
 	    sock_flag(sk, SOCK_DONE))
 		sk->sk_data_ready(sk);
 }
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 1e762a480df4..7baab79d5808 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1107,7 +1107,10 @@ virtio_transport_notify_poll_in(struct vsock_sock *vsk,
 				size_t target,
 				bool *data_ready_now)
 {
-	*data_ready_now = vsock_stream_has_data(vsk) >= target;
+	if (sk_vsock(vsk)->sk_type == SOCK_SEQPACKET)
+		*data_ready_now = virtio_transport_seqpacket_has_data(vsk) != 0;
+	else
+		*data_ready_now = vsock_stream_has_data(vsk) >= target;
 
 	return 0;
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 18:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 18:49 [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable Andrew Stellman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox