Skip to contentSkip to conversation

net/i40e: fix unexpected mbuf free in vPMD

PATCH In review Qi Zhang 4 participants 5 messages Oct 9, 2017 – Oct 10, 2017 Network drivers

lore
Share & tools
lore
#1 lore raw
In reply to Qi Zhang

Hi, qi

Is your patch duplicated with this http://www.dpdk.org/dev/patchwork/patch/29814/ ?

Thanks
Jingjing

Quoted 49 lines

-----Original Message-----
From: Zhang, Qi Z
Sent: Monday, October 9, 2017 4:54 PM
To: Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Cc: [email protected]; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [PATCH] net/i40e: fix unexpected mbuf free in vPMD

The patch reset tx queue sw_ring's mbuf to NULL after it is free in i40_tx_free_bufs, this prevent same mbuf be free again in i40e_dev_tx_queue_release. This fix follow the same implemenation of non- vPMD.

Fixes b4669bb95038 ("i40e: add vector Tx")
---
 drivers/net/i40e/i40e_rxtx_vec_common.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/i40e/i40e_rxtx_vec_common.h +3 -1
index 39a6da0..ed51b4d 100644
@@ -124,11 +124,13 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	  */
 	txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)];
 	m = rte_pktmbuf_prefree_seg(txep[0].mbuf);
+	txep[0].mbuf = NULL;
 	if (likely(m != NULL)) {
 		free[0] = m;
 		nb_free = 1;
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (likely(m != NULL)) {
 				if (likely(m->pool == free[0]->pool)) {
 					free[nb_free++] = m;
@@ -145,6 +147,7 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	} else {
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (m != NULL)
 				rte_mempool_put(m->pool, m);
 		}
--

2.9.5

Qi Zhang

author
#0 lore raw

PATCH 1/1 net/i40e: fix unexpected mbuf free in vPMD

The patch reset tx queue sw_ring's mbuf to NULL after it is free in i40_tx_free_bufs, this prevent same mbuf be free again in i40e_dev_tx_queue_release. This fix follow the same implemenation of non-vPMD.

Fixes b4669bb95038 ("i40e: add vector Tx")
---
 drivers/net/i40e/i40e_rxtx_vec_common.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/i40e/i40e_rxtx_vec_common.h +3 -0
index 39a6da0..ed51b4d 100644
@@ -124,11 +124,13 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	  */
 	txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)];
 	m = rte_pktmbuf_prefree_seg(txep[0].mbuf);
+	txep[0].mbuf = NULL;
 	if (likely(m != NULL)) {
 		free[0] = m;
 		nb_free = 1;
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (likely(m != NULL)) {
 				if (likely(m->pool == free[0]->pool)) {
 					free[nb_free++] = m;
@@ -145,6 +147,7 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	} else {
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (m != NULL)
 				rte_mempool_put(m->pool, m);
 		}
Signature · 1 line
2.9.5
#2 lore raw

Hi Zhang,

Quoted 11 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Monday, October 9, 2017 9:54 AM
To: Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Cc: [email protected]; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] net/i40e: fix unexpected mbuf free in vPMD

The patch reset tx queue sw_ring's mbuf to NULL after it is free in i40_tx_free_bufs, this prevent same mbuf be free again in i40e_dev_tx_queue_release. This fix follow the same implemenation of non-vPMD.

Wonder why we can't change i40e_dev_tx_queue_release() instead, so it will only go through the TXDs that were really armed? Let say from txq->tx_next_dd - tx_rs_thresh - 1 till txq->tx_tail? Let say _ixgbe_tx_queue_release_mbufs_vec() works that way. Then we probably can keep our runtime code intact. Konstantin

Quoted 37 lines
Fixes b4669bb95038 ("i40e: add vector Tx")
---
 drivers/net/i40e/i40e_rxtx_vec_common.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/i40e/i40e_rxtx_vec_common.h +3 -1
index 39a6da0..ed51b4d 100644
@@ -124,11 +124,13 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	  */
 	txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)];
 	m = rte_pktmbuf_prefree_seg(txep[0].mbuf);
+	txep[0].mbuf = NULL;
 	if (likely(m != NULL)) {
 		free[0] = m;
 		nb_free = 1;
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (likely(m != NULL)) {
 				if (likely(m->pool == free[0]->pool)) {
 					free[nb_free++] = m;
@@ -145,6 +147,7 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	} else {
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (m != NULL)
 				rte_mempool_put(m->pool, m);
 		}
--

2.9.5

#3 lore raw
Quoted 14 lines · Konstantin

Hi Zhang,

Quoted 11 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Monday, October 9, 2017 9:54 AM
To: Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Cc: [email protected]; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] net/i40e: fix unexpected mbuf free in vPMD

The patch reset tx queue sw_ring's mbuf to NULL after it is free in i40_tx_free_bufs, this prevent same mbuf be free again in i40e_dev_tx_queue_release. This fix follow the same implemenation of non-vPMD.

Quoted 7 lines

Wonder why we can't change i40e_dev_tx_queue_release() instead, so it will only go through the TXDs that were really armed? Let say from txq->tx_next_dd - tx_rs_thresh - 1 till txq->tx_tail? Let say _ixgbe_tx_queue_release_mbufs_vec() works that way. Then we probably can keep our runtime code intact. Konstantin

+1 to this. We should avoid adding writes to the TX path. Instead we should ensure that other routines properly track the buffers to be freed using the appropriate indexes.

/Bruce

#4 lore raw
In reply to Ananyev, Konstantin

Hi Konstantin:

Quoted 18 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Monday, October 9, 2017 8:44 PM
To: Zhang, Qi Z <[email protected]>; Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Cc: [email protected]; Zhang, Qi Z <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] net/i40e: fix unexpected mbuf free in vPMD

Hi Zhang,

Quoted 8 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Qi Zhang
Sent: Monday, October 9, 2017 9:54 AM
To: Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Cc: [email protected]; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] net/i40e: fix unexpected mbuf free in vPMD

Quoted 7 lines
Quoted 4 lines

The patch reset tx queue sw_ring's mbuf to NULL after it is free in i40_tx_free_bufs, this prevent same mbuf be free again in i40e_dev_tx_queue_release. This fix follow the same implemenation of non-vPMD.

Wonder why we can't change i40e_dev_tx_queue_release() instead, so it will only go through the TXDs that were really armed?

Yes we can, I've thought about this before the patch, but after I measure the performance impact, I saw less than 0.6% downgrade for single core performance. So I think maybe a simple fix could be good enough and low risk and an improvement can be delivered later after carefully validate.

Quoted 2 lines

Let say from txq->tx_next_dd - tx_rs_thresh - 1 till txq->tx_tail? Let say _ixgbe_tx_queue_release_mbufs_vec() works that way.

Yes, That's the same way I figured out, thanks for giving the detail instruction that confirm my thought :) Now, I think my v2 can upgrade to this directly.

Thanks
Qi

Quoted 42 lines

Then we probably can keep our runtime code intact.

Konstantin

Quoted 38 lines
Fixes b4669bb95038 ("i40e: add vector Tx")
---
 drivers/net/i40e/i40e_rxtx_vec_common.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/i40e/i40e_rxtx_vec_common.h +3 -1
index 39a6da0..ed51b4d 100644
@@ -124,11 +124,13 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	  */
 	txep = &txq->sw_ring[txq->tx_next_dd - (n - 1)];
 	m = rte_pktmbuf_prefree_seg(txep[0].mbuf);
+	txep[0].mbuf = NULL;
 	if (likely(m != NULL)) {
 		free[0] = m;
 		nb_free = 1;
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (likely(m != NULL)) {
 				if (likely(m->pool == free[0]->pool)) {
 					free[nb_free++] = m;
@@ -145,6 +147,7 @@ i40e_tx_free_bufs(struct i40e_tx_queue *txq)
 	} else {
 		for (i = 1; i < n; i++) {
 			m = rte_pktmbuf_prefree_seg(txep[i].mbuf);
+			txep[i].mbuf = NULL;
 			if (m != NULL)
 				rte_mempool_put(m->pool, m);
 		}
--

2.9.5