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=202504 header.b=H1fNlkM9; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id A04F25A0008 for ; Mon, 14 Apr 2025 04:29:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202504; t=1744597779; bh=V77EjRdFj2x8BwfVTDOBYgWJdDyPqH7GJrIxKA6HSlQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H1fNlkM9MM9pDS3EQKGA/d3TCobUKDYl/NF+I27tZpsDFd/RUIwpOaBchTlgcZs5Z G90Bg7YXO2ShsY8oTaJkxOYDYM/GmTRYJoUIiUNOWkrnnWlsH72nW1KFul4CMNwOcL nk6rWKS8Lj2JeqPpcuxAKcTQe4J4o6I+WjlNk/dCvEiZua/N4jxC7/dFj/p7RfmKqM sB2xxB2eGzup19muANL0hGPvnQwCSu3OPyE8iCafIOX0c3x0BPiNMA38fmU+nWHUw0 0sOgpvVHiZbEzqFyK/A2AlzBDT+9pLL2kxgHJ+4IeMfVew/YDJZpnk/tdXtD1FPhp5 AjBgCogytMozw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZbWTH3VC0z4wcQ; Mon, 14 Apr 2025 12:29:39 +1000 (AEST) Date: Mon, 14 Apr 2025 12:29:36 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 06/20] packet: Add packet_base() Message-ID: References: <20250411131031.1398006-1-lvivier@redhat.com> <20250411131031.1398006-7-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KfwnUq9wAq+zZZa/" Content-Disposition: inline In-Reply-To: <20250411131031.1398006-7-lvivier@redhat.com> Message-ID-Hash: EDER2WRVUTMGCJPV4RVZLQX3RARK7X7M X-Message-ID-Hash: EDER2WRVUTMGCJPV4RVZLQX3RARK7X7M 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: --KfwnUq9wAq+zZZa/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 11, 2025 at 03:10:16PM +0200, Laurent Vivier wrote: > packet_base() gets the data range from a packet descriptor from a > given pool. >=20 > It uses iov_tail to return the packet memory. >=20 > Signed-off-by: Laurent Vivier Logic looks fine. I kind of hate the name though; "base" of what? Maybe packet_data()? > --- > packet.c | 41 +++++++++++++++++++++++++++++++++++++++++ > packet.h | 5 +++++ > 2 files changed, 46 insertions(+) >=20 > diff --git a/packet.c b/packet.c > index 98ded4e27aae..c3f329d53507 100644 > --- a/packet.c > +++ b/packet.c > @@ -190,6 +190,47 @@ void *packet_get_do(const struct pool *p, const size= _t idx, > return r; > } > =20 > +/** > + * packet_base_do() - Get data range from packet descriptor from given p= ool > + * @p: Packet pool > + * @idx: Index of packet descriptor in pool > + * @data: IOV tail to store the address of the data (output) > + * @func: For tracing: name of calling function, NULL means no trace() > + * @line: For tracing: caller line of function call > + * > + * Return: true if @data contains valid data, false otherwise > + */ > +/* cppcheck-suppress unusedFunction */ > +bool packet_base_do(const struct pool *p, size_t idx, > + struct iov_tail *data, > + const char *func, int line) > +{ > + size_t i; > + > + ASSERT_WITH_MSG(p->count <=3D p->size, > + "Corrupt pool count: %zu, size: %zu, %s:%i", > + p->count, p->size, func, line); > + > + if (idx >=3D p->count) { > + debug("packet %zu from pool size: %zu, count: %zu, " > + "%s:%i", idx, p->size, p->count, func, line); > + return false; > + } I'm kind of tempted to suggest making this also an ASSERT(), in which case this function could return an iov_tail by value, which is probably a more natural interface. Stefano, any opinion? > + > + data->cnt =3D 1; > + data->off =3D 0; > + data->iov =3D &p->pkt[idx]; > + > + for (i =3D 0; i < data->cnt; i++) { > + ASSERT_WITH_MSG(!packet_check_range(p, data->iov[i].iov_base, > + data->iov[i].iov_len, > + func, line), > + "Corrupt packet pool, %s:%i", func, line); > + } > + > + return true; > +} > + > /** > * pool_flush() - Flush a packet pool > * @p: Pointer to packet pool > diff --git a/packet.h b/packet.h > index af40b39b5251..ee7a5304a034 100644 > --- a/packet.h > +++ b/packet.h > @@ -39,6 +39,9 @@ void *packet_get_try_do(const struct pool *p, const siz= e_t idx, > 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); > +bool packet_base_do(const struct pool *p, const size_t idx, > + struct iov_tail *data, > + const char *func, int line); > bool pool_full(const struct pool *p); > void pool_flush(struct pool *p); > =20 > @@ -49,6 +52,8 @@ void pool_flush(struct pool *p); > packet_get_try_do(p, idx, offset, len, left, __func__, __LINE__) > #define packet_get(p, idx, offset, len, left) \ > packet_get_do(p, idx, offset, len, left, __func__, __LINE__) > +#define packet_base(p, idx, data) \ > + packet_base_do(p, idx, data, __func__, __LINE__) > =20 > #define PACKET_POOL_DECL(_name, _size, _buf) \ > struct _name ## _t { \ --=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 --KfwnUq9wAq+zZZa/ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmf8cw8ACgkQzQJF27ox 2GdIcg/9EKoDBapKIteGeu/eB8y6Zjg9Yp0Ak4QmNLInKSogWTr8pY5cYNkhhBc7 Ip3JpFtVEhMiQmkDJ5HIhxrXHbMXlOZb6P1HLucr5j/zFEz1UiuqhohQIVlMjQd0 EUaGzdcUoj0cLxbmc1svZDL0qcoKT7tj6DrDi8NCxy5yAIR4yVZ6fN/6ZUu1cU3U d6Dqt+yDBmUxc6FSvNLEAWWQBJA6bsXwqvojxavt1S9xvjMTifp4LuAplcRM7JuG 6HcqxCL6hJSgzHtW6LM4s6Gyd94swTnB2OMDQs/tbk9PKHlkC5+x8PdZK6tTrWS6 3HvIldFWxgLbGbr2Xv1ED2AwXRfPZpAGD7F3H/jargvB4l6tbGnJotC3eozwvFN5 0k4/ZMltK3V/qrJwSlf3x6ahBVv/m187izDOi9On0tD2p3HkhNHmIf2DWTyGDN4x x8engLOsHG7U9R6bh+cc+Ew1xlOBUpx60GTEPxV//MkaaFrmrTjzXRaZcPqJBRt8 u1viTCCjJIUplfix18sBaY2mNQNqV5lngMOAbrfkJEZsNINfz5AYggqbFpObr5yf doCr+DpB04izOW59nwFd2x6eAP+CDnbFDgNh26xaPyQzrLiQQ5pkYB96c5SnE+QV sTbzwVnzEDHRIO2icPOoEF4+3N5CxlWBkM/jmxx6fX0QdMux9Es= =uflu -----END PGP SIGNATURE----- --KfwnUq9wAq+zZZa/--