From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20057.outbound.protection.outlook.com [40.107.2.57]) by dpdk.org (Postfix) with ESMTP id 7974F7FB1; Fri, 18 May 2018 10:28:02 +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=f6oyL5SFz8SmJUpk/o1YBrnyyMi3lY6uCCfemcctKvU=; b=rmMyCWBdvb1OplE7Ccrslx5pL3U2rUg6hlA9xg5W4bG2W6vSDp0SIqOP4r2+/C92V+3GaEXTCzPCJTxml32JWWfCjt8BRVYcaSHqLFPEC2ilvJsEdYYYmlVEgBp4lDs58fCnbLeP2uOZWxnjrwXvXyXH4BXx3DejfeHyk1FAm2Q= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by AM4PR0501MB2306.eurprd05.prod.outlook.com (2603:10a6:200:53::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.776.11; Fri, 18 May 2018 08:27:59 +0000 From: Ophir Munk To: dev@dpdk.org, Pascal Mazon , Keith Wiles Cc: Thomas Monjalon , Olga Shern , Ophir Munk , Shahaf Shuler , stable@dpdk.org Date: Fri, 18 May 2018 08:27:48 +0000 Message-Id: <1526632068-7467-1-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1526550455-14072-1-git-send-email-ophirmu@mellanox.com> References: <1526550455-14072-1-git-send-email-ophirmu@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR10CA0111.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:28::40) To AM4PR0501MB2306.eurprd05.prod.outlook.com (2603:10a6:200:53::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM4PR0501MB2306; X-Microsoft-Exchange-Diagnostics: 1; AM4PR0501MB2306; 3:pgSEL+x//tJxo0jZvGX9FueVh8/hDNmlzVgGXRH0/upYqJt7JJrYqrXMYgGPeAyu66GNhr1PfZbPuDOBFPRPjJwj79zvc9omOslfJYyOqqF3k/l7TF5aKcnINY63YFQ9aEJYel/8Jmmq3+NOQRXT2w6Uf4DDjRfHGGEFSEmXfoKoZFxhfrN/R6KDWehUTUsppKUmbprnDY8g9pbVbArtq3MdaIfMsoe9SqUgygAjdTZwBTk9d6iBnQvvPeprbXBS; 25:pOEAL21iMYD0D8Ze0ydHr/2BGNzecHkhNrO7DlASeugXrCwTNJJKXFuuoqs9rDm97wbCWyQnSLnZsQeSF/eOCRScCA5571YvFSu12YiUV0x/gBijNTy6mgSBqTfzb1ff95Jw2EAUAJd9Tly7fe+18nZUPu5xKdgiU+Mu2IPKl2/5pJGqxBx87qbp/XUJlgF+CoSluEOZQ1rkZf40NfuYvk/ZUa2qjf0Q3VOHNKioJxfwBy0gjblIusLdqo7azbwdfD43cpn4pmx/4ll6+ChxeJigCSm9+m7nvNMoxwju6+Ota/b3qI7n61KGi4IOYQRa2iuUZ4RWyFEpRU8CXFHZVw==; 31:AjIECjvuss8HaC0YH9a7eB6y2T7KF64WAScNJPZI99EIoyusZCV0E8s3rqiNF1VfVCX3zNzHEDN1pvXIjwaYZAtWtv/KErynnfzh43AIqb0FcLW2FJN8I4Yo03wTnNTd5s60uFu8bSxljiVhIiaADB+GN7re3tGD/+geQgDl8uoEEFJhrSUQf3V90AERVWbrctEQr+aKMmO4sTkZM4QPpeWEWP5ePaFiGVwGN7t58wk= X-MS-TrafficTypeDiagnostic: AM4PR0501MB2306: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM4PR0501MB2306; 20:sLdXDZk+YFCNxqMD5SvFGyEZvY2isNd/z7f0+QaT2jgy3vORbvegrUH9Lw38iZU+Z3Wf+VGbzYcY2yxSRnjHjVnlir+H39OZ1B44EfWRZmbJ0aEpGaJj+g4UcvQPOQ3CNkbTAmfEQh1rAi+VJQoQ8ax/ELuJu62VS5w0LUYDbST44E8S9Sv60TtAGV3RZKtypiv0Sn1045EwOsrIUvsB2+jNDRjVEH0ehSrfUKPHX/ljhqFZZVHPfxEp83BA6Fyv0mGnHzCMuzMAmRXFWYW6whQL6MdUND+xa/bBL3sV4vTZNp9MRA7wKyNVk85GqibcFnABVqNqJTOdbTSLXqYfjKqpLBGh5A6YzgR0jWUFBiDhCvHuW6Bsj14IgmgIw+SwmH1yT5Re1+vF0wax6+UfdxN33sIS1NJ3N68Josi+8jtFe7/WwyGpu9I4rcCNn/MYdEWxOZHYyTaHfwNIqm9t7SqA5j61Zv0+oBWWXlhaPQiQV+6A0oXtNd+t64SrRTBT; 4:MTXbytkG2eDo21vS9qvdj1aRrcfblX8y6K1qV7GBxPVgoH+cCYX/wES+wKdSMjjALdDAhs7SPvCVjIGstpuThOw/3Hm1pN3hGqsDrk2k6rg1rLWh2Qzrm1KSeq0zyLeO4EDCLO6k+jQ9SqGmE5OA0MkQdspAOsHl/EQkhW0T4UBl7UltPJdWcMAhipDDE/7KzdPKPqAdnWW8gjjaGtpEKMNMbNqCNixUc+Gg6Lnr0qK342I3jGjywOhVeVmeZnQF9d6Bi1/NubG9Uub782pQSA== 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)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:AM4PR0501MB2306; BCL:0; PCL:0; RULEID:; SRVR:AM4PR0501MB2306; X-Forefront-PRVS: 0676F530A9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(346002)(366004)(376002)(396003)(39860400002)(199004)(189003)(97736004)(386003)(26005)(486006)(53936002)(7696005)(52116002)(5660300001)(6666003)(8936002)(4720700003)(316002)(54906003)(16586007)(110136005)(50226002)(66066001)(86362001)(3846002)(105586002)(25786009)(106356001)(6116002)(186003)(76176011)(4326008)(16526019)(51416003)(55016002)(59450400001)(478600001)(21086003)(69596002)(305945005)(7736002)(476003)(2616005)(446003)(956004)(81156014)(81166006)(50466002)(36756003)(48376002)(47776003)(33026002)(68736007)(2906002)(8676002)(11346002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0501MB2306; H:mellanox.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:3; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR0501MB2306; 23:cyXTwaYjhViRBx0tzYryjYzUjZ/PWZTGgCo4SRp?= =?us-ascii?Q?Pgf8UOQQVZCV7gidSRsrD4bTR58GB62O7JN34dwC+W39TNBdxdjFYH7gVy1C?= =?us-ascii?Q?wvFQv2rbQXXafJtld9dINTDK40fwUVSBsqHw2XkOpQVDX3MI+AdBcpJJaXAY?= =?us-ascii?Q?0mlJkTB8ki8VPWaK41PXAUBrnUhoGmAOFNr8ikj8FZFXoArLa1fHz9UBf+QX?= =?us-ascii?Q?ZSRhthKxwYL7ztWYyiCiKEWFU80N+EBBGuUZwNfaovcsM/FRMIc/kQ3AjavD?= =?us-ascii?Q?3SE6AAGOrgR6X8vZNKeydzV7a8qdX4GgMFuqfgVkzhyGfN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=; 24:qoKhuVZXlevLP9/sG+Wu7ouK1yB1Xifpwv8cgFk8JC11rbeoEXTBIaEkvHeGxyX1hmwxYd8NVvQtMm6XkuebMwMVWBBY8DYwfZZPHccK7R0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR0501MB2306; 7:P1n0JFJhN+UqWDM0mr9iPVl5mqL8VvgdUvRmw+OsKMZJNt8GZAt1QrvN5J0xmZPVFNAaUmI6D0xf/N9dezIiKgJx+S0Zp7clHEgyBr2XeYzcWqS/GQXpMOB1IP0RHpD27G3g1DahyABuTlNAljADhdbJHuOHCkB7eG7VNQSBurmzJ6xdoUTSc/ZCazp1HnuQZp6GNGTvq7Q4P5GMI4iiqAekRSpjW1FfbyrniX7LRnKPWvLGHiUIMCAMsZYY37wU X-MS-Office365-Filtering-Correlation-Id: f4b01093-fbb6-4ba8-1caa-08d5bc994432 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2018 08:27:59.0145 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f4b01093-fbb6-4ba8-1caa-08d5bc994432 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0501MB2306 Subject: [dpdk-dev] [PATCH v3] net/tap: fix device removal 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: Fri, 18 May 2018 08:28:02 -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 drivers/net/tap/rte_eth_tap.c | 30 +++++++++++++++++++++++------- drivers/net/tap/rte_eth_tap.h | 1 + 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index c006d07..4518a85 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,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 +1974,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