From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top, Laurent Vivier <lvivier@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
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 [thread overview]
Message-ID: <20251103101629.1412331-2-sbrivio@redhat.com> (raw)
In-Reply-To: <20251103101629.1412331-1-sbrivio@redhat.com>
...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 <sbrivio@redhat.com>
---
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
next prev parent reply other threads:[~2025-11-03 10:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 10:16 [RFC PATCH 0/3] Fill exceeding size of vhost-user buffers explicitly Stefano Brivio
2025-11-03 10:16 ` Stefano Brivio [this message]
2025-11-04 15:01 ` [RFC PATCH 1/3] vu_common: Stick to size of input buffer in vu_send_single() Laurent Vivier
2025-11-04 16:09 ` Stefano Brivio
2025-11-04 16:24 ` Laurent Vivier
2025-11-03 10:16 ` [RFC PATCH 2/3] iov: Fix coding style of basic (non-IOV_TAIL) parts Stefano Brivio
2025-11-04 15:14 ` Laurent Vivier
2025-11-05 3:58 ` David Gibson
2025-11-03 10:16 ` [RFC PATCH 3/3] iov, vu_common: Make iov_from_buf() fill destination iov entirely Stefano Brivio
2025-11-04 15:11 ` Laurent Vivier
2025-11-05 4:01 ` David Gibson
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=20251103101629.1412331-2-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).