netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Luczaj <mhal@rbox.co>
To: "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	John Fastabend <john.fastabend@gmail.com>,
	 Jakub Sitnicki <jakub@cloudflare.com>,
	 "Michael S. Tsirkin" <mst@redhat.com>,
	 Stefano Garzarella <sgarzare@redhat.com>,
	 Bobby Eshleman <bobby.eshleman@bytedance.com>,
	 Stefan Hajnoczi <stefanha@redhat.com>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
	 Michal Luczaj <mhal@rbox.co>
Subject: [PATCH bpf 2/4] vsock: Update rx_bytes on read_skb()
Date: Wed, 09 Oct 2024 23:20:51 +0200	[thread overview]
Message-ID: <20241009-vsock-fixes-for-redir-v1-2-e455416f6d78@rbox.co> (raw)
In-Reply-To: <20241009-vsock-fixes-for-redir-v1-0-e455416f6d78@rbox.co>

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().

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: 634f1a7110b4 ("vsock: support sockmap")
Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
 net/vmw_vsock/virtio_transport_common.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 884ee128851e5ce8b01c78fcb95a408986f62936..ed1c1bed5700e5988a233cea146cf9fac95426e0 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1707,6 +1707,7 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto
 {
 	struct virtio_vsock_sock *vvs = vsk->trans;
 	struct sock *sk = sk_vsock(vsk);
+	struct virtio_vsock_hdr *hdr;
 	struct sk_buff *skb;
 	int off = 0;
 	int err;
@@ -1716,10 +1717,14 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto
 	 * works for types other than dgrams.
 	 */
 	skb = __skb_recv_datagram(sk, &vvs->rx_queue, MSG_DONTWAIT, &off, &err);
-	spin_unlock_bh(&vvs->rx_lock);
-
-	if (!skb)
+	if (!skb) {
+		spin_unlock_bh(&vvs->rx_lock);
 		return err;
+	}
+
+	hdr = virtio_vsock_hdr(skb);
+	virtio_transport_dec_rx_pkt(vvs, le32_to_cpu(hdr->len));
+	spin_unlock_bh(&vvs->rx_lock);
 
 	return recv_actor(sk, skb);
 }

-- 
2.46.2


  parent reply	other threads:[~2024-10-09 21:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 21:20 [PATCH bpf 0/4] bpf, vsock: Fixes related to sockmap/sockhash redirection Michal Luczaj
2024-10-09 21:20 ` [PATCH bpf 1/4] bpf, sockmap: SK_DROP on attempted redirects of unsupported af_vsock Michal Luczaj
2024-10-10 18:54   ` Martin KaFai Lau
2024-10-09 21:20 ` Michal Luczaj [this message]
2024-10-10  8:49   ` [PATCH bpf 2/4] vsock: Update rx_bytes on read_skb() Stefano Garzarella
     [not found]     ` <CALa-AnBQAhpBn2cPG4wW9c-dMq0JXAbkd4NSJL+Vtv=r=+hn2w@mail.gmail.com>
2024-10-11  8:40       ` [External] " Stefano Garzarella
2024-10-13 16:28         ` Michal Luczaj
2024-10-09 21:20 ` [PATCH bpf 3/4] vsock: Update msg_count " Michal Luczaj
2024-10-10  8:51   ` Stefano Garzarella
2024-10-09 21:20 ` [PATCH bpf 4/4] bpf, vsock: Drop static vsock_bpf_prot initialization Michal Luczaj
2024-10-10  8:55 ` [PATCH bpf 0/4] bpf, vsock: Fixes related to sockmap/sockhash redirection Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241009-vsock-fixes-for-redir-v1-2-e455416f6d78@rbox.co \
    --to=mhal@rbox.co \
    --cc=bobby.eshleman@bytedance.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jakub@cloudflare.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).