Bobby Eshleman <[email protected]> writes:

(I've just noticed I've missed replying to this review, sorry about that).

> On Fri, Nov 13, 2026 at 06:15:47PM +0100, Sergio Lopez wrote:
>> The guest already uses page-sized RX allocations. A datagram can exceed
>> one RX buffer. Growing every posted buffer to hold a full datagram would
>> increase virtqueue memory use and make small queued datagrams retain large
>> backing allocations. With delayed reads, a bounded receive queue could
>> then fill after only a few messages.
>>
>> Define START and EOM flags for datagram packets. Mark outgoing messages
>> with both flags, and let vhost split a message across guest RX buffers,
>> keeping START on the first fragment and EOM on the last. When a data
>> packet meets a descriptor with no payload space, vhost returns that
>> descriptor with zero used bytes. It drops datagrams but requeues stream
>> and seqpacket data for a later buffer.
>>
>> Reassemble consecutive fragments in the guest before tap or socket
>> delivery. Bound a partial message to 64 fragments and 64 KiB. Discard
>> incomplete messages on malformed packets, a new START, a peer mismatch,
>> an intervening non-datagram packet, or virtqueue teardown. Require complete
>> framing for host and loopback ingress.
>>
>> A QEMU reproducer now delivers a 9 KiB datagram as one message and all
>> 16 messages of a delayed-read burst. Paired host/guest selftests cover
>> 64 KiB messages and the burst through both a userspace backend and the
>> patched Linux vhost backend, with stream and seqpacket controls. A nested
>> vhost-vsock guest posting header-only RX buffers also passes stream and
>> seqpacket receive tests.
>>
>> Signed-off-by: Sergio Lopez <[email protected]>
>> ---
>>  drivers/vhost/vsock.c                   |  15 +++++
>>  include/uapi/linux/virtio_vsock.h       |   8 +++
>>  net/vmw_vsock/virtio_transport.c        | 115 
>> ++++++++++++++++++++++++++++++--
>>  net/vmw_vsock/virtio_transport_common.c |  11 ++-
>>  4 files changed, 141 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>> index f4fb2ac732f5..1ff4a9aff907 100644
>> --- a/drivers/vhost/vsock.c
>> +++ b/drivers/vhost/vsock.c
>> @@ -185,6 +185,19 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>>               * buffer, we split it using multiple buffers.
>>               */
>>              if (payload_len > iov_len - sizeof(*hdr)) {
>> +                    if (iov_len == sizeof(*hdr)) {
>> +                            /* Connected sockets must retry with the next 
>> buffer. */
>> +                            if (le16_to_cpu(hdr->type) ==
>> +                                VIRTIO_VSOCK_TYPE_DGRAM)
>> +                                    kfree_skb(skb);
>> +                            else
>> +                                    virtio_vsock_skb_queue_head(
>> +                                            &vsock->send_pkt_queue, 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
>> @@ -244,6 +257,8 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>>               */
>>              if (VIRTIO_VSOCK_SKB_CB(skb)->offset < skb->len) {
>>                      hdr->flags |= cpu_to_le32(flags_to_restore);
>> +                    if (le16_to_cpu(hdr->type) == VIRTIO_VSOCK_TYPE_DGRAM)
>> +                            hdr->flags &= 
>> ~cpu_to_le32(VIRTIO_VSOCK_DGRAM_START);
>>
>>                      /* We are queueing the same skb to handle
>>                       * the remaining bytes, and we want to deliver it
>> diff --git a/include/uapi/linux/virtio_vsock.h 
>> b/include/uapi/linux/virtio_vsock.h
>> index 27b4b2b8bf13..e1937f756eeb 100644
>> --- a/include/uapi/linux/virtio_vsock.h
>> +++ b/include/uapi/linux/virtio_vsock.h
>> @@ -101,6 +101,14 @@ enum virtio_vsock_shutdown {
>>  enum virtio_vsock_rw {
>>      VIRTIO_VSOCK_SEQ_EOM = 1,
>>      VIRTIO_VSOCK_SEQ_EOR = 2,
>> +    /*
>> +     * With VIRTIO_VSOCK_F_DGRAM, START marks the first RW packet of a
>> +     * datagram and EOM marks the last. Both are set for a datagram that
>> +     * fits in one packet. Fragments must be consecutive on the receive
>> +     * virtqueue. Each packet's len is its fragment length.
>> +     */
>> +    VIRTIO_VSOCK_DGRAM_EOM = VIRTIO_VSOCK_SEQ_EOM,
>> +    VIRTIO_VSOCK_DGRAM_START = 4,
>
> Should this be 4 if VIRTIO_VSOCK_DGRAM_EOM = VIRTIO_VSOCK_SEQ_EOM = 1?
> Seems like 3 is missing?

Yes, those are bitmasks. But they are also part of an enum, which is
weird and confusing. Perhaps I should prepend a patch removing the enum
and redefining those values in the form of "1U << 0"?

> Is VIRTIO_VSOCK_DGRAM_START strictly necessary? If we just received an
> EOM from a peer, then we know that the next pkt from that peer is also
> the start of a new dgram. We'd have to be careful to never abandon a
> datagram partway through, but for example I think we can just requeue
> the datagram fragment to later retry if we fail to place onto the vq?

Yeah, I thought about this quite a while too. Having START makes the
protocol less dependent on the transport semantics, allowing the guest
to identify an incomplete datagram to resume from a known boundary. I
think it makes the implementation more robust with a relatively small
cost.

Thanks!
Sergio.


Reply via email to