Netdev List
 help / color / mirror / Atom feed
* [PATCH net] vsock/virtio: wait for EOM before reporting SEQPACKET readable
@ 2026-12-02 18:13 Andrew Stellman
  2026-12-02 23:15 ` Bobby Eshleman
  2026-12-03 19:10 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Stellman @ 2026-12-02 18:13 UTC (permalink / raw)
  To: Stefan Hajnoczi, Stefano Garzarella
  Cc: Bobby Eshleman, Michael S. Tsirkin, Jason Wang,
	Eugenio Pérez, Xuan Zhuo, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, virtualization, kvm,
	netdev, linux-kernel

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

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")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
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(-)

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 1e762a480df4..d659986bb48b 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -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;
 }
-- 
2.53.0


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

* Re: [PATCH net] vsock/virtio: wait for EOM before reporting SEQPACKET readable
  2026-12-02 18:13 [PATCH net] vsock/virtio: wait for EOM before reporting SEQPACKET readable Andrew Stellman
@ 2026-12-02 23:15 ` Bobby Eshleman
  2026-12-03 19:10 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: Bobby Eshleman @ 2026-12-02 23:15 UTC (permalink / raw)
  To: Andrew Stellman
  Cc: Stefan Hajnoczi, Stefano Garzarella, Michael S. Tsirkin,
	Jason Wang, Eugenio Pérez, Xuan Zhuo, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	virtualization, kvm, netdev, linux-kernel

On Wed, Dec 02, 2026 at 01:13:07PM -0500, Andrew Stellman wrote:
> From: Andrew Stellman <astellman@stellman-greene.com>
> 
> 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")
> Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
> ---
> 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(-)
> 
> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> index 1e762a480df4..d659986bb48b 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -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.

> +	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

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

* Re: [PATCH net] vsock/virtio: wait for EOM before reporting SEQPACKET readable
  2026-12-02 18:13 [PATCH net] vsock/virtio: wait for EOM before reporting SEQPACKET readable Andrew Stellman
  2026-12-02 23:15 ` Bobby Eshleman
@ 2026-12-03 19:10 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 19:10 UTC (permalink / raw)
  To: bugs
  Cc: stefanha, sgarzare, bobbyeshleman, mst, jasowangio, eperezma,
	xuanzhuo, davem, edumazet, kuba, pabeni, horms, virtualization,
	kvm, netdev, linux-kernel

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch changes when poll() reports a SEQPACKET socket
  readable, but it does not change when sleeping pollers are woken.

--

vsock/virtio: wait for EOM before reporting SEQPACKET readable

For SEQPACKET sockets, this patch changes virtio_transport_notify_poll_in()
to use the completed-message count (msg_count) instead of comparing queued
bytes with the SO_RCVLOWAT target. As a result, poll() and epoll no longer
report a socket readable when only part of a message has arrived.

> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> index 1e762a480df49..d659986bb48b0 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -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;

[Severity: Medium]
This changes when poll() reports a SEQPACKET socket readable. Should the
wakeup side change as well?

For virtio, vhost and loopback, the RX wakeup comes from
virtio_transport_recv_connected() calling vsock_data_ready(). That happens
after virtio_transport_recv_enqueue() has done msg_count++ for an EOM packet.
vsock_data_ready() still uses the byte count and rcvlowat test:

net/vmw_vsock/af_vsock.c:vsock_data_ready() {
	...
	if (vsock_stream_has_data(vsk) >= sk->sk_rcvlowat ||
	    sock_flag(sk, SOCK_DONE))
		sk->sk_data_ready(sk);
}

So msg_count can go from 0 to 1, which makes poll() readable under the new
rule, without any wakeup being sent. A couple of ways this can happen:

  - Userspace sets SO_RCVLOWAT to, say, 4096 on a SEQPACKET socket and
    sleeps in poll(), select() or epoll_wait(). The peer then sends a
    complete 100 byte message. poll() with a zero timeout now returns
    EPOLLIN, but rx_bytes is 100, which is less than 4096. The sleeping
    waiter is not woken until its timeout expires, more data arrives, or
    the peer shuts down. Edge-triggered epoll never sees the transition.

  - With the default rcvlowat of 1, a peer sends a zero-length OP_RW
    packet with VIRTIO_VSOCK_SEQ_EOM into an empty queue. msg_count is
    incremented and rx_bytes stays at 0, so poll() reports readable but
    no wakeup is sent. Linux senders skip zero-length OP_RW packets in
    virtio_transport_send_pkt_info(), so this needs a non-Linux or
    modified peer.

Before this patch, poll readiness and the wakeup used the same
rx_bytes >= rcvlowat test, so they always agreed.

The commit message says:

  "SO_RCVLOWAT no longer affects SEQPACKET poll."

Isn't that only true for a non-sleeping poll? A sleeping poller is still
woken based on SO_RCVLOWAT.

Would it make sense to make vsock_data_ready() SEQPACKET-aware too? For
example, it could use the existing vsock_connectible_has_data() helper,
which already returns seqpacket_has_data() for SOCK_SEQPACKET. Another
option is to always wake for SEQPACKET once a message is complete.

> +	else
> +		*data_ready_now = vsock_stream_has_data(vsk) >= target;
>  
>  	return 0;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202181307.73934-1-bugs%40stellman-greene.com

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:13 [PATCH net] vsock/virtio: wait for EOM before reporting SEQPACKET readable Andrew Stellman
2026-12-02 23:15 ` Bobby Eshleman
2026-12-03 19:10 ` netdev-bot+sashiko

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