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 ADA1A45BB4; Wed, 23 Oct 2024 18:07:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9D1B242E6C; Wed, 23 Oct 2024 18:07:10 +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 5D77242E6A for ; Wed, 23 Oct 2024 18:07:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729699629; 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=jWDgB+zfAjB7nXeluDK8mrEXuOXqcv4mmsWNOFDh4Kc=; b=XKEuQmqBqAR2/JGV6gonraZHMH5iGH/kRLgQIavXjpYk91sC0/nJ6jrGNBV7XZu3b62NjW qdOuU6ttapYWPgnGUppMsz9EaDq9bs8g3NPhdp7YCZDEHHfSM9fprgkiDh6HJC8CgtlBTr q3OnaGTLDCrC8zo9/ocVT8KLagUI7ag= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-475-HsmqfgDtPTGZcwSwkpFfAg-1; Wed, 23 Oct 2024 12:07:07 -0400 X-MC-Unique: HsmqfgDtPTGZcwSwkpFfAg-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-539f1e9fb86so14283e87.0 for ; Wed, 23 Oct 2024 09:07:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729699626; x=1730304426; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jWDgB+zfAjB7nXeluDK8mrEXuOXqcv4mmsWNOFDh4Kc=; b=q5HvHxI1oE8Ec6Vz5tBgV4Y4N9zQ09F+tU5kJtRYR7VwLCGGT9mNXsrFN63RMF8bav 33+HBr9+iG80vKHQK0uFeHYw3XRAOUhcoR98YH6vVnj/GRBUXk2VggvJdZcuchAiuSu+ ECqZWyaM8aQGx34jxSJ/grApoOmJMSykPb99ZTDXyrVVOhOBHOytlqaBe+ShhmhUfgrH x1LtDwOoBhlukzCqiHryPxj+/Q71sgpwaYx7lS0oREaz9ZpoTiuCaaBJoG1B4hBm14Ve eLKw0ZWVVAUDXWbbCR20OCRmvNoqEpC+LUQUeaW00l7z8lu95HOoNb7iJ1zSege6KsKr Ty5A== X-Gm-Message-State: AOJu0Yzb//O76NJdKIKcQ5nQymAU/S5QPjfRyXXktakexGeI3UZECWqE f9YzKBGRR6QMZeuLMo4oHiDFL9X79YB61P6DNbS2Hk0crHskaiBV+8EvVFrdwZSqoJfA+BjjTm0 +uV53vc+3Nrjk0tc+rvK4JV0r6yc+7jnvP2/BMsa0OQYlOCKdXXhHIfbK1kCotp9WeMyJinCfX2 fgl13gNNdveKacUkI= X-Received: by 2002:a05:6512:3e25:b0:539:e668:5f90 with SMTP id 2adb3069b0e04-53b1317f67bmr2495160e87.7.1729699625780; Wed, 23 Oct 2024 09:07:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVQJzu86eCwzuUjRt8kcVE5vdhHTJrzb16XNWuXQ1eirUcSvOQzzymFzwlr4DlLe4mWw0nq8s5cm4uvj+T024= X-Received: by 2002:a05:6512:3e25:b0:539:e668:5f90 with SMTP id 2adb3069b0e04-53b1317f67bmr2495145e87.7.1729699625241; Wed, 23 Oct 2024 09:07:05 -0700 (PDT) MIME-Version: 1.0 References: <20241023151552.2863387-1-maxime.coquelin@redhat.com> <20241023151552.2863387-4-maxime.coquelin@redhat.com> In-Reply-To: <20241023151552.2863387-4-maxime.coquelin@redhat.com> From: David Marchand Date: Wed, 23 Oct 2024 18:06:54 +0200 Message-ID: Subject: Re: [PATCH 3/6] vhost: fix VDUSE reconnect device start failure To: Maxime Coquelin Cc: dev@dpdk.org, chenbox@nvidia.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Wed, Oct 23, 2024 at 5:16=E2=80=AFPM Maxime Coquelin wrote: > > 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 *remo= ve) > *remove =3D 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 =3D eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); > + if (fd < 0) { > + VHOST_CONFIG_LOG(dev->ifname, ERR, "Failed to create reco= nnect efd: %s", > + strerror(errno)); > + ret =3D -1; > + goto out_err; > + } > + > + ret =3D fdset_add(vduse.fdset, fd, vduse_reconnect_handler, NULL,= dev); > + if (ret) { > + VHOST_CONFIG_LOG(dev->ifname, ERR, "Failed to add reconne= ct efd %d to vduse fdset", > + fd); > + goto out_err_close; > + } > + > + ret =3D eventfd_write(fd, (eventfd_t)1); > + if (ret < 0) { > + VHOST_CONFIG_LOG(dev->ifname, ERR, "Failed to write to re= connect 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 =3D eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); > - if (reco_fd < 0) { > - VHOST_CONFIG_LOG(name, ERR, "Failed to create rec= o_fd: %s", > - strerror(errno)); > - ret =3D -1; > - goto out_dev_destroy; > - } > - > - ret =3D fdset_add(vduse.fdset, reco_fd, vduse_reconnect_h= andler, NULL, dev); > + ret =3D vduse_reconnect_start_device(dev); > if (ret) { > - VHOST_CONFIG_LOG(name, ERR, "Failed to add reconn= ect fd %d to vduse fdset", > - reco_fd); > - goto out_dev_destroy; > - } > - > - ret =3D eventfd_write(reco_fd, (eventfd_t)1); > - if (ret < 0) { > - VHOST_CONFIG_LOG(name, ERR, "Failed to write to r= econnect eventfd"); > + VHOST_CONFIG_LOG(name, ERR, "Failed to start devi= ce at reconnection"); We don't need a new log, there is already one for each error case in vduse_reconnect_start_device(). --=20 David Marchand