DPDK patches and discussions
 help / color / mirror / Atom feed
From: Guinan Sun <guinanx.sun@intel.com>
To: dev@dpdk.org
Cc: Beilei Xing <beilei.xing@intel.com>,
	Qi Zhang <qi.z.zhang@intel.com>,
	Jingjing Wu <jingjing.wu@intel.com>,
	Guinan Sun <guinanx.sun@intel.com>
Subject: [dpdk-dev] [PATCH v4] net/iavf: fix adding multicast MAC address
Date: Thu, 15 Oct 2020 08:43:05 +0000	[thread overview]
Message-ID: <20201015084305.48257-1-guinanx.sun@intel.com> (raw)
In-Reply-To: <20201015020204.12658-1-guinanx.sun@intel.com>

When the multicast address list is added, it will flush
previous addresses first, and then add new ones.
If the number of multicast address in the list exceeds
the upper limit, it will cause failure, then need to
roll back previous addresses. 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>
Acked-by: Beilei Xing <beilei.xing@intel.com>
---
v4:
* modify commit message
* add Acked-by
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


  parent reply	other threads:[~2020-10-15  8:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-15  2:02 [dpdk-dev] [PATCH] " Guinan Sun
2020-10-15  5:13 ` Peng, Yuan
2020-10-15  5:37   ` Xing, Beilei
2020-10-15  5:57     ` Sun, GuinanX
2020-10-15  6:43       ` Xing, Beilei
2020-10-15  6:46         ` Sun, GuinanX
2020-10-15  6:55 ` [dpdk-dev] [PATCH v2] " Guinan Sun
2020-10-15  8:13 ` [dpdk-dev] [PATCH v3] " Guinan Sun
2020-10-15  8:38   ` Xing, Beilei
2020-10-15  8:43 ` Guinan Sun [this message]
2020-10-20  9:06   ` [dpdk-dev] [PATCH v4] " Zhang, Qi Z

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201015084305.48257-1-guinanx.sun@intel.com \
    --to=guinanx.sun@intel.com \
    --cc=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).