Skip to contentSkip to conversation

mbuf: fix bulk allocation when debug enabled

PATCH In review Gregory Etelson 3 participants 5 messages May 6, 2017 – May 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mbuf: fix bulk allocation when debug enabled

The debug assertions when allocating a raw mbuf are not correct since commit 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool"), which triggers a panic when using this function in debug mode

---
 lib/librte_mbuf/rte_mbuf.h | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
lib/librte_mbuf/rte_mbuf.h +12 -13
index 9097f18..05b8300 100644
@@ -788,6 +788,13 @@ rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
 
+#define MBUF_RAW_ALLOC_CHECK(m_) do {				\
+	RTE_ASSERT(rte_mbuf_refcnt_read(m_) == 1);		\
+	RTE_ASSERT(m_->next == NULL);				\
+	RTE_ASSERT(m_->nb_segs == 1);				\
+	__rte_mbuf_sanity_check(m_, 0);				\
+} while (0)
+
 /**
  * Allocate an unitialized mbuf from mempool *mp*.
  *
@@ -815,11 +822,7 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &mb) < 0)
 		return NULL;
 	m = (struct rte_mbuf *)mb;
-	RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1);
-	RTE_ASSERT(m->next == NULL);
-	RTE_ASSERT(m->nb_segs == 1);
-	__rte_mbuf_sanity_check(m, 0);
-
+	MBUF_RAW_ALLOC_CHECK(m);
 	return m;
 }
 
@@ -1152,26 +1155,22 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	switch (count % 4) {
 	case 0:
 		while (idx != count) {
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
 	case 3:
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
 	case 2:
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
 	case 1:
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
Signature · 1 line
2.9.3
#1 lore raw

Hi,

Quoted 4 lines · Gregory Etelson

The debug assertions when allocating a raw mbuf are not correct since commit 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool"), which triggers a panic when using this function in debug mode

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
Quoted 10 lines
---
 lib/librte_mbuf/rte_mbuf.h | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
lib/librte_mbuf/rte_mbuf.h +0 -0
index 9097f18..05b8300 100644

lib/librte_mbuf/rte_mbuf.h rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value) · line 797

Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +7 -0
@@ -788,6 +788,13 @@ rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
 
+#define MBUF_RAW_ALLOC_CHECK(m_) do {				\
+	RTE_ASSERT(rte_mbuf_refcnt_read(m_) == 1);		\
+	RTE_ASSERT(m_->next == NULL);				\
+	RTE_ASSERT(m_->nb_segs == 1);				\
+	__rte_mbuf_sanity_check(m_, 0);				\
+} while (0)
+

Few nits:
- maybe 'm_' could be 'm'
- some parenthesis could be added for safety

Thomas, I know you're in hurry for 17.05, I think this fix should go in. If you want, I can send a v3 with this small changes if you need it now.

Regards,
Olivier

#2 lore raw

10/05/2017 16:42, Olivier Matz:

Quoted 35 lines

Hi,

Quoted 4 lines · Gregory Etelson

The debug assertions when allocating a raw mbuf are not correct since commit 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool"), which triggers a panic when using this function in debug mode

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
Quoted 10 lines
---
 lib/librte_mbuf/rte_mbuf.h | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
lib/librte_mbuf/rte_mbuf.h +0 -0
index 9097f18..05b8300 100644

lib/librte_mbuf/rte_mbuf.h rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value) · line 797

Quoted 10 lines
lib/librte_mbuf/rte_mbuf.h +7 -0
@@ -788,6 +788,13 @@ rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
 
+#define MBUF_RAW_ALLOC_CHECK(m_) do {				\
+	RTE_ASSERT(rte_mbuf_refcnt_read(m_) == 1);		\
+	RTE_ASSERT(m_->next == NULL);				\
+	RTE_ASSERT(m_->nb_segs == 1);				\
+	__rte_mbuf_sanity_check(m_, 0);				\
+} while (0)
+

Few nits:
- maybe 'm_' could be 'm'
- some parenthesis could be added for safety

Quoted 3 lines

Thomas, I know you're in hurry for 17.05, I think this fix should go in. If you want, I can send a v3 with this small changes if you need it now.

Yes, please a quick v3 would be appreciated.
Thanks

#3 lore raw

PATCH v3 1/1 mbuf: fix bulk allocation when debug enabled

In reply to Gregory Etelson

From: Gregory Etelson <[email protected]>

The debug assertions when allocating a raw mbuf are not correct since commit 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool"), which triggers a panic when using this function in debug mode

Change the expected number of segments to 1 instead of 0, and factorize these sanity checks.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")
---
 lib/librte_mbuf/rte_mbuf.h | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
lib/librte_mbuf/rte_mbuf.h +12 -13
index 9097f1859..1cb03109c 100644
@@ -788,6 +788,13 @@ rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
 void
 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
 
+#define MBUF_RAW_ALLOC_CHECK(m) do {				\
+	RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1);		\
+	RTE_ASSERT((m)->next == NULL);				\
+	RTE_ASSERT((m)->nb_segs == 1);				\
+	__rte_mbuf_sanity_check(m, 0);				\
+} while (0)
+
 /**
  * Allocate an unitialized mbuf from mempool *mp*.
  *
@@ -815,11 +822,7 @@ static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
 	if (rte_mempool_get(mp, &mb) < 0)
 		return NULL;
 	m = (struct rte_mbuf *)mb;
-	RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1);
-	RTE_ASSERT(m->next == NULL);
-	RTE_ASSERT(m->nb_segs == 1);
-	__rte_mbuf_sanity_check(m, 0);
-
+	MBUF_RAW_ALLOC_CHECK(m);
 	return m;
 }
 
@@ -1152,26 +1155,22 @@ static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
 	switch (count % 4) {
 	case 0:
 		while (idx != count) {
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
 	case 3:
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
 	case 2:
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
 	case 1:
-			RTE_ASSERT(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
-			rte_mbuf_refcnt_set(mbufs[idx], 1);
+			MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
 			rte_pktmbuf_reset(mbufs[idx]);
 			idx++;
 			/* fall-through */
Signature · 1 line
2.11.0
#4 lore raw

10/05/2017 17:13, Olivier Matz:

Quoted 6 lines

From: Gregory Etelson <[email protected]>

The debug assertions when allocating a raw mbuf are not correct since commit 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool"), which triggers a panic when using this function in debug mode

Quoted 7 lines

Change the expected number of segments to 1 instead of 0, and factorize these sanity checks.

Fixes 8f094a9ac5d7 ("mbuf: set mbuf fields while in pool")

Applied, thanks