[dpdk-dev] [PATCH v4 3/3] net/hinic: adds txq xstats member

Xiaoyun wang cloud.wangxiaoyun at huawei.com
Fri Apr 10 11:21:47 CEST 2020


Because some APPs may pass illegal parameters, driver increases
checks on illegal parameters and DFX statistics, which includes
sge_len0 and mbuf_null txq xstats member.

Signed-off-by: Xiaoyun wang <cloud.wangxiaoyun at huawei.com>
---
 drivers/net/hinic/hinic_pmd_ethdev.c |  2 ++
 drivers/net/hinic/hinic_pmd_tx.c     | 31 +++++++++++++++++++++++++++++++
 drivers/net/hinic/hinic_pmd_tx.h     |  2 ++
 3 files changed, 35 insertions(+)

diff --git a/drivers/net/hinic/hinic_pmd_ethdev.c b/drivers/net/hinic/hinic_pmd_ethdev.c
index 4091cf1..cfbca64 100644
--- a/drivers/net/hinic/hinic_pmd_ethdev.c
+++ b/drivers/net/hinic/hinic_pmd_ethdev.c
@@ -225,6 +225,8 @@ struct hinic_xstats_name_off {
 	{"copy_pkts", offsetof(struct hinic_txq_stats, cpy_pkts)},
 	{"rl_drop", offsetof(struct hinic_txq_stats, rl_drop)},
 	{"burst_pkts", offsetof(struct hinic_txq_stats, burst_pkts)},
+	{"sge_len0", offsetof(struct hinic_txq_stats, sge_len0)},
+	{"mbuf_null", offsetof(struct hinic_txq_stats, mbuf_null)},
 };
 
 #define HINIC_TXQ_XSTATS_NUM (sizeof(hinic_txq_stats_strings) / \
diff --git a/drivers/net/hinic/hinic_pmd_tx.c b/drivers/net/hinic/hinic_pmd_tx.c
index f24e3e4..258f2c1 100644
--- a/drivers/net/hinic/hinic_pmd_tx.c
+++ b/drivers/net/hinic/hinic_pmd_tx.c
@@ -334,7 +334,16 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
 		i = 0;
 		for (sge_idx = sges; (u64)sge_idx <= txq->sq_bot_sge_addr;
 		     sge_idx++) {
+			if (unlikely(mbuf == NULL)) {
+				txq->txq_stats.mbuf_null++;
+				return false;
+			}
+
 			dma_addr = rte_mbuf_data_iova(mbuf);
+			if (unlikely(mbuf->data_len == 0)) {
+				txq->txq_stats.sge_len0++;
+				return false;
+			}
 			hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
 				      mbuf->data_len);
 			mbuf = mbuf->next;
@@ -345,7 +354,16 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
 		sge_idx = (struct hinic_sq_bufdesc *)
 				((void *)txq->sq_head_addr);
 		for (; i < nb_segs; i++) {
+			if (unlikely(mbuf == NULL)) {
+				txq->txq_stats.mbuf_null++;
+				return false;
+			}
+
 			dma_addr = rte_mbuf_data_iova(mbuf);
+			if (unlikely(mbuf->data_len == 0)) {
+				txq->txq_stats.sge_len0++;
+				return false;
+			}
 			hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
 				      mbuf->data_len);
 			mbuf = mbuf->next;
@@ -357,7 +375,16 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
 	} else {
 		/* wqe is in continuous space */
 		for (i = 0; i < nb_segs; i++) {
+			if (unlikely(mbuf == NULL)) {
+				txq->txq_stats.mbuf_null++;
+				return false;
+			}
+
 			dma_addr = rte_mbuf_data_iova(mbuf);
+			if (unlikely(mbuf->data_len == 0)) {
+				txq->txq_stats.sge_len0++;
+				return false;
+			}
 			hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
 				      mbuf->data_len);
 			mbuf = mbuf->next;
@@ -378,6 +405,10 @@ static inline bool hinic_mbuf_dma_map_sge(struct hinic_txq *txq,
 
 		/* deal with the last mbuf */
 		dma_addr = rte_mbuf_data_iova(mbuf);
+		if (unlikely(mbuf->data_len == 0)) {
+			txq->txq_stats.sge_len0++;
+			return false;
+		}
 		hinic_set_sge((struct hinic_sge *)sge_idx, dma_addr,
 			      mbuf->data_len);
 		if (unlikely(sqe_info->around))
diff --git a/drivers/net/hinic/hinic_pmd_tx.h b/drivers/net/hinic/hinic_pmd_tx.h
index dabbc6c..d98abad 100644
--- a/drivers/net/hinic/hinic_pmd_tx.h
+++ b/drivers/net/hinic/hinic_pmd_tx.h
@@ -93,6 +93,8 @@ struct hinic_txq_stats {
 	u64 off_errs;
 	u64 cpy_pkts;
 	u64 burst_pkts;
+	u64 sge_len0;
+	u64 mbuf_null;
 };
 
 struct hinic_tx_info {
-- 
1.8.3.1



More information about the dev mailing list