* 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 18:26 ` sashiko-bot
2026-12-03 19:10 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ 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] 4+ 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 18:26 ` sashiko-bot
2026-12-03 19:10 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-03 18:26 UTC (permalink / raw)
To: Andrew Stellman; +Cc: virtualization, kvm, Michael S. Tsirkin, Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vsock/virtio: wakeup mismatch for SOCK_SEQPACKET in
vsock_data_ready()
--
commit 4cf63f25637b2c89719d5209aa6314e30eb8d4ba
Author: Andrew Stellman <astellman@stellman-greene.com>
vsock/virtio: wait for EOM before reporting SEQPACKET readable
This commit updates virtio_transport_notify_poll_in() to check
virtio_transport_seqpacket_has_data() instead of comparing queued bytes
against target for SOCK_SEQPACKET sockets.
> 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;
> + else
> + *data_ready_now = vsock_stream_has_data(vsk) >= target;
>
> return 0;
> }
[Severity: Medium]
Should vsock_data_ready() also check for a completed message on
SOCK_SEQPACKET sockets instead of comparing vsock_stream_has_data(vsk)
against sk->sk_rcvlowat?
When virtio_transport_recv_connected() enqueues a VIRTIO_VSOCK_OP_RW
packet, it wakes waiters through vsock_data_ready():
net/vmw_vsock/af_vsock.c:vsock_data_ready() {
struct vsock_sock *vsk = vsock_sk(sk);
if (vsock_stream_has_data(vsk) >= sk->sk_rcvlowat ||
sock_flag(sk, SOCK_DONE))
sk->sk_data_ready(sk);
}
Leaving vsock_data_ready() on the byte-count and sk_rcvlowat check while
virtio_transport_notify_poll_in() checks completed messages puts the wait
and wakeup conditions out of sync. If userspace raises SO_RCVLOWAT (or a
0-byte EOM message arrives with the default sk_rcvlowat of 1), a complete
message smaller than sk_rcvlowat makes virtio_transport_notify_poll_in()
report readable, but vsock_data_ready() does not call sk_data_ready(),
leaving threads blocked in poll(), epoll_wait(), or recv(). Conversely,
each non-EOM fragment of a multi-packet message exceeds the default
sk_rcvlowat of 1 and triggers sk_data_ready() (and SIGIO for O_ASYNC
sockets) even though poll and recv() still see no completed message.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202181307.73934-1-bugs@stellman-greene.com?part=1
^ permalink raw reply [flat|nested] 4+ 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 18:26 ` sashiko-bot
@ 2026-12-03 19:10 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ 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] 4+ messages in thread