DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mbuf: fix mbuf operations history recording
@ 2026-04-19 22:12 Morten Brørup
  2026-04-20 10:06 ` Thomas Monjalon
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Morten Brørup @ 2026-04-19 22:12 UTC (permalink / raw)
  To: dev, Shani Peretz, Thomas Monjalon; +Cc: Morten Brørup, stable

This addresses two bugs in mbuf operations history recording.

1. With mbuf operations history recording enabled, when allocating mbufs
from a mempool failed, the array of fetched mbuf pointers was not set, but
it was dereferenced for mbuf operations history recording anyway, which
would trigger a segmentation fault or cause undefined behavior.

This was fixed by changing how the return value from the mempool
allocation is checked, so the function returns early on failure, and only
proceeds on success.

2. When allocating a bulk of mbufs using rte_pktmbuf_alloc_bulk(), two
mbuf library allocation operations were recorded on the mbuf, because the
function calls rte_mbuf_raw_alloc_bulk() for allocation, and both
functions record a mbuf library allocation operation.

This was fixed by not recording a mbuf library allocation operation in
rte_pktmbuf_alloc_bulk().

Fixes: d265a24a32a4 ("mbuf: record mbuf operations history")
Cc: stable@dpdk.org

Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/mbuf/rte_mbuf.h | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index e7c3bbadd4..60ec8158cd 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -663,14 +663,14 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0)) {
-		for (unsigned int idx = 0; idx < count; idx++)
-			__rte_mbuf_raw_sanity_check_mp(mbufs[idx], mp);
-	}
+	if (unlikely(rc))
+		return rc;
+	for (unsigned int idx = 0; idx < count; idx++)
+		__rte_mbuf_raw_sanity_check_mp(mbufs[idx], mp);
 
 	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
 
-	return rc;
+	return 0;
 }
 
 /**
@@ -1068,8 +1068,6 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
-	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
-
 	rte_mbuf_raw_reset_bulk(pool, mbufs, count);
 
 	return 0;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] mbuf: fix mbuf operations history recording
  2026-04-19 22:12 [PATCH] mbuf: fix mbuf operations history recording Morten Brørup
@ 2026-04-20 10:06 ` Thomas Monjalon
  2026-04-20 11:24   ` Morten Brørup
  2026-04-22 12:29 ` Morten Brørup
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Thomas Monjalon @ 2026-04-20 10:06 UTC (permalink / raw)
  To: Morten Brørup; +Cc: dev, Shani Peretz, stable

20/04/2026 00:12, Morten Brørup:
> This addresses two bugs in mbuf operations history recording.
> 
> 1. With mbuf operations history recording enabled, when allocating mbufs
> from a mempool failed, the array of fetched mbuf pointers was not set, but
> it was dereferenced for mbuf operations history recording anyway, which
> would trigger a segmentation fault or cause undefined behavior.
> 
> This was fixed by changing how the return value from the mempool
> allocation is checked, so the function returns early on failure, and only
> proceeds on success.
> 
> 2. When allocating a bulk of mbufs using rte_pktmbuf_alloc_bulk(), two
> mbuf library allocation operations were recorded on the mbuf, because the
> function calls rte_mbuf_raw_alloc_bulk() for allocation, and both
> functions record a mbuf library allocation operation.
> 
> This was fixed by not recording a mbuf library allocation operation in
> rte_pktmbuf_alloc_bulk().
> 
> Fixes: d265a24a32a4 ("mbuf: record mbuf operations history")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
[...]

It would be better to make an explicit comparison != 0 below:

> +	if (unlikely(rc))
> +		return rc;

Thank you for the fixes.

Acked-by: Thomas Monjalon <thomas@monjalon.net>






^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] mbuf: fix mbuf operations history recording
  2026-04-20 10:06 ` Thomas Monjalon
@ 2026-04-20 11:24   ` Morten Brørup
  0 siblings, 0 replies; 6+ messages in thread
From: Morten Brørup @ 2026-04-20 11:24 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Shani Peretz, stable

> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Monday, 20 April 2026 12.06
> 
> 20/04/2026 00:12, Morten Brørup:
> > This addresses two bugs in mbuf operations history recording.
> >
> > 1. With mbuf operations history recording enabled, when allocating
> mbufs
> > from a mempool failed, the array of fetched mbuf pointers was not
> set, but
> > it was dereferenced for mbuf operations history recording anyway,
> which
> > would trigger a segmentation fault or cause undefined behavior.
> >
> > This was fixed by changing how the return value from the mempool
> > allocation is checked, so the function returns early on failure, and
> only
> > proceeds on success.
> >
> > 2. When allocating a bulk of mbufs using rte_pktmbuf_alloc_bulk(),
> two
> > mbuf library allocation operations were recorded on the mbuf, because
> the
> > function calls rte_mbuf_raw_alloc_bulk() for allocation, and both
> > functions record a mbuf library allocation operation.
> >
> > This was fixed by not recording a mbuf library allocation operation
> in
> > rte_pktmbuf_alloc_bulk().
> >
> > Fixes: d265a24a32a4 ("mbuf: record mbuf operations history")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
> [...]
> 
> It would be better to make an explicit comparison != 0 below:
> 
> > +	if (unlikely(rc))
> > +		return rc;

I would normally have done that, but decided to do it like rte_pktmbuf_alloc_bulk().
If it was a pointer, I would probably have compared != NULL regardless of conventions in the file.

> 
> Thank you for the fixes.
> 
> Acked-by: Thomas Monjalon <thomas@monjalon.net>

Thanks for the fast review response.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] mbuf: fix mbuf operations history recording
  2026-04-19 22:12 [PATCH] mbuf: fix mbuf operations history recording Morten Brørup
  2026-04-20 10:06 ` Thomas Monjalon
@ 2026-04-22 12:29 ` Morten Brørup
  2026-04-29 16:35 ` Konstantin Ananyev
  2026-05-11 13:39 ` [PATCH v2] " Morten Brørup
  3 siblings, 0 replies; 6+ messages in thread
From: Morten Brørup @ 2026-04-22 12:29 UTC (permalink / raw)
  To: dev

Recheck-request: iol-sample-apps-testing


^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] mbuf: fix mbuf operations history recording
  2026-04-19 22:12 [PATCH] mbuf: fix mbuf operations history recording Morten Brørup
  2026-04-20 10:06 ` Thomas Monjalon
  2026-04-22 12:29 ` Morten Brørup
@ 2026-04-29 16:35 ` Konstantin Ananyev
  2026-05-11 13:39 ` [PATCH v2] " Morten Brørup
  3 siblings, 0 replies; 6+ messages in thread
From: Konstantin Ananyev @ 2026-04-29 16:35 UTC (permalink / raw)
  To: Morten Brørup, dev@dpdk.org, Shani Peretz, Thomas Monjalon
  Cc: stable@dpdk.org


> This addresses two bugs in mbuf operations history recording.
> 
> 1. With mbuf operations history recording enabled, when allocating mbufs
> from a mempool failed, the array of fetched mbuf pointers was not set, but
> it was dereferenced for mbuf operations history recording anyway, which
> would trigger a segmentation fault or cause undefined behavior.
> 
> This was fixed by changing how the return value from the mempool
> allocation is checked, so the function returns early on failure, and only
> proceeds on success.
> 
> 2. When allocating a bulk of mbufs using rte_pktmbuf_alloc_bulk(), two
> mbuf library allocation operations were recorded on the mbuf, because the
> function calls rte_mbuf_raw_alloc_bulk() for allocation, and both
> functions record a mbuf library allocation operation.
> 
> This was fixed by not recording a mbuf library allocation operation in
> rte_pktmbuf_alloc_bulk().
> 
> Fixes: d265a24a32a4 ("mbuf: record mbuf operations history")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
> ---
>  lib/mbuf/rte_mbuf.h | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
> index e7c3bbadd4..60ec8158cd 100644
> --- a/lib/mbuf/rte_mbuf.h
> +++ b/lib/mbuf/rte_mbuf.h
> @@ -663,14 +663,14 @@ static __rte_always_inline int
>  rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs,
> unsigned int count)
>  {
>  	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
> -	if (likely(rc == 0)) {
> -		for (unsigned int idx = 0; idx < count; idx++)
> -			__rte_mbuf_raw_sanity_check_mp(mbufs[idx], mp);
> -	}
> +	if (unlikely(rc))
> +		return rc;
> +	for (unsigned int idx = 0; idx < count; idx++)
> +		__rte_mbuf_raw_sanity_check_mp(mbufs[idx], mp);
> 
>  	rte_mbuf_history_mark_bulk(mbufs, count,
> RTE_MBUF_HISTORY_OP_LIB_ALLOC);
> 
> -	return rc;
> +	return 0;
>  }
> 
>  /**
> @@ -1068,8 +1068,6 @@ static inline int rte_pktmbuf_alloc_bulk(struct
> rte_mempool *pool,
>  	if (unlikely(rc))
>  		return rc;
> 
> -	rte_mbuf_history_mark_bulk(mbufs, count,
> RTE_MBUF_HISTORY_OP_LIB_ALLOC);
> -
>  	rte_mbuf_raw_reset_bulk(pool, mbufs, count);
> 
>  	return 0;
> --

Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>

> 2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] mbuf: fix mbuf operations history recording
  2026-04-19 22:12 [PATCH] mbuf: fix mbuf operations history recording Morten Brørup
                   ` (2 preceding siblings ...)
  2026-04-29 16:35 ` Konstantin Ananyev
@ 2026-05-11 13:39 ` Morten Brørup
  3 siblings, 0 replies; 6+ messages in thread
From: Morten Brørup @ 2026-05-11 13:39 UTC (permalink / raw)
  To: dev, Shani Peretz, Thomas Monjalon, Konstantin Ananyev
  Cc: Morten Brørup, stable

This addresses two bugs in mbuf operations history recording.

1. With mbuf operations history recording enabled, when allocating mbufs
from a mempool failed, the array of fetched mbuf pointers was not set, but
it was dereferenced for mbuf operations history recording anyway, which
would trigger a segmentation fault or cause undefined behavior.

This was fixed by changing how the return value from the mempool
allocation is checked, so the function returns early on failure, and only
proceeds on success.

2. When allocating a bulk of mbufs using rte_pktmbuf_alloc_bulk(), two
mbuf library allocation operations were recorded on the mbuf, because the
function calls rte_mbuf_raw_alloc_bulk() for allocation, and both
functions record a mbuf library allocation operation.

This was fixed by not recording a mbuf library allocation operation in
rte_pktmbuf_alloc_bulk().

3. When freeing a bulk of segmented mbufs, the free operations were only
recorded on the first segments.

This was fixed by freeing the pending bulks of segments using
rte_mbuf_raw_free_bulk(), which records the free operation on the mbufs,
instead of calling rte_mempool_put_bulk() directly.
The bulk operation recording at the start of the function, which only
affected the first segments of segmented packets, was removed.

Fixes: d265a24a32a4 ("mbuf: record mbuf operations history")
Cc: stable@dpdk.org

Signed-off-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
---
v2:
* Added fix for rte_pktmbuf_free_bulk.
---
 lib/mbuf/rte_mbuf.c |  8 +++-----
 lib/mbuf/rte_mbuf.h | 12 +++++-------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/lib/mbuf/rte_mbuf.c b/lib/mbuf/rte_mbuf.c
index c2476e7704..005bfaa573 100644
--- a/lib/mbuf/rte_mbuf.c
+++ b/lib/mbuf/rte_mbuf.c
@@ -540,8 +540,8 @@ __rte_pktmbuf_free_seg_via_array(struct rte_mbuf *m,
 	if (likely(m != NULL)) {
 		if (*nb_pending == pending_sz ||
 		    (*nb_pending > 0 && m->pool != pending[0]->pool)) {
-			rte_mempool_put_bulk(pending[0]->pool,
-					(void **)pending, *nb_pending);
+			rte_mbuf_raw_free_bulk(pending[0]->pool,
+					pending, *nb_pending);
 			*nb_pending = 0;
 		}
 
@@ -562,8 +562,6 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 	struct rte_mbuf *m, *m_next, *pending[RTE_PKTMBUF_FREE_PENDING_SZ];
 	unsigned int idx, nb_pending = 0;
 
-	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_FREE);
-
 	for (idx = 0; idx < count; idx++) {
 		m = mbufs[idx];
 		if (unlikely(m == NULL))
@@ -581,7 +579,7 @@ void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
 	}
 
 	if (nb_pending > 0)
-		rte_mempool_put_bulk(pending[0]->pool, (void **)pending, nb_pending);
+		rte_mbuf_raw_free_bulk(pending[0]->pool, pending, nb_pending);
 }
 
 /* Creates a shallow copy of mbuf */
diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h
index e7c3bbadd4..60ec8158cd 100644
--- a/lib/mbuf/rte_mbuf.h
+++ b/lib/mbuf/rte_mbuf.h
@@ -663,14 +663,14 @@ static __rte_always_inline int
 rte_mbuf_raw_alloc_bulk(struct rte_mempool *mp, struct rte_mbuf **mbufs, unsigned int count)
 {
 	int rc = rte_mempool_get_bulk(mp, (void **)mbufs, count);
-	if (likely(rc == 0)) {
-		for (unsigned int idx = 0; idx < count; idx++)
-			__rte_mbuf_raw_sanity_check_mp(mbufs[idx], mp);
-	}
+	if (unlikely(rc))
+		return rc;
+	for (unsigned int idx = 0; idx < count; idx++)
+		__rte_mbuf_raw_sanity_check_mp(mbufs[idx], mp);
 
 	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
 
-	return rc;
+	return 0;
 }
 
 /**
@@ -1068,8 +1068,6 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	if (unlikely(rc))
 		return rc;
 
-	rte_mbuf_history_mark_bulk(mbufs, count, RTE_MBUF_HISTORY_OP_LIB_ALLOC);
-
 	rte_mbuf_raw_reset_bulk(pool, mbufs, count);
 
 	return 0;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-05-11 13:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-19 22:12 [PATCH] mbuf: fix mbuf operations history recording Morten Brørup
2026-04-20 10:06 ` Thomas Monjalon
2026-04-20 11:24   ` Morten Brørup
2026-04-22 12:29 ` Morten Brørup
2026-04-29 16:35 ` Konstantin Ananyev
2026-05-11 13:39 ` [PATCH v2] " Morten Brørup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox