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=T4F3r8IY; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 3D7685A0271 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=rXbpIwJhYzWx8PIx4lTeeumJ99xMdixviWjjB37MGa4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T4F3r8IYTO40cxInaUkMPbWZcYCI/tBDuEt5UuRd9aEsujiW/1RhRyCq4+aISTav9 4CyNp8IufqWMJt9sB6oUGo3vBMUz+zgl5NaCraDvA/pdWbJd0BCqG5wr27U2Dh/DL3 qOLtChZi7uQmt5/fN0qFf7P6ZOaNMOqqJZbZ4VQ+xFBRj1E/DHn2a/dzSTE4UNF/cf dJlDLfQ9EEgihgzSkFUnrFSm1b6Uptikm11yGy4w6jgGEttX6sONWdLGjhh2FEwztN qFQTzpsl5uoFm9I3VMMSMUysbVcE+alkUtNAtg/roCaZFr6ciH+AQn4JHHkwZPwWYr 4giaPXtuS0Jgw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZSr9m5CNcz4x3d; Thu, 3 Apr 2025 16:38:04 +1100 (AEDT) Date: Thu, 3 Apr 2025 15:59:48 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 05/18] packet: Add packet_base() Message-ID: References: <20250402172343.858187-1-lvivier@redhat.com> <20250402172343.858187-6-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="H/7r8uqleIo6+opZ" Content-Disposition: inline In-Reply-To: <20250402172343.858187-6-lvivier@redhat.com> Message-ID-Hash: ONQBYONULGELQSQJ4X7I6CGDXNEO3CC5 X-Message-ID-Hash: ONQBYONULGELQSQJ4X7I6CGDXNEO3CC5 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: --H/7r8uqleIo6+opZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 02, 2025 at 07:23:30PM +0200, Laurent Vivier wrote: > Signed-off-by: Laurent Vivier Needs commit message. > --- > packet.c | 37 +++++++++++++++++++++++++++++++++++++ > packet.h | 7 +++++++ > 2 files changed, 44 insertions(+) >=20 > diff --git a/packet.c b/packet.c > index 8b11e0850ff6..25ede38b94cb 100644 > --- a/packet.c > +++ b/packet.c > @@ -156,6 +156,43 @@ void *packet_get_do(const struct pool *p, size_t idx= , size_t offset, > return ptr; > } > =20 > +/** > + * packet_base_do() - Get data range from packet descriptor from given p= ool > + * @p: Packet pool > + * @idx: Index of packet descriptor in pool > + * @func: For tracing: name of calling function, NULL means no trace() > + * @line: For tracing: caller line of function call > + * > + * Return: pointer to start of data range, NULL on invalid range or desc= riptor All these comments need to be updated, they seem to be based on (an old version of?) packet_get_do and are no longer accurate. "packet_base()" also doesn't really convey the meaning to me. Not sure what a better name is, though. > + */ > +/* 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; > + > + if (idx >=3D p->size || idx >=3D p->count) { > + if (func) { > + trace("packet %zu from pool size: %zu, count: %zu, " > + "%s:%i", idx, p->size, p->count, func, line); > + } > + return NULL; > + } > + > + data->cnt =3D 1; > + data->off =3D 0; > + data->iov =3D &p->pkt[idx]; > + > + for (i =3D 0; i < data->cnt; i++) { > + if (packet_check_range(p, data->iov[i].iov_base, > + data->iov[i].iov_len, func, line)) > + return false; This looks to be based logically on versions of packet_get_do() before I did my rework in 38bcce997 and surrounding commits. If we get a packet_check_range() failure here it means the packet pool is already corrupt and we should just ASSERT. The conditions on func being non-NULL should also be gone. > + } > + > + return true; > +} > + > /** > * pool_flush() - Flush a packet pool > * @p: Pointer to packet pool > diff --git a/packet.h b/packet.h > index f386295da203..35058e747a43 100644 > --- a/packet.h > +++ b/packet.h > @@ -35,6 +35,9 @@ void packet_add_do(struct pool *p, struct iov_tail *dat= a, > 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); > void pool_flush(struct pool *p); > =20 > #define packet_add(p, data) \ > @@ -43,9 +46,13 @@ void pool_flush(struct pool *p); > #define packet_get(p, idx, offset, len, left) \ > packet_get_do(p, idx, offset, len, left, __func__, __LINE__) > =20 > + > #define packet_get_try(p, idx, offset, len, left) \ > packet_get_do(p, idx, offset, len, left, NULL, 0) > =20 > +#define packet_base(p, idx, data) \ > + packet_base_do(p, idx, data, __func__, __LINE__) > + > #define PACKET_POOL_DECL(_name, _size, _buf) \ > struct _name ## _t { \ > char *buf; \ --=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 --H/7r8uqleIo6+opZ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmfuFcQACgkQzQJF27ox 2Gd/MA/7BvXEz5yIWOtDV8f/YeUSaIFHZaMZwZkjxynOK/E+KwXGiBUTcLPyp/Vy UDpnYelgMSS3TstEDDJ0fAsjmmLOCTclJ14BIzkmjC/U8FL/LVy5tw9KNVYu6we3 vDV9r5k9iRVaThiYUE3ooNuHubK4M1VRekEPYadPGsjfsPjDJKA6lTTyK0Y7WMn0 pWqlypLGkVFW5SEP9Xz9ujJMpqGz+QVse50rLOEAEnpIcKKTl7q5y5edPrLbbSLQ hJHQ6y94NjKYBjThD/In1QW01jmlh/qwrWtVmH02svSE9yP5oPndyS9NwhUr/xJg JLGlr0fSr96hWKpzQC+e0ny6SWn+A0+JNZfSasd5exX5HhBFBV3/slEnNuhYFPBk fxrcm5AHDdtVoXqet+GkmQHtWHQSgN/Syd4vO431Djlc+RgIXP5VIzacDiLKXenf gD6NhftaC9+cTpvuilMukd8bpYcPK4jUAkZv/o+M0B19JCrtNuU9fsXZTu8FkDM5 PR3g5RJlQ8Cew6faO+y3BalPh6Zb5v1yvvXbM7Kw/XUk8Ub2tZcf9k7fB2yT2Qdc JKVA2NITojJeZAT70uDONdAaNMObXYVOoje365hoaZp/EjunG4OzLxtVYjtVsZuU 2u2r/WOAHsPDmQz1E+mrrRR4BJ5B7unFtAC9rPbn+FVm20Hh7nc= =loS7 -----END PGP SIGNATURE----- --H/7r8uqleIo6+opZ--