From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BBjHEeSA; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 54A305A0262 for ; Fri, 27 Mar 2026 18:58:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774634327; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OzoZ3Qhk/C4DFLoJxtyPbUoVy5Wok2Ue28aguF0/Isc=; b=BBjHEeSAKKXlUfpREo6VL7eqIIUTDQpJS79XirX0PEtwgw2KXuM2lp0M1fJnch1TiDbl16 xIaLsXzTmc/Ey4vBtZaadKywrXyCkMbybg6AHlclEajWkKcf5IsPCcNmvypqgun1ChFneo 8sH1UqGRCiTayLoRx0NsgrBu92AMKXI= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-247-QN_whE9sOtOnAtLa-gztrA-1; Fri, 27 Mar 2026 13:58:45 -0400 X-MC-Unique: QN_whE9sOtOnAtLa-gztrA-1 X-Mimecast-MFC-AGG-ID: QN_whE9sOtOnAtLa-gztrA_1774634325 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C748B18002C7 for ; Fri, 27 Mar 2026 17:58:44 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.96]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2AC61800351; Fri, 27 Mar 2026 17:58:43 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v5 5/8] udp_vu: Pass iov explicitly to helpers instead of using file-scoped array Date: Fri, 27 Mar 2026 18:58:31 +0100 Message-ID: <20260327175834.831995-6-lvivier@redhat.com> In-Reply-To: <20260327175834.831995-1-lvivier@redhat.com> References: <20260327175834.831995-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: k-1eP1Rm7iEHmYyh-PIrm324dZN6WODdhLA-PVI0O_M_1774634325 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: TGOOTFCRNMR2VD5ZN3TEMQGSTJ5FJJNZ X-Message-ID-Hash: TGOOTFCRNMR2VD5ZN3TEMQGSTJ5FJJNZ X-MailFrom: lvivier@redhat.com 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: Laurent Vivier 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: 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 --- udp_vu.c | 62 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/udp_vu.c b/udp_vu.c index 90d5cd71bab2..d9de97ac5e13 100644 --- a/udp_vu.c +++ b/udp_vu.c @@ -33,9 +33,6 @@ #include "udp_vu.h" #include "vu_common.h" -static struct iovec iov_vu [VIRTQUEUE_MAX_SIZE]; -static struct vu_virtq_element elem [VIRTQUEUE_MAX_SIZE]; - /** * udp_vu_hdrlen() - Sum size of all headers, from UDP to virtio-net * @v6: Set for IPv6 packet @@ -58,14 +55,14 @@ static size_t udp_vu_hdrlen(bool v6) /** * udp_vu_sock_recv() - Receive datagrams from socket into vhost-user buffers + * @iov: IO vector for the frame (in/out) + * @cnt: Number of IO vector entries (in/out) * @s: Socket to receive from * @v6: Set for IPv6 connections - * @iov_cnt: Number of collected iov in iov_vu (input) - * Number of iov entries used to store the datagram (output) * * Return: size of received data, -1 on error */ -static ssize_t udp_vu_sock_recv(int s, bool v6, size_t *iov_cnt) +static ssize_t udp_vu_sock_recv(struct iovec *iov, size_t *cnt, int s, bool v6) { struct msghdr msg = { 0 }; size_t hdrlen; @@ -75,23 +72,23 @@ static ssize_t udp_vu_sock_recv(int s, bool v6, size_t *iov_cnt) hdrlen = udp_vu_hdrlen(v6); /* reserve space for the headers */ - assert(iov_vu[0].iov_len >= MAX(hdrlen, ETH_ZLEN + VNET_HLEN)); - iov_vu[0].iov_base = (char *)iov_vu[0].iov_base + hdrlen; - iov_vu[0].iov_len -= hdrlen; + assert(iov[0].iov_len >= MAX(hdrlen, ETH_ZLEN + VNET_HLEN)); + iov[0].iov_base = (char *)iov[0].iov_base + hdrlen; + iov[0].iov_len -= hdrlen; /* read data from the socket */ - msg.msg_iov = iov_vu; - msg.msg_iovlen = *iov_cnt; + msg.msg_iov = iov; + msg.msg_iovlen = *cnt; dlen = recvmsg(s, &msg, 0); if (dlen < 0) return -1; /* restore the pointer to the headers address */ - iov_vu[0].iov_base = (char *)iov_vu[0].iov_base - hdrlen; - iov_vu[0].iov_len += hdrlen; + iov[0].iov_base = (char *)iov[0].iov_base - hdrlen; + iov[0].iov_len += hdrlen; - *iov_cnt = vu_pad(iov_vu, *iov_cnt, 0, dlen + hdrlen); + *cnt = vu_pad(iov, *cnt, 0, dlen + hdrlen); return dlen; } @@ -99,27 +96,28 @@ static ssize_t udp_vu_sock_recv(int s, bool v6, size_t *iov_cnt) /** * udp_vu_prepare() - Prepare the packet header * @c: Execution context + * @iov: IO vector for the frame (including vnet header) * @toside: Address information for one side of the flow * @dlen: Packet data length * * Return: Layer-4 length */ -static size_t udp_vu_prepare(const struct ctx *c, +static size_t udp_vu_prepare(const struct ctx *c, const struct iovec *iov, const struct flowside *toside, ssize_t dlen) { struct ethhdr *eh; size_t l4len; /* ethernet header */ - eh = vu_eth(iov_vu[0].iov_base); + eh = vu_eth(iov[0].iov_base); memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); memcpy(eh->h_source, c->our_tap_mac, sizeof(eh->h_source)); /* initialize header */ if (inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr)) { - struct iphdr *iph = vu_ip(iov_vu[0].iov_base); - struct udp_payload_t *bp = vu_payloadv4(iov_vu[0].iov_base); + struct iphdr *iph = vu_ip(iov[0].iov_base); + struct udp_payload_t *bp = vu_payloadv4(iov[0].iov_base); eh->h_proto = htons(ETH_P_IP); @@ -127,8 +125,8 @@ static size_t udp_vu_prepare(const struct ctx *c, l4len = udp_update_hdr4(iph, bp, toside, dlen, true); } else { - struct ipv6hdr *ip6h = vu_ip(iov_vu[0].iov_base); - struct udp_payload_t *bp = vu_payloadv6(iov_vu[0].iov_base); + struct ipv6hdr *ip6h = vu_ip(iov[0].iov_base); + struct udp_payload_t *bp = vu_payloadv6(iov[0].iov_base); eh->h_proto = htons(ETH_P_IPV6); @@ -143,23 +141,25 @@ static size_t udp_vu_prepare(const struct ctx *c, /** * udp_vu_csum() - Calculate and set checksum for a UDP packet * @toside: Address information for one side of the flow - * @iov_used: Number of used iov_vu items + * @iov: IO vector for the frame + * @cnt: Number of IO vector entries */ -static void udp_vu_csum(const struct flowside *toside, 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); } } @@ -174,7 +174,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]; 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; @@ -207,9 +209,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; } @@ -219,12 +221,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); } } -- 2.53.0