From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 822935A0621; Mon, 03 Nov 2025 11:16:29 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top, Laurent Vivier Subject: [RFC PATCH 1/3] vu_common: Stick to size of input buffer in vu_send_single() Date: Mon, 3 Nov 2025 11:16:27 +0100 Message-ID: <20251103101629.1412331-2-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251103101629.1412331-1-sbrivio@redhat.com> References: <20251103101629.1412331-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: WBY3HM3A2GWYAYTT4ARGALJG65JI3OFF X-Message-ID-Hash: WBY3HM3A2GWYAYTT4ARGALJG65JI3OFF X-MailFrom: sbrivio@passt.top 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: ...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. 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); -- 2.43.0