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 3780AA051C for ; Tue, 11 Feb 2020 12:29:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2DDC7A3; Tue, 11 Feb 2020 12:29:13 +0100 (CET) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by dpdk.org (Postfix) with ESMTP id 802BF1BFA5 for ; Tue, 11 Feb 2020 12:29:11 +0100 (CET) Received: by mail-wm1-f68.google.com with SMTP id t23so3054048wmi.1 for ; Tue, 11 Feb 2020 03:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2TBBzYBtwRKzaiIe5wMZ+2rX5EzUM3SIHYPgS6jpmXA=; b=Qw0aDvq2jIgsGcxakd5AfG8ZBRqjhBIj5SZFPh1RTVW2NuChZAtrccArb2/pTcaUA2 uJx2dxpsyXuwhaW4pAJlyEOBarHk5RWtI9Vzu6QIk0U26DztFkHy+zQ2Eb/AjkWxYKqg eonZFbr07QBc9qjmxeQRFSNzzY/RGYOQASiQRxZg/F0V1dsAM6Xm9pP+EsrTwcpgN8Mn 9MgOsMxqbSuzt7qubpSC1jdJnW/wnztXVPwnbT+N2QmMl3v1/pyEwv0j9iVYoFC7eUbD MRvcG86blRVhx1wqfzuJ/t6LhyoE1RIerWCw4E3LgCgNV/N8iI3w2gWhUQNsEfHKx7GQ 9lXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2TBBzYBtwRKzaiIe5wMZ+2rX5EzUM3SIHYPgS6jpmXA=; b=nFsCVSJ4+xTGs+/sVoqoAhIAtUv1KbQjliLw0/IBc2ZsOO3egis1q3DiLWZzjpWeRE 3ThARgAoUS/KtKBecezPeKH8/2o/+SBQO69iq7TMW4Xyce3fzP7hcVrBAqjtOGGC3yR7 Ri49sVsVWPUHXK5nDbGwDapiw7p+aST/knmOW2yn3itP46MDSnx3VPlXDW/dkGY35B8A 9BX18Ok5BxTs/yXkUf9iBOLRwje6gGm6Nf8HpcWCdERFmNjNbDRzyQDJ6NQ7+3quM7mV QJ23Io7k01yozoStz3RmvsYJDYZczaLqU+FuwYrrzsXEA6jLwGlOY40Ve1mReL2cdXaC L35Q== X-Gm-Message-State: APjAAAXprWsu+ZS5ndY1a5vtEnety4dUgF3O7MGc/76VmNaY3FPA126A SJ3mnLCsu9eNNFSITp0m2Vo= X-Google-Smtp-Source: APXvYqzjD8pfNn8qdLXtZ5jlj9NkUBRMd8O/SjyT/2kpPjSlJpZeLfZfhq+/FxEmVOXJoiSQUMUoQg== X-Received: by 2002:a1c:5f06:: with SMTP id t6mr5238975wmb.32.1581420551221; Tue, 11 Feb 2020 03:29:11 -0800 (PST) Received: from localhost ([88.98.246.218]) by smtp.gmail.com with ESMTPSA id e16sm4873847wrs.73.2020.02.11.03.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 03:29:10 -0800 (PST) From: luca.boccassi@gmail.com To: Tiwei Bie Cc: Stephen Hemminger , Maxime Coquelin , dpdk stable Date: Tue, 11 Feb 2020 11:20:37 +0000 Message-Id: <20200211112216.3929-91-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200211112216.3929-1-luca.boccassi@gmail.com> References: <20200211112216.3929-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'net/virtio-user: do not close tap when disabling queue pairs' has been queued to stable release 19.11.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to stable release 19.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 02/13/20. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Thanks. Luca Boccassi --- >From 45111bf63dd1e8f9726ece577ae38f4aea4d2e3e Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Mon, 25 Nov 2019 16:14:40 +0800 Subject: [PATCH] net/virtio-user: do not close tap when disabling queue pairs [ upstream commit 47ac9661b68275321fae0876cce743b9d17671fe ] Do not close the tap fds when disabling queue pairs, instead, we just need to unbind the backend. Otherwise, tap port can be destroyed unexpectedly. Fixes: e3b434818bbb ("net/virtio-user: support kernel vhost") Reported-by: Stephen Hemminger Signed-off-by: Tiwei Bie Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/vhost_kernel.c | 34 +++++++++++++++---- .../net/virtio/virtio_user/vhost_kernel_tap.c | 34 ++++++++++++------- .../net/virtio/virtio_user/vhost_kernel_tap.h | 8 +++++ drivers/net/virtio/virtio_user/vhost_user.c | 4 +++ .../net/virtio/virtio_user/virtio_user_dev.c | 5 ++- .../net/virtio/virtio_user/virtio_user_dev.h | 1 + 6 files changed, 65 insertions(+), 21 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index 5c81e8dd9f..2c805077af 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -330,16 +330,34 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev, vhostfd = dev->vhostfds[pair_idx]; + if (dev->qp_enabled[pair_idx] == enable) + return 0; + if (!enable) { - if (dev->tapfds[pair_idx] >= 0) { - close(dev->tapfds[pair_idx]); - dev->tapfds[pair_idx] = -1; + tapfd = dev->tapfds[pair_idx]; + if (vhost_kernel_set_backend(vhostfd, -1) < 0) { + PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel"); + return -1; } - return vhost_kernel_set_backend(vhostfd, -1); - } else if (dev->tapfds[pair_idx] >= 0) { + if (req_mq && vhost_kernel_tap_set_queue(tapfd, false) < 0) { + PMD_DRV_LOG(ERR, "fail to disable tap for vhost kernel"); + return -1; + } + dev->qp_enabled[pair_idx] = false; return 0; } + if (dev->tapfds[pair_idx] >= 0) { + tapfd = dev->tapfds[pair_idx]; + if (vhost_kernel_tap_set_offload(tapfd, dev->features) == -1) + return -1; + if (req_mq && vhost_kernel_tap_set_queue(tapfd, true) < 0) { + PMD_DRV_LOG(ERR, "fail to enable tap for vhost kernel"); + return -1; + } + goto set_backend; + } + if ((dev->features & (1ULL << VIRTIO_NET_F_MRG_RXBUF)) || (dev->features & (1ULL << VIRTIO_F_VERSION_1))) hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf); @@ -353,13 +371,15 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev, return -1; } + dev->tapfds[pair_idx] = tapfd; + +set_backend: if (vhost_kernel_set_backend(vhostfd, tapfd) < 0) { PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel"); - close(tapfd); return -1; } - dev->tapfds[pair_idx] = tapfd; + dev->qp_enabled[pair_idx] = true; return 0; } diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c index 76bf75423e..2fbfecba12 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c @@ -18,7 +18,7 @@ #include "../virtio_logs.h" #include "../virtio_pci.h" -static int +int vhost_kernel_tap_set_offload(int fd, uint64_t features) { unsigned int offload = 0; @@ -37,26 +37,34 @@ vhost_kernel_tap_set_offload(int fd, uint64_t features) offload |= TUN_F_UFO; } - if (offload != 0) { - /* Check if our kernel supports TUNSETOFFLOAD */ - if (ioctl(fd, TUNSETOFFLOAD, 0) != 0 && errno == EINVAL) { - PMD_DRV_LOG(ERR, "Kernel does't support TUNSETOFFLOAD\n"); - return -ENOTSUP; - } + /* Check if our kernel supports TUNSETOFFLOAD */ + if (ioctl(fd, TUNSETOFFLOAD, 0) != 0 && errno == EINVAL) { + PMD_DRV_LOG(ERR, "Kernel does't support TUNSETOFFLOAD\n"); + return -ENOTSUP; + } + if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) { + offload &= ~TUN_F_UFO; if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) { - offload &= ~TUN_F_UFO; - if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) { - PMD_DRV_LOG(ERR, "TUNSETOFFLOAD ioctl() failed: %s\n", - strerror(errno)); - return -1; - } + PMD_DRV_LOG(ERR, "TUNSETOFFLOAD ioctl() failed: %s\n", + strerror(errno)); + return -1; } } return 0; } +int +vhost_kernel_tap_set_queue(int fd, bool attach) +{ + struct ifreq ifr = { + .ifr_flags = attach ? IFF_ATTACH_QUEUE : IFF_DETACH_QUEUE, + }; + + return ioctl(fd, TUNSETQUEUE, &ifr); +} + int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq, const char *mac, uint64_t features) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h index e0e95b4f59..5c4447b296 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h @@ -2,6 +2,10 @@ * Copyright(c) 2016 Intel Corporation */ +#ifndef _VHOST_KERNEL_TAP_H +#define _VHOST_KERNEL_TAP_H + +#include #include /* TUN ioctls */ @@ -37,3 +41,7 @@ int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq, const char *mac, uint64_t features); +int vhost_kernel_tap_set_offload(int fd, uint64_t features); +int vhost_kernel_tap_set_queue(int fd, bool attach); + +#endif diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index a4b5c25cd3..d8e083ba8b 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -456,6 +456,9 @@ vhost_user_enable_queue_pair(struct virtio_user_dev *dev, { int i; + if (dev->qp_enabled[pair_idx] == enable) + return 0; + for (i = 0; i < 2; ++i) { struct vhost_vring_state state = { .index = pair_idx * 2 + i, @@ -466,6 +469,7 @@ vhost_user_enable_queue_pair(struct virtio_user_dev *dev, return -1; } + dev->qp_enabled[pair_idx] = enable; return 0; } diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index ffbaa75b7e..1c6b26f8d3 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -546,8 +546,11 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev) } if (dev->vhostfds) { - for (i = 0; i < dev->max_queue_pairs; ++i) + for (i = 0; i < dev->max_queue_pairs; ++i) { close(dev->vhostfds[i]); + if (dev->tapfds[i] >= 0) + close(dev->tapfds[i]); + } free(dev->vhostfds); free(dev->tapfds); } diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index ad86837717..3b6b6065a5 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -49,6 +49,7 @@ struct virtio_user_dev { struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES]; }; struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES]; + bool qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS]; struct virtio_user_backend_ops *ops; pthread_mutex_t mutex; -- 2.20.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2020-02-11 11:17:42.068799470 +0000 +++ 0091-net-virtio-user-do-not-close-tap-when-disabling-queu.patch 2020-02-11 11:17:38.532003815 +0000 @@ -1,14 +1,15 @@ -From 47ac9661b68275321fae0876cce743b9d17671fe Mon Sep 17 00:00:00 2001 +From 45111bf63dd1e8f9726ece577ae38f4aea4d2e3e Mon Sep 17 00:00:00 2001 From: Tiwei Bie Date: Mon, 25 Nov 2019 16:14:40 +0800 Subject: [PATCH] net/virtio-user: do not close tap when disabling queue pairs +[ upstream commit 47ac9661b68275321fae0876cce743b9d17671fe ] + Do not close the tap fds when disabling queue pairs, instead, we just need to unbind the backend. Otherwise, tap port can be destroyed unexpectedly. Fixes: e3b434818bbb ("net/virtio-user: support kernel vhost") -Cc: stable@dpdk.org Reported-by: Stephen Hemminger Signed-off-by: Tiwei Bie