From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 968F0606A31A for ; Mon, 30 Nov 2026 20:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=PaejA9bC Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A13E940647; Mon, 30 Nov 2026 21:52:35 +0100 (CET) Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by mails.dpdk.org (Postfix) with ESMTPS id B1BD740614 for ; Mon, 30 Nov 2026 21:52:33 +0100 (CET) Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-92106d5371dso142765036d6.1 for ; Mon, 30 Nov 2026 12:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796071952; x=1796676752; darn=dpdk.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=VJp0s8gzCFshUucBG/Lx9L7J89E7p1IYs/0XceaPzuE=; b=PaejA9bCKXS4BmWhNQ0o2AQg70DMVraiPdkTMJvZqRe+2rVU9YR3o265hcryGn+zYs 2Qc9ZaWz+ZOiltbUi47gJ4DghJQ2xN/BEenP2jamTi5eqexvjLoZksmHFq0q5C4b6Q+J xrClyTn6EchhzvOiO44a0i0hnAf9IttuYRzGoYPWjBvuhm4dygZ0J4pidrCcGg7ja5uR H6P9G8nsfUnKqcFA5G5jISN8ZxMF16fmmtwe0xLE6xElAqwploRJvHh7QYJNg/hERyZv X4nfhENOu+cvI5NcLB20BZ1RO2qS+A/dQKH3Ae05fV4CXgbSfjR0HWY65k2Bw82FhCBR 3PKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796071952; x=1796676752; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VJp0s8gzCFshUucBG/Lx9L7J89E7p1IYs/0XceaPzuE=; b=ywlA6qZjz62Q2W0Sm94SoSU+2Mp4bKl4w00eGdvzKbK9igytTb0AmKY8gKY9nL082P jeliqn0LhkdmWjlTbShddzkefA8Q9jN0QEGSFwz0ZBiz13ApsvzALfnyv9qvfOpYf/64 uPgOsb7M887h40s1kxZX2gPR2DNs0ZlnoBXrj7ckRnl7D6ApZlI72kxkVBC+p8lgvK9b Zu29YAlY3dducQ7I7fJQ1A3GBrprFlT0TUNaiqjbpBLSz8hl47eM6slOBF0dGufwn/e8 CX0ShucG7kHPRxRjBItbAHr4uZZzB9Ty3HNgVmgXCTUkvAcljqsZFpv4TIBtLU4hLLeT R9CA== X-Gm-Message-State: APuU4Z9bMcriiGLXiAZ8AkGgwvi+wXDEESxy3+1mUhImla/BJzfiZxqP PvxbH1zqx6MyI79QOfEgFrgWhH+khAOyhL+i3pVawjezaU80btKF3mVHZ8ulk2um X-Gm-Gg: AZFdTZdXALuBOYbrHAgIufGSbWrbZrpytBRo050HLSAKDrF7hZvGdBmVHt/SLGWBzU+ qcfn0jf4cmyopKlAGtuVglqBUwfXocPbfGWs4SANYU8uqvNr0EdEWElccJW6HiSF2tfyNZpKcit 4pBycLYKmjvJ11Vsuu89O/QXu20jtBrrgl5a821gqwhyruF3IGlUKHLGW0akzuT+nBcLQujXAVo iJj9S9UgAr6uh3K39+omYukbkCCNvlLnub7wFeTQqemfUUz+MUO7TBKPF1XXP3JwD9dQWSZetMs +l2cBORsdyQd/YDN9706EInVq5VkR1ymdGPn/zIXIVo0YftZFweFivavYr7Arr2DbEFody62kMk UDk5of8x6H4rL7klyTrJwkivhyXmM+3M1XSIguk9sWEzQATAQHz3Gxn6WbKLI8lt3XcT0beFH/s HpGE0qP934mE7rfFi2xApDk0ei2cNaLx3pdxxSuLTsDabMqSw/OUUF06bE6gAJxnEaEaeybTL0l CMMsxgsgVpuoZu4iCdeCypkigehO0WvP/Lrp6wnjnDH3rhbzyMBl/IrwrIntuNqNXkfrPWcvQ4w RrRFTP3Sv5U9KexAtfRUrW/+430lLZj6Sslbe3GoTGv/oZEto6hZlPBuY3PEUxmrzFL26YErGzW kjvajY+OtuxUVkTZlpT2D/dsh0a67BsSaoJYLW7Y7ytXUvBlOnHNEAlVSp7AoJTPwsSiv7UCK91 Y= X-Received: by 2002:ad4:5d45:0:b0:91e:8d7a:bd13 with SMTP id 6a1803df08f44-9212e0a5a17mr657754366d6.14.1796071952279; Mon, 30 Nov 2026 12:52:32 -0800 (PST) Received: from bos-lhvwah.bos01.corp.akamai.com (g2001-4878-8037-0700-526b-8dff-fef6-cfbf.deploy.static.akamaitechnologies.com. [2001:4878:8037:700:526b:8dff:fef6:cfbf]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921349b3a0csm304029476d6.14.2026.11.30.12.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 12:52:30 -0800 (PST) From: Robert Sanford To: dev@dpdk.org Cc: andrew.rybchenko@oktetlabs.ru, mb@smartsharesystems.com, olivier.matz@6wind.com, thomas@monjalon.net, Robert Sanford , stable@dpdk.org Subject: [PATCH v5 2/3] mempool: fix dump of unpopulated pool Date: Mon, 30 Nov 2026 15:51:51 -0500 Message-Id: <20261130205152.7107-3-rsanford2@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130205152.7107-1-rsanford2@gmail.com> References: <20261112154342.1484709-1-rsanford2@gmail.com> <20261130205152.7107-1-rsanford2@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Robert Sanford rte_mempool_create_empty() adds a mempool to the mempool list before the mempool has a store. The store is allocated, and RTE_MEMPOOL_F_POOL_CREATED is set, by the first populate call. In between, rte_mempool_dump() queries the mempool driver for the number of objects in the store. With the ring driver this dereferences a NULL ring, and the process crashes. rte_mempool_list_dump() calls rte_mempool_dump() for every mempool on the list, so it crashes when another thread has created a mempool but not populated it yet. The telemetry /mempool/info handler has the same problem: its rte_mempool_walk() callback queries the driver for the same count. Add rte_mempool_is_created(), which tests RTE_MEMPOOL_F_POOL_CREATED. In rte_mempool_dump() and in the telemetry callback, query the mempool driver only when it returns true, and report a common pool count of 0 otherwise, since the mempool has no objects yet. The rest of the mempool information is still reported. In statistics builds, rte_mempool_dump() also skips rte_mempool_ops_get_info() for such a mempool. The info is now zeroed first; it was left uninitialized for drivers without a get_info operation. The populating thread sets the flag without holding a lock, so set it with an atomic fetch-or with release ordering, and test it with an atomic load with acquire ordering. A reader that sees the flag then also sees the store. rte_mempool_walk() still passes mempools that are not populated yet to its callback. Document that the callback must check rte_mempool_is_created() before querying the mempool driver. rte_mempool_is_created() is public API because applications need it too: a callback passed to rte_mempool_walk() must not query the mempool driver of a mempool that is not created yet, and it has no other way to check that. The function is trivial and the library itself uses it, in rte_mempool_dump() and in the telemetry callback, so it is added directly as stable API, without an experimental stage. It is not inline, since it is not used in the fast path. Fixes: 449c49b93a6b ("mempool: support handler operations") Fixes: ab8a1cc4e3d8 ("mempool: add object usage counts in telemetry") Cc: stable@dpdk.org Signed-off-by: Robert Sanford Acked-by: Morten Brørup --- doc/guides/rel_notes/release_27_03.rst | 7 +++++ lib/mempool/rte_mempool.c | 37 +++++++++++++++++++++++--- lib/mempool/rte_mempool.h | 26 ++++++++++++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/doc/guides/rel_notes/release_27_03.rst b/doc/guides/rel_notes/release_27_03.rst index a91813faca..d2c8d86c36 100644 --- a/doc/guides/rel_notes/release_27_03.rst +++ b/doc/guides/rel_notes/release_27_03.rst @@ -55,6 +55,13 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added function to check if a mempool is created.** + + Added the ``rte_mempool_is_created()`` function + to check whether the store of a mempool has been created. + ``rte_mempool_walk()`` callbacks can use it to skip mempools + that are not populated yet before querying the mempool driver. + Removed Items ------------- diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index d9f339a3c2..6dc0f146a1 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -294,6 +294,22 @@ rte_mempool_free_memchunks(struct rte_mempool *mp) } } +RTE_EXPORT_SYMBOL(rte_mempool_is_created) +bool +rte_mempool_is_created(const struct rte_mempool *mp) +{ + /* + * Mempools are on the mempool list before the store is allocated, so + * rte_mempool_dump() and rte_mempool_walk() callbacks can find them + * while another thread populates them. + * Acquire: pairs with the release in mempool_ops_alloc_once(). + */ + return (rte_atomic_load_explicit( + (const RTE_ATOMIC(unsigned int) *)&mp->flags, + rte_memory_order_acquire) & + RTE_MEMPOOL_F_POOL_CREATED) != 0; +} + static int mempool_ops_alloc_once(struct rte_mempool *mp) { @@ -304,7 +320,13 @@ mempool_ops_alloc_once(struct rte_mempool *mp) ret = rte_mempool_ops_alloc(mp); if (ret != 0) return ret; - mp->flags |= RTE_MEMPOOL_F_POOL_CREATED; + /* + * Release: make the store visible before the flag, see + * rte_mempool_is_created(). + */ + rte_atomic_fetch_or_explicit( + (RTE_ATOMIC(unsigned int) *)&mp->flags, + RTE_MEMPOOL_F_POOL_CREATED, rte_memory_order_release); } return 0; } @@ -1283,10 +1305,14 @@ rte_mempool_dump(FILE *f, struct rte_mempool *mp) unsigned common_count; unsigned cache_count; size_t mem_len = 0; + bool created; RTE_ASSERT(f != NULL); RTE_ASSERT(mp != NULL); + /* the mempool driver can only be queried once the store exists */ + created = rte_mempool_is_created(mp); + fprintf(f, "mempool <%s>@%p\n", mp->name, mp); fprintf(f, " flags=%x\n", mp->flags); fprintf(f, " socket_id=%d\n", mp->socket_id); @@ -1318,14 +1344,16 @@ rte_mempool_dump(FILE *f, struct rte_mempool *mp) } cache_count = rte_mempool_dump_cache(f, mp); - common_count = rte_mempool_ops_get_count(mp); + common_count = created ? rte_mempool_ops_get_count(mp) : 0; if ((cache_count + common_count) > mp->size) common_count = mp->size - cache_count; fprintf(f, " common_pool_count=%u\n", common_count); /* sum and dump statistics */ #ifdef RTE_LIBRTE_MEMPOOL_STATS - rte_mempool_ops_get_info(mp, &info); + memset(&info, 0, sizeof(info)); + if (created) + rte_mempool_ops_get_info(mp, &info); memset(&sum, 0, sizeof(sum)); for (lcore_id = 0; lcore_id < RTE_MAX_LCORE + 1; lcore_id++) { sum.put_bulk += mp->stats[lcore_id].put_bulk; @@ -1653,7 +1681,8 @@ mempool_info_cb(struct rte_mempool *mp, void *arg) cache_count += cache->len; } rte_tel_data_add_dict_uint(info->d, "total_cache_count", cache_count); - common_count = rte_mempool_ops_get_count(mp); + /* the mempool driver can only be queried once the store exists */ + common_count = rte_mempool_is_created(mp) ? rte_mempool_ops_get_count(mp) : 0; if ((cache_count + common_count) > mp->size) common_count = mp->size - cache_count; rte_tel_data_add_dict_uint(info->d, "common_pool_count", common_count); diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h index 5de7678a7a..742db9d016 100644 --- a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -1325,6 +1325,9 @@ void rte_mempool_stats_reset(struct rte_mempool *mp); /** * Dump the status of the mempool to a file. * + * For a mempool that is not populated yet, the mempool driver is not + * queried, and the common pool count is reported as 0. + * * @param f * A pointer to a file for output * @param mp @@ -1785,6 +1788,24 @@ rte_mempool_get_contig_blocks(struct rte_mempool *mp, return ret; } +/** + * Check if the mempool driver has created the store of a mempool. + * + * rte_mempool_create_empty() adds a mempool to the mempool list, and + * assigns the default mempool driver, before the store exists. The + * mempool driver can still be changed with rte_mempool_set_ops_byname() + * until the store is created by the first populate call. Functions that + * query the mempool driver, such as rte_mempool_avail_count(), must only + * be called for a mempool that is created. rte_mempool_walk() callbacks + * can see mempools that are not created yet. + * + * @param mp + * A pointer to the mempool structure. + * @return + * true if the store has been created, false otherwise. + */ +bool rte_mempool_is_created(const struct rte_mempool *mp); + /** * Return the number of entries in the mempool. * @@ -1944,6 +1965,11 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags, * The mempool list is locked while the iterator function runs, so the * iterator function must not create or free a mempool. * + * The iterator function is also called for mempools that are not + * populated yet. Such a mempool has no store yet, so the iterator function + * must check rte_mempool_is_created() before calling functions that query + * the mempool driver, such as rte_mempool_avail_count(). + * * @param func * Iterator function * @param arg -- 2.34.1