From: Olivier Matz <olivier.matz@6wind.com>
To: dev@dpdk.org
Cc: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
Pallantla Poornima <pallantlax.poornima@intel.com>,
Wenwu Ma <wenwux.ma@intel.com>,
Peng Zhihong <zhihongx.peng@intel.com>,
Aaron Conole <aconole@redhat.com>,
Thomas Monjalon <thomas@monjalon.net>
Subject: [dpdk-dev] [PATCH v3 2/2] mbuf: better document usage of packet pool initializers
Date: Tue, 27 Apr 2021 15:56:46 +0200 [thread overview]
Message-ID: <20210427135646.871-2-olivier.matz@6wind.com> (raw)
In-Reply-To: <20210427135646.871-1-olivier.matz@6wind.com>
Clarify that the mempool private initializer and object initializer used
for packet pools require that the mempool private size is large enough.
Also add an assert (only enabled when -DRTE_ENABLE_ASSERT is passed) to
check this constraint.
Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
lib/mbuf/rte_mbuf.c | 5 +++++
lib/mbuf/rte_mbuf.h | 8 +++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/lib/mbuf/rte_mbuf.c b/lib/mbuf/rte_mbuf.c
index 3ff0a69187..f7e3c1a187 100644
--- a/lib/mbuf/rte_mbuf.c
+++ b/lib/mbuf/rte_mbuf.c
@@ -43,6 +43,8 @@ rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg)
struct rte_pktmbuf_pool_private default_mbp_priv;
uint16_t roomsz;
+ RTE_ASSERT(mp->private_data_size >=
+ sizeof(struct rte_pktmbuf_pool_private));
RTE_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf));
/* if no structure is provided, assume no mbuf private area */
@@ -83,6 +85,9 @@ rte_pktmbuf_init(struct rte_mempool *mp,
struct rte_mbuf *m = _m;
uint32_t mbuf_size, buf_len, priv_size;
+ RTE_ASSERT(mp->private_data_size >=
+ sizeof(struct rte_pktmbuf_pool_private));
+
priv_size = rte_pktmbuf_priv_size(mp);
mbuf_size = sizeof(struct rte_mbuf) + priv_size;
buf_len = rte_pktmbuf_data_room_size(mp);
diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index c4c9ebfaa0..a555f216ae 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -624,6 +624,9 @@ rte_mbuf_raw_free(struct rte_mbuf *m)
* address, and so on). This function is given as a callback function to
* rte_mempool_obj_iter() or rte_mempool_create() at pool creation time.
*
+ * This function expects that the mempool private area was previously
+ * initialized with rte_pktmbuf_pool_init().
+ *
* @param mp
* The mempool from which mbufs originate.
* @param opaque_arg
@@ -639,7 +642,7 @@ void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
void *m, unsigned i);
/**
- * A packet mbuf pool constructor.
+ * A packet mbuf pool constructor.
*
* This function initializes the mempool private data in the case of a
* pktmbuf pool. This private data is needed by the driver. The
@@ -648,6 +651,9 @@ void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
* pool creation. It can be extended by the user, for example, to
* provide another packet size.
*
+ * The mempool private area size must be at least equal to
+ * sizeof(struct rte_pktmbuf_pool_private).
+ *
* @param mp
* The mempool from which mbufs originate.
* @param opaque_arg
--
2.29.2
next prev parent reply other threads:[~2021-04-27 13:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-31 21:05 [dpdk-dev] [PATCH] test/mempool: Fix illegal pointer access in mempool test Wenwu Ma
2021-04-13 20:05 ` [dpdk-dev] [v2] test/mempool: fix heap buffer overflow Wenwu Ma
2021-04-13 11:52 ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2021-04-15 6:45 ` Olivier Matz
2021-04-15 12:51 ` Aaron Conole
2021-04-16 7:20 ` Olivier Matz
2021-04-27 13:56 ` [dpdk-dev] [PATCH v3 1/2] " Olivier Matz
2021-04-27 13:56 ` Olivier Matz [this message]
2021-04-27 14:22 ` [dpdk-dev] [PATCH v3 2/2] mbuf: better document usage of packet pool initializers Aaron Conole
2021-05-04 18:07 ` [dpdk-dev] [dpdk-stable] [PATCH v3 1/2] test/mempool: fix heap buffer overflow Thomas Monjalon
2021-04-15 2:04 ` [dpdk-dev] [PATCH] test/mempool: Fix illegal pointer access in mempool test Peng, ZhihongX
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=20210427135646.871-2-olivier.matz@6wind.com \
--to=olivier.matz@6wind.com \
--cc=aconole@redhat.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=pallantlax.poornima@intel.com \
--cc=thomas@monjalon.net \
--cc=wenwux.ma@intel.com \
--cc=zhihongx.peng@intel.com \
/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).