diff mbox series

[v2] app/testpmd: fix segment number check

Message ID 20210423160952.336272-1-ferruh.yigit@intel.com (mailing list archive)
State Accepted
Delegated to: Ferruh Yigit
Headers show
Series [v2] app/testpmd: fix segment number check | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Ferruh Yigit April 23, 2021, 4:09 p.m. UTC
From: Viacheslav Ovsiienko <viacheslavo@nvidia.com>

The --txpkts command line parameter was silently ignored due to
application was unable to check the Tx queue ring sizes for non
configured ports [1].

The "set txpkts <len0[,len1]*>" was also rejected if there
was some stopped or /unconfigured port.

This provides the following:

  - If fails to get ring size from the port, this can be because port is
    not initialized yet, ignore the check and just be sure segment size
    won't cause an out of bound access. The port descriptor check will
    be done during Tx setup.

  - The capability to send single packet is supposed to be very basic
    and always supported, the setting segment number to 1 is always
    allowed, no check performed

  - At the moment of Tx queue setup the descriptor number is checked
    against configured segment number

Bugzilla ID: 584
Fixes: 8dae835d88b7 ("app/testpmd: remove restriction on Tx segments set")
Cc: stable@dpdk.org

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: Andrew Boyer <aboyer@pensando.io>

v2:
* Become more flexible for the '--txpkts' command line, if not able to
  get the descriptor size from port, ignore the check.

  ('nb_txd' check was proposed before, this will require '--txd'
  parameter, but also enforces a specific order on the parameters,
  instead going with the option to flex the checks for parameter.)
---
 app/test-pmd/cmdline.c |  4 ++++
 app/test-pmd/config.c  | 32 ++++++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 8 deletions(-)

Comments

Li, Xiaoyun April 26, 2021, 11:23 a.m. UTC | #1
Hi

> -----Original Message-----
> From: Yigit, Ferruh <ferruh.yigit@intel.com>
> Sent: Saturday, April 24, 2021 00:10
> To: Viacheslav Ovsiienko <viacheslavo@nvidia.com>; Li, Xiaoyun
> <xiaoyun.li@intel.com>; Wei Hu (Xavier) <xavier.huwei@huawei.com>;
> Chengchang Tang <tangchengchang@huawei.com>
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; dev@dpdk.org; stable@dpdk.org;
> Andrew Boyer <aboyer@pensando.io>
> Subject: [PATCH v2] app/testpmd: fix segment number check
> 
> From: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
> 
> The --txpkts command line parameter was silently ignored due to application
> was unable to check the Tx queue ring sizes for non configured ports [1].

Remove this [1] or mark the following items as [1] [2] [3].

> 
> The "set txpkts <len0[,len1]*>" was also rejected if there was some stopped or
> /unconfigured port.
> 
> This provides the following:
> 
>   - If fails to get ring size from the port, this can be because port is
>     not initialized yet, ignore the check and just be sure segment size
>     won't cause an out of bound access. The port descriptor check will
>     be done during Tx setup.
> 
>   - The capability to send single packet is supposed to be very basic
>     and always supported, the setting segment number to 1 is always
>     allowed, no check performed
> 
>   - At the moment of Tx queue setup the descriptor number is checked
>     against configured segment number
> 
> Bugzilla ID: 584
> Fixes: 8dae835d88b7 ("app/testpmd: remove restriction on Tx segments set")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
> Cc: Andrew Boyer <aboyer@pensando.io>
> 
> v2:
> * Become more flexible for the '--txpkts' command line, if not able to
>   get the descriptor size from port, ignore the check.
> 
>   ('nb_txd' check was proposed before, this will require '--txd'
>   parameter, but also enforces a specific order on the parameters,
>   instead going with the option to flex the checks for parameter.)
> ---
>  app/test-pmd/cmdline.c |  4 ++++
>  app/test-pmd/config.c  | 32 ++++++++++++++++++++++++--------
>  2 files changed, 28 insertions(+), 8 deletions(-)

Except the one comment above for commit log,
Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
Ferruh Yigit April 27, 2021, 11:42 a.m. UTC | #2
On 4/26/2021 12:23 PM, Li, Xiaoyun wrote:
> Hi
> 
>> -----Original Message-----
>> From: Yigit, Ferruh <ferruh.yigit@intel.com>
>> Sent: Saturday, April 24, 2021 00:10
>> To: Viacheslav Ovsiienko <viacheslavo@nvidia.com>; Li, Xiaoyun
>> <xiaoyun.li@intel.com>; Wei Hu (Xavier) <xavier.huwei@huawei.com>;
>> Chengchang Tang <tangchengchang@huawei.com>
>> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; dev@dpdk.org; stable@dpdk.org;
>> Andrew Boyer <aboyer@pensando.io>
>> Subject: [PATCH v2] app/testpmd: fix segment number check
>>
>> From: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
>>
>> The --txpkts command line parameter was silently ignored due to application
>> was unable to check the Tx queue ring sizes for non configured ports [1].
> 
> Remove this [1] or mark the following items as [1] [2] [3].
> 
>>
>> The "set txpkts <len0[,len1]*>" was also rejected if there was some stopped or
>> /unconfigured port.
>>
>> This provides the following:
>>
>>   - If fails to get ring size from the port, this can be because port is
>>     not initialized yet, ignore the check and just be sure segment size
>>     won't cause an out of bound access. The port descriptor check will
>>     be done during Tx setup.
>>
>>   - The capability to send single packet is supposed to be very basic
>>     and always supported, the setting segment number to 1 is always
>>     allowed, no check performed
>>
>>   - At the moment of Tx queue setup the descriptor number is checked
>>     against configured segment number
>>
>> Bugzilla ID: 584
>> Fixes: 8dae835d88b7 ("app/testpmd: remove restriction on Tx segments set")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> ---
>> Cc: Andrew Boyer <aboyer@pensando.io>
>>
>> v2:
>> * Become more flexible for the '--txpkts' command line, if not able to
>>   get the descriptor size from port, ignore the check.
>>
>>   ('nb_txd' check was proposed before, this will require '--txd'
>>   parameter, but also enforces a specific order on the parameters,
>>   instead going with the option to flex the checks for parameter.)
>> ---
>>  app/test-pmd/cmdline.c |  4 ++++
>>  app/test-pmd/config.c  | 32 ++++++++++++++++++++++++--------
>>  2 files changed, 28 insertions(+), 8 deletions(-)
> 
> Except the one comment above for commit log,
> Acked-by: Xiaoyun Li <xiaoyun.li@intel.com>
> 

Applied to dpdk-next-net/main, thanks.


Above missing reference in the commit log removed while merging.
diff mbox series

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 12efbc0cab46..7feba8337781 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -2910,6 +2910,10 @@  cmd_setup_rxtx_queue_parsed(
 		if (!numa_support || socket_id == NUMA_NO_CONFIG)
 			socket_id = port->socket_id;
 
+		if (port->nb_tx_desc[res->qid] < tx_pkt_nb_segs) {
+			printf("Failed to setup TX queue: not enough descriptors\n");
+			return;
+		}
 		ret = rte_eth_tx_queue_setup(res->portid,
 					     res->qid,
 					     port->nb_tx_desc[res->qid],
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index e189062efde8..a4445a73bfa5 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -3697,13 +3697,15 @@  nb_segs_is_invalid(unsigned int nb_segs)
 	RTE_ETH_FOREACH_DEV(port_id) {
 		for (queue_id = 0; queue_id < nb_txq; queue_id++) {
 			ret = get_tx_ring_size(port_id, queue_id, &ring_size);
-
-			if (ret)
-				return true;
-
+			if (ret) {
+				/* Port may not be initialized yet, can't say
+				 * the port is invalid in this stage.
+				 */
+				continue;
+			}
 			if (ring_size < nb_segs) {
-				printf("nb segments per TX packets=%u >= "
-				       "TX queue(%u) ring_size=%u - ignored\n",
+				printf("nb segments per TX packets=%u >= TX "
+				       "queue(%u) ring_size=%u - txpkts ignored\n",
 				       nb_segs, queue_id, ring_size);
 				return true;
 			}
@@ -3719,12 +3721,26 @@  set_tx_pkt_segments(unsigned int *seg_lengths, unsigned int nb_segs)
 	uint16_t tx_pkt_len;
 	unsigned int i;
 
-	if (nb_segs_is_invalid(nb_segs))
+	/*
+	 * For single segment settings failed check is ignored.
+	 * It is a very basic capability to send the single segment
+	 * packets, suppose it is always supported.
+	 */
+	if (nb_segs > 1 && nb_segs_is_invalid(nb_segs)) {
+		printf("Tx segment size(%u) is not supported - txpkts ignored\n",
+			nb_segs);
 		return;
+	}
+
+	if (nb_segs > RTE_MAX_SEGS_PER_PKT) {
+		printf("Tx segment size(%u) is bigger than max number of segment(%u)\n",
+			nb_segs, RTE_MAX_SEGS_PER_PKT);
+		return;
+	}
 
 	/*
 	 * Check that each segment length is greater or equal than
-	 * the mbuf data sise.
+	 * 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).