Skip to contentSkip to conversation

app/testpmd: fix bonding mode set

PATCH Applied Min Hu (Connor) 2 participants 2 messages Jan 28, 2022 – Jan 31, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/testpmd: fix bonding mode set

when start testpmd, and type command like this, it will lead to Segmentation fault, like:

testpmd> create bonded device 4 0
testpmd> add bonding slave 0 2
testpmd> add bonding slave 1 2
testpmd> port start 2
testpmd> set bonding mode 0 2
testpmd> quit
Stopping port 0...
Stopping ports...
...
Bye...
Segmentation fault

The reason to the bug is that rte timer do not be cancelled when quit. That is, in 'bond_ethdev_start', resources are allocated according to different bonding mode. In 'bond_ethdev_stop', resources are free by the corresponding mode.

For example, 'bond_ethdev_start' start bond_mode_8023ad_ext_periodic_cb timer for bonding mode 4. and 'bond_ethdev_stop' cancel the timer only when the current bonding mode is 4. If the bonding mode is changed, and directly quit the process, the timer will still on, and freed memory will be accessed, then segmentation fault.

'bonding mode'changed means resources changed, reallocate resources for different mode should be done, that is, device should be restarted.

Fixes 2950a769315e ("bond: testpmd support")
---
 app/test-pmd/cmdline.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
app/test-pmd/cmdline.c +13 -0
index e626b1c7d9..2c47ab0f18 100644
@@ -5915,6 +5915,19 @@ static void cmd_set_bonding_mode_parsed(void *parsed_result,
 {
 	struct cmd_set_bonding_mode_result *res = parsed_result;
 	portid_t port_id = res->port_id;
+	struct rte_port *port = &ports[port_id];
+
+	/*
+	 * Bonding mode changed means resources of device changed, like whether
+	 * started rte timer or not. Device should be restarted when resources
+	 * of device changed.
+	 */
+	if (port->port_status != RTE_PORT_STOPPED) {
+		fprintf(stderr,
+			"\t Error: Can't config bonding mode when port %d is not stopped\n",
+			port_id);
+		return;
+	}
 
 	/* Set the bonding mode for the relevant port. */
 	if (0 != rte_eth_bond_mode_set(port_id, res->value))
Signature · 1 line
2.33.0
Tested-by on v1 1/1 Applied
#1 lore raw
Quoted 20 lines · Min Hu (Connor)

when start testpmd, and type command like this, it will lead to Segmentation fault, like:

testpmd> create bonded device 4 0
testpmd> add bonding slave 0 2
testpmd> add bonding slave 1 2
testpmd> port start 2
testpmd> set bonding mode 0 2
testpmd> quit
Stopping port 0...
Stopping ports...
...
Bye...
Segmentation fault

The reason to the bug is that rte timer do not be cancelled when quit. That is, in 'bond_ethdev_start', resources are allocated according to different bonding mode. In 'bond_ethdev_stop', resources are free by the corresponding mode.

Quoted 7 lines

For example, 'bond_ethdev_start' start bond_mode_8023ad_ext_periodic_cb timer for bonding mode 4. and 'bond_ethdev_stop' cancel the timer only when the current bonding mode is 4. If the bonding mode is changed, and directly quit the process, the timer will still on, and freed memory will be accessed, then segmentation fault.

'bonding mode'changed means resources changed, reallocate resources for

'bonding mode' changed ...

Quoted 6 lines

different mode should be done, that is, device should be restarted.

Fixes 2950a769315e ("bond: testpmd support")

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

Quoted 12 lines
---
  app/test-pmd/cmdline.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
app/test-pmd/cmdline.c +0 -0
index e626b1c7d9..2c47ab0f18 100644
@@ -5915,6 +5915,19 @@ static void cmd_set_bonding_mode_parsed(void *parsed_result,
  {
  	struct cmd_set_bonding_mode_result *res = parsed_result;
  	portid_t port_id = res->port_id;

app/test-pmd/cmdline.c static void cmd_set_bonding_mode_parsed(void *parsed_result, · line 5927

Quoted 10 lines
app/test-pmd/cmdline.c +10 -0
+	struct rte_port *port = &ports[port_id];
+
+	/*
+	 * Bonding mode changed means resources of device changed, like whether
+	 * started rte timer or not. Device should be restarted when resources
+	 * of device changed.
+	 */
+	if (port->port_status != RTE_PORT_STOPPED) {
+		fprintf(stderr,
+			"\t Error: Can't config bonding mode when port %d is not stopped\n",

Updated as "... Can't set bonding mode ..."

Quoted 6 lines
app/test-pmd/cmdline.c +3 -0
+			port_id);
+		return;
+	}
 
  	/* Set the bonding mode for the relevant port. */
  	if (0 != rte_eth_bond_mode_set(port_id, res->value))