From: Bruce Richardson <bruce.richardson@intel.com>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: <dev@dpdk.org>, Thomas Monjalon <thomas@monjalon.net>,
Stephen Hemminger <stephen@networkplumber.org>,
Konstantin Ananyev <konstantin.ananyev@huawei.com>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
Ivan Malov <ivan.malov@arknetworks.am>,
Chengwen Feng <fengchengwen@huawei.com>
Subject: Re: [PATCH v8 1/3] mbuf: de-inline sanity checking a reinitialized mbuf
Date: Thu, 9 Oct 2025 17:49:47 +0100 [thread overview]
Message-ID: <aOfnq0bx0py_XTQz@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20250823063002.24326-2-mb@smartsharesystems.com>
On Sat, Aug 23, 2025 at 06:30:00AM +0000, Morten Brørup wrote:
> Sanity checking a reinitialized mbuf (a.k.a. raw mbuf) has been refactored
> to follow the same design pattern as sanity checking a normal mbuf, and
> now depends on RTE_LIBRTE_MBUF_DEBUG instead of RTE_ENABLE_ASSERT.
>
> The details of the changes are as follows:
>
> Non-inlined functions rte_mbuf_raw_sanity_check() and rte_mbuf_raw_check()
> have been added.
> They do for a reinitialized mbuf what rte_mbuf_sanity_check() and
> rte_mbuf_check() do for a normal mbuf.
> They basically check the same conditions as __rte_mbuf_raw_sanity_check()
> previously did, but use "if (!condition) rte_panic(message)" instead of
> RTE_ASSERT(), so they don't depend on RTE_ENABLE_ASSERT.
>
> The inline function __rte_mbuf_raw_sanity_check() has been replaced
> by the new macro __rte_mbuf_raw_sanity_check_mp(), which either calls
> rte_mbuf_raw_sanity_check() or does nothing, depending on
> RTE_LIBRTE_MBUF_DEBUG, just like the __rte_mbuf_sanity_check() macro does
> for a normal mbuf.
>
> Note that the new macro __rte_mbuf_raw_sanity_check_mp() takes an optional
> mempool parameter to verify that the mbuf belongs to the expected mbuf
> pool.
> This addition is mainly relevant for sanity checking reinitialized mbufs
> freed directly into a given mempool by a PMD when using
> RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE.
>
> The macro __rte_mbuf_raw_sanity_check() has been kept for backwards API
> compatibility.
> It simply calls __rte_mbuf_raw_sanity_check_mp() without specifying a
> mempool.
>
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
> ---
Looks ok to me, one comment inline below.
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> v3:
> * Removed experimental status for the new functions.
> Experimental is optional for new symbols, to allow for future API
> changes. But this has been around for a long time. (Stephen Hemminger)
> * Consequentially, the added build check for ALLOW_EXPERIMENTAL_API with
> RTE_LIBRTE_MBUF_DEBUG is no longer needed, and was removed.
> v2:
> * Added explicit build check for ALLOW_EXPERIMENTAL_API being enabled when
> RTE_LIBRTE_MBUF_DEBUG is enabled, with descriptive error message if not
> so. (Ivan Malov)
> * Fixed typo in patch description.
> ---
> lib/mbuf/rte_mbuf.c | 61 ++++++++++++++++++++++++++++
> lib/mbuf/rte_mbuf.h | 96 +++++++++++++++++++++++++++------------------
> 2 files changed, 119 insertions(+), 38 deletions(-)
>
> diff --git a/lib/mbuf/rte_mbuf.c b/lib/mbuf/rte_mbuf.c
> index 9e7731a8a2..af39c13cf7 100644
> --- a/lib/mbuf/rte_mbuf.c
> +++ b/lib/mbuf/rte_mbuf.c
> @@ -373,6 +373,67 @@ rte_pktmbuf_pool_create_extbuf(const char *name, unsigned int n,
> return mp;
> }
>
> +/* do some sanity checks on a reinitialized mbuf: panic if it fails */
> +RTE_EXPORT_SYMBOL(rte_mbuf_raw_sanity_check)
> +void
> +rte_mbuf_raw_sanity_check(const struct rte_mbuf *m, const struct rte_mempool *mp)
> +{
> + const char *reason;
> +
> + if (rte_mbuf_raw_check(m, mp, &reason))
> + rte_panic("%s\n", reason);
> +}
> +
> +RTE_EXPORT_SYMBOL(rte_mbuf_raw_check)
> +int rte_mbuf_raw_check(const struct rte_mbuf *m, const struct rte_mempool *mp,
> + const char **reason)
> +{
> + /* check sanity */
> + if (rte_mbuf_check(m, 0, reason) == -1)
> + return -1;
> +
> + /* check initialized */
> + if (rte_mbuf_refcnt_read(m) != 1) {
> + *reason = "uninitialized ref cnt";
> + return -1;
> + }
> + if (m->next != NULL) {
> + *reason = "uninitialized next ptr";
> + return -1;
> + }
> + if (m->nb_segs != 1) {
> + *reason = "uninitialized nb_segs";
> + return -1;
> + }
> + if (RTE_MBUF_CLONED(m)) {
> + *reason = "cloned";
> + return -1;
> + }
> + if (RTE_MBUF_HAS_EXTBUF(m)) {
> + if (!RTE_MBUF_HAS_PINNED_EXTBUF(m)) {
> + *reason = "external buffer not pinned";
> + return -1;
> + }
> +
> + uint16_t cnt = rte_mbuf_ext_refcnt_read(m->shinfo);
> + if ((cnt == 0) || (cnt == UINT16_MAX)) {
> + *reason = "pinned external buffer bad ref cnt";
> + return -1;
> + }
> + if (cnt != 1) {
> + *reason = "pinned external buffer uninitialized ref cnt";
> + return -1;
> + }
> + }
> +
> + if (mp != NULL && m->pool != mp) {
> + *reason = "wrong mbuf pool";
> + return -1;
> + }
> +
> + return 0;
> +}
> +
> /* do some sanity checks on a mbuf: panic if it fails */
> RTE_EXPORT_SYMBOL(rte_mbuf_sanity_check)
> void
> diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
> index 06ab7502a5..552cda1ae5 100644
> --- a/lib/mbuf/rte_mbuf.h
> +++ b/lib/mbuf/rte_mbuf.h
> @@ -339,11 +339,17 @@ rte_pktmbuf_priv_flags(struct rte_mempool *mp)
>
> #ifdef RTE_LIBRTE_MBUF_DEBUG
>
> +/** check reinitialized mbuf type in debug mode */
> +#define __rte_mbuf_raw_sanity_check_mp(m, mp) rte_mbuf_raw_sanity_check(m, mp)
> +
> /** check mbuf type in debug mode */
> #define __rte_mbuf_sanity_check(m, is_h) rte_mbuf_sanity_check(m, is_h)
>
> #else /* RTE_LIBRTE_MBUF_DEBUG */
>
> +/** check reinitialized mbuf type in debug mode */
This is in release mode, not debug mode. Comment below seems wrong too.
> +#define __rte_mbuf_raw_sanity_check_mp(m, mp) do { } while (0)
> +
> /** check mbuf type in debug mode */
> #define __rte_mbuf_sanity_check(m, is_h) do { } while (0)
>
> @@ -513,6 +519,46 @@ rte_mbuf_ext_refcnt_update(struct rte_mbuf_ext_shared_info *shinfo,
> } while (0)
<snip>
next prev parent reply other threads:[~2025-10-09 16:50 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 15:02 [PATCH v5 0/3] mbuf: simplify handling of reinitialized mbufs Morten Brørup
2025-08-21 15:02 ` [PATCH v5 1/3] mbuf: de-inline sanity checking a reinitialized mbuf Morten Brørup
2025-08-21 15:02 ` [PATCH v5 2/3] promote reinitialized mbuf free and alloc bulk functions as stable Morten Brørup
2025-08-21 15:02 ` [PATCH v5 3/3] mbuf: no need to reset all fields on reinitialized mbufs Morten Brørup
2025-08-22 12:47 ` [PATCH v6 0/3] mbuf: simplify handling of " Morten Brørup
2025-08-22 12:47 ` [PATCH v6 1/3] mbuf: de-inline sanity checking a reinitialized mbuf Morten Brørup
2025-08-22 14:26 ` Morten Brørup
2025-08-22 12:47 ` [PATCH v6 2/3] mbuf: promote raw free and alloc bulk functions as stable Morten Brørup
2025-08-22 12:47 ` [PATCH v6 3/3] mbuf: no need to reset all fields on reinitialized mbufs Morten Brørup
2025-08-22 23:45 ` [PATCH v7 0/3] mbuf: simplify handling of " Morten Brørup
2025-08-22 23:45 ` [PATCH v7 1/3] mbuf: de-inline sanity checking a reinitialized mbuf Morten Brørup
2025-08-22 23:45 ` [PATCH v7 2/3] mbuf: promote raw free and alloc bulk functions as stable Morten Brørup
2025-08-22 23:45 ` [PATCH v7 3/3] mbuf: optimize reset of reinitialized mbufs Morten Brørup
2025-08-23 6:29 ` [PATCH v8 0/3] mbuf: simplify handling " Morten Brørup
2025-08-23 6:30 ` [PATCH v8 1/3] mbuf: de-inline sanity checking a reinitialized mbuf Morten Brørup
2025-10-09 16:49 ` Bruce Richardson [this message]
2025-10-09 17:12 ` Morten Brørup
2025-10-09 17:29 ` Thomas Monjalon
2025-10-09 17:55 ` Morten Brørup
2025-08-23 6:30 ` [PATCH v8 2/3] mbuf: promote raw free and alloc bulk functions as stable Morten Brørup
2025-10-09 16:53 ` Bruce Richardson
2025-08-23 6:30 ` [PATCH v8 3/3] mbuf: optimize reset of reinitialized mbufs Morten Brørup
2025-08-23 14:28 ` Stephen Hemminger
2025-10-09 17:15 ` Bruce Richardson
2025-10-09 17:35 ` Morten Brørup
2025-10-10 7:43 ` Bruce Richardson
2025-10-10 9:22 ` Morten Brørup
2025-10-06 14:43 ` [PATCH v8 0/3] mbuf: simplify handling " Morten Brørup
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aOfnq0bx0py_XTQz@bricha3-mobl1.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
--cc=ivan.malov@arknetworks.am \
--cc=konstantin.ananyev@huawei.com \
--cc=mb@smartsharesystems.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).