From patchwork Thu Sep 14 10:48:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ophir Munk X-Patchwork-Id: 28724 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E42803195; Thu, 14 Sep 2017 12:49:15 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0075.outbound.protection.outlook.com [104.47.1.75]) by dpdk.org (Postfix) with ESMTP id C29C325E5; Thu, 14 Sep 2017 12:49:13 +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; bh=JCP8FPeXg4Rli9m4mlFvXoubg2hTX3CKHnAEzW9NJuk=; b=NBnsI9FbAcrPJ9KiNQyztPGh3xevLFK4zqqbxFoTmKRCvO/ExL41fZ/ufZBBqNYkBeNqDapjr/zpuqHXClNfrG4BImCSCCGcDUdzgdqH6e2KEhaioEM9XP4tkGiN7ropbMDGHLHoux+xcbl18jIuLzUUB2GTobfPB5JmVpfQ+70= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ophirmu@mellanox.com; Received: from mellanox.com (37.142.13.130) by VI1PR05MB1261.eurprd05.prod.outlook.com (2a01:111:e400:5187::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.56.11; Thu, 14 Sep 2017 10:49:10 +0000 From: Ophir Munk To: Pascal Mazon Cc: Adrien Mazarguil , dev@dpdk.org, Thomas Monjalon , Olga Shern , stable@dpdk.org Date: Thu, 14 Sep 2017 10:48:46 +0000 Message-Id: <1505386126-29546-1-git-send-email-ophirmu@mellanox.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: VI1PR0501CA0031.eurprd05.prod.outlook.com (2603:10a6:800:60::17) To VI1PR05MB1261.eurprd05.prod.outlook.com (2a01:111:e400:5187::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0ce366c-2b77-482d-0fae-08d4fb5e3bc7 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(48565401081)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:VI1PR05MB1261; X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB1261; 3:eSohTuITV2F7KP5wuiGnPgRXdFJ72Ua3Bw6nEJzM67tsW+4v7br+B3ZNJl906rxfILBvC+fU/uVx+QO+5k3RBYSmrKY79/yNTj68Wid0ImU/AwodLMiaHpV4w0/ZrCbf1ADBFjt7aR+/xSB81Vii4vd4g5KObYkbYv8UOKJRtamXQjga+onhBiuvrlCbb2qoHSdppYfMjEnhAul+mMLnD1nUUTmzzVI2n/TNXBH7tQX65ZXamXCjpw5dXMfS9a4t; 25:KU6hbrdkdHWGvvN6vn+buN5GUpUDXgV8D7aAMdFe0TwmcJtdaS1m5+f/rfsHAZhUwV8sbeVNBPPnhgjrpfJEH7DH8/0yAk/zofQm0OqCquHY67Gop9vY5uOUPMEqH9TqtDTTSFeHj94+RWJ6+Isy5J4GnOuK0XENJoMnIfmq8lfBx6HY8mfkwTEMl3GCaVDKxg91eCFwul/TSYOQW3Kfhkp94yLuqpPNFZXMf7S9uVh/icoufjYBsJpZR16wHQW9shSe9QswwxSM+e+OVJ40Fs3lrw8D3BstygKvEFhHv+cTTLCO8IbWdwxdFlubcoytELMLHgqw1q1GROzAgFDeOg==; 31:FU2IuTdAFXJyONPEBkd834LMPH6EBSEbrlgB6v8CvyJGFTm+iZmnDWwxL3nq0LCP2On7djI7aszp78uI++v5qUO/lkhBi0gZz2bJ2b6RbPMfzCgzghX8XH6gOit0TIHzAMZqRLsNwWAsJitG9Hjt9rpgsX+vpwRpQCC/l3DJeg3DS9ajDS1cF+PVLQulPA7eGSXKtlYkD/1Vyp5kxR7fF434Xk5dMLXpW9XnkUUNoQM= X-MS-TrafficTypeDiagnostic: VI1PR05MB1261: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB1261; 20:a3xme2jSitRClXa6UKzWZd6GRo/wOo56q1sXuJjUGRQWYWKM4lBtHgCdPujx9rc6+6cYxM2UjdzzYfDpyfFox8aCjrfD5edXRWVHmZDF/72uPFS9ajoa/V+6YexzzjFu7yZ5hthZTfEZt94jpyuB0fWjHKyj01U9wLvTLzFA0h2xhBohtTcbNmR2G2Q58Fs9gsJBQ0ljJ4Gy805IDFh0ajf7xA3edSatjgSKS5rJwrKVaRI1AYwkmF6pWcntQJ7MCkY67uCq5fKE2KfBl6A1HONF0a3ZYl6tocvVdA5VcNXbbKkAji6bsnbfA8ij6Z2zbVwAi8/qJ8MJaKX07gklpPovs6p2jT6kivhoSS8RRRN0+8P+rK/RSvlMvmyasDxP61QdATXHsf3FLxPNTaLK1lXNKuumNNoKRVnA7Q/L6g4AjJTJdddJTUtXyPrnLRAFYyhjgftlyppOoT4kXEvUGo8D1TZihdKMwDbHAuDuKRTtVCloKXPbw9GrcmOpJHKw; 4:j9eZ2nTFAWO0QdzonxCD/mshGp0qlZ+h1k9ea7sNzCNUNXDE3vO2tYTUQh7jajS4uijkBFJqxQrlB2MSBuYJvEkirt7ev9zMMoArrsTk4OWiunNmsU0YvN4UfeiImKR9R1LkjcUkDzRTn5LZAPDLoLVITicG6koVe+jLz1cVG5DCV0Asc85weyLLNQinWjGmBRuaIi7IBGUsNu/PKFZmI/jEyRkVHSGSwXV4jaBiTahi/OBpC4yfBegurx6Um9KD X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123564025)(20161123562025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR05MB1261; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR05MB1261; X-Forefront-PRVS: 0430FA5CB7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(7370300001)(6009001)(346002)(376002)(189002)(199003)(24454002)(66066001)(50466002)(7350300001)(189998001)(81156014)(47776003)(8676002)(81166006)(2906002)(50986999)(6666003)(53936002)(55016002)(97736004)(50226002)(16526017)(16586007)(316002)(4720700003)(54906002)(6116002)(25786009)(3846002)(21086003)(4326008)(110136004)(86362001)(575784001)(68736007)(101416001)(105586002)(106356001)(33646002)(69596002)(36756003)(48376002)(305945005)(33026002)(5660300001)(6916009)(7736002)(5003940100001)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB1261; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR05MB1261; 23:IOtz8dZNXA5OXNMsV0MlUJiYNuomzpaLBAO6cm8JZ?= FpRyUEL/aNmUATCu31bbhp42MTu+LuJ8dxzMmifMs1UTaCjweL0KAPCtE0D8v4GVQVkZcF7LDOXcFPi22+SYYnRKWuZbbHUDW7RgBhihws/wINFYHsN6XwCQi7lVnsP/JkTiv3XaY+cc/oKRJd+YLtjfEQucmAsgF7Xe9Z+/SyahzyGxe34ERMF/IcHl78XQTcyAX9x+9l0CWeQAU5iHcuEWIrQgq/53y6dZ9DcvcD+WFnVVjiHDJIdv/3UakPScX8EdZNksST1QDslHojXTurT3OPW6n+gfwSywQSwgA17j6gXQROzkQYX1pUXTg2fAimS73ZgzMXBY/fRDgIorQaeLXziSmi/IX1L0igXAuK68LdfgBJnFRdatyTTTYia/GWueaxJFHWqKJfBJUwdjp/exZU2YxmDDR03oKB1lpWS7RaA6ndaB2Hu0miTZwfhCeuh36jH1ZI5K6O2/3+UEHzFHKbdTmE060z9ctL30zIQrWBCRsZwugG6xUqX0Ruu2M94jVFTJd8vd4LbpwpWMTIrWDU6cEKCXce9BjB8wlbh2UZ5jZyRIjZHZzAjVxxrGs8icU5wX0DQr9VLwqt+rvbY4ci9iBG7ihOo9OavTJTUww8+vsR+aAYwZmPjd2pqSW2KsOuaFc8zbeUbBxIDwV1ILMypUb5bSsZtRGKpmeEwkYhbM7/Otu36HEzoidVF5y0GSm1a+zNpWgPY+CjvMiKxq0cwmXh9z8QnmwGCACZCGM3oEV0GEb4M6ziNMp4YM+B5jqIlksKjCPdVjgFetm4UNjWn7V82OkBpQHBfZrdcGuZWkp8GNSXtDN5NlQXX8j6fB92zYShtuKtMUBTC2V8bz5/6/Pt02sKjLi2YO5Ndhm9FRULDmIWA6Q9j5CbeRaNlZMNEAHHyLeUYQzETIBOKj66AC1i6QPDW6Ra7uqYoHkXMctrJLwN5TvJNhkLbfxK2YdVrDDYEFlQ313wWOGA3AZ2f9psKflN7BHTKIdRQycYYUZLNqDkbNgoeYNKhnbbQzTIbYTRNW75f/3EIkREksS4bW9NuB3An5FwyhevwkkDJgxTsrhpH9oIWCRyKs8Hu3db0Wgp1C6xbGr4SWBGg2vKA0q1GuTSPJIVaJn7R/+KHF681Vw+R7A6IQZi9I6HHH19KEjvMo/07+tUDymZ13OXhYDkxrrA604j8LkeXWw== X-Microsoft-Exchange-Diagnostics: 1; VI1PR05MB1261; 6:Yyhz6v+TQcM/nlH/GsWlXME/9M9ama26UjmBSLIUWRs7hQrcKSdYzXlp9qDodZ5rqUrDFIlQKNHMh0qKxj5FrSqbUH3iF3ZyvfRo1v3BQKwnS/pE7LxpQKSe/QC2aWoQ3i/hhOiGF0yETYxYQiFHR16O2hZCnLmfBw5Y7EmBZdN9qKQ5yblNselMeba6LbyFHv3jsukS9+3w3vfdymsrYi4jK1nbYc8d2tB7wVi8aBOCnqU03a+nVnm+fegMHeHtXpxLZhT86XgDyJZlbwDAQAycf1tSZrd6cNq32oHWF4B4ZEtgte2ai+T/595MPECu934sTKoj0I+BIl8b+T1MmQ==; 5:BndYxt5ime4aryaEf6JRd09dMHyM/QHnajsiL7N/3T9CaDf140yMI/0TcZTOxerUFh0yu57EsbfYmCc0JdPbWJIRA7sckIuhfh8lWdUailNfEc8RzbXqz1N9bWv7UVEDPmBNHdec6yZiBt1sTmTQWQ==; 24:s7IFeZL5A4RYu8juxoRO4GXQ4BcdDM7FsQlCc8HFFTrIdX8LfZMnH7Xxs/AINXtTWTNECzQ1XmRHt1rpdxXn5iPMCO9rNrCw+CUN5TZ1+L8=; 7:4uQAbw7mxjcDYiSi6eqL8NCvpm3Uc3vyPLdMM4Su6d8QQ2ERTEIjOIgP4ySRtrk7VMabmjEzzqBKo0bTTkJmkmlf4/gSG1qenVFqmnikwP1bGOP83596gzqp6ruM9vI01qGR9QDcQ2yjjjziMjiC3Lxh+13eP9lcjnuU4Pn+PwPTa3u9K/w+FOtjgbv2/ZFTzL0i7rkGGqwuahB9tECWwwQCXG+xGMucgIFPhovEQ0k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2017 10:49:10.5262 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB1261 Subject: [dpdk-dev] [PATCH] net/tap: fix flow and port commands 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit fixes two bugs related to tap devices. The first bug occurs when executing in testpmd the following flow rule assuming tap device has 4 rx and tx pair queues "flow create 0 ingress pattern eth / end actions queue index 5 / end" This command will report on success and will print ""Flow rule #0 created" although it should have failed as queue index number 5 does not exist The second bug occurs when executing in testpmd "port start all" following a port configuration. Assuming 1 pair of rx and tx queues an error is reported: "Fail to start port 0" Before this commit a fixed max number (16) of rx and tx queue pairs were created on startup where the file descriptors (fds) of rx and tx pairs were identical. As a result in the first bug queue index 5 existed because the tap device was created with 16 rx and tx queue pairs regardless of the configured number of queues. In the second bug when tap device was started tx fd was closed before opening it and executing ioctl() on it. However closing the sole fd of the device caused ioctl to fail with "No such device". This commit creates the configured number of rx and tx queue pairs (up to max 16) and assigns a unique fd to each queue. It was written to solve the first bug and was found as the right fix for the second bug as well. Fixes: 02f96a0a82d1 ("net/tap: add TUN/TAP device PMD") Fixes: bf7b7f437b49 ("net/tap: create netdevice during probing") Fixes: de96fe68ae95 ("net/tap: add basic flow API patterns and actions") Cc: stable@dpdk.org Signed-off-by: Ophir Munk --- Pascal - I would appreciate your feedback on the following discussion: > > /* Immediately create the netdevice (this will create the 1st queue). */ > > - if (tap_setup_queue(dev, pmd, 0) == -1) > > + // 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) > > goto error_exit; > > > Adrien Mazarguil wrote: > Can this be removed entirely to instead wait until the application actually > requests the creation of the first queue? Ophir Munk wrote: Removing this piece of code is causing failure during tap device initialization and testpmd as well. The subsequent code following this removal contains hundreds of lines so I prefer getting Pasca advise why the immediate creation is required here and if possible - how to avoid it. drivers/net/tap/rte_eth_tap.c | 126 ++++++++++++++++++++++++++++++++---------- drivers/net/tap/rte_eth_tap.h | 1 + drivers/net/tap/tap_flow.c | 2 +- 3 files changed, 99 insertions(+), 30 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 9acea83..5520c24 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -603,8 +603,25 @@ enum ioctl_mode { } static int -tap_dev_configure(struct rte_eth_dev *dev __rte_unused) +tap_dev_configure(struct rte_eth_dev *dev) { + if (dev->data->nb_rx_queues > RTE_PMD_TAP_MAX_QUEUES) { + RTE_LOG(ERR, PMD, "%s: number of rx queues %d exceeds max num of queues %d\n", + dev->device->name, dev->data->nb_rx_queues, RTE_PMD_TAP_MAX_QUEUES); + return -1; + } + if (dev->data->nb_tx_queues > RTE_PMD_TAP_MAX_QUEUES) { + RTE_LOG(ERR, PMD, "%s: number of tx queues %d exceeds max num of queues %d\n", + dev->device->name, dev->data->nb_tx_queues, RTE_PMD_TAP_MAX_QUEUES); + return -1; + } + + RTE_LOG(INFO, PMD, "%s: %p: TX queues number update: 0 -> %u\n", + dev->device->name, (void *)dev, dev->data->nb_tx_queues); + + RTE_LOG(INFO, PMD, "%s: %p: RX queues number update: 0 -> %u\n", + dev->device->name, (void *)dev, dev->data->nb_rx_queues); + return 0; } @@ -673,9 +690,9 @@ enum ioctl_mode { unsigned long rx_nombuf = 0, ierrors = 0; const struct pmd_internals *pmd = dev->data->dev_private; - imax = (pmd->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? - pmd->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; - + /* rx queue statistics */ + imax = (dev->data->nb_rx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? + dev->data->nb_rx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; for (i = 0; i < imax; i++) { tap_stats->q_ipackets[i] = pmd->rxq[i].stats.ipackets; tap_stats->q_ibytes[i] = pmd->rxq[i].stats.ibytes; @@ -683,7 +700,13 @@ enum ioctl_mode { rx_bytes_total += tap_stats->q_ibytes[i]; rx_nombuf += pmd->rxq[i].stats.rx_nombuf; ierrors += pmd->rxq[i].stats.ierrors; + } + + /* tx queue statistics */ + imax = (dev->data->nb_tx_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS) ? + dev->data->nb_tx_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS; + for (i = 0; i < imax; i++) { tap_stats->q_opackets[i] = pmd->txq[i].stats.opackets; tap_stats->q_errors[i] = pmd->txq[i].stats.errs; tap_stats->q_obytes[i] = pmd->txq[i].stats.obytes; @@ -730,10 +753,14 @@ enum ioctl_mode { tap_flow_implicit_flush(internals, NULL); for (i = 0; i < internals->nb_queues; i++) { - if (internals->rxq[i].fd != -1) + if (internals->rxq[i].fd != -1) { close(internals->rxq[i].fd); - internals->rxq[i].fd = -1; - internals->txq[i].fd = -1; + internals->rxq[i].fd = -1; + } + if (internals->txq[i].fd != -1) { + close(internals->txq[i].fd); + internals->txq[i].fd = -1; + } } if (internals->remote_if_index) { @@ -887,30 +914,59 @@ enum ioctl_mode { static int tap_setup_queue(struct rte_eth_dev *dev, struct pmd_internals *internals, - uint16_t qid) + uint16_t qid, + int is_rx) { + int *fd; + int *other_fd; + const char *dir; struct pmd_internals *pmd = dev->data->dev_private; struct rx_queue *rx = &internals->rxq[qid]; struct tx_queue *tx = &internals->txq[qid]; - int fd = rx->fd == -1 ? tx->fd : rx->fd; - if (fd == -1) { - RTE_LOG(INFO, PMD, "Add queue to TAP %s for qid %d\n", - pmd->name, qid); - fd = tun_alloc(pmd); - if (fd < 0) { + if (is_rx) { + fd = &rx->fd; + other_fd = &tx->fd; + dir = "rx"; + } else { + fd = &tx->fd; + other_fd = &rx->fd; + dir = "tx"; + } + if (*fd != -1) { + /* fd for this queue already exists */ + RTE_LOG(DEBUG, PMD, "%s: fd %d for %s queue qid %d exists\n", + pmd->name, *fd, dir, qid); + } else if (*other_fd != -1) { + /* Only other_fd exists. dup it */ + *fd = dup(*other_fd); + if (*fd < 0) { + *fd = -1; + RTE_LOG(ERR, PMD, "%s: dup() failed.\n", + pmd->name); + return -1; + } else { + RTE_LOG(DEBUG, PMD, "%s: dup fd %d for %s queue qid %d (%d)\n", + pmd->name, *other_fd, dir, qid, *fd); + } + } else { + /* Both RX and TX fds do not exist (equal -1). Create fd */ + *fd = tun_alloc(pmd); + if (*fd < 0) { + *fd = -1; /* restore original value */ RTE_LOG(ERR, PMD, "%s: tun_alloc() failed.\n", pmd->name); return -1; + } else { + RTE_LOG(DEBUG, PMD, "%s: add %s queue for qid %d fd %d\n", + pmd->name, dir, qid, *fd); } } - rx->fd = fd; - tx->fd = fd; tx->mtu = &dev->data->mtu; rx->rxmode = &dev->data->dev_conf.rxmode; - return fd; + return *fd; } static int @@ -932,10 +988,10 @@ enum ioctl_mode { int fd; int i; - if ((rx_queue_id >= internals->nb_queues) || !mp) { + if ((rx_queue_id >= dev->data->nb_rx_queues) || !mp) { RTE_LOG(WARNING, PMD, - "nb_queues %d too small or mempool NULL\n", - internals->nb_queues); + "nb_rx_queues %d too small or mempool NULL\n", + dev->data->nb_rx_queues); return -1; } @@ -954,7 +1010,7 @@ enum ioctl_mode { rxq->iovecs = iovecs; dev->data->rx_queues[rx_queue_id] = rxq; - fd = tap_setup_queue(dev, internals, rx_queue_id); + fd = tap_setup_queue(dev, internals, rx_queue_id, 1); if (fd == -1) { ret = fd; goto error; @@ -1002,11 +1058,11 @@ enum ioctl_mode { struct pmd_internals *internals = dev->data->dev_private; int ret; - if (tx_queue_id >= internals->nb_queues) + if (tx_queue_id >= dev->data->nb_tx_queues) return -1; dev->data->tx_queues[tx_queue_id] = &internals->txq[tx_queue_id]; - ret = tap_setup_queue(dev, internals, tx_queue_id); + ret = tap_setup_queue(dev, internals, tx_queue_id, 0); if (ret == -1) return -1; @@ -1166,7 +1222,6 @@ enum ioctl_mode { .filter_ctrl = tap_dev_filter_ctrl, }; - static int eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, char *remote_iface, int fixed_mac_type) @@ -1193,6 +1248,7 @@ enum ioctl_mode { } pmd = dev->data->dev_private; + pmd->dev = dev; snprintf(pmd->name, sizeof(pmd->name), "%s", tap_name); pmd->nb_queues = RTE_PMD_TAP_MAX_QUEUES; @@ -1212,8 +1268,9 @@ enum ioctl_mode { data->dev_link = pmd_link; data->mac_addrs = &pmd->eth_addr; - data->nb_rx_queues = pmd->nb_queues; - data->nb_tx_queues = pmd->nb_queues; + /* Set the number of RX and TX queues */ + data->nb_rx_queues = 0; + data->nb_tx_queues = 0; dev->data = data; dev->dev_ops = &ops; @@ -1241,7 +1298,11 @@ enum ioctl_mode { } /* Immediately create the netdevice (this will create the 1st queue). */ - if (tap_setup_queue(dev, pmd, 0) == -1) + /* 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) goto error_exit; ifr.ifr_mtu = dev->data->mtu; @@ -1515,9 +1576,16 @@ enum ioctl_mode { tap_flow_implicit_flush(internals, NULL); nl_final(internals->nlsk_fd); } - for (i = 0; i < internals->nb_queues; i++) - if (internals->rxq[i].fd != -1) + for (i = 0; i < internals->nb_queues; i++) { + if (internals->rxq[i].fd != -1) { close(internals->rxq[i].fd); + internals->rxq[i].fd = -1; + } + if (internals->txq[i].fd != -1) { + close(internals->txq[i].fd); + internals->txq[i].fd = -1; + } + } close(internals->ioctl_sock); rte_free(eth_dev->data->dev_private); diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index 928a045..be57cc7 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -80,6 +80,7 @@ struct tx_queue { }; struct pmd_internals { + struct rte_eth_dev *dev; /* Ethernet device. */ char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */ char name[RTE_ETH_NAME_MAX_LEN]; /* Internal Tap device name */ uint16_t nb_queues; /* Number of queues supported */ diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c index 41f7345..c51f708 100644 --- a/drivers/net/tap/tap_flow.c +++ b/drivers/net/tap/tap_flow.c @@ -1092,7 +1092,7 @@ struct tap_flow_items { if (action) goto exit_action_not_supported; action = 1; - if (!queue || (queue->index >= pmd->nb_queues)) + if (!queue || (queue->index > pmd->dev->data->nb_rx_queues - 1)) goto exit_action_not_supported; if (flow) err = add_action_skbedit(flow, queue->index);