[2/2] net/bonding: fix selection logic

Message ID 20190805144454.10496-2-kkanas@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series [1/2] net/bonding: fix stack overflow in selection logic |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Krzysztof Kanas Aug. 5, 2019, 2:44 p.m. UTC
  From: Krzysztof Kanas <kkanas@marvell.com>

Fix max_index to return uint16_t as it is valid slave_id type.

Arrays agg_count and agg_bandwidth should be indexed by slave_id not by
aggregator port_id.

Fixes: 6d72657ce379 ("net/bonding: add other aggregator modes")
Cc: danielx.t.mrzyglod@intel.com

Signed-off-by: Krzysztof Kanas <kkanas@marvell.com>
---
 drivers/net/bonding/rte_eth_bond_8023ad.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
  

Comments

Ferruh Yigit Oct. 8, 2019, 2:34 p.m. UTC | #1
On 8/5/2019 3:44 PM, kkanas@marvell.com wrote:
> From: Krzysztof Kanas <kkanas@marvell.com>
> 
> Fix max_index to return uint16_t as it is valid slave_id type.
> 
> Arrays agg_count and agg_bandwidth should be indexed by slave_id not by
> aggregator port_id.

The port_id type has been fixed already with another patch [1] and it has been
merged, but this patch does more,
Can you please send a new version on top of latest next-net?

[1]
https://patches.dpdk.org/patch/51491/
Commit b15a8a91432b ("net/bonding: fix more incorrect slave id types")

> 
> Fixes: 6d72657ce379 ("net/bonding: add other aggregator modes")
> Cc: danielx.t.mrzyglod@intel.com
> 
> Signed-off-by: Krzysztof Kanas <kkanas@marvell.com>
> ---
>  drivers/net/bonding/rte_eth_bond_8023ad.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/bonding/rte_eth_bond_8023ad.c b/drivers/net/bonding/rte_eth_bond_8023ad.c
> index 89a8ba3de963..b923e69ef23a 100644
> --- a/drivers/net/bonding/rte_eth_bond_8023ad.c
> +++ b/drivers/net/bonding/rte_eth_bond_8023ad.c
> @@ -639,7 +639,7 @@ tx_machine(struct bond_dev_private *internals, uint16_t slave_id)
>  	SM_FLAG_CLR(port, NTT);
>  }
>  
> -static uint8_t
> +static uint16_t
>  max_index(uint64_t *a, int n)
>  {
>  	if (n <= 0)
> @@ -673,8 +673,8 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
>  	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
>  	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
>  	uint16_t default_slave = 0;
> -	uint8_t mode_count_id, mode_band_id;
>  	struct rte_eth_link link_info;
> +	uint16_t agg_new_idx = 0;
>  
>  	slaves = internals->active_slaves;
>  	slaves_count = internals->active_slave_count;
> @@ -687,9 +687,9 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
>  		if (agg->aggregator_port_id != slaves[i])
>  			continue;
>  
> -		agg_count[agg->aggregator_port_id] += 1;
> +		agg_count[i] += 1;
>  		rte_eth_link_get_nowait(slaves[i], &link_info);
> -		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
> +		agg_bandwidth[i] += link_info.link_speed;
>  
>  		/* Actors system ID is not checked since all slave device have the same
>  		 * ID (MAC address). */
> @@ -710,14 +710,12 @@ selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
>  
>  	switch (internals->mode4.agg_selection) {
>  	case AGG_COUNT:
> -		mode_count_id = max_index(
> -				(uint64_t *)agg_count, slaves_count);
> -		new_agg_id = mode_count_id;
> +		agg_new_idx = max_index(agg_count, slaves_count);
> +		new_agg_id = slaves[agg_new_idx];
>  		break;
>  	case AGG_BANDWIDTH:
> -		mode_band_id = max_index(
> -				(uint64_t *)agg_bandwidth, slaves_count);
> -		new_agg_id = mode_band_id;
> +		agg_new_idx = max_index(agg_bandwidth, slaves_count);
> +		new_agg_id = slaves[agg_new_idx];
>  		break;
>  	case AGG_STABLE:
>  		if (default_slave == slaves_count)
>
  

Patch

diff --git a/drivers/net/bonding/rte_eth_bond_8023ad.c b/drivers/net/bonding/rte_eth_bond_8023ad.c
index 89a8ba3de963..b923e69ef23a 100644
--- a/drivers/net/bonding/rte_eth_bond_8023ad.c
+++ b/drivers/net/bonding/rte_eth_bond_8023ad.c
@@ -639,7 +639,7 @@  tx_machine(struct bond_dev_private *internals, uint16_t slave_id)
 	SM_FLAG_CLR(port, NTT);
 }
 
-static uint8_t
+static uint16_t
 max_index(uint64_t *a, int n)
 {
 	if (n <= 0)
@@ -673,8 +673,8 @@  selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 	uint64_t agg_bandwidth[RTE_MAX_ETHPORTS] = {0};
 	uint64_t agg_count[RTE_MAX_ETHPORTS] = {0};
 	uint16_t default_slave = 0;
-	uint8_t mode_count_id, mode_band_id;
 	struct rte_eth_link link_info;
+	uint16_t agg_new_idx = 0;
 
 	slaves = internals->active_slaves;
 	slaves_count = internals->active_slave_count;
@@ -687,9 +687,9 @@  selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 		if (agg->aggregator_port_id != slaves[i])
 			continue;
 
-		agg_count[agg->aggregator_port_id] += 1;
+		agg_count[i] += 1;
 		rte_eth_link_get_nowait(slaves[i], &link_info);
-		agg_bandwidth[agg->aggregator_port_id] += link_info.link_speed;
+		agg_bandwidth[i] += link_info.link_speed;
 
 		/* Actors system ID is not checked since all slave device have the same
 		 * ID (MAC address). */
@@ -710,14 +710,12 @@  selection_logic(struct bond_dev_private *internals, uint16_t slave_id)
 
 	switch (internals->mode4.agg_selection) {
 	case AGG_COUNT:
-		mode_count_id = max_index(
-				(uint64_t *)agg_count, slaves_count);
-		new_agg_id = mode_count_id;
+		agg_new_idx = max_index(agg_count, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_BANDWIDTH:
-		mode_band_id = max_index(
-				(uint64_t *)agg_bandwidth, slaves_count);
-		new_agg_id = mode_band_id;
+		agg_new_idx = max_index(agg_bandwidth, slaves_count);
+		new_agg_id = slaves[agg_new_idx];
 		break;
 	case AGG_STABLE:
 		if (default_slave == slaves_count)