From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OKvAr0Jk; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 444305A026F for ; Tue, 04 Nov 2025 16:01:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762268473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=k+GhGyoF930jg/hrnpXZ0ddFPOfvCiVJue8Zm06h/QU=; b=OKvAr0Jk9YbS1Uxi7D2RISnPBrEwESusrj1YmRWSnxJ5Ayz7t/nHrfKIhucOxiMaUhXzAV KlugmZL221D9GuTh95Xuy7hsbsPfkNmpSv38GuFaMSHkyhadi9ZETxbk90mSt5oFWC4LTw 2xkIyYBXCzYoz53m7D8jdkBFlT2yf2g= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-y8hMpQLPOaKxgkkwIzzvug-1; Tue, 04 Nov 2025 10:01:10 -0500 X-MC-Unique: y8hMpQLPOaKxgkkwIzzvug-1 X-Mimecast-MFC-AGG-ID: y8hMpQLPOaKxgkkwIzzvug_1762268469 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-47740c1442dso24299795e9.1 for ; Tue, 04 Nov 2025 07:01:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762268469; x=1762873269; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=k+GhGyoF930jg/hrnpXZ0ddFPOfvCiVJue8Zm06h/QU=; b=Vif4KC+Kvaql7PIV7dELi2/0X6b1f5WKwCZYw3QdwEEkkeNXDN2TPh+vVBDZexpwU4 cqjXQWNVsQ5qul+e4e4hox4B5djzvl9+mp3/NDAdPzTVFMmoo8hL2UXmysPf17ealOoc L95d7k+EmXoYyaqpui7uKU3FiNeBncgZ7SqgRV3HS7ajssnoJdQ9SaE9EbA8C4TfsI0I jMiA3TnYwuwqU82HCteZJZOH3PbDKo4Cls365iftYGE/TyT5GJkxUhSM1zBXChjGHrwr woessutWtphkoYSEMqNm5ftwUcjZ3FO+uZS1ovHJYpPYpJ317B7/J9BlwKlLXb5aoYfx zogA== X-Forwarded-Encrypted: i=1; AJvYcCVxFw6RytHQEV9kXj39+2fqjvYk8GgXsJ2ZulNIKK7lvOprY8Wl48c19PxLdlfgzHdA82hWYiIq1UM=@passt.top X-Gm-Message-State: AOJu0YzUhtcG9fqHvUqEdYe4C/6jDrrhYoUQSZf1r6UCf2FjEVzvY/qk UHa+RnX/1wIiDCsb/cqYXnLFa2T5jdtAXvdMKOdMX55bbTM76ClVNh4e8Ui+eteSNF0bblXVbX2 pvv6IW2WO6SvfqNACUxy/Ma0wsZLaEWQCztSeQXhlmXwML3OuZ67uaw== X-Gm-Gg: ASbGnctW0Mr3kx0MC8rsKzPQj0NQpkguukfX5XoPPbajq5HH0iphxWc+S0h8WtsGyNu PEDYI48WVtCOMKxiT3LIem0WSkQthS8uoa+jl/pcMomicomXyPwqvfcxdq+kAsf64yR7sdTu9dJ M/sopJ2Fe7452Iu2X2AEvR+F+YTCyONWRkLOBw5ZnrxdHFuJE4d16EXn2fqi/cKw/z8sQhi0pTW Hb7hk/7vGg9qCYtK66HN0Yajqqe1fMgigCjJZFQnC2r/JHhL6bzW1Awtvtbk7z8akjP9IHuCHJW r/HOOFe9koOfskst0/fmTcDSVpHZT1uFOUROpFcBXVvW8KhQGmYar8Q6+2jtDIhLlw1dYA5h9+6 ZEwyaxuOK/cx1cy4ibPoRCAcLrH2NlbrCOKX24Q== X-Received: by 2002:a05:600c:548f:b0:475:dd9d:297b with SMTP id 5b1f17b1804b1-47730890156mr144907425e9.33.1762268469216; Tue, 04 Nov 2025 07:01:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiEHqdQZhgYN9JReJDINcdqx0oZpw+HprM9MNoxDNoaw6NUyzxaySHGrd4GEHAjHSJFD/AyQ== X-Received: by 2002:a05:600c:548f:b0:475:dd9d:297b with SMTP id 5b1f17b1804b1-47730890156mr144907085e9.33.1762268468732; Tue, 04 Nov 2025 07:01:08 -0800 (PST) Received: from ?IPV6:2a01:e0a:e10:ef90:343a:68f:2e91:95c? ([2a01:e0a:e10:ef90:343a:68f:2e91:95c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4773c2ff790sm221721105e9.7.2025.11.04.07.01.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Nov 2025 07:01:08 -0800 (PST) Message-ID: <7e3386c8-e0cc-4dc2-9be1-c938ef757896@redhat.com> Date: Tue, 4 Nov 2025 16:01:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 1/3] vu_common: Stick to size of input buffer in vu_send_single() To: Stefano Brivio , passt-dev@passt.top References: <20251103101629.1412331-1-sbrivio@redhat.com> <20251103101629.1412331-2-sbrivio@redhat.com> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; keydata= xsFNBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJ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9RJ/98/ghABHz9TN8TRo2b6WimV64FmlVn17Ri6FgFU3xNt9TTEChq AcNg88eYryKsYpFwegGpwUlaUaaGh1m9OrTzcQy+klVfZWaVJ9Nw0keoGRGb8j4XjVpL8+2x OhXKrM1fzzb8JtAuSbuzZSQPDwQEI5CKKxp7zf76J21YeRrEW4WDznPyVcDTa+tz++q2S/Bp P4W98bXCBIuQgs2m+OflERv5c3Ojldp04/S4NEjXEYRWdiCxN7ca5iPml5gLtuvhJMSy36gl U6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2TxL8enfx40PrfbDtWwqRID3WY8jLrjKfTd R3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPM oDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: <20251103101629.1412331-2-sbrivio@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: KYFafy28vOdWVnWtgb0HATd9Hj0QscSPb100-H-vE7A_1762268469 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: VQWERVFSAVEIMSIAVMW6A7FFKCRFYT5O X-Message-ID-Hash: VQWERVFSAVEIMSIAVMW6A7FFKCRFYT5O X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 11/3/25 11:16, Stefano Brivio wrote: > ...instead of copying, from the input buffer, the amount of available > bytes in the buffer provided via vhost-user. > > The existing behaviour should be harmless due to the fact that we > don't request overly large buffers from vhost-user, but it doesn't > look correct to me. I don't understand where is the problem. I think the existing behaviour is correct because the iov array is padded to size in vu_collect() by: if (iov->iov_len > size - current_size) iov->iov_len = size - current_size; total can be lesser than size but in this case we exit. So total should be equal to input size + sizeof(struct virtio_net_hdr_mrg_rxbuf). And in iov_from_buf() we copy the content of the buffer according the available room in the iovec and the size of the input buffer. Thanks, Laurent> > Signed-off-by: Stefano Brivio > --- > vu_common.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/vu_common.c b/vu_common.c > index b13b7c3..21cfb2a 100644 > --- a/vu_common.c > +++ b/vu_common.c > @@ -238,7 +238,7 @@ void vu_kick_cb(struct vu_dev *vdev, union epoll_ref ref, > * vu_send_single() - Send a buffer to the front-end using the RX virtqueue > * @c: execution context > * @buf: address of the buffer > - * @size: size of the buffer > + * @size: size of the input buffer > * > * Return: number of bytes sent, -1 if there is an error > */ > @@ -248,7 +248,7 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) > struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; > struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE]; > struct iovec in_sg[VIRTQUEUE_MAX_SIZE]; > - size_t total; > + size_t vu_buf_size; > int elem_cnt; > int i; > > @@ -261,21 +261,20 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) > > vu_init_elem(elem, in_sg, VIRTQUEUE_MAX_SIZE); > > - size += sizeof(struct virtio_net_hdr_mrg_rxbuf); > - elem_cnt = vu_collect(vdev, vq, elem, VIRTQUEUE_MAX_SIZE, size, &total); > - if (total < size) { > + elem_cnt = vu_collect(vdev, vq, elem, VIRTQUEUE_MAX_SIZE, > + size + sizeof(struct virtio_net_hdr_mrg_rxbuf), > + &vu_buf_size); > + if (vu_buf_size < size + sizeof(struct virtio_net_hdr_mrg_rxbuf)) { > debug("vu_send_single: no space to send the data " > - "elem_cnt %d size %zd", elem_cnt, total); > + "elem_cnt %d size %zd", elem_cnt, size); > goto err; > } > > vu_set_vnethdr(vdev, in_sg[0].iov_base, elem_cnt); > > - total -= sizeof(struct virtio_net_hdr_mrg_rxbuf); > - > /* copy data from the buffer to the iovec */ > iov_from_buf(in_sg, elem_cnt, sizeof(struct virtio_net_hdr_mrg_rxbuf), > - buf, total); > + buf, size); > > if (*c->pcap) { > pcap_iov(in_sg, elem_cnt, > @@ -284,9 +283,10 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size) > > vu_flush(vdev, vq, elem, elem_cnt); > > - trace("vhost-user sent %zu", total); > + trace("vhost-user sent %zu", > + vu_buf_size - sizeof(struct virtio_net_hdr_mrg_rxbuf)); > > - return total; > + return size; > err: > for (i = 0; i < elem_cnt; i++) > vu_queue_detach_element(vq);