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=fi3mD5uZ; 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 AA6355A0262 for ; Sun, 10 May 2026 00:27:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778365676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SZy3TlYsT04+kTEXNGcpGsEJdHAhtOIoYj4fu91Tz1A=; b=fi3mD5uZkyfhD26etAPRQLUXwfyaszNGdClSEP8N9zmj3MB7uf7oboUP2XDxxhbVJ8+viZ pp92RfRD0u+j5L+kzJtd3ewpo/V7B31AVUtNHAf11e4NTsrhtcOIcKx+bG/A0XxGUd5beR oLVUkeTAObkduiGWuk0/LUC7lrm3nkU= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-Rog9g5mAOjC4Yw5cWVfDZQ-1; Sat, 09 May 2026 18:27:54 -0400 X-MC-Unique: Rog9g5mAOjC4Yw5cWVfDZQ-1 X-Mimecast-MFC-AGG-ID: Rog9g5mAOjC4Yw5cWVfDZQ_1778365674 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-5102a9671c8so72859441cf.1 for ; Sat, 09 May 2026 15:27:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778365674; x=1778970474; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SZy3TlYsT04+kTEXNGcpGsEJdHAhtOIoYj4fu91Tz1A=; b=r1RkiWKEmGOEhxlmOAeufcg8h/mDGdydfTWdkRuC+aBRcvbtfgio1AftB14OWs4STR HTe/LmvlClsbVHhtbiJyBkMpHsK5i7/hMzdI9fuVXcZagJ81JexLjYKsU/YmDTriIegG VzDZZ1CRfgYb1Q7QQVof46cmeIDjOxj7w90iAZePmbzwK3umMUopLws+AwVzUcRI7s97 L2/ay+eCHvJi12WfSF6suuDpefDmysSiVzGrAF6zOrwdpOfq4qBKt7g/hOJy/QNx7n9K VYNoz76ZiSsLibnsaQAs/9q06aNDVY4vsAKqoYnE+pOd1AXLwCs4pH/tk/uOnsGkWv+n ulDQ== X-Forwarded-Encrypted: i=1; AFNElJ9e+c+Zpt3UhWaadF4JSk1IqNev03Hu1f5va8VNNBFGVgNFawfZdXvpgy9BgxkyfaKhELYYu7GU/es=@passt.top X-Gm-Message-State: AOJu0Yy9fHaglNAQEuCXtTaPkk4JTgn+7hYAQCbovC7u13nXjz2fgpj4 FLqN1Zgqv7HMgFxOSRjsF198cI4MLQgpDoCAiFmmHg3ehuF8/9tN7+f54qjT8Ft3l+DZzbWQ2Qd jib0SqB36ocXRjKwfIeyXuGJs2mW1xJL9oT5rln9u09QIQN5krsOYlg== X-Gm-Gg: Acq92OGJ5FvUn3wOLHE/RYWCU4uKnpQ0vFTu3SoH83U7BnO3aNqujfenwzW9UyvlOBA GGNIWAVAwX0wULHBnsINfrrIjjtsn6m75UiExNfHvELJ7nqcoyYI/a/as8ZRF9du8VLAt1ANSt2 +YM5qGnYYzXRbzac9xOEWqpqFErnn09Hq0L/SNE1nkqlNTRS6ApjZHTAfd1QOUiDSQAzpHotpDs 8bIU570Acl8K0mC/vyxwuuGG730Vpp0n3pzQBqPTvlfL37rR23xvBvrA7+4doftmoHkVAbzzawi aAQxz5wUfBEHkZaNI6WeZECSW31cbFTqhpOiQYU7+bnK5FuYXsZC2+RwNjDaEZhq29qiYBJeou7 4wZLNwguB4OY4UW48fUz7CwC6gYMTvfwSWtE6P4F0wqI3514qRYtY3XTkBGOVU4CvYaJyYVEnlB WTk0XaXyBMPch1 X-Received: by 2002:ac8:5e50:0:b0:50d:8792:b6d1 with SMTP id d75a77b69052e-5148e950e36mr117799671cf.38.1778365674119; Sat, 09 May 2026 15:27:54 -0700 (PDT) X-Received: by 2002:ac8:5e50:0:b0:50d:8792:b6d1 with SMTP id d75a77b69052e-5148e950e36mr117799321cf.38.1778365673607; Sat, 09 May 2026 15:27:53 -0700 (PDT) Received: from [192.168.2.15] (lnsm4-toronto63-142-116-28-118.internet.virginmobile.ca. [142.116.28.118]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-5148e7bef56sm51904651cf.15.2026.05.09.15.27.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 09 May 2026 15:27:53 -0700 (PDT) Message-ID: Date: Sat, 9 May 2026 18:27:52 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 3/3] udp: Pass iov_tail to udp_update_hdr4()/udp_update_hdr6() To: Laurent Vivier , passt-dev@passt.top References: <20260416160926.3822963-1-lvivier@redhat.com> <20260416160926.3822963-4-lvivier@redhat.com> From: Jon Maloy In-Reply-To: <20260416160926.3822963-4-lvivier@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6uWhq_SeMggRFkk8ggDCA0gppiOP3Wo2i-xJSsZK-IU_1778365674 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: 3O7LQ2U32GDUR3GW44GSDMTR33CJV7M2 X-Message-ID-Hash: 3O7LQ2U32GDUR3GW44GSDMTR33CJV7M2 X-MailFrom: jmaloy@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 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: On 2026-04-16 12:09, Laurent Vivier wrote: > Change udp_update_hdr4() and udp_update_hdr6() to take an iov_tail > pointing at the UDP frame instead of a contiguous udp_payload_t buffer > and explicit data length. This lets vhost-user pass scatter-gather > virtqueue buffers directly without an intermediate copy. > > The UDP header is built into a local struct udphdr and written back with > IOV_PUSH_HEADER(). On the tap side, udp_tap_prepare() wraps the > existing udp_payload_t in a two-element iov to match the new interface. > > Signed-off-by: Laurent Vivier Reviewed-by: Jon Maloy > --- > iov.c | 1 - > udp.c | 70 +++++++++++++++++++++++------------------ > udp_internal.h | 4 +-- > udp_vu.c | 85 ++++++++++++++++++++++++++------------------------ > 4 files changed, 86 insertions(+), 74 deletions(-) > > diff --git a/iov.c b/iov.c > index b1bcdc4649df..c0d9c6d21322 100644 > --- a/iov.c > +++ b/iov.c > @@ -368,7 +368,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_push_header_(struct iov_tail *tail, const void *v, size_t len) > { > size_t l; > diff --git a/udp.c b/udp.c > index 4eef10854d8a..536b9a74dd15 100644 > --- a/udp.c > +++ b/udp.c > @@ -255,20 +255,21 @@ static void udp_iov_init(const struct ctx *c) > /** > * udp_update_hdr4() - Update headers for one IPv4 datagram > * @ip4h: Pre-filled IPv4 header (except for tot_len and saddr) > - * @bp: Pointer to udp_payload_t to update > + * @payload: iov_tail with datagram to update > * @toside: Flowside for destination side > * @dlen: Length of UDP payload > * @no_udp_csum: Do not set UDP checksum > * > - * Return: size of IPv4 payload (UDP header + data) > + * Return: size of datagram (UDP header + data) > */ > -size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > +size_t udp_update_hdr4(struct iphdr *ip4h, struct iov_tail *payload, > const struct flowside *toside, size_t dlen, > bool no_udp_csum) > { > const struct in_addr *src = inany_v4(&toside->oaddr); > const struct in_addr *dst = inany_v4(&toside->eaddr); > - size_t l4len = dlen + sizeof(bp->uh); > + struct udphdr uh; > + size_t l4len = dlen + sizeof(uh); > size_t l3len = l4len + sizeof(*ip4h); > > assert(src && dst); > @@ -278,19 +279,18 @@ size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > ip4h->saddr = src->s_addr; > ip4h->check = csum_ip4_header(l3len, IPPROTO_UDP, *src, *dst); > > - bp->uh.source = htons(toside->oport); > - bp->uh.dest = htons(toside->eport); > - bp->uh.len = htons(l4len); > + uh.source = htons(toside->oport); > + uh.dest = htons(toside->eport); > + uh.len = htons(l4len); > if (no_udp_csum) { > - bp->uh.check = 0; > + uh.check = 0; > } else { > - const struct iovec iov = { > - .iov_base = bp->data, > - .iov_len = dlen > - }; > - struct iov_tail data = IOV_TAIL(&iov, 1, 0); > - csum_udp4(&bp->uh, *src, *dst, &data, dlen); > + struct iov_tail data = *payload; > + > + IOV_DROP_HEADER(&data, struct udphdr); > + csum_udp4(&uh, *src, *dst, &data, dlen); > } > + IOV_PUSH_HEADER(payload, uh); > > return l4len; > } > @@ -299,18 +299,19 @@ size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > * udp_update_hdr6() - Update headers for one IPv6 datagram > * @ip6h: Pre-filled IPv6 header (except for payload_len and > * addresses) > - * @bp: Pointer to udp_payload_t to update > + * @payload: iov_tail with datagram to update > * @toside: Flowside for destination side > * @dlen: Length of UDP payload > * @no_udp_csum: Do not set UDP checksum > * > - * Return: size of IPv6 payload (UDP header + data) > + * Return: size of datagram (UDP header + data) > */ > -size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct iov_tail *payload, > const struct flowside *toside, size_t dlen, > bool no_udp_csum) > { > - uint16_t l4len = dlen + sizeof(bp->uh); > + struct udphdr uh; > + uint16_t l4len = dlen + sizeof(uh); > > ip6h->payload_len = htons(l4len); > ip6h->daddr = toside->eaddr.a6; > @@ -319,24 +320,24 @@ size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > ip6h->nexthdr = IPPROTO_UDP; > ip6h->hop_limit = 255; > > - bp->uh.source = htons(toside->oport); > - bp->uh.dest = htons(toside->eport); > - bp->uh.len = ip6h->payload_len; > + uh.source = htons(toside->oport); > + uh.dest = htons(toside->eport); > + uh.len = htons(l4len); > + > if (no_udp_csum) { > /* 0 is an invalid checksum for UDP IPv6 and dropped by > * the kernel stack, even if the checksum is disabled by virtio > * flags. We need to put any non-zero value here. > */ > - bp->uh.check = 0xffff; > + uh.check = 0xffff; > } else { > - const struct iovec iov = { > - .iov_base = bp->data, > - .iov_len = dlen > - }; > - struct iov_tail data = IOV_TAIL(&iov, 1, 0); > - csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, &data, > - dlen); > + struct iov_tail data = *payload; > + > + IOV_DROP_HEADER(&data, struct udphdr); > + csum_udp6(&uh, &toside->oaddr.a6, &toside->eaddr.a6, > + &data, dlen); > } > + IOV_PUSH_HEADER(payload, uh); > > return l4len; > } > @@ -375,11 +376,18 @@ static void udp_tap_prepare(const struct mmsghdr *mmh, > struct ethhdr *eh = (*tap_iov)[UDP_IOV_ETH].iov_base; > struct udp_payload_t *bp = &udp_payload[idx]; > struct udp_meta_t *bm = &udp_meta[idx]; > + struct iovec iov[2]; > + struct iov_tail payload = IOV_TAIL(iov, ARRAY_SIZE(iov), 0); > size_t l4len, l2len; > > + iov[0].iov_base = &bp->uh; > + iov[0].iov_len = sizeof(bp->uh); > + iov[1].iov_base = bp->data; > + iov[1].iov_len = mmh[idx].msg_len; > + > eth_update_mac(eh, NULL, tap_omac); > if (!inany_v4(&toside->eaddr) || !inany_v4(&toside->oaddr)) { > - l4len = udp_update_hdr6(&bm->ip6h, bp, toside, > + l4len = udp_update_hdr6(&bm->ip6h, &payload, toside, > mmh[idx].msg_len, no_udp_csum); > > l2len = MAX(l4len + sizeof(bm->ip6h) + ETH_HLEN, ETH_ZLEN); > @@ -388,7 +396,7 @@ static void udp_tap_prepare(const struct mmsghdr *mmh, > eh->h_proto = htons_constant(ETH_P_IPV6); > (*tap_iov)[UDP_IOV_IP] = IOV_OF_LVALUE(bm->ip6h); > } else { > - l4len = udp_update_hdr4(&bm->ip4h, bp, toside, > + l4len = udp_update_hdr4(&bm->ip4h, &payload, toside, > mmh[idx].msg_len, no_udp_csum); > > l2len = MAX(l4len + sizeof(bm->ip4h) + ETH_HLEN, ETH_ZLEN); > diff --git a/udp_internal.h b/udp_internal.h > index 64e457748324..e6cbaab79519 100644 > --- a/udp_internal.h > +++ b/udp_internal.h > @@ -25,10 +25,10 @@ struct udp_payload_t { > } __attribute__ ((packed, aligned(__alignof__(unsigned int)))); > #endif > > -size_t udp_update_hdr4(struct iphdr *ip4h, struct udp_payload_t *bp, > +size_t udp_update_hdr4(struct iphdr *ip4h, struct iov_tail *payload, > const struct flowside *toside, size_t dlen, > bool no_udp_csum); > -size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct udp_payload_t *bp, > +size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct iov_tail *payload, > const struct flowside *toside, size_t dlen, > bool no_udp_csum); > void udp_sock_fwd(const struct ctx *c, int s, int rule_hint, > diff --git a/udp_vu.c b/udp_vu.c > index ef8e60cc390a..8cf50ca1c38f 100644 > --- a/udp_vu.c > +++ b/udp_vu.c > @@ -98,69 +98,73 @@ static ssize_t udp_vu_sock_recv(struct iovec *iov, size_t *cnt, int s, bool v6) > /** > * udp_vu_prepare() - Prepare the packet header > * @c: Execution context > - * @iov: IO vector for the frame (including vnet header) > + * @data: IO vector tail for the L2 frame, on return points to the L4 header > * @toside: Address information for one side of the flow > * @dlen: Packet data length > */ > -static void udp_vu_prepare(const struct ctx *c, const struct iovec *iov, > - const struct flowside *toside, ssize_t dlen) > +static void udp_vu_prepare(const struct ctx *c, struct iov_tail *data, > + const struct flowside *toside, size_t dlen) > { > - struct ethhdr *eh; > + bool ipv4 = inany_v4(&toside->eaddr) && inany_v4(&toside->oaddr); > + struct ethhdr eh; > > /* ethernet header */ > - 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)); > > - memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > - memcpy(eh->h_source, c->our_tap_mac, sizeof(eh->h_source)); > + if (ipv4) > + eh.h_proto = htons(ETH_P_IP); > + else > + eh.h_proto = htons(ETH_P_IPV6); > + IOV_PUSH_HEADER(data, eh); > > /* 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); > - > - eh->h_proto = htons(ETH_P_IP); > + if (ipv4) { > + struct iov_tail datagram; > + struct iphdr iph = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_UDP); > > - *iph = (struct iphdr)L2_BUF_IP4_INIT(IPPROTO_UDP); > + datagram = *data; > + IOV_DROP_HEADER(&datagram, struct iphdr); > + udp_update_hdr4(&iph, &datagram, toside, dlen, true); > > - udp_update_hdr4(iph, bp, toside, dlen, true); > + IOV_PUSH_HEADER(data, iph); > } else { > - 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); > + struct iov_tail datagram; > + struct ipv6hdr ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_UDP); > > - *ip6h = (struct ipv6hdr)L2_BUF_IP6_INIT(IPPROTO_UDP); > + datagram = *data; > + IOV_DROP_HEADER(&datagram, struct ipv6hdr); > + udp_update_hdr6(&ip6h, &datagram, toside, dlen, true); > > - udp_update_hdr6(ip6h, bp, toside, dlen, true); > + IOV_PUSH_HEADER(data, ip6h); > } > } > > /** > * udp_vu_csum() - Calculate and set checksum for a UDP packet > * @toside: Address information for one side of the flow > - * @iov: IO vector for the frame > - * @cnt: Number of IO vector entries > + * @data: IO vector tail for the L4 frame (point to the UDP header) > * @dlen: Data length > */ > -static void udp_vu_csum(const struct flowside *toside, const struct iovec *iov, > - size_t cnt, size_t dlen) > +static void udp_vu_csum(const struct flowside *toside, struct iov_tail *data, > + size_t dlen) > { > const struct in_addr *src4 = inany_v4(&toside->oaddr); > const struct in_addr *dst4 = inany_v4(&toside->eaddr); > - 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, cnt, (char *)&bp->data - base); > - csum_udp4(&bp->uh, *src4, *dst4, &data, dlen); > - } else { > - bp = vu_payloadv6(base); > - data = IOV_TAIL(iov, cnt, (char *)&bp->data - base); > - csum_udp6(&bp->uh, &toside->oaddr.a6, &toside->eaddr.a6, &data, > - dlen); > - } > + struct iov_tail current = *data; > + struct udphdr *uh, uh_storage; > + bool ipv4 = src4 && dst4; > + > + uh = IOV_REMOVE_HEADER(¤t, uh_storage); > + if (!uh) > + return; > + > + if (ipv4) > + csum_udp4(uh, *src4, *dst4, ¤t, dlen); > + else > + csum_udp6(uh, &toside->oaddr.a6, &toside->eaddr.a6, ¤t, dlen); > + > + IOV_PUSH_HEADER(data, *uh); > } > > /** > @@ -227,9 +231,10 @@ 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, iov_vu, toside, dlen); > + struct iov_tail data = IOV_TAIL(iov_vu, iov_cnt, VNET_HLEN); > + udp_vu_prepare(c, &data, toside, dlen); > if (*c->pcap) { > - udp_vu_csum(toside, iov_vu, iov_cnt, dlen); > + udp_vu_csum(toside, &data, dlen); > pcap_iov(iov_vu, iov_cnt, VNET_HLEN, > hdrlen + dlen - VNET_HLEN); > }