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=VeWZ0sGU; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id A5EFC5A0619 for ; Mon, 09 Mar 2026 10:48:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773049681; 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=nv+qcrA1A0TUrM0M4gV8ql7/xuaJGYFxoEr2Pnyh3BA=; b=VeWZ0sGUZMYwge3huUREDExqaEmQW756NtFdhCY4lFpQwyITcyA2QShuFwN/qEegMXDSjn sXKq6BgHy3lLSbrpzLqAZlH3qXrxznd4U+Gn1YgGdR3P7p+S8f5oiv7KNrgkgdJ4Nnd/60 kLDlodxehAeO7eXMiMg4R6JyhaE25e4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-My2lhleuOymW4z1EfacGWQ-1; Mon, 09 Mar 2026 05:48:00 -0400 X-MC-Unique: My2lhleuOymW4z1EfacGWQ-1 X-Mimecast-MFC-AGG-ID: My2lhleuOymW4z1EfacGWQ_1773049679 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 087341956050 for ; Mon, 9 Mar 2026 09:47:59 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.226.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0EA821956095; Mon, 9 Mar 2026 09:47:57 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2 08/13] udp_vu: Use iov_tail in udp_vu_prepare() Date: Mon, 9 Mar 2026 10:47:39 +0100 Message-ID: <20260309094744.1907754-9-lvivier@redhat.com> In-Reply-To: <20260309094744.1907754-1-lvivier@redhat.com> References: <20260309094744.1907754-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: fa_ooIVSK2S_WktdcAQhPLUHMtFqGg0eLtMOjd07fkA_1773049679 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: WNW5FLIVRC6EWLDDJAUZHR6SY3WSA5XP X-Message-ID-Hash: WNW5FLIVRC6EWLDDJAUZHR6SY3WSA5XP 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: Rework udp_vu_prepare() to use IOV_REMOVE_HEADER() and IOV_PUT_HEADER() to walk through Ethernet, IP and UDP headers instead of the layout-specific helpers (vu_eth(), vu_ip(), vu_payloadv4(), vu_payloadv6()) that assume a contiguous buffer. The payload length is now implicit in the iov_tail, so drop the dlen parameter. Signed-off-by: Laurent Vivier --- iov.c | 1 - udp_vu.c | 64 ++++++++++++++++++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/iov.c b/iov.c index 296f24b61067..1f554f5ac297 100644 --- a/iov.c +++ b/iov.c @@ -313,7 +313,6 @@ void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align) * * Return: number of bytes written */ -/* cppcheck-suppress unusedFunction */ size_t iov_put_header_(struct iov_tail *tail, const void *v, size_t len) { size_t l = len; diff --git a/udp_vu.c b/udp_vu.c index 2a5d3f822bf6..a21a03dbf23e 100644 --- a/udp_vu.c +++ b/udp_vu.c @@ -101,52 +101,54 @@ static ssize_t udp_vu_sock_recv(struct iovec *iov, size_t *cnt, int s, bool v6) * @c: Execution context * @data: IO vector tail for the frame * @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, const struct iov_tail *data, - const struct flowside *toside, ssize_t dlen) + const struct flowside *toside) { - const struct iovec *iov = data->iov; - struct ethhdr *eh; + struct iov_tail current = *data; + struct ethhdr *eh, eh_storage; + struct udphdr *uh, uh_storage; size_t l4len; /* ethernet header */ - eh = vu_eth(iov[0].iov_base); + eh = IOV_REMOVE_HEADER(¤t, eh_storage); 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[0].iov_base); - struct udp_payload_t *bp = vu_payloadv4(iov[0].iov_base); - const struct iovec payload_iov = { - .iov_base = bp->data, - .iov_len = dlen, - }; - struct iov_tail payload = IOV_TAIL(&payload_iov, 1, 0); + struct iphdr *iph, iph_storage; eh->h_proto = htons(ETH_P_IP); + iph = IOV_REMOVE_HEADER(¤t, iph_storage); *iph = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_UDP); - l4len = udp_update_hdr4(iph, &bp->uh, &payload, toside, true); + uh = IOV_REMOVE_HEADER(¤t, uh_storage); + l4len = udp_update_hdr4(iph, uh, ¤t, toside, true); + + current = *data; + IOV_PUT_HEADER(¤t, eh); + IOV_PUT_HEADER(¤t, iph); + IOV_PUT_HEADER(¤t, uh); } else { - struct ipv6hdr *ip6h = vu_ip(iov[0].iov_base); - struct udp_payload_t *bp = vu_payloadv6(iov[0].iov_base); - const struct iovec payload_iov = { - .iov_base = bp->data, - .iov_len = dlen, - }; - struct iov_tail payload = IOV_TAIL(&payload_iov, 1, 0); + struct ipv6hdr *ip6h, ip6h_storage; eh->h_proto = htons(ETH_P_IPV6); + ip6h = IOV_REMOVE_HEADER(¤t, ip6h_storage); *ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_UDP); - l4len = udp_update_hdr6(ip6h, &bp->uh, &payload, toside, true); + uh = IOV_REMOVE_HEADER(¤t, uh_storage); + l4len = udp_update_hdr6(ip6h, uh, ¤t, toside, true); + + current = *data; + IOV_PUT_HEADER(¤t, eh); + IOV_PUT_HEADER(¤t, ip6h); + IOV_PUT_HEADER(¤t, uh); } return l4len; @@ -165,9 +167,10 @@ static void udp_vu_csum(const struct flowside *toside, struct iov_tail payload = *data; struct udphdr *uh, uh_storage; bool ipv4 = src4 && dst4; + int hdrlen = sizeof(struct ethhdr) + + (ipv4 ? sizeof(struct iphdr) : sizeof(struct ipv6hdr)); - iov_drop_header(&payload, - udp_vu_hdrlen(!ipv4) - sizeof(struct udphdr)); + iov_drop_header(&payload, hdrlen); uh = IOV_REMOVE_HEADER(&payload, uh_storage); if (ipv4) @@ -207,9 +210,9 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx) } for (i = 0; i < n; i++) { + int elem_cnt, elem_used; size_t iov_cnt; ssize_t dlen; - int elem_cnt; vu_init_elem(elem, iov_vu, ARRAY_SIZE(elem)); @@ -224,19 +227,20 @@ void udp_vu_sock_to_tap(const struct ctx *c, int s, int n, flow_sidx_t tosidx) vu_queue_rewind(vq, elem_cnt); break; } + elem_used = iov_cnt; /* release unused buffers */ - vu_queue_rewind(vq, elem_cnt - iov_cnt); - + 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, iov_cnt); - udp_vu_prepare(c, &data, toside, dlen); + vu_set_vnethdr(iov_vu[0].iov_base, elem_used); + iov_drop_header(&data, VNET_HLEN); + udp_vu_prepare(c, &data, toside); if (*c->pcap) { udp_vu_csum(toside, &data); - pcap_iov(data.iov, data.cnt, VNET_HLEN); + pcap_iov(data.iov, data.cnt, data.off); } - vu_flush(vdev, vq, elem, data.cnt); + vu_flush(vdev, vq, elem, elem_used); } } } -- 2.53.0