Skip to contentSkip to conversation

vsock/virtio: wait for EOM before reporting SEQPACKET readable

PATCH In review Andrew Stellman 2 participants 2 messages Dec 2

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vsock/virtio: wait for EOM before reporting SEQPACKET readable

From: Andrew Stellman <[email protected]>

virtio_transport_notify_poll_in() compares queued bytes with the receive low-water mark for every socket type, but SEQPACKET recv() only returns a message once its EOM packet has arrived. When only the first packet of a message larger than 64 KiB is queued, poll() and epoll report the socket readable and a nonblocking recv() returns EAGAIN.

Use the completed-message count for SEQPACKET, as recv() does. An incomplete message is no longer reported readable, and SO_RCVLOWAT no longer affects SEQPACKET poll.

Fixes 9ac841f5e9f2 ("virtio/vsock: rest of SOCK_SEQPACKET support")

---
Tested on mainline 693c2e04e3f1 (7.4.0-rc5) in arm64 QEMU with KASAN over vsock loopback, with a test-only three-second delay after the first packet: before the fix poll() and epoll reported the socket readable while recv() returned EAGAIN, and with the fix they didn't.

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/virtio_transport_common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +5 -1
index 1e762a480df4..d659986bb48b 100644
@@ -1107,7 +1107,11 @@ 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;
+	/* A SEQPACKET message is readable only after its EOM packet arrives. */
+	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;
 }
Signature · 1 line
2.53.0
#1 lore raw
Quoted 34 lines · Andrew Stellman

From: Andrew Stellman <[email protected]>

virtio_transport_notify_poll_in() compares queued bytes with the receive low-water mark for every socket type, but SEQPACKET recv() only returns a message once its EOM packet has arrived. When only the first packet of a message larger than 64 KiB is queued, poll() and epoll report the socket readable and a nonblocking recv() returns EAGAIN.

Use the completed-message count for SEQPACKET, as recv() does. An incomplete message is no longer reported readable, and SO_RCVLOWAT no longer affects SEQPACKET poll.

Fixes 9ac841f5e9f2 ("virtio/vsock: rest of SOCK_SEQPACKET support")

---
Tested on mainline 693c2e04e3f1 (7.4.0-rc5) in arm64 QEMU with KASAN over vsock loopback, with a test-only three-second delay after the first packet: before the fix poll() and epoll reported the socket readable while recv() returned EAGAIN, and with the fix they didn't.

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/virtio_transport_common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +0 -0
index 1e762a480df4..d659986bb48b 100644

net/vmw_vsock/virtio_transport_common.c virtio_transport_notify_poll_in(struct vsock_sock *vsk, · line 1110

Quoted 5 lines
net/vmw_vsock/virtio_transport_common.c +1 -1
@@ -1107,7 +1107,11 @@ 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;
+	/* A SEQPACKET message is readable only after its EOM packet arrives. */

I'd probably drop this comment.

net/vmw_vsock/virtio_transport_common.c virtio_transport_notify_poll_in(struct vsock_sock *vsk, · line 1114

Quoted 4 lines
net/vmw_vsock/virtio_transport_common.c +4 -0
+	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;

This looks good, but I also noticed that vsock_data_ready() is still using vsock_stream_has_data() >= sk->sk_rcvlowat, so won't seqpacket readers still get woken up on incomplete messages (e.g., in virtio_transport_recv_connected())?

Maybe we should change vsock_data_ready() too to generally fix seqpacket rcvlowat?

Best,
Bobby