* Re: [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable
2026-12-03 18:49 [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable Andrew Stellman
@ 2026-12-04 16:12 ` Bobby Eshleman
2026-12-04 18:52 ` sashiko-bot
2026-12-04 19:13 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: Bobby Eshleman @ 2026-12-04 16:12 UTC (permalink / raw)
To: Andrew Stellman
Cc: Stefano Garzarella, Stefan Hajnoczi, 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
On Thu, Dec 03, 2026 at 01:49:26PM -0500, Andrew Stellman wrote:
> 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);
I don't love this ternary in the var assignment. Any chance we can do
something like this? (untested):
struct vsock_sock *vsk = vsock_sk(sk);
int target = 1;
if (sk->sk_type == SOCK_STREAM)
target = sk->sk_rcvlowat;
>
> - 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;
> }
The rest LGTM.
Best,
Bobby
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable
2026-12-03 18:49 [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable Andrew Stellman
2026-12-04 16:12 ` Bobby Eshleman
@ 2026-12-04 18:52 ` sashiko-bot
2026-12-04 19:13 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 18:52 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:
- [High] vsock: deferring vsock_data_ready() until EOM breaks BPF
sockmap SEQPACKET
--
commit f7a0289cd402e3133a79450eba0ffb3fc3a8bb87
Author: Andrew Stellman <astellman@stellman-greene.com>
vsock: wait for EOM before reporting SEQPACKET readable
This commit updates vsock_data_ready() and virtio_transport_notify_poll_in()
to check for a complete message rather than queued bytes on SOCK_SEQPACKET
sockets.
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 1d7d53542724f..d403d3226ef8b 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);
> }
[Severity: High]
Does deferring sk->sk_data_ready() until EOM break BPF sockmap verdict
programs on SOCK_SEQPACKET sockets?
When a multi-fragment SOCK_SEQPACKET message arrives (for example, split
across guest RX buffers by vhost_transport_do_send_pkt()), vvs->msg_count
stays zero on the non-EOM fragments. vsock_data_ready() then invokes
sk_psock_verdict_data_ready() only once when the EOM fragment arrives.
sk_psock_verdict_data_ready() calls virtio_transport_read_skb() once, and
virtio_transport_read_skb() only dequeues a single skb from vvs->rx_queue.
Fragments 2..N, including the EOM packet, are left stranded in vvs->rx_queue
with vvs->msg_count still 1 and no further sk_data_ready() call.
Under an SK_DROP verdict on fragment 1, vsock_bpf_recvmsg() sees
vsock_has_data() true with an empty psock queue and falls back to
__vsock_recvmsg(), delivering fragments 2..N directly to userspace and
bypassing the BPF policy.
If vsock_data_ready() is deferred until EOM, should
virtio_transport_read_skb() loop to drain vvs->rx_queue like tcp_read_skb()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203184926.10262-1-bugs@stellman-greene.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable
2026-12-03 18:49 [PATCH net v2] vsock: wait for EOM before reporting SEQPACKET readable Andrew Stellman
2026-12-04 16:12 ` Bobby Eshleman
2026-12-04 18:52 ` sashiko-bot
@ 2026-12-04 19:13 ` netdev-bot+sashiko
2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 19:13 UTC (permalink / raw)
To: bugs
Cc: sgarzare, stefanha, bobbyeshleman, mst, jasowangio, eperezma,
xuanzhuo, davem, edumazet, kuba, pabeni, willemb, horms,
virtualization, kvm, netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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).
- [High] The patch suppresses data-ready callbacks for pre-EOM SEQPACKET
fragments, and this breaks vsock SOCK_SEQPACKET sockets that sit in a…
--
vsock: wait for EOM before reporting SEQPACKET readable
For SOCK_SEQPACKET sockets, this patch changes
virtio_transport_notify_poll_in() and vsock_data_ready() to look for a
complete message (msg_count != 0) rather than the number of queued
bytes. Poll no longer reports the socket readable, and data-ready
wakeups no longer fire, before the EOM packet has arrived.
SO_RCVLOWAT no longer affects SEQPACKET poll or wakeups.
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 1d7d53542724f..d403d3226ef8b 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);
> }
[Severity: High]
Can this stall a SOCK_SEQPACKET vsock socket that is in a BPF sockmap
with a verdict program?
sock_map_sk_state_allowed() accepts established vsock SEQPACKET
sockets. When a verdict program is attached, sk_psock_start_verdict()
sets sk->sk_data_ready to sk_psock_verdict_data_ready(). That function
calls read_skb() once per callback and does not loop:
net/core/skmsg.c:sk_psock_verdict_data_ready() {
...
copied = ops->read_skb(sk, sk_psock_verdict_recv);
...
}
For virtio, read_skb() ends up in virtio_transport_read_skb(), which
dequeues a single skb and decrements msg_count only when that skb
carries EOM:
net/vmw_vsock/virtio_transport_common.c:virtio_transport_read_skb() {
...
skb = __skb_recv_datagram(sk, &vvs->rx_queue, MSG_DONTWAIT, &off, &err);
...
if (le32_to_cpu(hdr->flags) & VIRTIO_VSOCK_SEQ_EOM)
vvs->msg_count--;
...
}
Before this patch, virtio_transport_recv_connected() called
vsock_data_ready() for every enqueued packet. With the default
sk_rcvlowat of 1, each of those calls produced a callback.
A message can arrive as several skbs, F1..Fn-1 without EOM and Fn
with EOM. vhost_transport_do_send_pkt() splits host-to-guest packets
to the guest RX buffer size and keeps EOM only on the last piece. The
receive side merges only small payloads into the previous skb. With
the new gate:
F1..Fn-1 enqueued, msg_count == 0 -> no sk_data_ready()
Fn enqueued, msg_count == 1 -> one sk_data_ready()
sk_psock_verdict_data_ready()
vsock_read_skb()
virtio_transport_read_skb() -> dequeues F1 only
msg_count stays 1
F2..Fn then stay in vvs->rx_queue until another packet arrives or
SOCK_DONE is set. Each later callback drains only one more skb, so the
verdict and redirect path falls further behind with every
multi-fragment message. Wouldn't a request/response or proxy setup
hang here, since the rest of the message is never handed to the
verdict program?
The commit message says only that SO_RCVLOWAT no longer affects
SEQPACKET data-ready wakeups. It doesn't mention that pre-EOM
fragments no longer get a callback, or how that affects psock
consumers. Should the sockmap case be handled here, either by keeping
a per-skb callback when a psock is attached or by draining up to the
EOM in the read_skb path?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203184926.10262-1-bugs%40stellman-greene.com
^ permalink raw reply [flat|nested] 4+ messages in thread