On 2026-04-16 11:57, Laurent Vivier wrote:
udp_vu_sock_recv(), udp_vu_prepare(), and udp_vu_csum() all operated on the file-scoped iov_vu[] array directly. Pass iov and count as explicit parameters instead, and move iov_vu[] and elem[] to function-local statics in udp_vu_sock_to_tap(), the only function that needs them.
Signed-off-by: Laurent Vivier
Reviewed-by: David Gibson
Reviewed-by: Jon Maloy
--- udp_vu.c | 67 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 32 deletions(-)
[...] oside, int iov_used)
+static void udp_vu_csum(const struct flowside *toside, const struct iovec *iov, + size_t cnt) { const struct in_addr *src4 = inany_v4(&toside->oaddr); const struct in_addr *dst4 = inany_v4(&toside->eaddr); - char *base = iov_vu[0].iov_base; + char *base = iov[0].iov_base; struct udp_payload_t *bp; struct iov_tail data;
if (src4 && dst4) { bp = vu_payloadv4(base); - data = IOV_TAIL(iov_vu, iov_used, (char *)&bp->data - base); + data = IOV_TAIL(iov, cnt, (char *)&bp->data - base); csum_udp4(&bp->uh, *src4, *dst4, &data); } else { bp = vu_payloadv6(base); - data = IOV_TAIL(iov_vu, iov_used, (char *)&bp->data - base); + data = IOV_TAIL(iov, cnt, (char *)&bp->data - base); csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, &data); } } @@ -179,7 +180,9 @@ static void udp_vu_csum(const struct flowside *toside, int iov_used) void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx) { const struct flowside *toside = flowside_at_sidx(tosidx); + static struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE];
I think this declaration should move one line down. /jon
bool v6 = !(inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)); + static struct iovec iov_vu[VIRTQUEUE_MAX_SIZE]; struct vu_dev *vdev = c->vdev; struct vu_virtq *vq = &vdev->vq[VHOST_USER_RX_QUEUE]; int i; @@ -212,9 +215,9 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx)
assert((size_t)elem_cnt == iov_cnt); /* one iovec per element */
- dlen = udp_vu_sock_recv(s, v6, &iov_cnt); + dlen = udp_vu_sock_recv(iov_vu, &iov_cnt, s, v6); if (dlen < 0) { - vu_queue_rewind(vq, iov_cnt); + vu_queue_rewind(vq, elem_cnt); break; }
@@ -224,12 +227,12 @@ 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) { - udp_vu_prepare(c, toside, dlen); + udp_vu_prepare(c, iov_vu, toside, dlen); if (*c->pcap) { - udp_vu_csum(toside, iov_cnt); + udp_vu_csum(toside, iov_vu, iov_cnt); pcap_iov(iov_vu, iov_cnt, VNET_HLEN); } - vu_flush(vdev, vq, elem, iov_cnt); + vu_flush(vdev, vq, elem, elem_used); vu_queue_notify(vdev, vq); } }