Skip to contentSkip to conversation

net/bonding: a couple minor fixes

PATCH Applied Hyong Youb Kim 3 participants 8 messages Jan 10, 2019 – Feb 21, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover net/bonding: a couple minor fixes

A couple patches for minor issues found during in-house testing. I do not have a strong opinion on the first one, as it is just a warning message not technically a bug. But, the second one addresses an easy-to-reproduce crash. If someone has a better/cleaner fix, I am all ears.

Hyong Youb Kim (2):
net/bonding: do not set promisc on non-existent primary port net/bonding: avoid the next active slave going out of bound

 drivers/net/bonding/rte_eth_bond_pmd.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Signature · 1 line
2.16.2
#1 lore raw

PATCH 1/2 net/bonding: do not set promisc on non-existent primary port

For active-backup, tlb, and alb mode, bond_ethdev_promiscuous_{enable,disable} tries to set promisc mode on the primary port, even when there are no slaves. It is harmless, as rte_eth_promiscuous_{enable,disable} does nothing if the port number is invalid. But, it does print a warning message. Here is an example from testpmd.

testpmd> create bonded device 5 0
Created new bonded device net_bonding_testpmd_0 on (port 4). Invalid port_id=33
testpmd> set promisc 4 off
Invalid port_id=33

33 in this case is RTE_MAX_ETHPORTS + 1, the invalid primary port number used within the bonding driver. This warning message is harmless but can be confusing to the user. So do not try to set promisc on a primary port when we know it does not exist (i.e. no slaves).

Fixes 2efb58cbab6e ("bond: new link bonding library")
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/bonding/rte_eth_bond_pmd.c +6 -0
index 44deaf119..daf2440cd 100644
@@ -2593,6 +2593,9 @@ bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev)
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
+		/* Do not touch promisc when there cannot be primary ports */
+		if (internals->slave_count == 0)
+			break;
 		rte_eth_promiscuous_enable(internals->current_primary_port);
 	}
 }
@@ -2621,6 +2624,9 @@ bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev)
 	case BONDING_MODE_TLB:
 	case BONDING_MODE_ALB:
 	default:
+		/* Do not touch promisc when there cannot be primary ports */
+		if (internals->slave_count == 0)
+			break;
 		rte_eth_promiscuous_disable(internals->current_primary_port);
 	}
 }
Signature · 1 line
2.16.2
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] net/bonding: do not set promisc on non-existent primary port

Quoted 19 lines · Hyong Youb Kim

For active-backup, tlb, and alb mode, bond_ethdev_promiscuous_{enable,disable} tries to set promisc mode on the primary port, even when there are no slaves. It is harmless, as rte_eth_promiscuous_{enable,disable} does nothing if the port number is invalid. But, it does print a warning message. Here is an example from testpmd.

testpmd> create bonded device 5 0
Created new bonded device net_bonding_testpmd_0 on (port 4). Invalid port_id=33
testpmd> set promisc 4 off
Invalid port_id=33

33 in this case is RTE_MAX_ETHPORTS + 1, the invalid primary port number used within the bonding driver. This warning message is harmless but can be confusing to the user. So do not try to set promisc on a primary port when we know it does not exist (i.e. no slaves).

Quoted 4 lines
Fixes 2efb58cbab6e ("bond: new link bonding library")
Quoted 29 lines
---
  drivers/net/bonding/rte_eth_bond_pmd.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/net/bonding/rte_eth_bond_pmd.c +6 -0
index 44deaf119..daf2440cd 100644
@@ -2593,6 +2593,9 @@ bond_ethdev_promiscuous_enable(struct rte_eth_dev *eth_dev)
  	case BONDING_MODE_TLB:
  	case BONDING_MODE_ALB:
  	default:
+		/* Do not touch promisc when there cannot be primary ports */
+		if (internals->slave_count == 0)
+			break;
  		rte_eth_promiscuous_enable(internals->current_primary_port);
  	}
  }
@@ -2621,6 +2624,9 @@ bond_ethdev_promiscuous_disable(struct rte_eth_dev *dev)
  	case BONDING_MODE_TLB:
  	case BONDING_MODE_ALB:
  	default:
+		/* Do not touch promisc when there cannot be primary ports */
+		if (internals->slave_count == 0)
+			break;
  		rte_eth_promiscuous_disable(internals->current_primary_port);
  	}
  }
Applied
#3 lore raw

Re: [PATCH 1/2] net/bonding: do not set promisc on non-existent primary port

Quoted 22 lines · Chas Williams
Quoted 19 lines · Hyong Youb Kim

For active-backup, tlb, and alb mode, bond_ethdev_promiscuous_{enable,disable} tries to set promisc mode on the primary port, even when there are no slaves. It is harmless, as rte_eth_promiscuous_{enable,disable} does nothing if the port number is invalid. But, it does print a warning message. Here is an example from testpmd.

testpmd> create bonded device 5 0
Created new bonded device net_bonding_testpmd_0 on (port 4). Invalid port_id=33
testpmd> set promisc 4 off
Invalid port_id=33

33 in this case is RTE_MAX_ETHPORTS + 1, the invalid primary port number used within the bonding driver. This warning message is harmless but can be confusing to the user. So do not try to set promisc on a primary port when we know it does not exist (i.e. no slaves).

Quoted 6 lines
Quoted 4 lines
Fixes 2efb58cbab6e ("bond: new link bonding library")

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

#4 lore raw

PATCH 2/2 net/bonding: avoid the next active slave going out of bound

In reply to Hyong Youb Kim

For bonding modes like broadcast that use bond_ethdev_rx_burst(), it is fairly easy to produce a crash simply by bringing a slave port's link down. When slave links go down, the driver on one thread reduces active_slave_count via the LSC callback and deactivate_slave(). At the same time, bond_ethdev_rx_burst() running on a forwarding thread may increment active_slave (next active slave) beyond active_slave_count. Here is a typical sequence of events.

At time 0:
active_slave_count = 3
active_slave = 2

At time 1:
A slave link goes down.
Thread 0 (main) reduces active_slave_count to 2.

At time 2:
Thread 1 (forwarding) executes bond_ethdev_rx_burst().
- Reads active_slave_count = 2.
- Increments active_slave at the end to 3.

Quoted 1 line

From this point on, everytime bond_ethdev_rx_burst() runs,

active_slave increments by one, eventually going well out of bound of the active_slaves array and causing a crash.

Make the rx burst function to first check that active_slave is within bound. If not, reset it to 0 to avoid out-of-range array access.

Fixes e1110e977648 ("net/bonding: fix Rx slave fairness")
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/net/bonding/rte_eth_bond_pmd.c +14 -0
index daf2440cd..bc2405e54 100644
@@ -68,6 +68,15 @@ bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	internals = bd_rx_q->dev_private;
 	slave_count = internals->active_slave_count;
 	active_slave = internals->active_slave;
+	/*
+	 * Reset the active slave index, in case active_slave goes out
+	 * of bound.  It can hapen when slave links go down, and
+	 * another thread (LSC callback) shrinks the slave count.
+	 */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}
 
 	for (i = 0; i < slave_count && nb_pkts; i++) {
 		uint16_t num_rx_slave;
@@ -273,6 +282,11 @@ bond_ethdev_rx_burst_8023ad_fast_queue(void *queue, struct rte_mbuf **bufs,
 	active_slave = internals->active_slave;
 	memcpy(slaves, internals->active_slaves,
 			sizeof(internals->active_slaves[0]) * slave_count);
+	/* active_slave may go out of bound. See bond_ethdev_rx_burst() */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}
 
 	for (i = 0; i < slave_count && nb_pkts; i++) {
 		uint16_t num_rx_slave;
Signature · 1 line
2.16.2
Acked-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] net/bonding: avoid the next active slave going out of bound

Quoted 25 lines · Hyong Youb Kim

For bonding modes like broadcast that use bond_ethdev_rx_burst(), it is fairly easy to produce a crash simply by bringing a slave port's link down. When slave links go down, the driver on one thread reduces active_slave_count via the LSC callback and deactivate_slave(). At the same time, bond_ethdev_rx_burst() running on a forwarding thread may increment active_slave (next active slave) beyond active_slave_count. Here is a typical sequence of events.

At time 0:
active_slave_count = 3
active_slave = 2

At time 1:
A slave link goes down.
Thread 0 (main) reduces active_slave_count to 2.

At time 2:
Thread 1 (forwarding) executes bond_ethdev_rx_burst().
- Reads active_slave_count = 2.
- Increments active_slave at the end to 3.

From this point on, everytime bond_ethdev_rx_burst() runs,
active_slave increments by one, eventually going well out of bound of the active_slaves array and causing a crash.

Quoted 7 lines

Make the rx burst function to first check that active_slave is within bound. If not, reset it to 0 to avoid out-of-range array access.

Fixes e1110e977648 ("net/bonding: fix Rx slave fairness")
Quoted 37 lines
---
  drivers/net/bonding/rte_eth_bond_pmd.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/net/bonding/rte_eth_bond_pmd.c +14 -0
index daf2440cd..bc2405e54 100644
@@ -68,6 +68,15 @@ bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
  	internals = bd_rx_q->dev_private;
  	slave_count = internals->active_slave_count;
  	active_slave = internals->active_slave;
+	/*
+	 * Reset the active slave index, in case active_slave goes out
+	 * of bound.  It can hapen when slave links go down, and
+	 * another thread (LSC callback) shrinks the slave count.
+	 */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}
 
  	for (i = 0; i < slave_count && nb_pkts; i++) {
  		uint16_t num_rx_slave;
@@ -273,6 +282,11 @@ bond_ethdev_rx_burst_8023ad_fast_queue(void *queue, struct rte_mbuf **bufs,
  	active_slave = internals->active_slave;
  	memcpy(slaves, internals->active_slaves,
  			sizeof(internals->active_slaves[0]) * slave_count);
+	/* active_slave may go out of bound. See bond_ethdev_rx_burst() */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}
 
  	for (i = 0; i < slave_count && nb_pkts; i++) {
  		uint16_t num_rx_slave;

A message that is not in the archive (sent off-list or not yet received): 7AE31235A30B41498D1C31348DC858BD5B5329AB@IRSMSX103.ger.corp.intel.com

#7 lore raw

Re: [PATCH 2/2] net/bonding: avoid the next active slave going out of bound

Quoted 100 lines · JananeeX M

Hi

Quoted 59 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Chas Williams
Sent: Saturday, February 09, 2019 6:47 PM
To: Hyong Youb Kim <[email protected]>; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; Chas Williams <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 2/2] net/bonding: avoid the next active slave going out of bound

Quoted 25 lines · Hyong Youb Kim

For bonding modes like broadcast that use bond_ethdev_rx_burst(), it is fairly easy to produce a crash simply by bringing a slave port's link down. When slave links go down, the driver on one thread reduces active_slave_count via the LSC callback and deactivate_slave(). At the same time, bond_ethdev_rx_burst() running on a forwarding thread may increment active_slave (next active slave) beyond active_slave_count. Here is a typical sequence of events.

At time 0:
active_slave_count = 3
active_slave = 2

At time 1:
A slave link goes down.
Thread 0 (main) reduces active_slave_count to 2.

At time 2:
Thread 1 (forwarding) executes bond_ethdev_rx_burst().
- Reads active_slave_count = 2.
- Increments active_slave at the end to 3.

From this point on, everytime bond_ethdev_rx_burst() runs,
active_slave increments by one, eventually going well out of bound of the active_slaves array and causing a crash.

Quoted 7 lines

Make the rx burst function to first check that active_slave is within bound. If not, reset it to 0 to avoid out-of-range array access.

Fixes e1110e977648 ("net/bonding: fix Rx slave fairness")

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst(void *queue, struct rte_mbuf

Quoted 10 lines
---
  drivers/net/bonding/rte_eth_bond_pmd.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
index daf2440cd..bc2405e54 100644
@@ -68,6 +68,15 @@ bond_ethdev_rx_burst(void *queue, struct rte_mbuf

**bufs, uint16_t nb_pkts)

Quoted 12 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) · line 79

Quoted 12 lines
drivers/net/bonding/rte_eth_bond_pmd.c +9 -0
  	internals = bd_rx_q->dev_private;
  	slave_count = internals->active_slave_count;
  	active_slave = internals->active_slave;
+	/*
+	 * Reset the active slave index, in case active_slave goes out
+	 * of bound.  It can hapen when slave links go down, and
+	 * another thread (LSC callback) shrinks the slave count.
+	 */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}

Instead of introducing new conditions again at the top of functions, it would be better to check greater than, equal to >= instead of the equal to in below condition. if (++internals->active_slave == slave_count)

                internals->active_slave = 0;

Thereby we can reduce the multiple if conditions and still ensure internals->active_slave points to correct index always.

Quoted 5 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst_8023ad_fast_queue(void

Quoted 4 lines
drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
  	for (i = 0; i < slave_count && nb_pkts; i++) {
  		uint16_t num_rx_slave;
@@ -273,6 +282,11 @@ bond_ethdev_rx_burst_8023ad_fast_queue(void

*queue, struct rte_mbuf **bufs,

Quoted 8 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst_8023ad_fast_queue(void *queue, struct rte_mbuf **bufs, · line 289

Quoted 8 lines
drivers/net/bonding/rte_eth_bond_pmd.c +5 -0
  	active_slave = internals->active_slave;
  	memcpy(slaves, internals->active_slaves,
  			sizeof(internals->active_slaves[0]) * slave_count);
+	/* active_slave may go out of bound. See bond_ethdev_rx_burst() */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}

Same as above comment would be better.

Quoted 4 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)

Quoted 4 lines
drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
  	for (i = 0; i < slave_count && nb_pkts; i++) {
  		uint16_t num_rx_slave;
 
Quoted 5 lines

It would be better to check the internals->active_slave during deactivate_slave() as well in rte_eth_bond_api.c. Since slave counts would be decremented during de-activation and resetting here appropriately would be better.

Regards
M.P.Jananee

I don't see this comment on the patchwork, can you double check if your comment hit the mailing list?

#8 lore raw

Re: [dpdk-stable] [PATCH 2/2] net/bonding: avoid the next active slave going out of bound

Quoted 104 lines · Ferruh Yigit
Quoted 103 lines · JananeeX M

Hi

Quoted 59 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Chas Williams
Sent: Saturday, February 09, 2019 6:47 PM
To: Hyong Youb Kim <[email protected]>; Yigit, Ferruh <[email protected]>; Doherty, Declan <[email protected]>; Chas Williams <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 2/2] net/bonding: avoid the next active slave going out of bound

Quoted 25 lines · Hyong Youb Kim

For bonding modes like broadcast that use bond_ethdev_rx_burst(), it is fairly easy to produce a crash simply by bringing a slave port's link down. When slave links go down, the driver on one thread reduces active_slave_count via the LSC callback and deactivate_slave(). At the same time, bond_ethdev_rx_burst() running on a forwarding thread may increment active_slave (next active slave) beyond active_slave_count. Here is a typical sequence of events.

At time 0:
active_slave_count = 3
active_slave = 2

At time 1:
A slave link goes down.
Thread 0 (main) reduces active_slave_count to 2.

At time 2:
Thread 1 (forwarding) executes bond_ethdev_rx_burst().
- Reads active_slave_count = 2.
- Increments active_slave at the end to 3.

From this point on, everytime bond_ethdev_rx_burst() runs,
active_slave increments by one, eventually going well out of bound of the active_slaves array and causing a crash.

Quoted 7 lines

Make the rx burst function to first check that active_slave is within bound. If not, reset it to 0 to avoid out-of-range array access.

Fixes e1110e977648 ("net/bonding: fix Rx slave fairness")

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst(void *queue, struct rte_mbuf

Quoted 10 lines
---
  drivers/net/bonding/rte_eth_bond_pmd.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
index daf2440cd..bc2405e54 100644
@@ -68,6 +68,15 @@ bond_ethdev_rx_burst(void *queue, struct rte_mbuf

**bufs, uint16_t nb_pkts)

Quoted 12 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) · line 79

Quoted 12 lines
drivers/net/bonding/rte_eth_bond_pmd.c +9 -0
  	internals = bd_rx_q->dev_private;
  	slave_count = internals->active_slave_count;
  	active_slave = internals->active_slave;
+	/*
+	 * Reset the active slave index, in case active_slave goes out
+	 * of bound.  It can hapen when slave links go down, and
+	 * another thread (LSC callback) shrinks the slave count.
+	 */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}

Instead of introducing new conditions again at the top of functions, it would be better to check greater than, equal to >= instead of the equal to in below condition. if (++internals->active_slave == slave_count)

                internals->active_slave = 0;

Thereby we can reduce the multiple if conditions and still ensure internals->active_slave points to correct index always.

Quoted 5 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst_8023ad_fast_queue(void

Quoted 4 lines
drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
  	for (i = 0; i < slave_count && nb_pkts; i++) {
  		uint16_t num_rx_slave;
@@ -273,6 +282,11 @@ bond_ethdev_rx_burst_8023ad_fast_queue(void

*queue, struct rte_mbuf **bufs,

Quoted 8 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst_8023ad_fast_queue(void *queue, struct rte_mbuf **bufs, · line 289

Quoted 8 lines
drivers/net/bonding/rte_eth_bond_pmd.c +5 -0
  	active_slave = internals->active_slave;
  	memcpy(slaves, internals->active_slaves,
  			sizeof(internals->active_slaves[0]) * slave_count);
+	/* active_slave may go out of bound. See bond_ethdev_rx_burst() */
+	if (active_slave >= slave_count) {
+		internals->active_slave = 0;
+		active_slave = 0;
+	}

Same as above comment would be better.

Quoted 4 lines

drivers/net/bonding/rte_eth_bond_pmd.c bond_ethdev_rx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)

Quoted 4 lines
drivers/net/bonding/rte_eth_bond_pmd.c +0 -0
  	for (i = 0; i < slave_count && nb_pkts; i++) {
  		uint16_t num_rx_slave;
 

It would be better to check the internals->active_slave during deactivate_slave() as well in rte_eth_bond_api.c. Since slave counts would be decremented during de-activation and resetting here appropriately would be better.

Quoted 6 lines
Quoted 2 lines

Regards
M.P.Jananee

I don't see this comment on the patchwork, can you double check if your comment hit the mailing list?

For record, this patch superseded by:
https://patches.dpdk.org/patch/50346/