From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0059.outbound.protection.outlook.com [104.47.2.59]) by dpdk.org (Postfix) with ESMTP id 19BB0239 for ; Mon, 21 May 2018 09:52:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SH/yd74nYLAUFUkI0uwXgWNsRovyPa+TQ/Bo40o8htk=; b=iQh3sfJC5W5Iaj4RexTVYYqvjlQPQ+sqY6Q0NjJkmVdj0nClbbVP9YtltE9YcJXfNAMSER2oraS5gjVi1c107cdax1ZbmvEYJUgxEVX543LuPA51gZFQx9oDNQeVL38o0IT6ArtM8qLnxPBje1kl6U0czbHyyUjSBZZHLVD+jf4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0501MB2315.eurprd05.prod.outlook.com (2603:10a6:3:27::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Mon, 21 May 2018 07:52:41 +0000 From: Ophir Munk To: Ophir Munk Cc: stable@dpdk.org Date: Mon, 21 May 2018 07:52:31 +0000 Message-Id: <1526889151-14579-1-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1526632068-7467-1-git-send-email-ophirmu@mellanox.com> References: <1526632068-7467-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0501CA0027.eurprd05.prod.outlook.com (2603:10a6:800:60::13) To HE1PR0501MB2315.eurprd05.prod.outlook.com (2603:10a6:3:27::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(2017052603328)(7153060)(7193020); SRVR:HE1PR0501MB2315; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2315; 3:u77c74wB6MZlGoMGvPl1n5KM8MM6WJxfgwC3wQrEdlYMr278hFWCGDavnXOEz0dmEOM2WrQQytOYtpMcKo5MqTyFNd2SPCUK2jNIQnVjxphxMVcYRlcvDFNaBZHYib43GeLeHjUgpyXSIM+JjTPUtJGdZSgsUkfSCISbsPQ2f2lnY5FdOI/pjzzdYVQycIvmMCgyINjPvmOG+wU0k14/YaEONhH5Uc0nGH7B4rV3e9PyyHfaoAxDf748SpUesRNj; 25:lHfM06p9R7qOKeRIV1mw9dPqlkreILb0BrAhKCsL77u9+x/s6MpXx3aCtudtWb3gY5kE8MVDm3srVnKDZdPVWFpQ3dIvD6olrV3SMb+sJ2RFAuWMAAQsVITGbP0eYM3HvYuIDPjMc5f6TLQb+51llTOgyXLHnLXxdVDTtSWG+/NPOATN5Cqi5cL7stS3tI/C7yMIJW/8n5g/7If9HbSxhF/wKTdQSR2ZtuKAxsCul6xXefaAy//DbdaZlgpsRD1Nypt9sEK4peh/YVhtFQe6EuHJI3OoX48HXKuGjd7p8NMXvKCr/Sez0WDSxDelgyVtRQE2CXJADx8VBjCnZMJC2g==; 31:yTMiZbYhvkDu5MQK90qd5AGXT9JM1dlLDw4jxyPa9jiEk4kqmt7Z2Y6Ck2mBPnEBEoYoqDVW6iTGyYhSaXusw4jyWbw2HIsQqnHVR3Q+6BAnQbfP4eooK/LMR9qSrPX3ndifAmG2DqeFI9iM5ZX5/5HXhAlN3s72zURDrZQ2Mw27ePlBwVsV+ZErpDzCA2PRbvHrZGOKPuHuwykGQA/u+uZfKwLpCLiwofxHQDjuo3I= X-MS-TrafficTypeDiagnostic: HE1PR0501MB2315: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2315; 20:IfC92lzxbgmDcffFKjYCrv0JbFj+0YkZ6rt26mcKvp7kWJ3OKcVWEIdjlpig0GvTUkvLgdTzVULuRMbdwIJXCiu6L05+BVE8rRRa2got519SGce05aYpo33voAz87kLeboxFFOFqimMxoeaTvX0LkjcQkI4YH/lsWQR+10muWVON3b9+5RmaP6Nus0cRRJmCjsbjtE2ZN14Ye8oDNR9D4S92SulxtLaYaXnOFkrRnKAPyqMFaUXK4Xz7PuIuoakwYIYQ75n2olYJvJBKZOuSmOGovje7DPN5cnUqO1vgMf+vdTfT5TrOFNVOnZEMWkwjnpLvCYjxVZxoSehFT2usJ+2a3PvGBBuK70+Zf1MA0EhuBq+UimzLWg/Y9dnGQSZZDCXJ8nVIV6ABMgoj+V+D4WcoIzYyDTHQRbZdEKjN7qUNvdlpghKtgiB5uzqQJloJHxkMyEEathOr/5THzOclj0xqKB8Bgbzk2rKR6jk8azPuG7TDnS4eQ5j+XEh1aIb9; 4:yZUc2EIkOPuiBW/WW519ecMx83fGuJkbngUQbXhu2PA53uCo8QykzH8YHqZ1L5kw2oN0+ulMLhc+tC9RYsZieFV7UKPvtK3ah3UtOV5HlyX9d0F21GCvHsIIH+S45tVFYuCJ2iTWFCdxCcIspthLJHE5o+iCzcb5pQkFg98LFXV4PE5PcQMeGUyWfFPvyFPzWmhcXF2eGJTF3W6SJ3AVp1qB/N4Wkt1wrpvrJLsysCDbaU/NvkjBX6EBd5IqtoP7f4CybhPLTGyYdF++DBURAw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231254)(944501410)(52105095)(3002001)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:HE1PR0501MB2315; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2315; X-Forefront-PRVS: 06793E740F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(39380400002)(396003)(376002)(366004)(346002)(39860400002)(199004)(189003)(55016002)(69596002)(50226002)(81156014)(81166006)(6862004)(21086003)(316002)(36756003)(305945005)(7736002)(53936002)(5660300001)(51416003)(4326008)(3846002)(6116002)(7696005)(97736004)(8936002)(52116002)(8676002)(50466002)(16526019)(386003)(48376002)(486006)(106356001)(68736007)(478600001)(16586007)(76176011)(86362001)(476003)(446003)(26005)(2906002)(2616005)(956004)(59450400001)(11346002)(105586002)(4720700003)(37006003)(7049001)(6200100001)(66066001)(33026002)(25786009)(6666003)(47776003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0501MB2315; H:mellanox.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0501MB2315; 23:nphut5uBccCWk1AHTiFei4QGxs/u2w+AcJVnRpx?= =?us-ascii?Q?MPai4wNhMQPrFWlcBFCawrnXyCl9Grf0GhLOZE0Kf9wVaH5tDE1/Ui/WjL7h?= =?us-ascii?Q?PGm1j8mhyKcUmFk5CayMlz77gOXwuq532jg/CuHA1pGak/Phg2QJBwZNgxmh?= =?us-ascii?Q?I9EgrZy+rOkBvY9Ry8N12ouKaglmzFmkuPecM8xSk3KSmDZhW6R45KnqumLS?= =?us-ascii?Q?KAhMR5m6tj83wujn3e/C3anEVM4enT8kzR0aG/2U+kGFAxQAp5vl2oxsd3Ou?= =?us-ascii?Q?S+olMrAcf/c9gQ/oljMfzrO5Zb4Bcf03kWItxK0pP0g50ynQuzEjtQdEvDWB?= =?us-ascii?Q?2IKLKTlAAuUk8Wz4cmngVW32XFkT0J3wqI1AgMrRO8kASibVZBo9KzJrRSLU?= =?us-ascii?Q?sZ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RiJSiKfRZ04jko=; 24:ZCyKh8cvCroD/9wCbjVooMjL2GnxmgiQSlb9n//0M1his/+rEuoiSYunfxL7Uz+nihBoGs85SLe6LVDcLOM+ZuUWew3cukzvvpZK3gqvTl4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2315; 7:n6RVe6++8TfuJIHL5pYVwEASYpuJPsM0qQ3MjWv6J6tU3kpbNfX04xIv1lJaVYIH5b2c62fJeS1V6C3cDDb7EOppA3QgbN2QXhUpUJmEQMbygyJ1SXncxps+abZghuLQVU32pejgJitxSl70VBj11Qhw/SqBjoU9Zma2H5ndUULkUnYNEM5queCaNs0chq66XOIRD8p9pymPU2w2cS3ZF2D01d58S6EuQHUuDp00GW06ueDblAUQhmN9L3KawqHZ X-MS-Office365-Filtering-Correlation-Id: 26830357-c53b-42cd-0a27-08d5beefd4b4 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2018 07:52:41.2198 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26830357-c53b-42cd-0a27-08d5beefd4b4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2315 Subject: [dpdk-stable] [PATCH v4] net/tap: fix device removal when no queues exist 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: Mon, 21 May 2018 07:52:43 -0000 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") Cc: stable@dpdk.org Signed-off-by: Ophir Munk --- v1: Initial release v2: Reword commit message (a fixing patch) v3: Following review comments (return value of ka_fd) and commit message typo fixing v4: Explicit setting ka_fd = -1 in eth_dev_tap_create() call 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 c006d07..52ef799 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -929,6 +929,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 @@ -1549,6 +1558,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; @@ -1561,13 +1571,17 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, rte_memcpy(&pmd->eth_addr, mac_addr, sizeof(*mac_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) { + TAP_LOG(ERR, "Unable to create %s interface", tuntap_name); goto error_exit; + } ifr.ifr_mtu = dev->data->mtu; if (tap_ioctl(pmd, SIOCSIFMTU, &ifr, 1, LOCAL_AND_REMOTE) < 0) @@ -1961,9 +1975,12 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev) close(internals->ioctl_sock); rte_free(eth_dev->data->dev_private); - 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 babe42d..575dce4 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -81,6 +81,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.7.4