From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0053.outbound.protection.outlook.com [104.47.2.53]) by dpdk.org (Postfix) with ESMTP id 61E6AD592 for ; Wed, 16 May 2018 18:10:33 +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=0RpZBUWBqByspEHWzPFjBfoBH8NroMKHP/Wz3dYRE4g=; b=cZiEw9oNPzArMmeV5VxCTNT0MMKrDsaA/4dmFpavMFGSg0xkpWsjkLo/B9LbEbUJxb5eDMAnlluNBoIshdwQxG4fSeJPa6T/wVdLC2nLOKPgyqYWJ5dLB3ElsHU5Kf9LCGMbyXehSvdUAETA9yvNkz2WycX1svxQG4VsZm3DTKw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by VI1PR0501MB2317.eurprd05.prod.outlook.com (2603:10a6:800:2c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Wed, 16 May 2018 16:10:30 +0000 From: Ophir Munk To: dev@dpdk.org, Pascal Mazon , Keith Wiles Cc: Thomas Monjalon , Olga Shern , Ophir Munk , Shahaf Shuler Date: Wed, 16 May 2018 16:10:19 +0000 Message-Id: <1526487019-3737-1-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1P194CA0049.EURP194.PROD.OUTLOOK.COM (2603:10a6:803:3c::38) To VI1PR0501MB2317.eurprd05.prod.outlook.com (2603:10a6:800:2c::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2317; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2317; 3:hIR2tCNw6QOLb44rYqdXRw+nokcjkD/U1in8niBZcBjbVhyeUVbgduAO5QU6Sc/OxTdNf66BRScvvaeLWW3wSsxxU4Ihx3sCFzvl4shd1Twiur2q7oQ08RLNrkqtTQ94DiAd/Y+TU7aaqO9y1XeKv3Foq0VqvV7HFz5urG5p/mclWIq+oK+hD5LBMGv0IZ/8XaEzVxoHlN1b5xvivnRFfxTMk/ReBA/TbjolioLrX4NV/QcILbr4fJMpVqe7q6Fw; 25:aBEwBWSmvl3PNHaK3o7bAKjNGLT2KOFzLVUCx2aNeOc0U/Oc9Bd1V01KmgNb2YVpnkKcvC5/dQJ/SU7YVCWo4tTwXmAzwbPa/47ebtZvCQkjVNom5ke0XY22DzR8hlqpBQSJhEEeJoJOGfHBTzo3ImRmjI/NTZM3rEC+BCrB50oY2+kSa9PPMx95cVGGRuCFLxaP1n/CTO5wC16H9JQa8PQjv7PKM5APdSm+Oaro3b7bd2Y3ZcGGDX+qz69FsN1fChJ1fOwmguTPVUhQwy4tHxcYzUvdWav9Shtz2ers9Un3feFR3GZ9/wnS5Ecmjwv3+TtwfYT0rW7GflWqU5d/UA==; 31:ILRSMnFXIefEfB7cJ8CY8BQUZIsLPtCQ478pbOQ+9jFMpuzniN//27g1/V0E0VaMOkXZBvo572XrsTftB5ieR52TlsJCUIGEbhf1sS/RRw2hKrybJEF6jMU/UtI9o8k4cxpfEPWrCEu9v88dGBF+y7v00dDiJi8bqRTSlpSNCHU8LhfZR9yIlX27OWw+ZvSttByxLlBiwtbzkzmnJ5pVQDuak9mzkh4SeebF2DfL2gw= X-MS-TrafficTypeDiagnostic: VI1PR0501MB2317: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2317; 20:dUA7hWLqnpYbgSsz8xBNAIa2hPXqYBZvuUuErVFi+yuSgpaGExE8367WH1FvbjxdtFY4du1iNUs0ioAGybvExOyzjI3H/y1HDDWjoZVyhUOr42d3GC3ujWDGAnFbeXPQctN2aaa8AbkZTzwm8cAalOj4IZ7atB3WxRxKzfOM2dhVtw1yg3ZVmjgUt7FQpBLpKT3C2WnPEeK1jNwLvkywsHQ0LYV5H7x+6ao24j+xbbZLjgW+xYow6TUrIZ90KNxkA3GDM3GZvu/MPq6f3oIA77wTMR6eci9hIwpCDrpe4ism9xPfXJZ+SrLN5FBBt9PQzl37D/yLbUneHmQI9TMpZCc1LJbZJbeeusNxxJw1PSIX88Jhmgad+dWxZoM09ZjKJ5h5ex5ypZmzgdvq26BVnXfIrUCZtJEpjTC1fd/bNNvzD9S9Ya94UMQ3Y+m/h/yr+6nsJfWFzevdqIjOWnXMkY0kWmt8a1mySsK56TsZOG0HJVek76f0fjUQjbvNPw5g; 4:wdE6XRTxunBp/OJ8P2isrQyozO2IAz/B8AnAkR1Kh+nVhIsgFTEZDqy2ka4EpWZ3SVKxOx8UpvVX72/wJZIIIu+GcChyKHdqENZJM4WH72g76dLlwkPj0XtaMSMlYkFo95KfTgpGhe5Zka1n7KH6J7iyRAWVh8My8z/34+hPISEn9McAdNFwDZmbOmlGipcLhRvigGosxEsEjm7hrBQN6LdjWb9qMOsNrmgsT1neA+c/fIms3JpYPlym39ism0nx2g4UpsmL81WBocQNXOGwqA== 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)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR0501MB2317; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2317; X-Forefront-PRVS: 0674DC6DD3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(39860400002)(39380400002)(366004)(396003)(189003)(199004)(68736007)(50466002)(48376002)(6116002)(3846002)(8936002)(105586002)(478600001)(50226002)(69596002)(106356001)(25786009)(47776003)(66066001)(8676002)(81166006)(81156014)(7736002)(386003)(107886003)(59450400001)(16586007)(53936002)(186003)(4326008)(316002)(16526019)(476003)(4720700003)(33026002)(6666003)(55016002)(305945005)(2616005)(956004)(26005)(5660300001)(486006)(97736004)(2906002)(21086003)(86362001)(52116002)(51416003)(54906003)(36756003)(110136005)(7696005); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2317; H:mellanox.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0501MB2317; 23:q3iDOo4wDhg/O+ULfNg6z+ZoGMyNv5h5tuf5yoU?= =?us-ascii?Q?JscH0tdwkzuHEiwWy6Gb+8hV3WMxqu/klPKFL2p6PrDbTo3zs7Zy42/WWyuP?= =?us-ascii?Q?YJbZqRSORbng7tmFz4FtEIoWNeobNNe9vl85Wqj9fN5IqacQHviOlhnC5liJ?= =?us-ascii?Q?YHj5mNdZE2F+WkCG2uhQOd5C4tANQEtsdpiDEHLt4j4/LJRSWUVlHxQkOmIS?= =?us-ascii?Q?AgwW68PpZCyyMbYbAFS6ztIReV5yTZZEMb8OVDXdPJl1WjnQvgYtpbc8EQZI?= =?us-ascii?Q?Qam7bATuYHQPIOn1bGp4+dmXz9Q/h2hcm9fps7NeXVBUxEjTCMO37RXa298O?= =?us-ascii?Q?NeoXJkSqW4Fi2ustmWsUNQotLKxvJMzb1fu2XVDfYKfZNZnRXqZQo8+ye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dXaQP7B?= X-Microsoft-Antispam-Message-Info: XD4ToOAseY+44olib4JtfvPlOhey3TEfPiV8HejbeGs2yTUh6g7eFyjNJF5aHT+gBHR48OA+py9aFHISDKIA3lZ6SEw3QnufwcQmlIic80eSfR8NAGYbBzMtebZwo0p1896Phy+MpN3CW9Ti1WtgBhRuO3g6AFxw63ZuHJSdLzufIKdRSf+4rz8wSEXCRPK+ X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2317; 6:AQccTNf6wwyN9F1Eh7+TLjBhqBTOFMuahKrf354Je7CSMvwIJK6v6hFjo8BgjI8WtwmL2CA8d9duyAqf82ZYxw5UI2c4pXl8aB+AsMPeRkt2AnCjKga3VZc4g5qvLfNXRZdw0mIeWvZR6Jehx9nooPj2BerYVB/nTmEQNbgS58K4afaYhuWKFSHcvy9ib1e+C/u3h6JtgNanV8m5RhanllIN3c6VA4iYRMI4UUsJjA7kW37UJwwhWLYg9XPGmTKdxcuGGY7kJwFlNee41rhieNWfvGAfxp1L4VQPVsuq4b2cQHCcgFn3nohlvYtNBLPka+5nW3b8JG6hRLseY4y7TIwUX1rLh78ZS9r5p+wVHjXEuF8NYUg4UQVagsvXT/0XDPBn//8p1t/6+sOJEyLHdhEtB0DtKEcw5opKIJQpMKzsX0ku3ZgNwndlsDhhK6OEp2xltqAGUABKHhnNATXTxA==; 5:rCKmNzEizSQ9d/Hp96CyymPJtV97ky9nTbzTKaEbfZhEyrMoZnHtvAd6+ulMjZDyxwOrquzStMMpsymtCDiFr5H7tmjPN5q3fe7G4xW7v78//LE8LIt7iqfmC9aFXx4G6531gR+glXYBMl7ExdkJCeXy+HU30DgMRDA8was/uwA=; 24:4DjEVhn1a1U8u69rNVogOuiEsp5TFOpf05ng+YVSigrkkptRY5k09V6HtnGPQq7Pa92lJeMPjq8R01ovqDsFCxjhjkL49boHywJ42tI4Jug= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2317; 7:lfBoAXlREi/L6s2iCGX7RsMeaeHJcVBmZWF2Q3DoJFMwZdHE01aL1pUju+tKUp5fdWZzcP9va4ZOZSunHchSnKNvPbT4MlLa6cbtOZ5BezTTKVwW5ne6eEqO+OPbmXK2zxEhBc8L2knCRR2hhiIR64EG26i65HDtg5NrIxS8r5jzjPzRN0MZyAdpXeZSJRP7mzkaG7ikP7RZL7OnXi3l+/LHmTRUjk0s8n76Lkn8mUw7qfeN9VhSvdMDBymopFKd X-MS-Office365-Filtering-Correlation-Id: 3813d4cb-0e15-4c53-e4ca-08d5bb478c7e X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 May 2018 16:10:30.7460 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3813d4cb-0e15-4c53-e4ca-08d5bb478c7e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2317 Subject: [dpdk-dev] [PATCH v1] net/tap: keep device alive when no queues exist X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 May 2018 16:10:33 -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. It's only purpose is to serve as a keep-alive mechanism for the TAP device. Signed-off-by: Ophir Munk --- 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..6901edc 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 @@ -1561,13 +1570,18 @@ 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 < 0) { + 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