Skip to contentSkip to conversation

test: fix buffer overflow

PATCH Applied Zhang,Alvin 4 participants 5 messages Nov 25, 2020 – Jan 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: fix buffer overflow

From: Alvin Zhang <[email protected]>

The Tx buffer may overflow when there is more than one port.

Fixes 002ade70e933 ("app/test: measure cycles per packet in Rx/Tx")
---
 app/test/test_pmd_perf.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
app/test/test_pmd_perf.c +8 -10
index 4db816a..3a248d5 100644
@@ -606,10 +606,10 @@ enum {
 static int
 exec_burst(uint32_t flags, int lcore)
 {
-	unsigned i, portid, nb_tx = 0;
+	unsigned int portid, nb_tx = 0;
 	struct lcore_conf *conf;
 	uint32_t pkt_per_port;
-	int num, idx = 0;
+	int num, i, idx = 0;
 	int diff_tsc;
 
 	conf = &lcore_conf[lcore];
@@ -628,16 +628,14 @@ enum {
 		rte_atomic64_set(&start, 1);
 
 	/* start xmit */
+	i = 0;
 	while (num) {
 		nb_tx = RTE_MIN(MAX_PKT_BURST, num);
-		for (i = 0; i < conf->nb_ports; i++) {
-			portid = conf->portlist[i];
-			nb_tx = rte_eth_tx_burst(portid, 0,
-					 &tx_burst[idx], nb_tx);
-			idx += nb_tx;
-			num -= nb_tx;
-		}
-
+		portid = conf->portlist[i];
+		nb_tx = rte_eth_tx_burst(portid, 0, &tx_burst[idx], nb_tx);
+		idx += nb_tx;
+		num -= nb_tx;
+		i = (i >= conf->nb_ports - 1) ? 0 : (i + 1);
 	}
 
 	sleep(5);
Signature · 1 line
1.8.3.1
#2 lore raw
In reply to Zhang,Alvin

Hi, Alvin

Quoted 47 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Zhang,Alvin
Sent: Wednesday, November 25, 2020 5:46 PM
To: Liang, Cunming <[email protected]>
Cc: [email protected]; Zhang, AlvinX <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] test: fix buffer overflow

From: Alvin Zhang <[email protected]>

The Tx buffer may overflow when there is more than one port.

Fixes 002ade70e933 ("app/test: measure cycles per packet in Rx/Tx")
---
 app/test/test_pmd_perf.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
app/test/test_pmd_perf.c index renamed from app/test/test_pmd_perf.c +0 -0

4db816a..3a248d5 100644

app/test/test_pmd_perf.c +3 -5
@@ -606,10 +606,10 @@ enum {
 static int
 exec_burst(uint32_t flags, int lcore)
 {
-	unsigned i, portid, nb_tx = 0;
+	unsigned int portid, nb_tx = 0;
 	struct lcore_conf *conf;
 	uint32_t pkt_per_port;
-	int num, idx = 0;
+	int num, i, idx = 0;
 	int diff_tsc;
 
 	conf = &lcore_conf[lcore];
@@ -628,16 +628,14 @@ enum {
 		rte_atomic64_set(&start, 1);
 
 	/* start xmit */
+	i = 0;
 	while (num) {
 		nb_tx = RTE_MIN(MAX_PKT_BURST, num);
-		for (i = 0; i < conf->nb_ports; i++) {
-			portid = conf->portlist[i];
-			nb_tx = rte_eth_tx_burst(portid, 0,

app/test/test_pmd_perf.c enum { · line 638

Quoted 10 lines
app/test/test_pmd_perf.c +5 -5
-					 &tx_burst[idx], nb_tx);
-			idx += nb_tx;
-			num -= nb_tx;
-		}
-
+		portid = conf->portlist[i];
+		nb_tx = rte_eth_tx_burst(portid, 0, &tx_burst[idx], nb_tx);
+		idx += nb_tx;
+		num -= nb_tx;
+		i = (i >= conf->nb_ports - 1) ? 0 : (i + 1);

If conf->nb_ports = 1, after the above assign, the i should be 1 and is that your expected?

Quoted 5 lines
app/test/test_pmd_perf.c +0 -1
 	}
 
 	sleep(5);
--

1.8.3.1

Acked-by
#3 lore raw
Quoted 62 lines

-----Original Message-----
From: Guo, Jia
Sent: Friday, January 15, 2021 4:31 PM
To: 'Zhang,Alvin' <[email protected]>; Liang, Cunming <[email protected]>
Cc: [email protected]; Zhang, AlvinX <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] test: fix buffer overflow

Hi, Alvin

Quoted 51 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Zhang,Alvin
Sent: Wednesday, November 25, 2020 5:46 PM
To: Liang, Cunming <[email protected]>
Cc: [email protected]; Zhang, AlvinX <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH] test: fix buffer overflow

From: Alvin Zhang <[email protected]>

The Tx buffer may overflow when there is more than one port.

Fixes 002ade70e933 ("app/test: measure cycles per packet in Rx/Tx")
---
 app/test/test_pmd_perf.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
app/test/test_pmd_perf.c index renamed from app/test/test_pmd_perf.c +0 -0

4db816a..3a248d5 100644

app/test/test_pmd_perf.c +3 -10
@@ -606,10 +606,10 @@ enum {
 static int
 exec_burst(uint32_t flags, int lcore)  {
-	unsigned i, portid, nb_tx = 0;
+	unsigned int portid, nb_tx = 0;
 	struct lcore_conf *conf;
 	uint32_t pkt_per_port;
-	int num, idx = 0;
+	int num, i, idx = 0;
 	int diff_tsc;
 
 	conf = &lcore_conf[lcore];
@@ -628,16 +628,14 @@ enum {
 		rte_atomic64_set(&start, 1);
 
 	/* start xmit */
+	i = 0;
 	while (num) {
 		nb_tx = RTE_MIN(MAX_PKT_BURST, num);
-		for (i = 0; i < conf->nb_ports; i++) {
-			portid = conf->portlist[i];
-			nb_tx = rte_eth_tx_burst(portid, 0,
-					 &tx_burst[idx], nb_tx);
-			idx += nb_tx;
-			num -= nb_tx;
-		}
-
Quoted 8 lines

app/test/test_pmd_perf.c enum { · line 638

Quoted 5 lines
app/test/test_pmd_perf.c +5 -0
+		portid = conf->portlist[i];
+		nb_tx = rte_eth_tx_burst(portid, 0, &tx_burst[idx], nb_tx);
+		idx += nb_tx;
+		num -= nb_tx;
+		i = (i >= conf->nb_ports - 1) ? 0 : (i + 1);

If conf->nb_ports = 1, after the above assign, the i should be 1 and is that your expected?

Please ignore above comment, this code should be works.

Quoted 6 lines
Quoted 6 lines
app/test/test_pmd_perf.c +0 -1
 	}
 
 	sleep(5);
--

1.8.3.1