From patchwork Thu Mar 28 13:08:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 138954 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 923FD43D6C; Thu, 28 Mar 2024 14:08:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C3B69410FC; Thu, 28 Mar 2024 14:08:34 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 4B26C406BC for ; Thu, 28 Mar 2024 14:08:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711631311; 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=lbHyf2Z5EpWrr5n9eaLRVssJCBZP6TFjepYJo8BDChE=; b=F6L7AAKknd0UGpZCSXPn+lCGWpkm6nRtHD925/zCswz6gQ3OLzrXPncn7Wzl369YdQHpJJ CQX2ynIm9RqRkQzKxgh7mK2YK++0I7Jx4tH7zKAtboUt+fdT02XRQy9F9Uj1FFTpxkwnjt ep6u0cncHVp0y+3oFvQRtT0mXzlKRcY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-aCwUbzSvPyO6-N3wXxP61w-1; Thu, 28 Mar 2024 09:08:28 -0400 X-MC-Unique: aCwUbzSvPyO6-N3wXxP61w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C4B980F7E5; Thu, 28 Mar 2024 13:08:28 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6993E492BDA; Thu, 28 Mar 2024 13:08:25 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin , stable@dpdk.org Subject: [PATCH v2 3/4] net/virtio-user: fix shadow control queue notification init Date: Thu, 28 Mar 2024 14:08:12 +0100 Message-ID: <20240328130813.3696005-4-maxime.coquelin@redhat.com> In-Reply-To: <20240328130813.3696005-1-maxime.coquelin@redhat.com> References: <20240328130813.3696005-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 The Virtio-user control queue kick and call FDs were not uninitialized at device stop time. This patch fixes this using the queues iterator helper for both initialization and uninitialization. Fixes: 90966e8e5b67 ("net/virtio-user: send shadow virtqueue info to the backend") Cc: stable@dpdk.org Acked-by: David Marchand Signed-off-by: Maxime Coquelin --- .../net/virtio/virtio_user/virtio_user_dev.c | 90 +++++++++---------- 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 0776c54deb..912e87fecf 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -33,6 +33,45 @@ const char * const virtio_user_backend_strings[] = { [VIRTIO_USER_BACKEND_VHOST_VDPA] = "VHOST_VDPA", }; +static int +virtio_user_uninit_notify_queue(struct virtio_user_dev *dev, uint32_t queue_sel) +{ + if (dev->kickfds[queue_sel] >= 0) { + close(dev->kickfds[queue_sel]); + dev->kickfds[queue_sel] = -1; + } + + if (dev->callfds[queue_sel] >= 0) { + close(dev->callfds[queue_sel]); + dev->callfds[queue_sel] = -1; + } + + return 0; +} + +static int +virtio_user_init_notify_queue(struct virtio_user_dev *dev, uint32_t queue_sel) +{ + /* May use invalid flag, but some backend uses kickfd and + * callfd as criteria to judge if dev is alive. so finally we + * use real event_fd. + */ + dev->callfds[queue_sel] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); + if (dev->callfds[queue_sel] < 0) { + PMD_DRV_LOG(ERR, "(%s) Failed to setup callfd for queue %u: %s", + dev->path, queue_sel, strerror(errno)); + return -1; + } + dev->kickfds[queue_sel] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); + if (dev->kickfds[queue_sel] < 0) { + PMD_DRV_LOG(ERR, "(%s) Failed to setup kickfd for queue %u: %s", + dev->path, queue_sel, strerror(errno)); + return -1; + } + + return 0; +} + static int virtio_user_destroy_queue(struct virtio_user_dev *dev, uint32_t queue_sel) { @@ -423,33 +462,9 @@ virtio_user_dev_init_mac(struct virtio_user_dev *dev, const char *mac) static int virtio_user_dev_init_notify(struct virtio_user_dev *dev) { - uint32_t i, j, nr_vq; - int callfd; - int kickfd; - - nr_vq = dev->max_queue_pairs * 2; - if (dev->hw_cvq) - nr_vq++; - for (i = 0; i < nr_vq; i++) { - /* May use invalid flag, but some backend uses kickfd and - * callfd as criteria to judge if dev is alive. so finally we - * use real event_fd. - */ - callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); - if (callfd < 0) { - PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path, strerror(errno)); - goto err; - } - kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); - if (kickfd < 0) { - close(callfd); - PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path, strerror(errno)); - goto err; - } - dev->callfds[i] = callfd; - dev->kickfds[i] = kickfd; - } + if (virtio_user_foreach_queue(dev, virtio_user_init_notify_queue) < 0) + goto err; if (dev->device_features & (1ULL << VIRTIO_F_NOTIFICATION_DATA)) if (dev->ops->map_notification_area && @@ -458,16 +473,7 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev) return 0; err: - for (j = 0; j < i; j++) { - if (dev->kickfds[j] >= 0) { - close(dev->kickfds[j]); - dev->kickfds[j] = -1; - } - if (dev->callfds[j] >= 0) { - close(dev->callfds[j]); - dev->callfds[j] = -1; - } - } + virtio_user_foreach_queue(dev, virtio_user_uninit_notify_queue); return -1; } @@ -475,18 +481,8 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev) static void virtio_user_dev_uninit_notify(struct virtio_user_dev *dev) { - uint32_t i; + virtio_user_foreach_queue(dev, virtio_user_uninit_notify_queue); - for (i = 0; i < dev->max_queue_pairs * 2; ++i) { - if (dev->kickfds[i] >= 0) { - close(dev->kickfds[i]); - dev->kickfds[i] = -1; - } - if (dev->callfds[i] >= 0) { - close(dev->callfds[i]); - dev->callfds[i] = -1; - } - } if (dev->ops->unmap_notification_area && dev->notify_area) dev->ops->unmap_notification_area(dev); }