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 679BAA054F; Tue, 18 Feb 2020 17:16:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7E07D1BFA0; Tue, 18 Feb 2020 17:16:12 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 4731A1BF9E for ; Tue, 18 Feb 2020 17:16:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582042570; 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=akZnHgXgphNDTIdA9E0nYVLel/XvtMZ6vA62PLlo42E=; b=Z3jITU0of7UkmdrdD18fLitcDJgJJpBISl62ZblGSH67nqQHN/3TIWpCWpO5IVtZNeDJJa 1QAoNiMPrTTvocBTl8Df0nPvUJV4yiYrLsCTxuFjrhpAoZEwyAhjQq//UnCwqWBWWC1RKT CfSsAArsJLKcSJQtsZYoo5BvuMT1qHE= Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-152-ssuIw5-vOluTxEHpqZoPkQ-1; Tue, 18 Feb 2020 11:16:08 -0500 Received: by mail-ua1-f69.google.com with SMTP id b18so4080770uap.14 for ; Tue, 18 Feb 2020 08:16:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+u7oYAZLiK9i3GC7HV7rW5a4CpPsPQLPirWzjtsQmxE=; b=ct5IZ6b3QAID5V/ZLTTELHhUynqcxG65I147wEcey+RPgsMhin6NbiX/DhuF4HDzp9 iz7pJjNajOJtJ0nFpStNfd74wi64rUZxhzLPtQkeS21/qAhw8CkEoXZEhEwUwbbZuYr+ t/5hYHABhy8y5GEPZzMPVNAmqi2JWyrwGnnu3qh/U47gbhJj81aHUgURV2WpDvNY028G nbpcGktx0yWsipaXYL1gRvpMbHQxNFJga39bPNMgG8xMtlmPfffKgmFSZJtLZoP2CEdD 6Ot+yzslO/5y9Mzy/kMDFrjwo+W7FjurGZm+P24iILJ2XKrPrE9SKz0aUS9OIGWg9BRK 5iYQ== X-Gm-Message-State: APjAAAUShhpLY8Hcv6z5sYa8HIYlJXrS9oLoGv34GUhSwS/+vG69/0VK tlNAsaVLGa5dlxsmCJoS9vRJTvCtOZwK0sj+bkwiKKlHIt5kQMj2di13+lBXbiYz3OWWjG7Y0Ne LQj6Xwlp+BbtRm7ff2Zk= X-Received: by 2002:a67:905:: with SMTP id 5mr11688588vsj.105.1582042567440; Tue, 18 Feb 2020 08:16:07 -0800 (PST) X-Google-Smtp-Source: APXvYqw/Mv9oZgBDgsb5JBkUv8gOahhJHol2YQ+1q3T6DVZFEXUKR/zbb/ymbbMjQ4jueFMZnKhzN402mwv0Eep7WUo= X-Received: by 2002:a67:905:: with SMTP id 5mr11688555vsj.105.1582042566874; Tue, 18 Feb 2020 08:16:06 -0800 (PST) MIME-Version: 1.0 References: <20200218143514.553307-1-maxime.coquelin@redhat.com> <20200218143514.553307-2-maxime.coquelin@redhat.com> In-Reply-To: <20200218143514.553307-2-maxime.coquelin@redhat.com> From: David Marchand Date: Tue, 18 Feb 2020 17:15:55 +0100 Message-ID: To: Maxime Coquelin Cc: dev , oda@valinux.co.jp, yinan.wang@intel.com, Tiwei Bie , Adrian Moreno Zapata X-MC-Unique: ssuIw5-vOluTxEHpqZoPkQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [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" On Tue, Feb 18, 2020 at 3:35 PM Maxime Coquelin wrote: > > 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 > --- > 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_et= h_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 =3D rte_zmalloc_socket(name, sizeof(*list), 0, numa_node); > if (list =3D=3D NULL) > - goto error; > + return -1; > > vring_state =3D rte_zmalloc_socket(name, sizeof(*vring_state), > 0, numa_node); > if (vring_state =3D=3D NULL) > - goto error; > + goto free_list; > > list->eth_dev =3D 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] =3D vring_state; > > if (rte_vhost_driver_register(internal->iface_name, internal->fla= gs)) > - goto error; > + goto list_remove; > > if (internal->disable_flags) { > if (rte_vhost_driver_disable_features(internal->iface_nam= e, > internal->disable_f= lags)) > - 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] =3D NULL; We allocate/store in vring_states after inserting list in &internal_list. Probably nitpicking but I would expect the opposite order on cleanup. > rte_free(vring_state); > +free_list: > rte_free(list); > > return -1; > -- > 2.24.1 > In any case, Reviewed-by: David Marchand -- David Marchand