From patchwork Thu Oct 15 08:13:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinan Sun X-Patchwork-Id: 80840 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 56E0AA04DB; Thu, 15 Oct 2020 10:25:29 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9A7E31DCEF; Thu, 15 Oct 2020 10:25:27 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 88B5A1C296 for ; Thu, 15 Oct 2020 10:25:25 +0200 (CEST) IronPort-SDR: n8IE2eegHv3Q+WhhAworFM9gcWPebJVTDsYb0WqJCgUPvMOzwNXUj3NkZMoIblCOJzp3Mzq3zU Z2Qc40Osf5LQ== X-IronPort-AV: E=McAfee;i="6000,8403,9774"; a="230489111" X-IronPort-AV: E=Sophos;i="5.77,378,1596524400"; d="scan'208";a="230489111" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2020 01:25:24 -0700 IronPort-SDR: O1leryqWkC3APLKAZkWpKkZQV5P3wufpSiCvEX9RK1zg4MFAon35OP33qq91w2QOsUsjXQbynn hebKySmhvZGQ== X-IronPort-AV: E=Sophos;i="5.77,378,1596524400"; d="scan'208";a="531162051" Received: from unknown (HELO localhost.localdomain) ([10.239.255.52]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2020 01:25:22 -0700 From: Guinan Sun To: dev@dpdk.org Cc: Beilei Xing , Qi Zhang , Jingjing Wu , Guinan Sun Date: Thu, 15 Oct 2020 08:13:52 +0000 Message-Id: <20201015081352.36768-1-guinanx.sun@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201015020204.12658-1-guinanx.sun@intel.com> References: <20201015020204.12658-1-guinanx.sun@intel.com> Subject: [dpdk-dev] [PATCH v3] net/iavf: fix adding multicast MAC address X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Tested-by: Peng Yuan Acked-by: Beilei Xing --- 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;