[v3] net/iavf: fix adding multicast MAC address

Message ID 20201015081352.36768-1-guinanx.sun@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers
Series [v3] net/iavf: fix adding multicast MAC address |

Checks

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

Commit Message

Guinan Sun Oct. 15, 2020, 8:13 a.m. UTC
When the multicast address list is added, it will flush
previous addresses first, and then add new ones.
So when the number of multicast addresses added to the list
exceeds the upper limit causes a failure, should add the
previous addresses back. This patch fixes the issue.

Fixes: 05e4c3aff35f ("net/iavf: support multicast configuration")

Signed-off-by: Guinan Sun <guinanx.sun@intel.com>
Tested-by: Peng Yuan <yuan.peng@intel.com>
---
v3:
* modify commit message
v2:
* modify the variable name
---
 drivers/net/iavf/iavf_ethdev.c | 30 ++++++++++++++++++++++--------
 drivers/net/iavf/iavf_vchnl.c  |  3 ---
 2 files changed, 22 insertions(+), 11 deletions(-)
  

Comments

Xing, Beilei Oct. 15, 2020, 8:38 a.m. UTC | #1
> -----Original Message-----
> From: Guinan Sun <guinanx.sun@intel.com>
> Sent: Thursday, October 15, 2020 4:14 PM
> To: dev@dpdk.org
> Cc: Xing, Beilei <beilei.xing@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>;
> Wu, Jingjing <jingjing.wu@intel.com>; Sun, GuinanX <guinanx.sun@intel.com>
> Subject: [PATCH v3] net/iavf: fix adding multicast MAC address
> 
> When the multicast address list is added, it will flush previous addresses first,
> and then add new ones.
> So when the number of multicast addresses added to the list exceeds the
> upper limit causes a failure, should add the previous addresses back. This
> patch fixes the issue.

If the number of multicast address list exceeds the upper limit, it will
cause failure, then need to roll back previous addresses.

Except this,
Acked-by: Beilei Xing <beilei.xing@intel.com>

> 
> Fixes: 05e4c3aff35f ("net/iavf: support multicast configuration")
> 
> Signed-off-by: Guinan Sun <guinanx.sun@intel.com>
> Tested-by: Peng Yuan <yuan.peng@intel.com>
> ---
> v3:
> * modify commit message
> v2:
> * modify the variable name
> ---
>  drivers/net/iavf/iavf_ethdev.c | 30 ++++++++++++++++++++++--------
> drivers/net/iavf/iavf_vchnl.c  |  3 ---
>  2 files changed, 22 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
> index e68e3bc71..8a7577230 100644
> --- a/drivers/net/iavf/iavf_ethdev.c
> +++ b/drivers/net/iavf/iavf_ethdev.c
> @@ -164,7 +164,14 @@ iavf_set_mc_addr_list(struct rte_eth_dev *dev,
>  	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data-
> >dev_private);
>  	struct iavf_adapter *adapter =
>  		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
> -	int err;
> +	int err, ret;
> +
> +	if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
> +		PMD_DRV_LOG(ERR,
> +			    "can't add more than a limited number (%u) of
> addresses.",
> +			    (uint32_t)IAVF_NUM_MACADDR_MAX);
> +		return -EINVAL;
> +	}
> 
>  	/* flush previous addresses */
>  	err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf-
> >mc_addrs_num, @@ -172,17 +179,24 @@ iavf_set_mc_addr_list(struct
> rte_eth_dev *dev,
>  	if (err)
>  		return err;
> 
> -	vf->mc_addrs_num = 0;
> -
>  	/* add new ones */
>  	err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num,
> true);
> -	if (err)
> -		return err;
> 
> -	vf->mc_addrs_num = mc_addrs_num;
> -	memcpy(vf->mc_addrs, mc_addrs, mc_addrs_num *
> sizeof(*mc_addrs));
> +	if (err) {
> +		/* if adding mac address list fails, should add the previous
> +		 * addresses back.
> +		 */
> +		ret = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs,
> +						vf->mc_addrs_num, true);
> +		if (ret)
> +			return ret;
> +	} else {
> +		vf->mc_addrs_num = mc_addrs_num;
> +		memcpy(vf->mc_addrs,
> +		       mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
> +	}
> 
> -	return 0;
> +	return err;
>  }
> 
>  static int
> diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c index
> db0b76876..a2295f879 100644
> --- a/drivers/net/iavf/iavf_vchnl.c
> +++ b/drivers/net/iavf/iavf_vchnl.c
> @@ -1107,9 +1107,6 @@ iavf_add_del_mc_addr_list(struct iavf_adapter
> *adapter,
>  	if (mc_addrs == NULL || mc_addrs_num == 0)
>  		return 0;
> 
> -	if (mc_addrs_num > IAVF_NUM_MACADDR_MAX)
> -		return -EINVAL;
> -
>  	list = (struct virtchnl_ether_addr_list *)cmd_buffer;
>  	list->vsi_id = vf->vsi_res->vsi_id;
>  	list->num_elements = mc_addrs_num;
> --
> 2.17.1
  

Patch

diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
index e68e3bc71..8a7577230 100644
--- a/drivers/net/iavf/iavf_ethdev.c
+++ b/drivers/net/iavf/iavf_ethdev.c
@@ -164,7 +164,14 @@  iavf_set_mc_addr_list(struct rte_eth_dev *dev,
 	struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
 	struct iavf_adapter *adapter =
 		IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
-	int err;
+	int err, ret;
+
+	if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
+		PMD_DRV_LOG(ERR,
+			    "can't add more than a limited number (%u) of addresses.",
+			    (uint32_t)IAVF_NUM_MACADDR_MAX);
+		return -EINVAL;
+	}
 
 	/* flush previous addresses */
 	err = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
@@ -172,17 +179,24 @@  iavf_set_mc_addr_list(struct rte_eth_dev *dev,
 	if (err)
 		return err;
 
-	vf->mc_addrs_num = 0;
-
 	/* add new ones */
 	err = iavf_add_del_mc_addr_list(adapter, mc_addrs, mc_addrs_num, true);
-	if (err)
-		return err;
 
-	vf->mc_addrs_num = mc_addrs_num;
-	memcpy(vf->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
+	if (err) {
+		/* if adding mac address list fails, should add the previous
+		 * addresses back.
+		 */
+		ret = iavf_add_del_mc_addr_list(adapter, vf->mc_addrs,
+						vf->mc_addrs_num, true);
+		if (ret)
+			return ret;
+	} else {
+		vf->mc_addrs_num = mc_addrs_num;
+		memcpy(vf->mc_addrs,
+		       mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
+	}
 
-	return 0;
+	return err;
 }
 
 static int
diff --git a/drivers/net/iavf/iavf_vchnl.c b/drivers/net/iavf/iavf_vchnl.c
index db0b76876..a2295f879 100644
--- a/drivers/net/iavf/iavf_vchnl.c
+++ b/drivers/net/iavf/iavf_vchnl.c
@@ -1107,9 +1107,6 @@  iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
 	if (mc_addrs == NULL || mc_addrs_num == 0)
 		return 0;
 
-	if (mc_addrs_num > IAVF_NUM_MACADDR_MAX)
-		return -EINVAL;
-
 	list = (struct virtchnl_ether_addr_list *)cmd_buffer;
 	list->vsi_id = vf->vsi_res->vsi_id;
 	list->num_elements = mc_addrs_num;