From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 09/13] vu_common: Pass iov_tail to vu_set_vnethdr()
Date: Thu, 12 Mar 2026 15:34:25 +1100 [thread overview]
Message-ID: <abJCUYXKjhNoF7hl@zatzit> (raw)
In-Reply-To: <20260309094744.1907754-10-lvivier@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 5639 bytes --]
On Mon, Mar 09, 2026 at 10:47:40AM +0100, Laurent Vivier wrote:
> 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>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> tcp_vu.c | 8 +++++---
> udp_vu.c | 3 +--
> vu_common.c | 21 +++++++++++++++------
> vu_common.h | 2 +-
> 4 files changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/tcp_vu.c b/tcp_vu.c
> index 8da2dcfe78d0..688f48905d46 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(flags_elem[0].in_sg[0].iov_base, 1);
> + vu_set_vnethdr(&payload, 1);
>
> eh = vu_eth(flags_elem[0].in_sg[0].iov_base);
>
> @@ -454,6 +455,7 @@ 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);
> size_t frame_size = iov_size(iov, buf_cnt);
> bool push = i == head_cnt - 1;
> ssize_t dlen;
> @@ -461,7 +463,7 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
> ASSERT(frame_size >= hdrlen);
>
> dlen = frame_size - hdrlen;
> - vu_set_vnethdr(iov->iov_base, buf_cnt);
> + vu_set_vnethdr(&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 a21a03dbf23e..414750ff742a 100644
> --- a/udp_vu.c
> +++ b/udp_vu.c
> @@ -233,8 +233,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 (iov_cnt > 0) {
> struct iov_tail data = IOV_TAIL(iov_vu, iov_cnt, 0);
> - vu_set_vnethdr(iov_vu[0].iov_base, elem_used);
> - iov_drop_header(&data, VNET_HLEN);
> + vu_set_vnethdr(&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 8afa5199908f..3538e59581b7 100644
> --- a/vu_common.c
> +++ b/vu_common.c
> @@ -120,17 +120,24 @@ int vu_collect(const struct vu_dev *vdev, struct vu_virtq *vq,
> }
>
> /**
> - * vu_set_vnethdr() - set virtio-net headers
> - * @vnethdr: Address of the header to set
> + * vu_set_vnethdr() - set virtio-net header
> + * @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(struct virtio_net_hdr_mrg_rxbuf *vnethdr, int num_buffers)
> +void vu_set_vnethdr(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;
> /* Note: if VIRTIO_NET_F_MRG_RXBUF is not negotiated,
> * num_buffers must be 1
> */
> vnethdr->num_buffers = htole16(num_buffers);
> +
> + IOV_PUT_HEADER(data, vnethdr);
> }
>
> /**
> @@ -267,6 +274,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;
> @@ -295,15 +303,16 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size)
> }
> elem_cnt = iov_truncate(in_sg, elem_cnt, size);
>
> - vu_set_vnethdr(in_sg[0].iov_base, elem_cnt);
> + data = IOV_TAIL(&in_sg[0], elem_cnt, 0);
> + vu_set_vnethdr(&data, elem_cnt);
>
> size -= VNET_HLEN;
>
> /* copy data from the buffer to the iovec */
> - iov_from_buf(in_sg, elem_cnt, VNET_HLEN, buf, size);
> + iov_from_buf(in_sg, elem_cnt, data.off, buf, size);
>
> 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 5de0c987b936..d068c61695f8 100644
> --- a/vu_common.h
> +++ b/vu_common.h
> @@ -55,7 +55,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(struct virtio_net_hdr_mrg_rxbuf *vnethdr, int num_buffers);
> +void vu_set_vnethdr(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);
> void vu_kick_cb(struct vu_dev *vdev, union epoll_ref ref,
> --
> 2.53.0
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-03-12 4:39 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 9:47 [PATCH v2 00/13] vhost-user,udp: Handle multiple iovec entries per virtqueue element Laurent Vivier
2026-03-09 9:47 ` [PATCH v2 01/13] iov: Add iov_truncate() helper and use it in vu handlers Laurent Vivier
2026-03-09 9:47 ` [PATCH v2 02/13] vhost-user: Centralise 802.3 frame padding in vu_collect() and vu_flush() Laurent Vivier
2026-03-12 2:05 ` David Gibson
2026-03-09 9:47 ` [PATCH v2 03/13] vhost-user: Use ARRAY_SIZE(elem) instead of VIRTQUEUE_MAX_SIZE Laurent Vivier
2026-03-09 9:47 ` [PATCH v2 04/13] udp_vu: Use iov_tail to manage virtqueue buffers Laurent Vivier
2026-03-12 2:38 ` David Gibson
2026-03-09 9:47 ` [PATCH v2 05/13] udp_vu: Move virtqueue management from udp_vu_sock_recv() to its caller Laurent Vivier
2026-03-12 3:44 ` David Gibson
2026-03-09 9:47 ` [PATCH v2 06/13] iov: Add IOV_PUT_HEADER() to write header data back to iov_tail Laurent Vivier
2026-03-12 4:12 ` David Gibson
2026-03-12 8:20 ` Laurent Vivier
2026-03-09 9:47 ` [PATCH v2 07/13] udp: Pass iov_tail to udp_update_hdr4()/udp_update_hdr6() Laurent Vivier
2026-03-12 4:16 ` David Gibson
2026-03-09 9:47 ` [PATCH v2 08/13] udp_vu: Use iov_tail in udp_vu_prepare() Laurent Vivier
2026-03-12 4:30 ` David Gibson
2026-03-12 8:19 ` Laurent Vivier
2026-03-12 9:51 ` David Gibson
2026-03-09 9:47 ` [PATCH v2 09/13] vu_common: Pass iov_tail to vu_set_vnethdr() Laurent Vivier
2026-03-12 4:34 ` David Gibson [this message]
2026-03-09 9:47 ` [PATCH v2 10/13] vu_common: Accept explicit iovec counts in vu_set_element() Laurent Vivier
2026-03-09 9:47 ` [PATCH v2 11/13] vu_common: Accept explicit iovec count per element in vu_init_elem() Laurent Vivier
2026-03-09 9:47 ` [PATCH v2 12/13] vu_common: Prepare to use multibuffer with guest RX Laurent Vivier
2026-03-09 9:47 ` [PATCH v2 13/13] vhost-user,udp: Use 2 iovec entries per element Laurent Vivier
2026-03-12 4:39 ` David Gibson
2026-03-12 8:08 ` Laurent Vivier
2026-03-12 9:47 ` David Gibson
2026-03-12 10:42 ` Laurent Vivier
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=abJCUYXKjhNoF7hl@zatzit \
--to=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).