Skip to content

Commit 3543152

Browse files
mmhalborkmann
authored andcommitted
vsock: Update rx_bytes on read_skb()
Make sure virtio_transport_inc_rx_pkt() and virtio_transport_dec_rx_pkt() calls are balanced (i.e. virtio_vsock_sock::rx_bytes doesn't lie) after vsock_transport::read_skb(). While here, also inform the peer that we've freed up space and it has more credit. Failing to update rx_bytes after packet is dequeued leads to a warning on SOCK_STREAM recv(): [ 233.396654] rx_queue is empty, but rx_bytes is non-zero [ 233.396702] WARNING: CPU: 11 PID: 40601 at net/vmw_vsock/virtio_transport_common.c:589 Fixes: 634f1a7 ("vsock: support sockmap") Suggested-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Michal Luczaj <mhal@rbox.co> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20241013-vsock-fixes-for-redir-v2-2-d6577bbfe742@rbox.co
1 parent 9c5bd93 commit 3543152

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

net/vmw_vsock/virtio_transport_common.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto
17071707
{
17081708
struct virtio_vsock_sock *vvs = vsk->trans;
17091709
struct sock *sk = sk_vsock(vsk);
1710+
struct virtio_vsock_hdr *hdr;
17101711
struct sk_buff *skb;
17111712
int off = 0;
17121713
int err;
@@ -1716,10 +1717,16 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto
17161717
* works for types other than dgrams.
17171718
*/
17181719
skb = __skb_recv_datagram(sk, &vvs->rx_queue, MSG_DONTWAIT, &off, &err);
1720+
if (!skb) {
1721+
spin_unlock_bh(&vvs->rx_lock);
1722+
return err;
1723+
}
1724+
1725+
hdr = virtio_vsock_hdr(skb);
1726+
virtio_transport_dec_rx_pkt(vvs, le32_to_cpu(hdr->len));
17191727
spin_unlock_bh(&vvs->rx_lock);
17201728

1721-
if (!skb)
1722-
return err;
1729+
virtio_transport_send_credit_update(vsk);
17231730

17241731
return recv_actor(sk, skb);
17251732
}

0 commit comments

Comments
 (0)