From: Bobby Eshleman <bobbyeshleman@meta.com>
To: Sergio Lopez <slp@redhat.com>
Cc: "Stefano Garzarella" <sgarzare@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Bryan Tan" <bryan-bt.tan@broadcom.com>,
"Vishnu Dasa" <vishnu.dasa@broadcom.com>,
"Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Haiyang Zhang" <haiyangz@microsoft.com>,
"Wei Liu" <wei.liu@kernel.org>,
"Dexuan Cui" <decui@microsoft.com>,
virtualization@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
bpf@vger.kernel.org, linux-hyperv@vger.kernel.org
Subject: Re: [PATCH RFC 7/8] vsock: preserve host-to-guest datagram boundaries
Date: Mon, 2 Nov 2026 14:29:37 -0800 [thread overview]
Message-ID: <aukO0YEZmiMIISaP@devvm29614.prn0.facebook.com> (raw)
In-Reply-To: <20261028-vsock-dgram-support-v1-7-e457cf7cee78@sinrega.org>
On Wed, Oct 28, 2026 at 05:04:36PM +0100, Sergio Lopez wrote:
> Vhost splits large datagrams across guest RX buffers, delivering each
> fragment as a separate message. Allocate full-size RX buffers with
> page fragments when datagrams are negotiated, and drop whole datagrams
> if a guest buffer is too small. Refill empty RX queues even when only
> one full-size buffer fits in the ring.
I wonder if it might be better to do what seqpacket does, and just split
the datagram across the buffers (for seqpacket, until the EOM flag is
seen)? I'd expect that we will get better utilization of our vq buffers
this way?
Best,
Bobby
>
> Signed-off-by: Sergio Lopez <slp@redhat.com>
> ---
> drivers/vhost/vsock.c | 8 ++++++++
> net/vmw_vsock/virtio_transport.c | 28 +++++++++++++++++++---------
> 2 files changed, 27 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 79ffdb28f4d9..2294ed8d30a8 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c
> @@ -185,6 +185,14 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
> * buffer, we split it using multiple buffers.
> */
> if (payload_len > iov_len - sizeof(*hdr)) {
> + /* Datagrams must fit in a single descriptor chain. */
> + if (le16_to_cpu(hdr->type) == VIRTIO_VSOCK_TYPE_DGRAM) {
> + kfree_skb(skb);
> + vhost_add_used(vq, head, 0);
> + added = true;
> + continue;
> + }
> +
> payload_len = iov_len - sizeof(*hdr);
>
> /* As we are copying pieces of large packet's buffer to
> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> index 14ce0836bc39..d256274088b3 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -54,6 +54,7 @@ struct virtio_vsock {
> bool rx_run;
> int rx_buf_nr;
> int rx_buf_max_nr;
> + struct scatterlist in_bufs[MAX_SKB_FRAGS + 1];
>
> u32 guest_cid;
> bool seqpacket_allow;
> @@ -312,22 +313,31 @@ virtio_transport_cancel_pkt(struct vsock_sock *vsk)
> static void virtio_vsock_rx_fill(struct virtio_vsock *vsock)
> {
> int total_len = VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE;
> - struct scatterlist pkt, *p;
> struct virtqueue *vq;
> struct sk_buff *skb;
> int ret;
>
> vq = vsock->vqs[VSOCK_VQ_RX];
> + /* A datagram must fit in one RX buffer, including its header. */
> + if (vsock->dgram_allow)
> + total_len = VIRTIO_VSOCK_SKB_HEADROOM +
> + VIRTIO_VSOCK_MAX_PKT_BUF_SIZE;
>
> do {
> - skb = virtio_vsock_alloc_linear_skb(total_len, GFP_KERNEL);
> + skb = virtio_vsock_alloc_skb(total_len, GFP_KERNEL);
> if (!skb)
> break;
>
> memset(skb->head, 0, VIRTIO_VSOCK_SKB_HEADROOM);
> - sg_init_one(&pkt, virtio_vsock_hdr(skb), total_len);
> - p = &pkt;
> - ret = virtqueue_add_sgs(vq, &p, 0, 1, skb, GFP_KERNEL);
> + /* Post the header and the entire payload as one RX buffer. */
> + virtio_vsock_skb_put(skb, total_len - VIRTIO_VSOCK_SKB_HEADROOM);
> + skb_push(skb, VIRTIO_VSOCK_SKB_HEADROOM);
> + sg_init_table(vsock->in_bufs, ARRAY_SIZE(vsock->in_bufs));
> + ret = skb_to_sgvec(skb, vsock->in_bufs, 0, total_len);
> + skb_pull(skb, VIRTIO_VSOCK_SKB_HEADROOM);
> + if (ret >= 0)
> + ret = virtqueue_add_inbuf(vq, vsock->in_bufs, ret, skb,
> + GFP_KERNEL);
> if (ret < 0) {
> kfree_skb(skb);
> break;
> @@ -698,7 +708,7 @@ static void virtio_transport_rx_work(struct work_struct *work)
>
> /* Drop short/long packets */
> if (unlikely(len < sizeof(*hdr) ||
> - len > virtio_vsock_skb_len(skb))) {
> + len > sizeof(*hdr) + skb->len)) {
> kfree_skb(skb);
> continue;
> }
> @@ -710,8 +720,7 @@ static void virtio_transport_rx_work(struct work_struct *work)
> continue;
> }
>
> - if (payload_len)
> - virtio_vsock_skb_put(skb, payload_len);
> + pskb_trim_unique(skb, payload_len);
>
> virtio_transport_deliver_tap_pkt(skb);
>
> @@ -723,7 +732,8 @@ static void virtio_transport_rx_work(struct work_struct *work)
> } while (!virtqueue_enable_cb(vq));
>
> out:
> - if (vsock->rx_buf_nr < vsock->rx_buf_max_nr / 2)
> + if (!vsock->rx_buf_nr ||
> + vsock->rx_buf_nr < vsock->rx_buf_max_nr / 2)
> virtio_vsock_rx_fill(vsock);
> out_nofill:
> mutex_unlock(&vsock->rx_lock);
>
> --
> 2.56.0
>
next prev parent reply other threads:[~2026-11-02 22:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 16:04 [PATCH RFC 0/8] vsock: add datagram support to virtio and vhost Sergio Lopez
2026-10-28 16:04 ` [PATCH RFC 1/8] vsock: expose the core port allocator to transports Sergio Lopez
2026-10-28 16:04 ` [PATCH RFC 2/8] vsock: report datagram receive and send queue state Sergio Lopez
2026-10-28 16:04 ` [PATCH RFC 3/8] vsock/virtio: implement the datagram data path Sergio Lopez
2026-11-03 20:05 ` Bobby Eshleman
2026-11-03 20:15 ` Bobby Eshleman
2026-10-28 16:04 ` [PATCH RFC 4/8] vsock/virtio: negotiate datagram support on the guest Sergio Lopez
2026-10-28 16:04 ` [PATCH RFC 5/8] vhost/vsock: negotiate datagram support with guests Sergio Lopez
2026-10-28 16:04 ` [PATCH RFC 6/8] vsock: allow datagrams to use directional transports Sergio Lopez
2026-10-28 16:04 ` [PATCH RFC 7/8] vsock: preserve host-to-guest datagram boundaries Sergio Lopez
2026-11-02 22:29 ` Bobby Eshleman [this message]
2026-10-28 16:04 ` [PATCH RFC 8/8] vsock: add datagram tests to vsock_test Sergio Lopez
2026-10-28 17:25 ` [PATCH RFC 0/8] vsock: add datagram support to virtio and vhost Alexei Starovoitov
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=aukO0YEZmiMIISaP@devvm29614.prn0.facebook.com \
--to=bobbyeshleman@meta.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bpf@vger.kernel.org \
--cc=bryan-bt.tan@broadcom.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@kernel.org \
--cc=eperezma@redhat.com \
--cc=haiyangz@microsoft.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=slp@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=vishnu.dasa@broadcom.com \
--cc=wei.liu@kernel.org \
--cc=xuanzhuo@linux.alibaba.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
all inboxes | Powered by JetHome®