patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Itsuro Oda <oda@valinux.co.jp>
To: stable@dpdk.org
Subject: [dpdk-stable] [PATCH 18.11] net/vhost: fix setup error path
Date: Mon,  9 Mar 2020 13:10:07 +0900	[thread overview]
Message-ID: <20200309041007.14289-2-oda@valinux.co.jp> (raw)
In-Reply-To: <20200309041007.14289-1-oda@valinux.co.jp>

[ upstream commit 3e00307549ef7c90a9752f58f1d423542399267c ]

If for some reason vhost_driver_setup() fails, the list
element for the device may be freed without being removed
from the internal list of devices.

This patch fixes all the error paths, by unregistering the
device from Vhost library it has been registered, remove
the device from the list, reset device vring_state pointer
from the global table and only free vring state if it had
been allocated.

Fixes: 3d01b759d267 ("net/vhost: delay driver setup")
Cc: stable@dpdk.org

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 87fae4e47..5e58ae572 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -874,12 +874,12 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)
 
 	list = rte_zmalloc_socket(name, sizeof(*list), 0, numa_node);
 	if (list == NULL)
-		goto error;
+		return -1;
 
 	vring_state = rte_zmalloc_socket(name, sizeof(*vring_state),
 					 0, numa_node);
 	if (vring_state == NULL)
-		goto error;
+		goto free_list;
 
 	list->eth_dev = eth_dev;
 	pthread_mutex_lock(&internal_list_lock);
@@ -890,24 +890,31 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev)
 	vring_states[eth_dev->data->port_id] = vring_state;
 
 	if (rte_vhost_driver_register(internal->iface_name, internal->flags))
-		goto error;
+		goto list_remove;
 
 	if (rte_vhost_driver_callback_register(internal->iface_name,
 					       &vhost_ops) < 0) {
 		VHOST_LOG(ERR, "Can't register callbacks\n");
-		goto error;
+		goto drv_unreg;
 	}
 
 	if (rte_vhost_driver_start(internal->iface_name) < 0) {
 		VHOST_LOG(ERR, "Failed to start driver for %s\n",
 			  internal->iface_name);
-		goto error;
+		goto drv_unreg;
 	}
 
 	return 0;
 
-error:
+drv_unreg:
+	rte_vhost_driver_unregister(internal->iface_name);
+list_remove:
+	vring_states[eth_dev->data->port_id] = NULL;
+	pthread_mutex_lock(&internal_list_lock);
+	TAILQ_REMOVE(&internal_list, list, next);
+	pthread_mutex_unlock(&internal_list_lock);
 	rte_free(vring_state);
+free_list:
 	rte_free(list);
 
 	return -1;
-- 
2.17.0


      reply	other threads:[~2020-03-09  4:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09  4:10 [dpdk-stable] [PATCH 18.11] net/vhost: delay driver setup Itsuro Oda
2020-03-09  4:10 ` Itsuro Oda [this message]

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=20200309041007.14289-2-oda@valinux.co.jp \
    --to=oda@valinux.co.jp \
    --cc=stable@dpdk.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 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).