From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1B75142B27; Tue, 16 May 2023 18:04:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B0DDA406B6; Tue, 16 May 2023 18:04:04 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 2514C4003C for ; Tue, 16 May 2023 18:04:03 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 7C73B20D82; Tue, 16 May 2023 18:04:00 +0200 (CEST) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH] lib/mempool : rte_mempool_avail_count, fixing return bigger than mempool size X-MimeOLE: Produced By Microsoft Exchange V6.5 Date: Tue, 16 May 2023 18:03:58 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D87923@smartserver.smartshare.dk> In-Reply-To: <20230516082349.041c0e68@hermes.local> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH] lib/mempool : rte_mempool_avail_count, fixing return bigger than mempool size Thread-Index: AdmICm7SWh39lClKTqeATc2wZfk+pgABRqJg References: <20230516134146.480047-1-yasinncaner@gmail.com> <20230516082349.041c0e68@hermes.local> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Stephen Hemminger" , "Yasin CANER" Cc: , "Yasin CANER" , "Olivier Matz" , "Andrew Rybchenko" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Stephen Hemminger [mailto:stephen@networkplumber.org] > Sent: Tuesday, 16 May 2023 17.24 >=20 > On Tue, 16 May 2023 13:41:46 +0000 > Yasin CANER wrote: >=20 > > From: Yasin CANER > > > > after a while working rte_mempool_avail_count function returns = bigger > > than mempool size that cause miscalculation = rte_mempool_in_use_count. > > > > it helps to avoid miscalculation rte_mempool_in_use_count. > > > > Bugzilla ID: 1229 > > > > Signed-off-by: Yasin CANER >=20 > An alternative that avoids some code duplication. >=20 > diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c > index cf5dea2304a7..2406b112e7b0 100644 > --- a/lib/mempool/rte_mempool.c > +++ b/lib/mempool/rte_mempool.c > @@ -1010,7 +1010,7 @@ rte_mempool_avail_count(const struct rte_mempool > *mp) > count =3D rte_mempool_ops_get_count(mp); >=20 > if (mp->cache_size =3D=3D 0) > - return count; > + goto exit; This bug can only occur here (i.e. with cache_size=3D=3D0) if = rte_mempool_ops_get_count() returns an incorrect value. The bug should = be fixed there instead. >=20 > for (lcore_id =3D 0; lcore_id < RTE_MAX_LCORE; lcore_id++) > count +=3D mp->local_cache[lcore_id].len; > @@ -1019,6 +1019,7 @@ rte_mempool_avail_count(const struct rte_mempool > *mp) > * due to race condition (access to len is not locked), the > * total can be greater than size... so fix the result > */ > +exit: > if (count > mp->size) > return mp->size; > return count;