From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3697E45BB3; Wed, 23 Oct 2024 17:16:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2CB3142E54; Wed, 23 Oct 2024 17:16:12 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 3C8E842D87 for ; Wed, 23 Oct 2024 17:16:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729696566; 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=GRG/MgLlrIFQ0SDAInph043v7Ur5QngU3BCAynqPwkE=; b=JORq0whAh4al1WpJdJCKtRoVi+TcmW2G2d0bryLBcziJJX8rOOEQPgmBDqGBBBt0KncNM1 KOErXGQ0+b/VsioAGQKp0P4Kg9MyNqmzzdk2+7rSXINSz9Smkyd8Vf5CNj07Z6Fga2/BMC VbetV2JEJZxRK+KmOHy6zX3uqTet7hk= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-135-2nAPUw6kPvKsUcqzMfH6ZQ-1; Wed, 23 Oct 2024 11:16:03 -0400 X-MC-Unique: 2nAPUw6kPvKsUcqzMfH6ZQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E05A21955F65; Wed, 23 Oct 2024 15:16:02 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.26]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8EBDD19560A2; Wed, 23 Oct 2024 15:16:01 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH 3/6] vhost: fix VDUSE reconnect device start failure Date: Wed, 23 Oct 2024 17:15:49 +0200 Message-ID: <20241023151552.2863387-4-maxime.coquelin@redhat.com> In-Reply-To: <20241023151552.2863387-1-maxime.coquelin@redhat.com> References: <20241023151552.2863387-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch fixes a FD leak in the VDUSE device reconnect code fails to start the device. Also take the opportunity to refactor the related code into a dedicated function. Fixes: da79cc7fda76 ("vhost: add reconnection support to VDUSE") Signed-off-by: Maxime Coquelin --- lib/vhost/vduse.c | 63 +++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index d1373d0549..c8c4761293 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -476,6 +476,46 @@ vduse_reconnect_handler(int fd, void *arg, int *remove) *remove = 1; } +static int +vduse_reconnect_start_device(struct virtio_net *dev) +{ + int fd, ret; + + /* + * Make vduse_device_start() being executed in the same + * context for both reconnection and fresh startup. + */ + fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + if (fd < 0) { + VHOST_CONFIG_LOG(dev->ifname, ERR, "Failed to create reconnect efd: %s", + strerror(errno)); + ret = -1; + goto out_err; + } + + ret = fdset_add(vduse.fdset, fd, vduse_reconnect_handler, NULL, dev); + if (ret) { + VHOST_CONFIG_LOG(dev->ifname, ERR, "Failed to add reconnect efd %d to vduse fdset", + fd); + goto out_err_close; + } + + ret = eventfd_write(fd, (eventfd_t)1); + if (ret < 0) { + VHOST_CONFIG_LOG(dev->ifname, ERR, "Failed to write to reconnect eventfd"); + goto out_err_fdset; + } + + return 0; + +out_err_fdset: + fdset_del(vduse.fdset, fd); +out_err_close: + close(fd); +out_err: + return ret; +} + int vduse_device_create(const char *path, bool compliant_ol_flags) { @@ -741,28 +781,9 @@ vduse_device_create(const char *path, bool compliant_ol_flags) } if (reconnect && dev->status & VIRTIO_DEVICE_STATUS_DRIVER_OK) { - /* - * Make vduse_device_start() being executed in the same - * context for both reconnection and fresh startup. - */ - reco_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); - if (reco_fd < 0) { - VHOST_CONFIG_LOG(name, ERR, "Failed to create reco_fd: %s", - strerror(errno)); - ret = -1; - goto out_dev_destroy; - } - - ret = fdset_add(vduse.fdset, reco_fd, vduse_reconnect_handler, NULL, dev); + ret = vduse_reconnect_start_device(dev); if (ret) { - VHOST_CONFIG_LOG(name, ERR, "Failed to add reconnect fd %d to vduse fdset", - reco_fd); - goto out_dev_destroy; - } - - ret = eventfd_write(reco_fd, (eventfd_t)1); - if (ret < 0) { - VHOST_CONFIG_LOG(name, ERR, "Failed to write to reconnect eventfd"); + VHOST_CONFIG_LOG(name, ERR, "Failed to start device at reconnection"); goto out_dev_destroy; } } -- 2.46.2