All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yong Wang <yongwang@vmware.com>
To: <stephen@networkplumber.org>
Cc: <dev@dpdk.org>, <gyang@vmware.com>, <diproiettod@vmware.com>,
	<jsnell@iki.fi>, Yong Wang <yongwang@vmware.com>
Subject: [PATCH v3 3/6] net/vmxnet3: reallocate shared memzone on re-config
Date: Mon, 29 Aug 2016 12:18:47 -0700	[thread overview]
Message-ID: <1472498330-18591-4-git-send-email-yongwang@vmware.com> (raw)
In-Reply-To: <1472498330-18591-1-git-send-email-yongwang@vmware.com>

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 <yongwang@vmware.com>
Reviewed-by: Guolin Yang <gyang@vmware.com>
Reviewed-by: Daniele Di Proietto <ddiproietto@vmware.com>
Tested-by: Daniele Di Proietto <ddiproietto@vmware.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 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 d402b83..cdbcb78 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

  parent reply	other threads:[~2016-08-29 19:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-13  0:58 [PATCH 0/4] various vmxnet3 fixes and enhancement Yong Wang
2016-08-13  0:58 ` [PATCH 1/4] net/vmxnet3: improve error checks and return values Yong Wang
2016-08-13  0:58 ` [PATCH 2/4] net/vmxnet3: coding style changes Yong Wang
2016-08-13  0:58 ` [PATCH 3/4] net/vmxnet3: reallocate shared memzone on re-config Yong Wang
2016-08-13  0:58 ` [PATCH 4/4] net/vmxnet3: enable lro Yong Wang
2016-08-22 11:21   ` Thomas Monjalon
2016-08-24  0:05   ` [PATCH v2 0/6] various vmxnet3 fixes and enhancement Yong Wang
2016-08-24  0:05     ` [PATCH v2 1/6] net/vmxnet3: improve error checks and return values Yong Wang
2016-08-29 19:18       ` [PATCH v3 0/6] various vmxnet3 fixes and enhancement Yong Wang
2016-08-29 19:18         ` [PATCH v3 1/6] net/vmxnet3: improve error checks and return values Yong Wang
2016-08-29 19:18         ` [PATCH v3 2/6] net/vmxnet3: coding style changes Yong Wang
2016-08-29 19:18         ` Yong Wang [this message]
2016-08-29 19:18         ` [PATCH v3 4/6] net/vmxnet3: update feature doc Yong Wang
2016-08-29 19:18         ` [PATCH v3 5/6] net/vmxnet3: update nic doc Yong Wang
2016-08-29 19:18         ` [PATCH v3 6/6] net/vmxnet3: enable lro Yong Wang
2016-09-19 14:44         ` [PATCH v3 0/6] various vmxnet3 fixes and enhancement Bruce Richardson
2016-08-24  0:05     ` [PATCH v2 2/6] net/vmxnet3: coding style changes Yong Wang
2016-08-24  0:05     ` [PATCH v2 3/6] net/vmxnet3: reallocate shared memzone on re-config Yong Wang
2016-08-24  0:05     ` [PATCH v2 4/6] net/vmxnet3: update feature doc Yong Wang
2016-08-24  0:05     ` [PATCH v2 5/6] net/vmxnet3: update nic doc Yong Wang
2016-08-24  0:05     ` [PATCH v2 6/6] net/vmxnet3: enable lro Yong Wang
2016-08-24 19:17     ` [PATCH v2 0/6] various vmxnet3 fixes and enhancement Stephen Hemminger

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=1472498330-18591-4-git-send-email-yongwang@vmware.com \
    --to=yongwang@vmware.com \
    --cc=dev@dpdk.org \
    --cc=diproiettod@vmware.com \
    --cc=gyang@vmware.com \
    --cc=jsnell@iki.fi \
    --cc=stephen@networkplumber.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.