From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 60498A054F; Tue, 18 Feb 2020 18:24:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1006B1C001; Tue, 18 Feb 2020 18:24:08 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 035D81C000 for ; Tue, 18 Feb 2020 18:24:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582046646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hx48P68VGw11SBRB3/eaLVMR3MnNl8z9dJXDkoXOBEY=; b=OrZA/kaEw3pdRwzP4+WJzsrP+BS5IYw44+UFAceLeg1iTW9lYn1YmY4BjNLr+9k5TM6VVC bHRr5s/fSLkzkY1jbeNMnwpVJi+nfjiUdkRWWXojX2qZllWNQaDMlM2lgCvQ1ks7TjWVhZ N1+QlhzqxNHn84XQybXXW60luvnoiD8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-V-zyNwZlOUW3d5SeX59Naw-1; Tue, 18 Feb 2020 12:24:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72DF8800D48; Tue, 18 Feb 2020 17:24:02 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A4C22CC39; Tue, 18 Feb 2020 17:24:00 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, oda@valinux.co.jp, yinan.wang@intel.com, tiwei.bie@intel.com, amorenoz@redhat.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Tue, 18 Feb 2020 18:22:39 +0100 Message-Id: <20200218172240.558516-2-maxime.coquelin@redhat.com> In-Reply-To: <20200218172240.558516-1-maxime.coquelin@redhat.com> References: <20200218172240.558516-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: V-zyNwZlOUW3d5SeX59Naw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-dev] [PATCH 1/2] net/vhost: fix Vhost setup error path 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" 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") Signed-off-by: Maxime Coquelin Reviewed-by: David Marchand --- drivers/net/vhost/rte_eth_vhost.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_= vhost.c index 90263ae77c..4a7b1b608c 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -878,12 +878,12 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev) =20 =09list =3D rte_zmalloc_socket(name, sizeof(*list), 0, numa_node); =09if (list =3D=3D NULL) -=09=09goto error; +=09=09return -1; =20 =09vring_state =3D rte_zmalloc_socket(name, sizeof(*vring_state), =09=09=09=09=09 0, numa_node); =09if (vring_state =3D=3D NULL) -=09=09goto error; +=09=09goto free_list; =20 =09list->eth_dev =3D eth_dev; =09pthread_mutex_lock(&internal_list_lock); @@ -894,30 +894,37 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev) =09vring_states[eth_dev->data->port_id] =3D vring_state; =20 =09if (rte_vhost_driver_register(internal->iface_name, internal->flags)) -=09=09goto error; +=09=09goto list_remove; =20 =09if (internal->disable_flags) { =09=09if (rte_vhost_driver_disable_features(internal->iface_name, =09=09=09=09=09=09 internal->disable_flags)) -=09=09=09goto error; +=09=09=09goto drv_unreg; =09} =20 =09if (rte_vhost_driver_callback_register(internal->iface_name, =09=09=09=09=09 &vhost_ops) < 0) { =09=09VHOST_LOG(ERR, "Can't register callbacks\n"); -=09=09goto error; +=09=09goto drv_unreg; =09} =20 =09if (rte_vhost_driver_start(internal->iface_name) < 0) { =09=09VHOST_LOG(ERR, "Failed to start driver for %s\n", =09=09=09 internal->iface_name); -=09=09goto error; +=09=09goto drv_unreg; =09} =20 =09return 0; =20 -error: +drv_unreg: +=09rte_vhost_driver_unregister(internal->iface_name); +list_remove: +=09vring_states[eth_dev->data->port_id] =3D NULL; +=09pthread_mutex_lock(&internal_list_lock); +=09TAILQ_REMOVE(&internal_list, list, next); +=09pthread_mutex_unlock(&internal_list_lock); =09rte_free(vring_state); +free_list: =09rte_free(list); =20 =09return -1; --=20 2.24.1