From patchwork Tue Feb 18 14:35:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 65872 X-Patchwork-Delegate: maxime.coquelin@redhat.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 EDA46A054F; Tue, 18 Feb 2020 15:35:34 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C561A1C133; Tue, 18 Feb 2020 15:35:31 +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 67DEB1C132 for ; Tue, 18 Feb 2020 15:35:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582036529; 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=VzIhRtKFBdvrQuL+dNpwQ2S4FwVOjrNth1NOMdLTi3c=; b=ASM50aGsGv8HsBlpyaRmzgHc7+99m0rL57igAiPQ9TPOfg7wsXcSKpml/LVNBHTKVenkcx ZVQL2l2wWHqSGYseQnlFCcmxnTMMXJMfXnPfSc9ve231ybYWC+wIqGn1nIMw2F/WnxLzBS A88JPHTl93CmV3lSjfOvEJ9PKcSx58c= 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-223-JzDFmHdvNgOLKUAAtbnAgw-1; Tue, 18 Feb 2020 09:35:25 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1FB57800D5E; Tue, 18 Feb 2020 14:35:24 +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 8D8E6863CC; Tue, 18 Feb 2020 14:35:22 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, oda@valinux.co.jp, yinan.wang@intel.com, tiwei.bie@intel.com, amorenoz@redhat.com Cc: Maxime Coquelin Date: Tue, 18 Feb 2020 15:35:13 +0100 Message-Id: <20200218143514.553307-2-maxime.coquelin@redhat.com> In-Reply-To: <20200218143514.553307-1-maxime.coquelin@redhat.com> References: <20200218143514.553307-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: JzDFmHdvNgOLKUAAtbnAgw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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..c0056bc8bf 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) 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); @@ -894,30 +894,37 @@ 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 (internal->disable_flags) { if (rte_vhost_driver_disable_features(internal->iface_name, internal->disable_flags)) - goto error; + goto drv_unreg; } 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: + pthread_mutex_lock(&internal_list_lock); + TAILQ_REMOVE(&internal_list, list, next); + pthread_mutex_unlock(&internal_list_lock); + vring_states[eth_dev->data->port_id] = NULL; rte_free(vring_state); +free_list: rte_free(list); return -1; From patchwork Tue Feb 18 14:35:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 65873 X-Patchwork-Delegate: maxime.coquelin@redhat.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 C0E46A054F; Tue, 18 Feb 2020 15:35:43 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 288161C139; Tue, 18 Feb 2020 15:35:36 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id BB66F1C138 for ; Tue, 18 Feb 2020 15:35:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582036534; 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=03gogVWcyz9U27YBJpku4G4csoFzJqPjK6ULFhB71LU=; b=AwlcuG9f6efQCbFwHVqibIr6kxMliQnCmI9oaHxLXe6OSF2fKikWRBNezttt855VhChCg7 EVEUbAQHpX9GqcW7UxROMOESHGMUohrsa8Dbw+RbUDrHDpIiL0C8Nu2C5THbdzYXjYpz02 3y3JuaTPYeluTnveMZkBHHrYqtv5i5Y= 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-340-WNePHa9yOR-D7AQTZOrVqQ-1; Tue, 18 Feb 2020 09:35:27 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F9CE85EE6B; Tue, 18 Feb 2020 14:35:26 +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 7C4A7863CC; Tue, 18 Feb 2020 14:35:24 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, oda@valinux.co.jp, yinan.wang@intel.com, tiwei.bie@intel.com, amorenoz@redhat.com Cc: Maxime Coquelin Date: Tue, 18 Feb 2020 15:35:14 +0100 Message-Id: <20200218143514.553307-3-maxime.coquelin@redhat.com> In-Reply-To: <20200218143514.553307-1-maxime.coquelin@redhat.com> References: <20200218143514.553307-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: WNePHa9yOR-D7AQTZOrVqQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH 2/2] net/vhost: prevent multiple setup on reconfig 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" Ethdev's .dev_configure callback can be called multiple time during a device life-time, but Vhost makes the wrong assumption that it is not the case and try to setup again the device on reconfiguration. This patch ensures the device hasn't been already setup before proceeding. Fixes: 3d01b759d267 ("net/vhost: delay driver setup") Reported-by: Yinan Wang Signed-off-by: Maxime Coquelin Tested-by: Yinan Wang Tested-by: Yinan Wang Reviewed-by: David Marchand --- drivers/net/vhost/rte_eth_vhost.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index c0056bc8bf..c4643da120 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -876,6 +876,11 @@ vhost_driver_setup(struct rte_eth_dev *eth_dev) unsigned int numa_node = eth_dev->device->numa_node; const char *name = eth_dev->device->name; + /* Don't try to setup again if it has already been done. */ + list = find_internal_resource(internal->iface_name); + if (list) + return 0; + list = rte_zmalloc_socket(name, sizeof(*list), 0, numa_node); if (list == NULL) return -1;