From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=bZ7d04Qz; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 12B1A5A0008 for ; Thu, 03 Apr 2025 07:38:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1743658684; bh=WJIu+Jf19zHj94sA81a9uUm60P91px0tvd4y6KOTCw0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bZ7d04QzniLKTuI+f9PL8bIURrFamRb3Ki5PPgheEfbGoqAxFA44h7q583kxIpdFk +igQR9WhTQ9QuOIyG4360gdEEGLml0s21UOQ4+bc33u21e/2vysT13lUHmIYUNpJxP 2tvhY8F9wgtu0IPYhe8wKfF/SxhOqMKN9AAHoL2BfUUjI1ohanrimGr7kO3RGm6Zt0 EX6MVP5iIE0V1pzRrUIUxNJW1qgnWAhKVL/QEhUA5avJsqKgmZr7GzmK8OzjvLSDvf 1kopUqRpSx2KfbpQp3h/NodhIA29WwK3mRcpkFlW5TTasr47jTNH4uB2RbEx1U3Wg5 WL2VjI2n152TQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZSr9m559Lz4wc4; Thu, 3 Apr 2025 16:38:04 +1100 (AEDT) Date: Thu, 3 Apr 2025 15:54:09 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 04/18] packet: Use iov_tail with packet_add() Message-ID: References: <20250402172343.858187-1-lvivier@redhat.com> <20250402172343.858187-5-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4iZ2aGX30ozweTbJ" Content-Disposition: inline In-Reply-To: <20250402172343.858187-5-lvivier@redhat.com> Message-ID-Hash: QR64XCFJP55M72PMQZ27HEZIUO4N4ICO X-Message-ID-Hash: QR64XCFJP55M72PMQZ27HEZIUO4N4ICO X-MailFrom: dgibson@gandalf.ozlabs.org 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: passt-dev@passt.top 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: --4iZ2aGX30ozweTbJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 02, 2025 at 07:23:29PM +0200, Laurent Vivier wrote: Needs at least some sort of commit message. > Signed-off-by: Laurent Vivier But otherwise, Reviewed-by: David Gibson > --- > iov.h | 1 + > packet.c | 15 ++++++++++++--- > packet.h | 8 +++++--- > tap.c | 32 ++++++++++++++++++-------------- > 4 files changed, 36 insertions(+), 20 deletions(-) >=20 > diff --git a/iov.h b/iov.h > index f9b5fdf0803e..99442d031549 100644 > --- a/iov.h > +++ b/iov.h > @@ -17,6 +17,7 @@ > =20 > #include > #include > +#include > =20 > #define IOV_OF_LVALUE(lval) \ > (struct iovec){ .iov_base =3D &(lval), .iov_len =3D sizeof(lval) } > diff --git a/packet.c b/packet.c > index bcac03750dc0..8b11e0850ff6 100644 > --- a/packet.c > +++ b/packet.c > @@ -64,15 +64,16 @@ static int packet_check_range(const struct pool *p, c= onst char *ptr, size_t len, > /** > * packet_add_do() - Add data as packet descriptor to given pool > * @p: Existing pool > - * @len: Length of new descriptor > - * @start: Start of data > + * @data: Data to add > * @func: For tracing: name of calling function, NULL means no trace() > * @line: For tracing: caller line of function call > */ > -void packet_add_do(struct pool *p, size_t len, const char *start, > +void packet_add_do(struct pool *p, struct iov_tail *data, > const char *func, int line) > { > size_t idx =3D p->count; > + const char *start; > + size_t len; > =20 > if (idx >=3D p->size) { > trace("add packet index %zu to pool with size %zu, %s:%i", > @@ -80,6 +81,14 @@ void packet_add_do(struct pool *p, size_t len, const c= har *start, > return; > } > =20 > + if (!iov_tail_prune(data)) > + return; > + > + ASSERT(data->cnt =3D=3D 1); /* we don't support iovec */ > + > + len =3D data->iov[0].iov_len - data->off; > + start =3D (char *)data->iov[0].iov_base + data->off; > + > if (packet_check_range(p, start, len, func, line)) > return; > =20 > diff --git a/packet.h b/packet.h > index d099f026631b..f386295da203 100644 > --- a/packet.h > +++ b/packet.h > @@ -6,6 +6,8 @@ > #ifndef PACKET_H > #define PACKET_H > =20 > +#include "iov.h" > + > /* Maximum size of a single packet stored in pool, including headers */ > #define PACKET_MAX_LEN UINT16_MAX > =20 > @@ -28,15 +30,15 @@ struct pool { > }; > =20 > int vu_packet_check_range(void *buf, const char *ptr, size_t len); > -void packet_add_do(struct pool *p, size_t len, const char *start, > +void packet_add_do(struct pool *p, struct iov_tail *data, > const char *func, int line); > void *packet_get_do(const struct pool *p, const size_t idx, > size_t offset, size_t len, size_t *left, > const char *func, int line); > void pool_flush(struct pool *p); > =20 > -#define packet_add(p, len, start) \ > - packet_add_do(p, len, start, __func__, __LINE__) > +#define packet_add(p, data) \ > + packet_add_do(p, data, __func__, __LINE__) > =20 > #define packet_get(p, idx, offset, len, left) \ > packet_get_do(p, idx, offset, len, left, __func__, __LINE__) > diff --git a/tap.c b/tap.c > index ab3effe80f89..4b54807c4101 100644 > --- a/tap.c > +++ b/tap.c > @@ -683,6 +683,7 @@ resume: > size_t l2len, l3len, hlen, l4len; > const struct ethhdr *eh; > const struct udphdr *uh; > + struct iov_tail data; > struct iphdr *iph; > const char *l4h; > =20 > @@ -694,7 +695,8 @@ resume: > if (ntohs(eh->h_proto) =3D=3D ETH_P_ARP) { > PACKET_POOL_P(pkt, 1, in->buf, in->buf_size); > =20 > - packet_add(pkt, l2len, (char *)eh); > + data =3D IOV_TAIL_FROM_BUF((void *)eh, l2len, 0); > + packet_add(pkt, &data); > arp(c, pkt); > continue; > } > @@ -739,7 +741,8 @@ resume: > =20 > tap_packet_debug(iph, NULL, NULL, 0, NULL, 1); > =20 > - packet_add(pkt, l4len, l4h); > + data =3D IOV_TAIL_FROM_BUF((void *)l4h, l4len, 0); > + packet_add(pkt, &data); > icmp_tap_handler(c, PIF_TAP, AF_INET, > &iph->saddr, &iph->daddr, > pkt, now); > @@ -753,7 +756,8 @@ resume: > if (iph->protocol =3D=3D IPPROTO_UDP) { > PACKET_POOL_P(pkt, 1, in->buf, in->buf_size); > =20 > - packet_add(pkt, l2len, (char *)eh); > + data =3D IOV_TAIL_FROM_BUF((void *)eh, l2len, 0); > + packet_add(pkt, &data); > if (dhcp(c, pkt)) > continue; > } > @@ -802,7 +806,8 @@ resume: > #undef L4_SET > =20 > append: > - packet_add((struct pool *)&seq->p, l4len, l4h); > + data =3D IOV_TAIL_FROM_BUF((void *)l4h, l4len, 0); > + packet_add((struct pool *)&seq->p, &data); > } > =20 > for (j =3D 0, seq =3D tap4_l4; j < seq_count; j++, seq++) { > @@ -858,6 +863,7 @@ resume: > struct in6_addr *saddr, *daddr; > const struct ethhdr *eh; > const struct udphdr *uh; > + struct iov_tail data; > struct ipv6hdr *ip6h; > uint8_t proto; > char *l4h; > @@ -911,7 +917,8 @@ resume: > if (l4len < sizeof(struct icmp6hdr)) > continue; > =20 > - packet_add(pkt, l4len, l4h); > + data =3D IOV_TAIL_FROM_BUF(l4h, l4len, 0); > + packet_add(pkt, &data); > =20 > if (ndp(c, (struct icmp6hdr *)l4h, saddr, pkt)) > continue; > @@ -930,7 +937,8 @@ resume: > if (proto =3D=3D IPPROTO_UDP) { > PACKET_POOL_P(pkt, 1, in->buf, in->buf_size); > =20 > - packet_add(pkt, l4len, l4h); > + data =3D IOV_TAIL_FROM_BUF(l4h, l4len, 0); > + packet_add(pkt, &data); > =20 > if (dhcpv6(c, pkt, saddr, daddr)) > continue; > @@ -984,7 +992,8 @@ resume: > #undef L4_SET > =20 > append: > - packet_add((struct pool *)&seq->p, l4len, l4h); > + data =3D IOV_TAIL_FROM_BUF(l4h, l4len, 0); > + packet_add((struct pool *)&seq->p, &data); > } > =20 > for (j =3D 0, seq =3D tap6_l4; j < seq_count; j++, seq++) { > @@ -1058,18 +1067,13 @@ void tap_add_packet(struct ctx *c, struct iov_tai= l *data) > proto_update_l2_buf(c->guest_mac, NULL); > } > =20 > - iov_tail_prune(data); > - ASSERT(data->cnt =3D=3D 1); /* packet_add() doesn't support iovec */ > - > switch (ntohs(eh->h_proto)) { > case ETH_P_ARP: > case ETH_P_IP: > - packet_add(pool_tap4, data->iov[0].iov_len - data->off, > - (char *)data->iov[0].iov_base + data->off); > + packet_add(pool_tap4, data); > break; > case ETH_P_IPV6: > - packet_add(pool_tap6, data->iov[0].iov_len - data->off, > - (char *)data->iov[0].iov_base + data->off); > + packet_add(pool_tap6, data); > break; > default: > break; --=20 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 --4iZ2aGX30ozweTbJ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmfuFHAACgkQzQJF27ox 2Geq7g/+IkPcoYreOUyS26f8Mbo9aWusBrjvMB0Dl1LDEtSXilKcYFsOZYU4NDDp KKMXHDhC9vEmYfiADKio5gFFtk9dFifZcsA7knm6SMpLFKwlGt1xH2Jeph8AWlE5 NPpz/yQE1xkonHvs+yhpPKYCkIoJwSgYSsru4wmGEXeBnhTctCPckDOmMrkJPMC0 fogk2NvU96al4gNBX7aUPdUX9mD0uFQGiY9wAmU3VCh62q/4Nm6nouTbeCZSN7M+ rSL1PDM+ftTH0w3yEu6OZ6RM6uixOGraUf4gH96BXf6FhH8m/prh7QlTPYwHcIEM rtnj1C3EC5FbkZUEN986Mav7/Mvn5P2eD8U+5iL2F0j2INnHtyCvtiiLJWmkEJaQ V0dif+JneoklDVIPmHFo32hqJchspTODIssKvuMJlQQj0OuHCn2jFpIZBrtirpPn V/YLl66KEusNQRq/cmyPYpe6TjuyNL8GdLcQCHn7xRd/UYYlTHA1ejitgdGP97ae aR+d3+WPLER50Jc0ryIYaRjwEjaUlNm896Wa8FCQDvLHXbeQuGrEfktMVUtOJGW/ pt9rSsxRArjlZ1SNs3KeNbuDLHBNGrxEk+wijJs8uXmGCNZW3IiVMwhNR2VB+6d/ AeEYt5OXH+e7A+70/ulYh7eY6tsREtWC3CxLaBQqDQx3U0S8bHo= =RPMS -----END PGP SIGNATURE----- --4iZ2aGX30ozweTbJ--