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 1D85EA054C for ; Fri, 14 Feb 2020 18:04:12 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5A38D1B53; Fri, 14 Feb 2020 18:04:11 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by dpdk.org (Postfix) with ESMTP id 8C64311A4 for ; Fri, 14 Feb 2020 18:04:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581699849; 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; bh=a2zhMD0ZJiZTRrTNyudOp10eG19CUqdMq79dybSC5/k=; b=GCctBzDyJJZU09bxJ7zQhPME2DfJ19P9oZXshsh5E6Ij4rTF6muOEHwJIa7mKUlYOCWVDW 0unlXcRswR+PPezUuHNzj0wrDybZvaCQkASnMe1UQb4ycwHn1S22RUrTEnr6KSWLPuMdhm x94Rrf0nZc+7X/YEGwO2qKxES268l5k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-223-gx_v1fOJNr22zR1V3Bul5A-1; Fri, 14 Feb 2020 12:03:59 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B543E107ACC4; Fri, 14 Feb 2020 17:03:58 +0000 (UTC) Received: from rh.redhat.com (unknown [10.33.36.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id D97F584BCD; Fri, 14 Feb 2020 17:03:53 +0000 (UTC) From: Kevin Traynor To: Tiwei Bie Cc: Stephen Hemminger , Maxime Coquelin , dpdk stable Date: Fri, 14 Feb 2020 17:02:55 +0000 Message-Id: <20200214170337.25093-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: gx_v1fOJNr22zR1V3Bul5A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] patch 'net/virtio-user: do not close tap when disabling queue pairs' has been queued to LTS release 18.11.7 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 LTS release 18.11.7 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/20/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 rebasi= ng (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/ebf749a4653c63d3f9= 63139f509c1c9997ab7239 Thanks. Kevin. --- >From ebf749a4653c63d3f963139f509c1c9997ab7239 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 pai= rs [ 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/vi= rtio/virtio_user/vhost_kernel.c index 6b19180d72..23972493ff 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -332,14 +332,32 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev= *dev, =09vhostfd =3D dev->vhostfds[pair_idx]; =20 +=09if (dev->qp_enabled[pair_idx] =3D=3D enable) +=09=09return 0; + =09if (!enable) { -=09=09if (dev->tapfds[pair_idx] >=3D 0) { -=09=09=09close(dev->tapfds[pair_idx]); -=09=09=09dev->tapfds[pair_idx] =3D -1; +=09=09tapfd =3D dev->tapfds[pair_idx]; +=09=09if (vhost_kernel_set_backend(vhostfd, -1) < 0) { +=09=09=09PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel"); +=09=09=09return -1; =09=09} -=09=09return vhost_kernel_set_backend(vhostfd, -1); -=09} else if (dev->tapfds[pair_idx] >=3D 0) { +=09=09if (req_mq && vhost_kernel_tap_set_queue(tapfd, false) < 0) { +=09=09=09PMD_DRV_LOG(ERR, "fail to disable tap for vhost kernel"); +=09=09=09return -1; +=09=09} +=09=09dev->qp_enabled[pair_idx] =3D false; =09=09return 0; =09} =20 +=09if (dev->tapfds[pair_idx] >=3D 0) { +=09=09tapfd =3D dev->tapfds[pair_idx]; +=09=09if (vhost_kernel_tap_set_offload(tapfd, dev->features) =3D=3D -1) +=09=09=09return -1; +=09=09if (req_mq && vhost_kernel_tap_set_queue(tapfd, true) < 0) { +=09=09=09PMD_DRV_LOG(ERR, "fail to enable tap for vhost kernel"); +=09=09=09return -1; +=09=09} +=09=09goto set_backend; +=09} + =09if ((dev->features & (1ULL << VIRTIO_NET_F_MRG_RXBUF)) || =09 (dev->features & (1ULL << VIRTIO_F_VERSION_1))) @@ -355,11 +373,13 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev= *dev, =09} =20 +=09dev->tapfds[pair_idx] =3D tapfd; + +set_backend: =09if (vhost_kernel_set_backend(vhostfd, tapfd) < 0) { =09=09PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel"); -=09=09close(tapfd); =09=09return -1; =09} =20 -=09dev->tapfds[pair_idx] =3D tapfd; +=09dev->qp_enabled[pair_idx] =3D true; =09return 0; } diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/ne= t/virtio/virtio_user/vhost_kernel_tap.c index fbd9e979d7..361011ce65 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c @@ -19,5 +19,5 @@ #include "../virtio_pci.h" =20 -static int +int vhost_kernel_tap_set_offload(int fd, uint64_t features) { @@ -38,18 +38,16 @@ vhost_kernel_tap_set_offload(int fd, uint64_t features) =09} =20 -=09if (offload !=3D 0) { -=09=09/* Check if our kernel supports TUNSETOFFLOAD */ -=09=09if (ioctl(fd, TUNSETOFFLOAD, 0) !=3D 0 && errno =3D=3D EINVAL) { -=09=09=09PMD_DRV_LOG(ERR, "Kernel does't support TUNSETOFFLOAD\n"); -=09=09=09return -ENOTSUP; -=09=09} +=09/* Check if our kernel supports TUNSETOFFLOAD */ +=09if (ioctl(fd, TUNSETOFFLOAD, 0) !=3D 0 && errno =3D=3D EINVAL) { +=09=09PMD_DRV_LOG(ERR, "Kernel does't support TUNSETOFFLOAD\n"); +=09=09return -ENOTSUP; +=09} =20 +=09if (ioctl(fd, TUNSETOFFLOAD, offload) !=3D 0) { +=09=09offload &=3D ~TUN_F_UFO; =09=09if (ioctl(fd, TUNSETOFFLOAD, offload) !=3D 0) { -=09=09=09offload &=3D ~TUN_F_UFO; -=09=09=09if (ioctl(fd, TUNSETOFFLOAD, offload) !=3D 0) { -=09=09=09=09PMD_DRV_LOG(ERR, "TUNSETOFFLOAD ioctl() failed: %s\n", -=09=09=09=09=09strerror(errno)); -=09=09=09=09return -1; -=09=09=09} +=09=09=09PMD_DRV_LOG(ERR, "TUNSETOFFLOAD ioctl() failed: %s\n", +=09=09=09=09strerror(errno)); +=09=09=09return -1; =09=09} =09} @@ -58,4 +56,14 @@ vhost_kernel_tap_set_offload(int fd, uint64_t features) } =20 +int +vhost_kernel_tap_set_queue(int fd, bool attach) +{ +=09struct ifreq ifr =3D { +=09=09.ifr_flags =3D attach ? IFF_ATTACH_QUEUE : IFF_DETACH_QUEUE, +=09}; + +=09return ioctl(fd, TUNSETQUEUE, &ifr); +} + int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq, diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h b/drivers/ne= t/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 @@ -3,4 +3,8 @@ */ =20 +#ifndef _VHOST_KERNEL_TAP_H +#define _VHOST_KERNEL_TAP_H + +#include #include =20 @@ -38,2 +42,6 @@ int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq, =09=09=09 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/virt= io/virtio_user/vhost_user.c index 0a88d5957e..a42cf480af 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -457,4 +457,7 @@ vhost_user_enable_queue_pair(struct virtio_user_dev *de= v, =09int i; =20 +=09if (dev->qp_enabled[pair_idx] =3D=3D enable) +=09=09return 0; + =09for (i =3D 0; i < 2; ++i) { =09=09struct vhost_vring_state state =3D { @@ -467,4 +470,5 @@ vhost_user_enable_queue_pair(struct virtio_user_dev *de= v, =09} =20 +=09dev->qp_enabled[pair_idx] =3D enable; =09return 0; } diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net= /virtio/virtio_user/virtio_user_dev.c index f6356eabc6..a199350df9 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -534,6 +534,9 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev) =20 =09if (dev->vhostfds) { -=09=09for (i =3D 0; i < dev->max_queue_pairs; ++i) +=09=09for (i =3D 0; i < dev->max_queue_pairs; ++i) { =09=09=09close(dev->vhostfds[i]); +=09=09=09if (dev->tapfds[i] >=3D 0) +=09=09=09=09close(dev->tapfds[i]); +=09=09} =09=09free(dev->vhostfds); =09=09free(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 3e3a7b787f..d8a5070a28 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -41,4 +41,5 @@ struct virtio_user_dev { =09char=09=09path[PATH_MAX]; =09struct vring=09vrings[VIRTIO_MAX_VIRTQUEUES]; +=09bool=09=09qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS]; =09struct virtio_user_backend_ops *ops; =09pthread_mutex_t=09mutex; --=20 2.21.1 --- Diff of the applied patch vs upstream commit (please double-check if non-= empty: --- --- -=092020-02-14 17:02:37.108535157 +0000 +++ 0001-net-virtio-user-do-not-close-tap-when-disabling-queu.patch=092020-= 02-14 17:02:36.907408856 +0000 @@ -1 +1 @@ -From 47ac9661b68275321fae0876cce743b9d17671fe Mon Sep 17 00:00:00 2001 +From ebf749a4653c63d3f963139f509c1c9997ab7239 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 47ac9661b68275321fae0876cce743b9d17671fe ] + @@ -11 +12,0 @@ -Cc: stable@dpdk.org @@ -26 +27 @@ -index 5c81e8dd9f..2c805077af 100644 +index 6b19180d72..23972493ff 100644 @@ -29 +30 @@ -@@ -331,14 +331,32 @@ vhost_kernel_enable_queue_pair(struct virtio_user_de= v *dev, +@@ -332,14 +332,32 @@ vhost_kernel_enable_queue_pair(struct virtio_user_de= v *dev, @@ -67 +68 @@ -@@ -354,11 +372,13 @@ vhost_kernel_enable_queue_pair(struct virtio_user_de= v *dev, +@@ -355,11 +373,13 @@ vhost_kernel_enable_queue_pair(struct virtio_user_de= v *dev, @@ -84 +85 @@ -index 76bf75423e..2fbfecba12 100644 +index fbd9e979d7..361011ce65 100644 @@ -159 +160 @@ -index a4b5c25cd3..d8e083ba8b 100644 +index 0a88d5957e..a42cf480af 100644 @@ -177 +178 @@ -index ffbaa75b7e..1c6b26f8d3 100644 +index f6356eabc6..a199350df9 100644 @@ -180 +181 @@ -@@ -547,6 +547,9 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev) +@@ -534,6 +534,9 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev) @@ -192 +193 @@ -index ad86837717..3b6b6065a5 100644 +index 3e3a7b787f..d8a5070a28 100644 @@ -195,3 +196,3 @@ -@@ -50,4 +50,5 @@ struct virtio_user_dev { - =09}; - =09struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES]; +@@ -41,4 +41,5 @@ struct virtio_user_dev { + =09char=09=09path[PATH_MAX]; + =09struct vring=09vrings[VIRTIO_MAX_VIRTQUEUES]; @@ -199 +199,0 @@ -=20 @@ -200,0 +201 @@ + =09pthread_mutex_t=09mutex;