public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH 08/12] vu_common: Pass iov_tail to vu_set_vnethdr()
Date: Fri, 27 Feb 2026 15:03:26 +0100	[thread overview]
Message-ID: <20260227140330.2216753-9-lvivier@redhat.com> (raw)
In-Reply-To: <20260227140330.2216753-1-lvivier@redhat.com>

Refactor vu_set_vnethdr() to take an iov_tail pointer instead of a
direct pointer to the virtio_net_hdr_mrg_rxbuf structure.
This makes the function use IOV_PEEK_HEADER() and IOV_PUT_HEADER()
to read and write the virtio-net header through the iov_tail abstraction.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 tcp_vu.c    |  8 +++++---
 udp_vu.c    |  3 +--
 vu_common.c | 24 ++++++++++++++++--------
 vu_common.h |  3 +--
 4 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/tcp_vu.c b/tcp_vu.c
index 98e5974fee0e..92667507ac9b 100644
--- a/tcp_vu.c
+++ b/tcp_vu.c
@@ -94,10 +94,11 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
 	if (elem_cnt != 1)
 		return -1;
 
-	ASSERT(flags_elem[0].in_sg[0].iov_len >=
+	payload = IOV_TAIL(&flags_elem[0].in_sg[0], elem_cnt, 0);
+	ASSERT(iov_tail_size(&payload) >=
 	       MAX(hdrlen + sizeof(*opts), ETH_ZLEN + VNET_HLEN));
 
-	vu_set_vnethdr(vdev, flags_elem[0].in_sg[0].iov_base, 1);
+	vu_set_vnethdr(vdev, &payload, 1);
 
 	eh = vu_eth(flags_elem[0].in_sg[0].iov_base);
 
@@ -448,11 +449,12 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
 	for (i = 0, previous_dlen = -1, check = NULL; i < head_cnt; i++) {
 		struct iovec *iov = &elem[head[i]].in_sg[0];
 		int buf_cnt = head[i + 1] - head[i];
+		struct iov_tail data = IOV_TAIL(iov, buf_cnt, 0);
 		ssize_t dlen = iov_size(iov, buf_cnt) - hdrlen;
 		bool push = i == head_cnt - 1;
 		size_t l2len;
 
-		vu_set_vnethdr(vdev, iov->iov_base, buf_cnt);
+		vu_set_vnethdr(vdev, &data, buf_cnt);
 
 		/* The IPv4 header checksum varies only with dlen */
 		if (previous_dlen != dlen)
diff --git a/udp_vu.c b/udp_vu.c
index 6d87f4872268..5ae79b9bb0c5 100644
--- a/udp_vu.c
+++ b/udp_vu.c
@@ -234,8 +234,7 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx)
 		vu_queue_rewind(vq, elem_cnt - elem_used);
 
 		if (data.cnt > 0) {
-			vu_set_vnethdr(vdev, data.iov[0].iov_base, elem_used);
-			iov_drop_header(&data, VNET_HLEN);
+			vu_set_vnethdr(vdev, &data, elem_used);
 			udp_vu_prepare(c, &data, toside);
 			if (*c->pcap) {
 				udp_vu_csum(toside, &data);
diff --git a/vu_common.c b/vu_common.c
index 7a8cd18f4e81..a8d5fcdaea83 100644
--- a/vu_common.c
+++ b/vu_common.c
@@ -120,18 +120,25 @@ int vu_collect(const struct vu_dev *vdev, struct vu_virtq *vq,
 }
 
 /**
- * vu_set_vnethdr() - set virtio-net headers
+ * vu_set_vnethdr() - set virtio-net header
  * @vdev:		vhost-user device
- * @vnethdr:		Address of the header to set
+ * @data:		IOV tail to write header to, updated to
+ * 			point after the virtio-net header
  * @num_buffers:	Number of guest buffers of the frame
  */
-void vu_set_vnethdr(const struct vu_dev *vdev,
-		    struct virtio_net_hdr_mrg_rxbuf *vnethdr,
+void vu_set_vnethdr(const struct vu_dev *vdev, struct iov_tail *data,
 		    int num_buffers)
 {
+	struct virtio_net_hdr_mrg_rxbuf vnethdr_storage, *vnethdr;
+
+	vnethdr = IOV_PEEK_HEADER(data, vnethdr_storage);
+
 	vnethdr->hdr = VU_HEADER;
+
 	if (vu_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
 		vnethdr->num_buffers = htole16(num_buffers);
+
+	IOV_PUT_HEADER(data, vnethdr);
 }
 
 /**
@@ -248,6 +255,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];
+	struct iov_tail data;
 	size_t total;
 	int elem_cnt;
 	int i;
@@ -269,15 +277,15 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size)
 		goto err;
 	}
 
-	vu_set_vnethdr(vdev, in_sg[0].iov_base, elem_cnt);
-
+	data = IOV_TAIL(&in_sg[0], elem_cnt, 0);
+	vu_set_vnethdr(vdev, &data, elem_cnt);
 	total -= VNET_HLEN;
 
 	/* copy data from the buffer to the iovec */
-	iov_from_buf(in_sg, elem_cnt, VNET_HLEN, buf, total);
+	iov_from_buf(data.iov, data.cnt, data.off, buf, total);
 
 	if (*c->pcap)
-		pcap_iov(in_sg, elem_cnt, VNET_HLEN);
+		pcap_iov(data.iov, data.cnt, data.off);
 
 	vu_flush(vdev, vq, elem, elem_cnt);
 
diff --git a/vu_common.h b/vu_common.h
index 052aff710502..41cf18936300 100644
--- a/vu_common.h
+++ b/vu_common.h
@@ -49,8 +49,7 @@ void vu_init_elem(struct vu_virtq_element *elem, struct iovec *iov,
 int vu_collect(const struct vu_dev *vdev, struct vu_virtq *vq,
 	       struct vu_virtq_element *elem, int max_elem, size_t size,
 	       size_t *collected);
-void vu_set_vnethdr(const struct vu_dev *vdev,
-		    struct virtio_net_hdr_mrg_rxbuf *vnethdr,
+void vu_set_vnethdr(const struct vu_dev *vdev, struct iov_tail *data,
 		    int num_buffers);
 void vu_flush(const struct vu_dev *vdev, struct vu_virtq *vq,
 	      struct vu_virtq_element *elem, int elem_cnt);
-- 
2.53.0


  parent reply	other threads:[~2026-02-27 14:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 14:03 [PATCH 00/12] vhost-user,udp: Handle multiple iovec entries per virtqueue element Laurent Vivier
2026-02-27 14:03 ` [PATCH 01/12] iov: Add iov_tail_truncate() and iov_tail_zero_end() Laurent Vivier
2026-03-01 23:47   ` David Gibson
2026-02-27 14:03 ` [PATCH 02/12] vhost-user: Use ARRAY_SIZE(elem) instead of VIRTQUEUE_MAX_SIZE Laurent Vivier
2026-03-01 23:48   ` David Gibson
2026-02-27 14:03 ` [PATCH 03/12] udp_vu: Use iov_tail to manage virtqueue buffers Laurent Vivier
2026-03-02  0:03   ` David Gibson
2026-02-27 14:03 ` [PATCH 04/12] udp_vu: Move virtqueue management from udp_vu_sock_recv() to its caller Laurent Vivier
2026-03-02  0:05   ` David Gibson
2026-02-27 14:03 ` [PATCH 05/12] iov: Add IOV_PUT_HEADER() to write header data back to iov_tail Laurent Vivier
2026-03-02  0:08   ` David Gibson
2026-02-27 14:03 ` [PATCH 06/12] udp: Pass iov_tail to udp_update_hdr4()/udp_update_hdr6() Laurent Vivier
2026-03-02  0:13   ` David Gibson
2026-02-27 14:03 ` [PATCH 07/12] udp_vu: Use iov_tail in udp_vu_prepare() Laurent Vivier
2026-03-02  0:24   ` David Gibson
2026-02-27 14:03 ` Laurent Vivier [this message]
2026-03-02  0:51   ` [PATCH 08/12] vu_common: Pass iov_tail to vu_set_vnethdr() David Gibson
2026-02-27 14:03 ` [PATCH 09/12] vu_common: Accept explicit iovec counts in vu_set_element() Laurent Vivier
2026-03-02  0:54   ` David Gibson
2026-02-27 14:03 ` [PATCH 10/12] vu_common: Accept explicit iovec count per element in vu_init_elem() Laurent Vivier
2026-03-02  0:55   ` David Gibson
2026-02-27 14:03 ` [PATCH 11/12] vu_common: Prepare to use multibuffer with guest RX Laurent Vivier
2026-03-02  0:59   ` David Gibson
2026-02-27 14:03 ` [PATCH 12/12] vhost-user,udp: Use 2 iovec entries per element Laurent Vivier
2026-03-02  1:03   ` 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=20260227140330.2216753-9-lvivier@redhat.com \
    --to=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).