From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EX13-EDG-OU-002.vmware.com (ex13-edg-ou-002.vmware.com [208.91.0.190]) by dpdk.org (Postfix) with ESMTP id 6A2995960 for ; Sat, 13 Aug 2016 03:15:01 +0200 (CEST) Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Fri, 12 Aug 2016 18:14:05 -0700 Received: from sc2-edge-ivybridge-01.eng.vmware.com (unknown [10.172.139.164]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id D901640630; Fri, 12 Aug 2016 18:14:59 -0700 (PDT) From: Yong Wang To: CC: , , , , Yong Wang Date: Fri, 12 Aug 2016 17:58:28 -0700 Message-ID: <1471049909-18117-4-git-send-email-yongwang@vmware.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471049909-18117-1-git-send-email-yongwang@vmware.com> References: <1471049909-18117-1-git-send-email-yongwang@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: yongwang@vmware.com does not designate permitted sender hosts) Subject: [dpdk-dev] [PATCH 3/4] net/vmxnet3: reallocate shared memzone on re-config X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Aug 2016 01:15:01 -0000 When adding a DPDK port to a bridge using ovs-vswitchd with DPDK, the vmxnet3 device fails to activate due to mismatched magic number. Doing this will incur the following operations: start the port, stop the port, reconfigure and re-start the port. The reconfig could request different number of tx/rx queues but the driver bypasses allocating the queuedesc memzone of proper size (which depends on the queue size) if there is an existing one. This results in a memzone with wrong size and potential invalid memory access. To fix this, this change will free the memzone if found and reserve a new one. Signed-off-by: Yong Wang Reviewed-by: Guolin Yang Reviewed-by: Daniele Di Proietto Tested-by: Daniele Di Proietto --- drivers/net/vmxnet3/vmxnet3_ethdev.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c index a2cb2dd..6b1e720 100644 --- a/drivers/net/vmxnet3/vmxnet3_ethdev.c +++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c @@ -131,7 +131,8 @@ static const struct eth_dev_ops vmxnet3_eth_dev_ops = { static const struct rte_memzone * gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size, - const char *post_string, int socket_id, uint16_t align) + const char *post_string, int socket_id, + uint16_t align, bool reuse) { char z_name[RTE_MEMZONE_NAMESIZE]; const struct rte_memzone *mz; @@ -140,6 +141,13 @@ gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size, dev->driver->pci_drv.name, dev->data->port_id, post_string); mz = rte_memzone_lookup(z_name); + if (!reuse) { + if (mz) + rte_memzone_free(mz); + return rte_memzone_reserve_aligned(z_name, size, socket_id, + 0, align); + } + if (mz) return mz; @@ -384,7 +392,7 @@ vmxnet3_dev_configure(struct rte_eth_dev *dev) * on current socket */ mz = gpa_zone_reserve(dev, sizeof(struct Vmxnet3_DriverShared), - "shared", rte_socket_id(), 8); + "shared", rte_socket_id(), 8, 1); if (mz == NULL) { PMD_INIT_LOG(ERR, "ERROR: Creating shared zone"); @@ -397,10 +405,14 @@ vmxnet3_dev_configure(struct rte_eth_dev *dev) /* * Allocate a memzone for Vmxnet3_RxQueueDesc - Vmxnet3_TxQueueDesc - * on current socket + * on current socket. + * + * We cannot reuse this memzone from previous allocation as its size + * depends on the number of tx and rx queues, which could be different + * from one config to another. */ - mz = gpa_zone_reserve(dev, size, "queuedesc", - rte_socket_id(), VMXNET3_QUEUE_DESC_ALIGN); + mz = gpa_zone_reserve(dev, size, "queuedesc", rte_socket_id(), + VMXNET3_QUEUE_DESC_ALIGN, 0); if (mz == NULL) { PMD_INIT_LOG(ERR, "ERROR: Creating queue descriptors zone"); return -ENOMEM; @@ -415,8 +427,9 @@ vmxnet3_dev_configure(struct rte_eth_dev *dev) if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) { /* Allocate memory structure for UPT1_RSSConf and configure */ - mz = gpa_zone_reserve(dev, sizeof(struct VMXNET3_RSSConf), "rss_conf", - rte_socket_id(), RTE_CACHE_LINE_SIZE); + mz = gpa_zone_reserve(dev, sizeof(struct VMXNET3_RSSConf), + "rss_conf", rte_socket_id(), + RTE_CACHE_LINE_SIZE, 1); if (mz == NULL) { PMD_INIT_LOG(ERR, "ERROR: Creating rss_conf structure zone"); -- 1.9.1