From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id 992D02C8 for ; Wed, 23 May 2018 14:11:33 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id r13-v6so13714099wrj.10 for ; Wed, 23 May 2018 05:11:33 -0700 (PDT) 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; bh=6RTRqbjglImq2Og7hwV9Q+hS8HQYHyLkk8yTTOwS5To=; b=b5pEmjUKCMaS02PmnZvgGhiTmys/MJ4Tl9J38B5HeHMDv+28/B72NzApHsA+0Mpwhh xHYfxZpKRAGlARKT16c+UNkUeySURMn0ItHsX/TARVN3jfO1HvPs7My45fTuOQvFw1mC LvGJ14l/AVA7kPxWyw/soo/BMQCCpgoqMzhXX2+SE0JGlMmCwWkXpEIgpA6dVC/OBBM7 2aXkEWrbgjFdH9dNbVn+hH0vxoon+S+pTKMXSFKRxc2XPMjWvxSfUgKmS3COYMDwxtx6 WVd1rT+9PXz3uiyeLCIoPcw0nHCCUVMMaZ7yyGsRRWqs8EnKHBq9gz9x2AGwELssvdGZ zWuw== 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; bh=6RTRqbjglImq2Og7hwV9Q+hS8HQYHyLkk8yTTOwS5To=; b=PO94/YqXYmlR7xN5NSkeDOrerOeOhchnDAIrf919mjUOvk3mw2TLLZtb6CIe8l1/oB 1WHPApr2ZZgVDVk9ILEj9SwowxKzhRT9C/Qyv6bSfRvGuwKehEo6FM+L+JXQEbAujHd2 GqMc1cIetDYktTD0Es5b7tAljuoa4gFuvxfm3NOURwuTOg/ceuVXHw7vlBA0cpVC26J9 4BxsGwt6NnaIEhHifbEW3th7wQyHfKn352BmTJ4rc+qnMwtGvMGHiTmEbgZ531cBKB6D atN4UH30WbEHTV9p9xJSBpbk76UHppbFjOon9v0nKd7+kpq79wm4WbzQO0QbDS3IEtq3 FAog== X-Gm-Message-State: ALKqPwf8hC3YptSut6iWJU4tftEffaSVDHBXThXWea/x2jy9XU+BSAsI SArRPkrRCPvR4956FDL1Cyw= X-Google-Smtp-Source: AB8JxZr5M3fc9cV2vdaE7AYHkSrOyMV3BFAgL22qP8MMV4QHjZEEyAwmnvXPtt1Z2MwQDPCiE9V2/A== X-Received: by 2002:adf:b852:: with SMTP id u18-v6mr2195680wrf.162.1527077493318; Wed, 23 May 2018 05:11:33 -0700 (PDT) Received: from localhost ([2a00:23c5:be9a:5200:ce4c:82c0:d567:ecbb]) by smtp.gmail.com with ESMTPSA id o4-v6sm3697378wrp.19.2018.05.23.05.11.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 05:11:32 -0700 (PDT) From: luca.boccassi@gmail.com To: Ophir Munk Cc: Keith Wiles , dpdk stable Date: Wed, 23 May 2018 13:09:59 +0100 Message-Id: <20180523121010.8385-48-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180523121010.8385-1-luca.boccassi@gmail.com> References: <20180516101323.2234-2-luca.boccassi@gmail.com> <20180523121010.8385-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'net/tap: fix device removal when no queue exist' has been queued to stable release 18.02.2 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: , X-List-Received-Date: Wed, 23 May 2018 12:11:33 -0000 Hi, FYI, your patch has been queued to stable release 18.02.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/25/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From 94106a31e6645023b9a942dc4dd58fee334a6321 Mon Sep 17 00:00:00 2001 From: Ophir Munk Date: Mon, 21 May 2018 07:54:33 +0000 Subject: [PATCH] net/tap: fix device removal when no queue exist [ upstream commit 3101191c63ab25a9d743b96cc004eec2e9a8c1cc ] TAP device is created following its first queue creation. Multiple queues can be added or removed over time. In Linux terminology those are file descriptors which are opened or closed over time. As long as the number of opened file descriptors is positive - TAP device will appear as a Linux device. In case all queues are released (the equivalent of all file descriptors being closed) the TAP device will be removed. This can lead to abnormalities in different scenarios where the TAP device should exist even if all its queues are released. In order to make TAP existence independent of its number of queues - an extra file descriptor is opened on TAP creation and is closed on TAP closure. Its only purpose is to serve as a keep-alive mechanism for the TAP device. Fixes: bf7b7f437b49 ("net/tap: create netdevice during probing") Signed-off-by: Ophir Munk Acked-by: Keith Wiles --- drivers/net/tap/rte_eth_tap.c | 31 ++++++++++++++++++++++++------- drivers/net/tap/rte_eth_tap.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 6ce02c9b6..b9b9397b9 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -824,6 +824,15 @@ tap_dev_close(struct rte_eth_dev *dev) ioctl(internals->ioctl_sock, SIOCSIFFLAGS, &internals->remote_initial_flags); } + + if (internals->ka_fd != -1) { + close(internals->ka_fd); + internals->ka_fd = -1; + } + /* + * Since TUN device has no more opened file descriptors + * it will be removed from kernel + */ } static void @@ -1389,6 +1398,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, dev->intr_handle = &pmd->intr_handle; /* Presetup the fds to -1 as being not valid */ + pmd->ka_fd = -1; for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) { pmd->rxq[i].fd = -1; pmd->txq[i].fd = -1; @@ -1405,13 +1415,17 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, eth_random_addr((uint8_t *)&pmd->eth_addr); } - /* Immediately create the netdevice (this will create the 1st queue). */ - /* rx queue */ - if (tap_setup_queue(dev, pmd, 0, 1) == -1) - goto error_exit; - /* tx queue */ - if (tap_setup_queue(dev, pmd, 0, 0) == -1) + /* + * Allocate a TUN device keep-alive file descriptor that will only be + * closed when the TUN device itself is closed or removed. + * This keep-alive file descriptor will guarantee that the TUN device + * exists even when all of its queues are closed + */ + pmd->ka_fd = tun_alloc(pmd); + if (pmd->ka_fd == -1) { + RTE_LOG(ERR, PMD, "Unable to create %s interface", tap_name); goto error_exit; + } ifr.ifr_mtu = dev->data->mtu; if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0) @@ -1685,9 +1699,12 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev) close(internals->ioctl_sock); rte_free(eth_dev->data->dev_private); rte_free(eth_dev->data); - rte_eth_dev_release_port(eth_dev); + if (internals->ka_fd != -1) { + close(internals->ka_fd); + internals->ka_fd = -1; + } return 0; } diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index 53a506add..dcafd6df1 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -76,6 +76,7 @@ struct pmd_internals { struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */ struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */ struct rte_intr_handle intr_handle; /* LSC interrupt handle. */ + int ka_fd; /* keep-alive file descriptor */ }; /* tap_intr.c */ -- 2.14.2