fm10k: fix a crash bug when quit from testpmd
PATCH 1/1 fm10k: fix a crash bug when quit from testpmd
From: "Chen Jing D(Mark)" <[email protected]>
When the fm10k port is closed, both func tx_queue_clean() and fm10k_tx_queue_release_mbufs_vec() will try to release buffer in SW ring. The latter func won't do sanity check on those pointers and cause crash.
The fix include 2 parts.
1. Remove Vector TX buffer release func since it can share the release functions with regular TX.
2. Add log to print out what actual Rx/Tx func is used.
--- drivers/net/fm10k/fm10k.h | 1 - drivers/net/fm10k/fm10k_ethdev.c | 17 ++++++++++++----- drivers/net/fm10k/fm10k_rxtx_vec.c | 28 ---------------------------- 3 files changed, 12 insertions(+), 34 deletions(-)
drivers/net/fm10k/fm10k.h +0 -1
@@ -237,7 +237,6 @@ struct fm10k_tx_queue { };struct fm10k_txq_ops { -void (*release_mbufs)(struct fm10k_tx_queue *txq);void (*reset)(struct fm10k_tx_queue *txq); };
drivers/net/fm10k/fm10k_ethdev.c +12 -5
@@ -386,7 +386,6 @@ fm10k_check_mq_mode(struct rte_eth_dev *dev) }static const struct fm10k_txq_ops def_txq_ops = { - .release_mbufs = tx_queue_free, .reset = tx_queue_reset, };
@@ -1073,7 +1072,7 @@ fm10k_dev_queue_release(struct rte_eth_dev *dev)for (i =0 ; i < dev->data->nb_tx_queues; i++) {struct fm10k_tx_queue *txq = dev->data->tx_queues[i]; - txq->ops->release_mbufs (txq); +tx_queue_free (txq); } }
@@ -1793,7 +1792,7 @@ fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,if (dev->data->tx_queues[queue_id] !=NULL ) {struct fm10k_tx_queue *txq = dev->data->tx_queues[queue_id]; - txq->ops->release_mbufs (txq); +tx_queue_free (txq); dev->data->tx_queues[queue_id] =NULL ; }
@@ -1872,7 +1871,7 @@ fm10k_tx_queue_release(void *queue)struct fm10k_tx_queue *q = queue;PMD_INIT_FUNC_TRACE (); - q->ops->release_mbufs (q); +tx_queue_free (q); } static int
@@ -2439,13 +2438,16 @@ fm10k_set_tx_function(struct rte_eth_dev *dev) }if (use_sse) { +PMD_INIT_LOG (ERR ,"Use vector Tx func" );for (i =0 ; i < dev->data->nb_tx_queues; i++) { txq = dev->data->tx_queues[i];fm10k_txq_vec_setup (txq); } dev->tx_pkt_burst = fm10k_xmit_pkts_vec; - }else + }else { dev->tx_pkt_burst = fm10k_xmit_pkts; +PMD_INIT_LOG (ERR ,"Use regular Tx func" ); + } } static void __attribute__((cold))
@@ -2469,6 +2471,11 @@ fm10k_set_rx_function(struct rte_eth_dev *dev) (dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec || dev->rx_pkt_burst == fm10k_recv_pkts_vec); +if (rx_using_sse) +PMD_INIT_LOG (ERR ,"Use vector Rx func" ); +else +PMD_INIT_LOG (ERR ,"Use regular Rx func" ); +for (i =0 ; i < dev->data->nb_rx_queues; i++) {struct fm10k_rx_queue *rxq = dev->data->rx_queues[i];
drivers/net/fm10k/fm10k_rxtx_vec.c +0 -28
@@ -45,8 +45,6 @@#endif static void -fm10k_tx_queue_release_mbufs_vec (struct fm10k_tx_queue *txq); -static void fm10k_reset_tx_queue (struct fm10k_tx_queue *txq);/* Handling the offload flags (olflags) field takes computation
@@ -634,7 +632,6 @@ fm10k_recv_scattered_pkts_vec(void *rx_queue, }static const struct fm10k_txq_ops vec_txq_ops = { - .release_mbufs = fm10k_tx_queue_release_mbufs_vec, .reset = fm10k_reset_tx_queue, };
@@ -795,31 +792,6 @@ fm10k_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts, }static void __attribute__((cold)) -fm10k_tx_queue_release_mbufs_vec (struct fm10k_tx_queue *txq) -{ -unsigned i; -const uint16_t max_desc = (uint16_t )(txq->nb_desc -1 ); - -if (txq->sw_ring ==NULL || txq->nb_free == max_desc) -return ; - -/* release the used mbufs in sw_ring */ -for (i = txq->next_dd - (txq->rs_thresh -1 ); - i != txq->next_free; - i = (i +1 ) & max_desc) -rte_pktmbuf_free_seg (txq->sw_ring[i]); - - txq->nb_free = max_desc; - -/* reset tx_entry */ -for (i =0 ; i < txq->nb_desc; i++) - txq->sw_ring[i] =NULL ; - -rte_free (txq->sw_ring); - txq->sw_ring =NULL ; -} - -static void __attribute__((cold))fm10k_reset_tx_queue (struct fm10k_tx_queue *txq) {static const struct fm10k_tx_desc zeroed_desc = {0 };
Signature · 1 line
1.7.7.6
Quoted 7 lines · Chen Jing D(Mark)
From: "Chen Jing D(Mark)" <[email protected]>
When the fm10k port is closed, both func
tx_queue_clean()andfm10k_tx_queue_release_mbufs_vec()will try to release buffer in SW ring. The latter func won't do sanity check on those pointers and cause crash.
Quoted 7 lines
The fix include 2 parts.
1. Remove Vector TX buffer release func since it can share the release functions with regular TX.
2. Add log to print out what actual Rx/Tx func is used.Signed-off-by Chen Jing D(Mark) <[email protected]>---
Quoted 139 lines
drivers/net/fm10k/fm10k.h | 1 - drivers/net/fm10k/fm10k_ethdev.c | 17 ++++++++++++----- drivers/net/fm10k/fm10k_rxtx_vec.c | 28 ---------------------------- 3 files changed, 12 insertions(+), 34 deletions(-)drivers/net/fm10k/fm10k.h +0
-1@@ -237,7 +237,6 @@ struct fm10k_tx_queue { };struct fm10k_txq_ops { -void (*release_mbufs)(struct fm10k_tx_queue *txq);void (*reset)(struct fm10k_tx_queue *txq); };drivers/net/fm10k/fm10k_ethdev.c +12
-5@@ -386,7 +386,6 @@ fm10k_check_mq_mode(struct rte_eth_dev *dev) }static const struct fm10k_txq_ops def_txq_ops = { - .release_mbufs = tx_queue_free, .reset = tx_queue_reset, };@@ -1073,7 +1072,7 @@ fm10k_dev_queue_release(struct rte_eth_dev *dev)for (i =0 ; i < dev->data->nb_tx_queues; i++) {struct fm10k_tx_queue *txq = dev->data->tx_queues[i]; - txq->ops->release_mbufs (txq); +tx_queue_free (txq); } }@@ -1793,7 +1792,7 @@ fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,if (dev->data->tx_queues[queue_id] !=NULL ) {struct fm10k_tx_queue *txq = dev->data->tx_queues[queue_id]; - txq->ops->release_mbufs (txq); +tx_queue_free (txq); dev->data->tx_queues[queue_id] =NULL ; }@@ -1872,7 +1871,7 @@ fm10k_tx_queue_release(void *queue)struct fm10k_tx_queue *q = queue;PMD_INIT_FUNC_TRACE (); - q->ops->release_mbufs (q); +tx_queue_free (q); } static int@@ -2439,13 +2438,16 @@ fm10k_set_tx_function(struct rte_eth_dev *dev) }if (use_sse) { +PMD_INIT_LOG (ERR ,"Use vector Tx func" );for (i =0 ; i < dev->data->nb_tx_queues; i++) { txq = dev->data->tx_queues[i];fm10k_txq_vec_setup (txq); } dev->tx_pkt_burst = fm10k_xmit_pkts_vec; - }else + }else { dev->tx_pkt_burst = fm10k_xmit_pkts; +PMD_INIT_LOG (ERR ,"Use regular Tx func" ); + } } static void __attribute__((cold))@@ -2469,6 +2471,11 @@ fm10k_set_rx_function(struct rte_eth_dev *dev) (dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec || dev->rx_pkt_burst == fm10k_recv_pkts_vec); +if (rx_using_sse) +PMD_INIT_LOG (ERR ,"Use vector Rx func" ); +else +PMD_INIT_LOG (ERR ,"Use regular Rx func" ); +for (i =0 ; i < dev->data->nb_rx_queues; i++) {struct fm10k_rx_queue *rxq = dev->data->rx_queues[i];drivers/net/fm10k/fm10k_rxtx_vec.c +0
-28@@ -45,8 +45,6 @@#endif static void -fm10k_tx_queue_release_mbufs_vec (struct fm10k_tx_queue *txq); -static void fm10k_reset_tx_queue (struct fm10k_tx_queue *txq);/* Handling the offload flags (olflags) field takes computation @@ -634,7 +632,6 @@ fm10k_recv_scattered_pkts_vec(void *rx_queue, }static const struct fm10k_txq_ops vec_txq_ops = { - .release_mbufs = fm10k_tx_queue_release_mbufs_vec, .reset = fm10k_reset_tx_queue, };@@ -795,31 +792,6 @@ fm10k_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts, }static void __attribute__((cold)) -fm10k_tx_queue_release_mbufs_vec (struct fm10k_tx_queue *txq) -{ -unsigned i; -const uint16_t max_desc = (uint16_t )(txq->nb_desc -1 ); - -if (txq->sw_ring ==NULL || txq->nb_free == max_desc) -return ; - -/* release the used mbufs in sw_ring */ -for (i = txq->next_dd - (txq->rs_thresh -1 ); - i != txq->next_free; - i = (i +1 ) & max_desc) -rte_pktmbuf_free_seg (txq->sw_ring[i]); - - txq->nb_free = max_desc; - -/* reset tx_entry */ -for (i =0 ; i < txq->nb_desc; i++) - txq->sw_ring[i] =NULL ; - -rte_free (txq->sw_ring); - txq->sw_ring =NULL ; -} - -static void __attribute__((cold))fm10k_reset_tx_queue (struct fm10k_tx_queue *txq) {static const struct fm10k_tx_desc zeroed_desc = {0 };
2015-11-12 12:57, Chen Jing D:
Quoted 11 lines
From: "Chen Jing D(Mark)" <[email protected]>
When the fm10k port is closed, both func
tx_queue_clean()andfm10k_tx_queue_release_mbufs_vec()will try to release buffer in SW ring. The latter func won't do sanity check on those pointers and cause crash.The fix include 2 parts.
1. Remove Vector TX buffer release func since it can share the release functions with regular TX.
2. Add log to print out what actual Rx/Tx func is used.
2 parts mean 2 patches.
[...]
drivers/net/fm10k/fm10k_ethdev.c fm10k_set_rx_function(struct rte_eth_dev *dev) · line 2477
Quoted 4 lines
drivers/net/fm10k/fm10k_ethdev.c +4
-0+if (rx_using_sse) +PMD_INIT_LOG (ERR ,"Use vector Rx func" ); +else +PMD_INIT_LOG (ERR ,"Use regular Rx func" );
Why using en error log level?
Quoted 17 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Tuesday, November 24, 2015 6:55 AM
To: Chen, Jing D
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] fm10k: fix a crash bug when quit from testpmd2015-11-12 12:57, Chen Jing D:
Quoted 7 lines
From: "Chen Jing D(Mark)" <[email protected]>
When the fm10k port is closed, both func
tx_queue_clean()andfm10k_tx_queue_release_mbufs_vec()will try to release buffer in SW ring. The latter func won't do sanity check on those pointers and cause crash.
Quoted 6 lines
Quoted 4 lines
The fix include 2 parts.
1. Remove Vector TX buffer release func since it can share the release functions with regular TX.
2. Add log to print out what actual Rx/Tx func is used.2 parts mean 2 patches.
OK, I'll send 2.
Quoted 8 lines
[...]
drivers/net/fm10k/fm10k_ethdev.c fm10k_set_rx_function(struct rte_eth_dev *dev) · line 2477
Quoted 4 lines
drivers/net/fm10k/fm10k_ethdev.c +4
-0+if (rx_using_sse) +PMD_INIT_LOG (ERR ,"Use vector Rx func" ); +else +PMD_INIT_LOG (ERR ,"Use regular Rx func" );Why using en error log level?
Because fm10k will decide best rx/tx func in running time, some users complain they can't find which rx/tx func they are using. the error level log will help them.
2015-11-24 02:20, Chen, Jing D:
Quoted 9 lines
From: Thomas Monjalon
Quoted 7 lines
2015-11-12 12:57, Chen Jing D:
drivers/net/fm10k/fm10k_ethdev.c fm10k_set_rx_function(struct rte_eth_dev *dev) · line 2477
Quoted 4 lines
drivers/net/fm10k/fm10k_ethdev.c +4
-0+if (rx_using_sse) +PMD_INIT_LOG (ERR ,"Use vector Rx func" ); +else +PMD_INIT_LOG (ERR ,"Use regular Rx func" );Why using en error log level?
Quoted 3 lines
Because fm10k will decide best rx/tx func in running time, some users complain they can't find which rx/tx func they are using. the error level log will help them.
But this is not an error.
Please check how other drivers advertise the chosen implementation.
PATCH v2 1/1 fm10k: fix a crash bug when quit from testpmd
In reply to Chen Jing D(Mark)From: "Chen Jing D(Mark)" <[email protected]>
When the fm10k port is closed, both func tx_queue_clean() and fm10k_tx_queue_release_mbufs_vec() will try to release buffer in SW ring. The latter func won't do sanity check on those pointers and cause crash.
The fix removed Vector TX buffer release func since it can share the release functions with regular TX.
--- drivers/net/fm10k/fm10k.h | 1 - drivers/net/fm10k/fm10k_ethdev.c | 7 +++---- drivers/net/fm10k/fm10k_rxtx_vec.c | 28 ---------------------------- 3 files changed, 3 insertions(+), 33 deletions(-)
v2 changes:
- remove debug info for actual rx/tx func.
drivers/net/fm10k/fm10k.h +0 -1
@@ -237,7 +237,6 @@ struct fm10k_tx_queue { };struct fm10k_txq_ops { -void (*release_mbufs)(struct fm10k_tx_queue *txq);void (*reset)(struct fm10k_tx_queue *txq); };
drivers/net/fm10k/fm10k_ethdev.c +3 -4
@@ -386,7 +386,6 @@ fm10k_check_mq_mode(struct rte_eth_dev *dev) }static const struct fm10k_txq_ops def_txq_ops = { - .release_mbufs = tx_queue_free, .reset = tx_queue_reset, };
@@ -1073,7 +1072,7 @@ fm10k_dev_queue_release(struct rte_eth_dev *dev)for (i =0 ; i < dev->data->nb_tx_queues; i++) {struct fm10k_tx_queue *txq = dev->data->tx_queues[i]; - txq->ops->release_mbufs (txq); +tx_queue_free (txq); } }
@@ -1761,7 +1760,7 @@ fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,if (dev->data->tx_queues[queue_id] !=NULL ) {struct fm10k_tx_queue *txq = dev->data->tx_queues[queue_id]; - txq->ops->release_mbufs (txq); +tx_queue_free (txq); dev->data->tx_queues[queue_id] =NULL ; }
@@ -1836,7 +1835,7 @@ fm10k_tx_queue_release(void *queue)struct fm10k_tx_queue *q = queue;PMD_INIT_FUNC_TRACE (); - q->ops->release_mbufs (q); +tx_queue_free (q); } static int
drivers/net/fm10k/fm10k_rxtx_vec.c +0 -28
@@ -45,8 +45,6 @@#endif static void -fm10k_tx_queue_release_mbufs_vec (struct fm10k_tx_queue *txq); -static void fm10k_reset_tx_queue (struct fm10k_tx_queue *txq);/* Handling the offload flags (olflags) field takes computation
@@ -634,7 +632,6 @@ fm10k_recv_scattered_pkts_vec(void *rx_queue, }static const struct fm10k_txq_ops vec_txq_ops = { - .release_mbufs = fm10k_tx_queue_release_mbufs_vec, .reset = fm10k_reset_tx_queue, };
@@ -795,31 +792,6 @@ fm10k_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts, }static void __attribute__((cold)) -fm10k_tx_queue_release_mbufs_vec (struct fm10k_tx_queue *txq) -{ -unsigned i; -const uint16_t max_desc = (uint16_t )(txq->nb_desc -1 ); - -if (txq->sw_ring ==NULL || txq->nb_free == max_desc) -return ; - -/* release the used mbufs in sw_ring */ -for (i = txq->next_dd - (txq->rs_thresh -1 ); - i != txq->next_free; - i = (i +1 ) & max_desc) -rte_pktmbuf_free_seg (txq->sw_ring[i]); - - txq->nb_free = max_desc; - -/* reset tx_entry */ -for (i =0 ; i < txq->nb_desc; i++) - txq->sw_ring[i] =NULL ; - -rte_free (txq->sw_ring); - txq->sw_ring =NULL ; -} - -static void __attribute__((cold))fm10k_reset_tx_queue (struct fm10k_tx_queue *txq) {static const struct fm10k_tx_desc zeroed_desc = {0 };
Signature · 1 line
1.7.7.6
Thomas Monjalon
Applied2015-11-24 11:10, Chen Jing D:
Quoted 5 lines
When the fm10k port is closed, both func
tx_queue_clean()andfm10k_tx_queue_release_mbufs_vec()will try to release buffer in SW ring. The latter func won't do sanity check on those pointers and cause crash.
Quoted 7 lines
The fix removed Vector TX buffer release func since it can share the release functions with regular TX.
Fixes fb9066e479a6(fm10k: reset and release mbuf)Signed-off-by Chen Jing D(Mark) <[email protected]>Acked-by Michael Qiu <[email protected]>
Applied, thanks