From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50043.outbound.protection.outlook.com [40.107.5.43]) by dpdk.org (Postfix) with ESMTP id 5791B1B7DD; Thu, 8 Feb 2018 13:20:54 +0100 (CET) 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=AsBLU4t3gA5xNFyfCb83mPhXo+IAi2d0ve3EOklgyrk=; b=rms6Ov01iVmYAoqSAcKRhfk5yfAbf2ugpB1avB5kXwirgXQieKohsvNbR+C4CNlpJAXssEG87tPaeDvtC5v5/9xAPNWb1INGSI1sD5fqhEjbdbTFqFuWqJvK1+bhDwMKjBScN2jFcwhT9PJyt+/R/9BO2VzI1elmKdHUWNrGR0o= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by HE1PR0501MB2666.eurprd05.prod.outlook.com (2603:10a6:3:cb::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Thu, 8 Feb 2018 12:20:50 +0000 From: Matan Azrad To: Gaetan Rivet Cc: dev@dpdk.org, Ophir Munk , stable@dpdk.org Date: Thu, 8 Feb 2018 12:20:27 +0000 Message-Id: <1518092427-4333-3-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1518092427-4333-1-git-send-email-matan@mellanox.com> References: <1507243328-11287-1-git-send-email-ophirmu@mellanox.com> <1518092427-4333-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: DB3PR0202CA0026.eurprd02.prod.outlook.com (2603:10a6:8:1::39) To HE1PR0501MB2666.eurprd05.prod.outlook.com (2603:10a6:3:cb::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b0188757-7acc-45d3-80af-08d56eee650c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:HE1PR0501MB2666; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2666; 3:vOxccBDo3UeRpGKTUoACJzpGZnCSh1mBWrQV9LVoug55fu19kTEwAw2Jj1/4/gLLqaHGSCRJyBMIfashRXWJhHcZiZj313rjwOqrvZqe85uk01SJ6NU4K8HPGaNMdo89ZHITHN0l1jmMm41uJXenahdc1YbC5W+39hRaTpuwBEU9p0/chX0PPNXOuby45TnXBAurYDAN3yadQSKvSMkVrhAZcP/MWy+oQHYBVTjt0HZyQEdEV+p1BHsObFbTNSim; 25:B5JM49I6HyFqtAPKo3+iEywKADKRL5o34T8wdqbWsCVaehL3/MkkYa2hE6uv5yJ1GdhrhPu8mbSO3ZAcS5hUQZ9E7NmUXoSc+hzoTIiMkORREJQnt1QjVvAZ0dXj4T85VImSBkJDEBtpxa7+AtKmQGGSODPuk4og+KzxoYGmsPRJDt8n3z/O7Fh/Ccty5XmNdCiUEH8cUHT/pKwBbs5b98D36glJTQr646hoRHlfK/3BeLVg25+tBniiSM2b6LdPQW07rYuFNRAryeJStZZvt8+rwKfxlRO/1pBeOIh4SdXVLTH7RMgLQaVAt8wCv4hFFK/zWSZeKtpfNT7l02Hmiw==; 31:B4TJwR7sYNiH/0AeOXLErRLGS7QSPjkSq6q2pV3sfv0c7MLA6IWN6mTMRXvKZZzJKjXA48xTDUFkYBo6AaD1NBmHrX39C6pdMub8L9hD/zB8Dxv+YN94+YsfLClx5SJdERYEnDL76Svj+vFlmpUYZJNEXb9dKa9jbWlND1GgZ4E0z4ILa/R3q4Y/IPUIwcMM9S3VZ77xR6n2JgJtyRx9jQoVJRlly5M+oLsn2WMQrVM= X-MS-TrafficTypeDiagnostic: HE1PR0501MB2666: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2666; 20:Zjqq7DOr3MBVmeEbQypoyG435mJKiv2cl9mUMk/2OToek6AJaAol7Ofu6Du3sqwEoFgoGCzMC2ODP4NGsUcVxjQr4MeDEzmmh7MyPPY3hJtQoKs/1JY15xTfNlKBmpctUnfFEWM3ME3slt2OuPn/FlVNiMhgNk8yrNaaHEUg+vNH/Aa/NvEW5Jt/sAxDESGb+BFclkJTzQAOIkIoN37MY2WK5rdTvHkl03fYxD2A/9LqwvoimwaEHLNeiFRpKwfqrJXNTRouy53H8r52PWO1VbpDm0+jBebdX5OqZaHdYW2SNPE74lxC33x0lCjKuTrJDzGoN3BTK8J4J5XlcOBerNeMzbs4AZN0dZJL1Gp1TF+lb80adov/eXkynZ6eDOVnGpYktBge+3DuOWEEFQ0x+VRnAxjvArc+mhyaYVVh5J5YhPUAk4Dy0E1qlXeQgIqOtFb0dJZnflJ1kH6MmW7V1gtwWD0dSo5Vd4+i1PeuvkSEHz9MbSBrsOf6HDswLyBu; 4:Lj4wh/njnJ1MpxjB8brPUYQHTfi5OKyryBLodvqTJpq/eZht+aD36uKB7evkI9KCZKcGmRJnTiknirGGS5WWxZ23YLWrt9o/uJpzxGQx+C9b0+x6e55/KHTXbH2l34ajZScYsrLNj3vU4VEB+9O5s5qnbXcKF7EwQcLHeaKam6AGygj4RpxwpQEPTKj4JClZzPwlaYXAeBa9/IRZUJpFAYXb7mxOEzpxPNVtz2xYxdkcguDXSFrTgoNfHC+zdxzSWgy1lsvh8cKhpjnvFmD0bA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(3231101)(2400082)(944501161)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:HE1PR0501MB2666; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0501MB2666; X-Forefront-PRVS: 0577AD41D6 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(376002)(396003)(346002)(366004)(189003)(199004)(66066001)(16586007)(53936002)(47776003)(68736007)(5660300001)(59450400001)(105586002)(50226002)(106356001)(316002)(86362001)(69596002)(21086003)(97736004)(81156014)(8676002)(26005)(386003)(81166006)(52116002)(51416003)(6916009)(7696005)(2950100002)(76176011)(2906002)(4720700003)(8936002)(3846002)(36756003)(6116002)(6666003)(186003)(16526019)(33026002)(7736002)(25786009)(48376002)(55016002)(4326008)(478600001)(305945005)(50466002); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0501MB2666; 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; HE1PR0501MB2666; 23:/3hfQIlc+6K4NuxLRKWH+wLiPh+0axBATMQc/IL?= =?us-ascii?Q?okHYgzdEWrOsHTiRAObaCw+eVss8tPUHoHCJueRrVoHPOLTdNyf3VYMFi1wi?= =?us-ascii?Q?JGJrBudiXn4IxB/sq8QcblwzspHRbBdDwjzKOUzk/ya+cZ6jtLge/8dQ+pWQ?= =?us-ascii?Q?0XWyNlf/YywwLL8mOlcMKxaaggP9eJ2r14iy7A1sr+48YXnVvHKKpTXBQPfy?= =?us-ascii?Q?EHNMTwivpM3AGNEeZYJERonKSzBTL7aHLROOyloBMLVlWVvjfVtNLxZtAG1+?= =?us-ascii?Q?Gs0pVCdQjaSJ6Woy+Mxo2DSuuXrFdlgiE+9UyN6nfMZrLo+snYH1F9JKD9lB?= =?us-ascii?Q?kbZguzkagPKybkJnLYhRGVk/pQegQTCWwYn0QuVJ3zsza46ao6qKZ68C3T98?= =?us-ascii?Q?uaqr/A6cHlx2iBR9fXOAoEc4DPdav9tQuwHn5aD5hio3xx19FKnLmaKkNWub?= =?us-ascii?Q?c4eB+cSLuLzheJpkITkuxlvSEHqmVwodJCT1ufyikdi1Rge41LoHeZqnsCEq?= =?us-ascii?Q?Hwwuh24N8a/7sh8I4vydWSiNxRFr/FGtAnL5Pr+mjzeVrJReg1zxl31pygcz?= =?us-ascii?Q?YaADnZFaiVvJx/bctZ1Ial9cLeK129tC+dDszoRFMUIgIKvaDkhWmrWdsP0I?= =?us-ascii?Q?Gqodrae8y527JF9/dkKS3/m/NCB3UQnFSXBxY4bL3OiCx1JREl5pvZ79nJdN?= =?us-ascii?Q?VY7eisLy7s5k0rlffF2j6vmeN/daxUPfe4mmmrtd6P7519Y/nGTlbueRq6QL?= =?us-ascii?Q?7RBWzLB/dBsTQ5xEK+PK+hBMXewOYrM7VOLwpdXmlWLhwnrn0WV7s+M3xWY+?= =?us-ascii?Q?MWAtle5gO2xa36hLvodUyoBG+ufKmYza1T2OHUUVq/3WGu4Kgk0YwQ9CwSC7?= =?us-ascii?Q?K4UaLZX/VPDczn2IOLBkDTJ1XTgBimsJalhEAmMjyLidb3wWACFLW6wyezBY?= =?us-ascii?Q?yRYqEkZ0OjdrVPRzNyNzRzVBtGPKGh6ZRmWlpFS66fj0JGfPKR+IVt+wgeu0?= =?us-ascii?Q?fA2s8AvG4w8l3vQe41dMEFAxvf8n//izlR60xq0sIAn+90yx3G82JZ1vbG9X?= =?us-ascii?Q?xbqpvMI/UZXu5rMFobuRf8gNFCQJWMBT9J+3/uLcx9vbmjBpjMdG+eWnWSm6?= =?us-ascii?Q?UK4Pva3hyLETSE/PgOs3nL9Q8HX9xtxfkr7kINosAqWoeF2mxRVIJ3HcFetN?= =?us-ascii?Q?hyQ1twaUIvYLofNdePLkfl4MDSlPIpl1TCmFb?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0501MB2666; 6:9d39TMvuaGw6lB16RuVZ3aIINoPCz6ITuL/REz8FpvPy0Zft2fyCAm4U1YcxYQZaeQ7f70yg1Mhs1c8azR0nvD08CrpMkqUWOPC3GIbOomb44lDkN7I7UQL35iIMRoKlfehgxMQZFYkeYHB2M4S4T2cJP1ray0NeEueu5Lu5t00gGXZIs72KfMgrpx8MecRYn/VFFZ0cuyEy2szII+K3LE7KCUCBekLJN8JNxr5risfv2C8OZhFAxLwNJ0YHMX0AXqlw3I68XQx06Bt+P7DHudAi6PJIPKOxdO9CB0gLIwKl078ZaK8dOqZ0rK+U3ncpZlmD/hBOmNNmka6MmhhVM48U1qPpbzHs1tD5vQV78Qg=; 5:4RHLU6xWaf8PwEoim55+gWipXhK8aewdma2jLagQk9zkcxqWhwdT/md9LFbms/eQa36p953p/I5Ua1SVzE4yBwlxNNF+OeE85uXOLqY4lGB54NddXUh3DoWpUVYWfNb5zjkAORmEdrXn62/TxKcWL8TAf3UEkkmy4ZdU3qAy2Pc=; 24:/0mzsI0PZ5RH3uXhbSCrq6KivKpEaXMa1NRzQIH2C18ncPw3S/vc3ynJRa1wO1ZKadkScp/b4p7EdD9Iop06y5Uuyn4tCIsuaICqd9d7tiA=; 7:vBEg1l8g5LTVlHIvyO6T/a7qug+jV4oFXN3uefWu7G49gMM8m1Ss9H35KZn4ct2HGLMarbcG3AMwU3+QY/PEyWO9sHu8fyu5R13jpKVOfMphsWaM+pu93A7tTZmaG2QW1x/UknU/dgh4qYgG0T9vSka54TlcHe/4/JLxYFqCyVNtKDM3mQJJ9922tsv4ipq4hPvZYOG3EUuxAN+yJomczKJXrL8IheDdvaNE/P4NIxkyRK5/jDVnBgzA76++zBLo SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2018 12:20:50.9695 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0188757-7acc-45d3-80af-08d56eee650c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0501MB2666 Subject: [dpdk-dev] [PATCH v4 2/2] net/failsafe: fix calling device during RMV events 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: Thu, 08 Feb 2018 12:20:54 -0000 From: Ophir Munk This commit prevents control path operations from failing after a sub device removal. Following are the failure steps: 1. The physical device is removed due to change in one of PF parameters (e.g. MTU) 2. The interrupt thread flags the device 3. Within 2 seconds Interrupt thread initializes the actual device removal, then every 2 seconds it tries to re-sync (plug in) the device. The trials fail as long as VF parameter mismatches the PF parameter. 4. A control thread initiates a control operation on failsafe which initiates this operation on the device. 5. A race condition occurs between the control thread and interrupt thread when accessing the device data structures. This commit mitigates the race condition in step 5. This commit fixes failsafe criteria to determine when the device is removed such that it will avoid calling the sub device operations during that time and will only call them otherwise. Fixes: a46f8d584eb8 ("net/failsafe: add fail-safe PMD") Cc: stable@dpdk.org Signed-off-by: Ophir Munk Signed-off-by: Matan Azrad --- drivers/net/failsafe/failsafe_ether.c | 2 ++ drivers/net/failsafe/failsafe_flow.c | 8 +++--- drivers/net/failsafe/failsafe_ops.c | 50 ++++++++++++++++++++------------- drivers/net/failsafe/failsafe_private.h | 26 ++++++++++++++--- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/drivers/net/failsafe/failsafe_ether.c b/drivers/net/failsafe/failsafe_ether.c index 4c6e938..ca42376 100644 --- a/drivers/net/failsafe/failsafe_ether.c +++ b/drivers/net/failsafe/failsafe_ether.c @@ -377,6 +377,8 @@ i); goto err_remove; } + if (PRIV(dev)->state < DEV_STARTED) + sdev->remove = 0; } } /* diff --git a/drivers/net/failsafe/failsafe_flow.c b/drivers/net/failsafe/failsafe_flow.c index 4d18e8e..d4a69cf 100644 --- a/drivers/net/failsafe/failsafe_flow.c +++ b/drivers/net/failsafe/failsafe_flow.c @@ -55,7 +55,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_flow_validate on sub_device %d", i); ret = rte_flow_validate(PORT_ID(sdev), attr, patterns, actions, error); @@ -80,7 +80,7 @@ uint8_t i; flow = fs_flow_allocate(attr, patterns, actions); - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { flow->flows[i] = rte_flow_create(PORT_ID(sdev), attr, patterns, actions, error); if (flow->flows[i] == NULL && fs_err(sdev, -rte_errno)) { @@ -115,7 +115,7 @@ return -EINVAL; } ret = 0; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { int local_ret; if (flow->flows[i] == NULL) @@ -144,7 +144,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_flow_flush on sub_device %d", i); ret = rte_flow_flush(PORT_ID(sdev), error); if ((ret = fs_err(sdev, ret))) { diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c index 7a67e16..3312cb2 100644 --- a/drivers/net/failsafe/failsafe_ops.c +++ b/drivers/net/failsafe/failsafe_ops.c @@ -131,7 +131,6 @@ dev->data->dev_conf.intr_conf.lsc = 0; } DEBUG("Configuring sub-device %d", i); - sdev->remove = 0; ret = rte_eth_dev_configure(PORT_ID(sdev), dev->data->nb_rx_queues, dev->data->nb_tx_queues, @@ -182,6 +181,9 @@ FOREACH_SUBDEV(sdev, i, dev) { if (sdev->state != DEV_ACTIVE) continue; + if (sdev->remove == 1 && PRIV(dev)->state < DEV_STARTED) + /* Application shouldn't start removed sub-devices. */ + continue; DEBUG("Starting sub_device %d", i); ret = rte_eth_dev_start(PORT_ID(sdev)); if (ret) { @@ -197,6 +199,7 @@ return ret; } sdev->state = DEV_STARTED; + sdev->remove = 0; } if (PRIV(dev)->state < DEV_STARTED) PRIV(dev)->state = DEV_STARTED; @@ -211,7 +214,7 @@ uint8_t i; PRIV(dev)->state = DEV_STARTED - 1; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_STARTED) { rte_eth_dev_stop(PORT_ID(sdev)); failsafe_rx_intr_uninstall_subdevice(sdev); sdev->state = DEV_STARTED - 1; @@ -226,7 +229,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i); ret = rte_eth_dev_set_link_up(PORT_ID(sdev)); if ((ret = fs_err(sdev, ret))) { @@ -245,7 +248,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i); ret = rte_eth_dev_set_link_down(PORT_ID(sdev)); if ((ret = fs_err(sdev, ret))) { @@ -265,8 +268,15 @@ uint8_t i; failsafe_hotplug_alarm_cancel(dev); - if (PRIV(dev)->state == DEV_STARTED) + if (PRIV(dev)->state == DEV_STARTED) { + /* + * Clean remove flags to allow stop for all sub-devices because + * there is not hot-plug alarm to stop the removed sub-devices. + */ + FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) + sdev->remove = 0; dev->dev_ops->dev_stop(dev); + } PRIV(dev)->state = DEV_ACTIVE - 1; FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Closing sub_device %d", i); @@ -417,7 +427,7 @@ return -rte_errno; } rxq->enable_events = 1; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx); ret = fs_err(sdev, ret); if (ret) @@ -448,7 +458,7 @@ return -rte_errno; } rxq->enable_events = 0; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { ret = rte_eth_dev_rx_intr_disable(PORT_ID(sdev), idx); ret = fs_err(sdev, ret); if (ret) @@ -587,7 +597,7 @@ struct sub_device *sdev; uint8_t i; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) rte_eth_promiscuous_enable(PORT_ID(sdev)); } @@ -597,7 +607,7 @@ struct sub_device *sdev; uint8_t i; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) rte_eth_promiscuous_disable(PORT_ID(sdev)); } @@ -607,7 +617,7 @@ struct sub_device *sdev; uint8_t i; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) rte_eth_allmulticast_enable(PORT_ID(sdev)); } @@ -617,7 +627,7 @@ struct sub_device *sdev; uint8_t i; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) rte_eth_allmulticast_disable(PORT_ID(sdev)); } @@ -629,7 +639,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling link_update on sub_device %d", i); ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete); if (ret && ret != -1 && sdev->remove == 0 && @@ -692,7 +702,7 @@ struct sub_device *sdev; uint8_t i; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { rte_eth_stats_reset(PORT_ID(sdev)); memset(&sdev->stats_snapshot, 0, sizeof(struct rte_eth_stats)); } @@ -797,7 +807,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i); ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu); if ((ret = fs_err(sdev, ret))) { @@ -816,7 +826,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i); ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on); if ((ret = fs_err(sdev, ret))) { @@ -850,7 +860,7 @@ uint8_t i; int ret; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i); ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf); if ((ret = fs_err(sdev, ret))) { @@ -871,7 +881,7 @@ /* No check: already done within the rte_eth_dev_mac_addr_remove * call for the fail-safe device. */ - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) rte_eth_dev_mac_addr_remove(PORT_ID(sdev), &dev->data->mac_addrs[index]); PRIV(dev)->mac_addr_pool[index] = 0; @@ -888,7 +898,7 @@ uint8_t i; RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR); - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq); if ((ret = fs_err(sdev, ret))) { ERROR("Operation rte_eth_dev_mac_addr_add failed for sub_device %" @@ -910,7 +920,7 @@ struct sub_device *sdev; uint8_t i; - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr); } @@ -929,7 +939,7 @@ *(const void **)arg = &fs_flow_ops; return 0; } - FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) { + FOREACH_SUBDEV_STATE_SAFE(sdev, i, dev, DEV_ACTIVE) { DEBUG("Calling rte_eth_dev_filter_ctrl on sub_device %d", i); ret = rte_eth_dev_filter_ctrl(PORT_ID(sdev), type, op, arg); if ((ret = fs_err(sdev, ret))) { diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h index f3be152..0f3b543 100644 --- a/drivers/net/failsafe/failsafe_private.h +++ b/drivers/net/failsafe/failsafe_private.h @@ -250,10 +250,23 @@ int failsafe_eth_lsc_event_callback(uint16_t port_id, * dev: (struct rte_eth_dev *), fail-safe ethdev * state: (enum dev_state), minimum acceptable device state */ + #define FOREACH_SUBDEV_STATE(s, i, dev, state) \ - for (s = fs_find_next((dev), 0, state, &i); \ + for (s = fs_find_next((dev), 0, state, 0, &i); \ s != NULL; \ - s = fs_find_next((dev), i + 1, state, &i)) + s = fs_find_next((dev), i + 1, state, 0, &i)) + +/** + * Stateful iterator construct over fail-safe safe sub-devices: + * s: (struct sub_device *), iterator + * i: (uint8_t), increment + * dev: (struct rte_eth_dev *), fail-safe ethdev + * state: (enum dev_state), minimum acceptable device state + */ +#define FOREACH_SUBDEV_STATE_SAFE(s, i, dev, state) \ + for (s = fs_find_next((dev), 0, state, 1, &i); \ + s != NULL; \ + s = fs_find_next((dev), i + 1, state, 1, &i)) /** * Iterator construct over fail-safe sub-devices: @@ -328,6 +341,7 @@ int failsafe_eth_lsc_event_callback(uint16_t port_id, fs_find_next(struct rte_eth_dev *dev, uint8_t sid, enum dev_state min_state, + uint8_t check_remove, uint8_t *sid_out) { struct sub_device *subs; @@ -336,8 +350,12 @@ int failsafe_eth_lsc_event_callback(uint16_t port_id, subs = PRIV(dev)->subs; tail = PRIV(dev)->subs_tail; while (sid < tail) { - if (subs[sid].state >= min_state) - break; + if (subs[sid].state >= min_state) { + if (check_remove == 0) + break; + if (PRIV(dev)->subs[sid].remove == 0) + break; + } sid++; } *sid_out = sid; -- 1.8.3.1