From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0F694A0C4B for ; Thu, 2 Sep 2021 10:20:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EB9984067E; Thu, 2 Sep 2021 10:20:23 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id BCD224003C; Thu, 2 Sep 2021 10:20:21 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10094"; a="206246638" X-IronPort-AV: E=Sophos;i="5.84,371,1620716400"; d="scan'208";a="206246638" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2021 01:20:20 -0700 X-IronPort-AV: E=Sophos;i="5.84,371,1620716400"; d="scan'208";a="520950851" Received: from shwdenpg235.ccr.corp.intel.com ([10.253.106.22]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2021 01:20:18 -0700 From: Alvin Zhang To: xiaoyun.li@intel.com, konstantin.ananyev@intel.com Cc: dev@dpdk.org, Alvin Zhang , stable@dpdk.org Date: Thu, 2 Sep 2021 16:20:13 +0800 Message-Id: <20210902082013.7704-1-alvinx.zhang@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH] app/testpmd: fix random number of Tx segments X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" When random number of segments in Tx packets is enabled, the total data space length of all segments must be greater or equal than the size of an Eth/IP/UDP/timestamp packet, that's total 14 + 20 + 8 + 16 bytes. Otherwise the Tx engine may cause the application to crash. Bugzilla ID: 797 Fixes: 79bec05b32b7 ("app/testpmd: add ability to split outgoing packets") Cc: stable@dpdk.org Signed-off-by: Alvin Zhang --- app/test-pmd/config.c | 16 +++++++++++----- app/test-pmd/testpmd.c | 5 +++++ app/test-pmd/testpmd.h | 5 +++++ app/test-pmd/txonly.c | 7 +++++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 31d8ba1..5105b3b 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -3837,10 +3837,11 @@ struct igb_ring_desc_16_bytes { * Check that each segment length is greater or equal than * the mbuf data size. * Check also that the total packet length is greater or equal than the - * size of an empty UDP/IP packet (sizeof(struct rte_ether_hdr) + - * 20 + 8). + * size of an Eth/IP/UDP + timestamp packet + * (sizeof(struct rte_ether_hdr) + 20 + 8 + 16). */ tx_pkt_len = 0; + tx_pkt_nb_min_segs = 0; for (i = 0; i < nb_segs; i++) { if (seg_lengths[i] > mbuf_data_size[0]) { fprintf(stderr, @@ -3849,11 +3850,16 @@ struct igb_ring_desc_16_bytes { return; } tx_pkt_len = (uint16_t)(tx_pkt_len + seg_lengths[i]); + + if (!tx_pkt_nb_min_segs && + tx_pkt_len >= (sizeof(struct rte_ether_hdr) + 20 + 8 + 16)) + tx_pkt_nb_min_segs = i + 1; } - if (tx_pkt_len < (sizeof(struct rte_ether_hdr) + 20 + 8)) { + + if (!tx_pkt_nb_min_segs) { fprintf(stderr, "total packet length=%u < %d - give up\n", - (unsigned) tx_pkt_len, - (int)(sizeof(struct rte_ether_hdr) + 20 + 8)); + (unsigned int) tx_pkt_len, + (int)(sizeof(struct rte_ether_hdr) + 20 + 8 + 16)); return; } diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 6cbe9ba..c496e59 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -232,6 +232,11 @@ struct fwd_engine * fwd_engines[] = { }; uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */ +/**< Minimum number of segments in TXONLY packets to accommodate all packet + * headers. + */ +uint8_t tx_pkt_nb_min_segs = 1; + enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF; /**< Split policy for packets to TX. */ diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 16a3598..f5bc427 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -464,6 +464,11 @@ enum dcb_mode_enable extern uint16_t tx_pkt_length; /**< Length of TXONLY packet */ extern uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT]; /**< Seg. lengths */ extern uint8_t tx_pkt_nb_segs; /**< Number of segments in TX packets */ + +/**< Minimum number of segments in TXONLY packets to accommodate all packet + * headers. + */ +extern uint8_t tx_pkt_nb_min_segs; extern uint32_t tx_pkt_times_intra; extern uint32_t tx_pkt_times_inter; diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index aed820f..27e4458 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -195,8 +195,11 @@ uint32_t nb_segs, pkt_len; uint8_t i; - if (unlikely(tx_pkt_split == TX_PKT_SPLIT_RND)) - nb_segs = rte_rand() % tx_pkt_nb_segs + 1; + if (unlikely(tx_pkt_split == TX_PKT_SPLIT_RND) && + tx_pkt_nb_segs > tx_pkt_nb_min_segs) + nb_segs = rte_rand() % + (tx_pkt_nb_segs - tx_pkt_nb_min_segs + 1) + + tx_pkt_nb_min_segs; else nb_segs = tx_pkt_nb_segs; -- 1.8.3.1