From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C5513A0C52; Mon, 1 Nov 2021 07:31:30 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E6444111E; Mon, 1 Nov 2021 07:31:23 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) by mails.dpdk.org (Postfix) with ESMTP id 5925040DF6; Mon, 1 Nov 2021 07:31:21 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hIv84dv4DmLtRc2OxLWUCkFnnXl1pAa+vZs8xOO5cI+5BjmN3BozruklUTV4z7uPnAuzA/fhhDxwcnjTjhiov8pys0Ggn1yg7L8apMpU+biRjKOh6Q5hFeK40mtlkaPZZTrrP2pbc52GNwLMIZi2tz4hkfdurbRre4B+tLCZTWaaYeqvcftXIEKdF/WweN8s9tP42ZTf5DGjZNWec/iiiYq0ORLiHTc1jDTX+cGdarKVN19Or7XXFCl1adUkKbWzcyEtYO1j6yzi/RG67uhfvXfbv1aQUCWe4y00beDFSvdJg1lulCEqM/F3bJssvhcrX8T4I88+IxFenbMaA/zaMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aJFlxQdhLZGWn1IdK3fhgIXHRtwJWkodPRyPNllRxPE=; b=T3y17uMZgUUhsR4nPahERXrrcDC1XPN3fg0dCPkFCAQlIurE5Ca1i0533ps70AghWvJgeFI0R2ZaNQS9+1BRVpJ5patG9uUACNV1rTmnlXPTrmD318DfzI3frb6Rgds3d9m7l2fQLem/4JChpfmDpr4t8J/h8N+5XilLvesj2ERjL8VyDYNoW0nJbt64eJu45TNma/hCGhI42AqbEppjFRkpZzntkfYaRvkfn7XKBFTVkvsvJBnLtiZeFD5kLxY7HKabP96njMDMpE2zP+8Q3+fdPb8HTfPAImOIolReZEY1ws59QOvKH2erzv0DBB6C/otT+OBcD49pc1a3oqTXdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aJFlxQdhLZGWn1IdK3fhgIXHRtwJWkodPRyPNllRxPE=; b=kDnzta1MT9nSASH1gUeDpqgIk5p9K3BHcojxgU1DRXXyQH8FNZgjXACnGrj3ciONrTW9Yg5T52XTkUQKUKAGM1KtKDIjT+JSRTl52bvjhYqw+1bUzFqaGPb0GgraZh/YL44FZQJAAtE7xHFK4n5Bgrsh7y70fXvpzeBkzk1Gbp9alcNkpyOO8n2JePIoKAH3fdr+PMW/FzIJctZGAEvk0koOdAFtEl5gJxFH/2CK69ihcUKJ/ns1Qomgy2l91AwCjj1JrWGYrn2fobsRAJ/jpR2c11x9eVINHIhRweFcRd4cZXpUjLyNOgLmp72rrcqcEPOO1+Lh9fZnk8Ar3NoEtw== Received: from BN6PR20CA0062.namprd20.prod.outlook.com (2603:10b6:404:151::24) by MN2PR12MB3024.namprd12.prod.outlook.com (2603:10b6:208:cb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Mon, 1 Nov 2021 06:31:17 +0000 Received: from BN8NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:404:151:cafe::4d) by BN6PR20CA0062.outlook.office365.com (2603:10b6:404:151::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.13 via Frontend Transport; Mon, 1 Nov 2021 06:31:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT014.mail.protection.outlook.com (10.13.177.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4649.14 via Frontend Transport; Mon, 1 Nov 2021 06:31:17 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 1 Nov 2021 06:31:08 +0000 From: Jiawei Wang To: , , , , Suanming Mou CC: , , Date: Mon, 1 Nov 2021 08:30:40 +0200 Message-ID: <20211101063040.25303-2-jiaweiw@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20211101063040.25303-1-jiaweiw@nvidia.com> References: <20211101063040.25303-1-jiaweiw@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7e739dc1-81a8-46fc-4646-08d99d01362f X-MS-TrafficTypeDiagnostic: MN2PR12MB3024: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xJlhpQDrf1vJmJV2DJCL2bXu+zz97SgBARmyhgTWnnSiZRxdTZZa3veUcLYht8SRgTqv+MLkL1g8ZHveTtJavrIPMnHQdxjZ9unVq46bSlqfABsoB1dX5Spu96AJ3GWXzabB9WKHnYyeRW1xt6zNttrsutrVN91IbdjsikLdIhuyA3cVQCn1GKTn/trcVBeAjnTjbqkUiEgCoduGb3GBNEI8exHwjC/0FKvEkJFf/oejeHPi9CPU3WKDCCkvvRnBmgW2bu13snMn+sH42PRqQqeuqPNbpH6opb6DqHfpm3RHrAwJUhOdbL0pVnkGcUjjjB/DHdPz4WrBHYsMzFYBsQuPhCrbAeU0Evvaf3YyhEkndx8JLjAepkYzh9ivYvLbxIpyzikMLpiJl8HHY+WkepIFbelhJoZKUFm8kDqrzJ2TQXH4HjDDewKPzJvGaHmCryZiuzshd8YH6WT4ZOcq0GCpkE82ZJG8eyXzhe8cM7v4ciWCk8iSMgol1btJQrLUOngzGNv7CImefrLe09BkRtEPLCM8YtGtqx9UslQmDjKxQWngFCWY4sQlydWop9HkQA/NXkR55wb3FYqFQ9JQcJ1HC95DBV4nbzq3Go4o1Qs/GG4tZigh/mO6rP9dbo0TRqfyapC8yiaO3hDSS3T5OF75z41TOklr3LS2uvH6Vo7/087Te5RlENh3Mnsn+bK8LucDWrl5pwV71iKBBgSe+Q== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(6666004)(7636003)(55016002)(70206006)(356005)(8936002)(83380400001)(2616005)(70586007)(8676002)(4326008)(508600001)(6636002)(26005)(16526019)(186003)(7696005)(36756003)(6286002)(86362001)(110136005)(54906003)(1076003)(82310400003)(47076005)(336012)(5660300002)(36906005)(36860700001)(2906002)(316002)(426003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2021 06:31:17.7682 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e739dc1-81a8-46fc-4646-08d99d01362f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3024 Subject: [dpdk-dev] [PATCH 2/2] net/mlx5: fix meter action pool protection X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" The ASO meter action with flows creation could be supported on multiple threads. The meter pools were created to manage the meter object resources, if there is no room in the current meter pool then resize the meter pool to the new pool size and free the old one. There's a race condition while one thread resizes the meter pool and the old pool resource be freed, and another thread query the meter object by index on the old pool, the return value is invalid. This patch adds a read-write lock to protect the pool resource while resizing and query. Fixes: a5835d530f00 ("net/mlx5: optimize Rx queue match") Cc: stable@dpdk.org Signed-off-by: Jiawei Wang Acked-by: Matan Azrad --- drivers/net/mlx5/mlx5.c | 1 + drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_flow.h | 2 ++ drivers/net/mlx5/mlx5_flow_dv.c | 3 +++ drivers/net/mlx5/mlx5_flow_meter.c | 17 +++++++---------- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index b90752c56d..4ba850af26 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -632,6 +632,7 @@ mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh) } if (sh->meter_aso_en) { rte_spinlock_init(&sh->mtrmng->pools_mng.mtrsl); + rte_rwlock_init(&sh->mtrmng->pools_mng.resize_mtrwl); LIST_INIT(&sh->mtrmng->pools_mng.meters); } sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 5e88dfcfea..39c001aa1b 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -895,6 +895,7 @@ struct mlx5_aso_mtr_pools_mng { volatile uint16_t n_valid; /* Number of valid pools. */ uint16_t n; /* Number of pools. */ rte_spinlock_t mtrsl; /* The ASO flow meter free list lock. */ + rte_rwlock_t resize_mtrwl; /* Lock for resize objects. */ struct aso_meter_list meters; /* Free ASO flow meter list. */ struct mlx5_aso_sq sq; /*SQ using by ASO flow meter. */ struct mlx5_aso_mtr_pool **pools; /* ASO flow meter pool array. */ diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 01ecfab9f4..5509c28f01 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -1337,7 +1337,9 @@ mlx5_aso_meter_by_idx(struct mlx5_priv *priv, uint32_t idx) /* Decrease to original index. */ idx--; MLX5_ASSERT(idx / MLX5_ASO_MTRS_PER_POOL < pools_mng->n); + rte_rwlock_read_lock(&pools_mng->resize_mtrwl); pool = pools_mng->pools[idx / MLX5_ASO_MTRS_PER_POOL]; + rte_rwlock_read_unlock(&pools_mng->resize_mtrwl); return &pool->mtrs[idx % MLX5_ASO_MTRS_PER_POOL]; } diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 22081dddd3..8962d26c75 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -6398,14 +6398,17 @@ flow_dv_mtr_pool_create(struct rte_eth_dev *dev, struct mlx5_aso_mtr **mtr_free) return NULL; } pool->devx_obj = dcs; + rte_rwlock_write_lock(&pools_mng->resize_mtrwl); pool->index = pools_mng->n_valid; if (pool->index == pools_mng->n && flow_dv_mtr_container_resize(dev)) { mlx5_free(pool); claim_zero(mlx5_devx_cmd_destroy(dcs)); + rte_rwlock_write_unlock(&pools_mng->resize_mtrwl); return NULL; } pools_mng->pools[pool->index] = pool; pools_mng->n_valid++; + rte_rwlock_write_unlock(&pools_mng->resize_mtrwl); for (i = 1; i < MLX5_ASO_MTRS_PER_POOL; ++i) { pool->mtrs[i].offset = i; LIST_INSERT_HEAD(&pools_mng->meters, &pool->mtrs[i], next); diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c index ba4e9fca17..f4a7b697e6 100644 --- a/drivers/net/mlx5/mlx5_flow_meter.c +++ b/drivers/net/mlx5/mlx5_flow_meter.c @@ -1789,24 +1789,21 @@ mlx5_flow_meter_find(struct mlx5_priv *priv, uint32_t meter_id, struct mlx5_aso_mtr_pools_mng *pools_mng = &priv->sh->mtrmng->pools_mng; union mlx5_l3t_data data; + uint16_t n_valid; if (priv->sh->meter_aso_en) { - rte_spinlock_lock(&pools_mng->mtrsl); - if (!pools_mng->n_valid || !priv->mtr_idx_tbl) { - rte_spinlock_unlock(&pools_mng->mtrsl); + rte_rwlock_read_lock(&pools_mng->resize_mtrwl); + n_valid = pools_mng->n_valid; + rte_rwlock_read_unlock(&pools_mng->resize_mtrwl); + if (!n_valid || !priv->mtr_idx_tbl || + (mlx5_l3t_get_entry(priv->mtr_idx_tbl, meter_id, &data) || + !data.dword)) return NULL; - } - if (mlx5_l3t_get_entry(priv->mtr_idx_tbl, meter_id, &data) || - !data.dword) { - rte_spinlock_unlock(&pools_mng->mtrsl); - return NULL; - } if (mtr_idx) *mtr_idx = data.dword; aso_mtr = mlx5_aso_meter_by_idx(priv, data.dword); /* Remove reference taken by the mlx5_l3t_get_entry. */ mlx5_l3t_clear_entry(priv->mtr_idx_tbl, meter_id); - rte_spinlock_unlock(&pools_mng->mtrsl); if (!aso_mtr || aso_mtr->state == ASO_METER_FREE) return NULL; return &aso_mtr->fm; -- 2.18.1