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 F1F72A0C52; Mon, 1 Nov 2021 07:31:22 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 962B2410E6; Mon, 1 Nov 2021 07:31:21 +0100 (CET) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2048.outbound.protection.outlook.com [40.107.96.48]) by mails.dpdk.org (Postfix) with ESMTP id 436F240DF6; Mon, 1 Nov 2021 07:31:19 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gxaHwD1Ayic9x1sBHT94R2vCwSWubanCRgw5N5BOsnVIyJNWpFRs2/xhKlYBIK+30KQX6AWskMqsO9C27kBHMZo9hIgdJYIQyzSIhF79GOLzXm+JK/PAJjgEAUNLNq+zy3pp2ztVorVySfA9gWuMDEJbAjHiB+MgG67niCjswGGN2aE2MKoWwphbqoSVf6KEL6pcX7xWCzvY88ARP63xwJ4MoeVQmHo5pmHrG1W1AAc+W95QAsduxaFsRU9jK8zYYEL3yH8Etd8oLpK1mQTMvgw0C+4dqzWFVvff8BxRMjaimCJ11afDKaoZUKLtHh0HoZTLjOaiQDwV2oVMjQPSFQ== 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=D1q9v1TE3oTVIhdVrUqmb9BPsxq9qDlNqHpfdncOvMM=; b=DJCi0lMHThkZh0ZaAiKBcLNoex0ohtc7433Fv8DFZO1Znw0xMzq7o15/nPe4DgCMww99WVeN8QT8h+PbDDy+3AQW00LXcJYwvV8FKrnyGFkZ9fssQF+nef0Czr1bBIa48dUHPYVGWEM6+SVT/Ot+qcZ+tle+TLY6DIRQvNE+G1d97OwYM/c/8H6fJ+fvK7Nsl33ew0Ru+FddgkEaZhKRwOp4ocFn2pEthOGAt4K1eFlP2pojE3kiDZ3Lr11E90CE6/reBJovAeN9HagKUxpkqTWQlf0CzsyLbSXT6irmqblFe+1L1d5y4QpCGk7ku8RlvOtGEuwFJQt+YIgD//Vo7Q== 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=D1q9v1TE3oTVIhdVrUqmb9BPsxq9qDlNqHpfdncOvMM=; b=uKeuTJwtAInJYv7pKxguWEDJkG1rHkDpl9oElsULZVgZobevpl6/Lq18novrjQ5LkvzDl9QlWo/ONmGkeHJ5pn/1awDxc+NWgkKVoYGDQQJJhnOMF8+SsF5WtGu7Qk4xYhuzbgjNA9nbzpKEdxTJlvcpqd0DUGH7BIsUhAe4UdkWfvNNLFYWotzoQDeTOod/xGcWk12gVs0eY0K2m1X9htzid2rsfbsrmcK5dBLoXTjF4EKVJYut9+Ye0F+od5S4iXMhrJNyYmbr0qIsdxJmV4vA54hnoyjmB1mXHGRfwGeMQswZCtwUskQLituW0faCc6wOEJOeDoLajUmLGUJH3Q== Received: from BN6PR20CA0062.namprd20.prod.outlook.com (2603:10b6:404:151::24) by BYAPR12MB3063.namprd12.prod.outlook.com (2603:10b6:a03:d6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Mon, 1 Nov 2021 06:31:17 +0000 Received: from BN8NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:404:151:cafe::a5) 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:16 +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:16 +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:00 +0000 From: Jiawei Wang To: , , , , Suanming Mou CC: , , Date: Mon, 1 Nov 2021 08:30:39 +0200 Message-ID: <20211101063040.25303-1-jiaweiw@nvidia.com> X-Mailer: git-send-email 2.18.1 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: 3d6fb346-8183-458d-2b0f-08d99d01358d X-MS-TrafficTypeDiagnostic: BYAPR12MB3063: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /482+OpsU2XnraW1gw7FUkrwJ6RMkLuemt4QfvRweS7Bi5dRdXZiIf34/Hmwo2pVbBaiaFV9z1quBZK/S7ZYTYpW8QkURwaws+aXBOvLMhLAvNlfyVZyeD137FpIPO1c4Jj/+jAYxNe4uEYtv6fpzLQkS5tnfU10r4Lo5gpphqIEx/xfZGKMlUfRWz4WBoTSFGbsqAW6nNXvgdq1dd4hZPstroAVrRfZ2H7wiTYl2tuRSKZoZAjY/8D1kXACxJTpI3u0RjFQqeOxNEdkhrIzTGL7ho2f3N28ZwKiIojUZ4hyv4IXpGOMLah5u4u1EoKO37Y6viA5aiQsieRzV6L+NPu+qwIZlO+5I3SKPCWjWqsJR1h6ix+0Wq9rPRr2QZqjAbXsmOiUga8T8/vyla99qPGAp/qVAUSoth/r5VdoXWcnEoNRo//87J3oti1W86t1XoBX3t8IVo1YbwzGpyhDHXqbOhhzJr0YHN12tFBWzsJmQY/4ZfqTfWkR2TtCsSYmH80oiJoOkGihd2+rNm8THnOPnG+7mJ9sfv0uvVy5xEp/MpMCh6cUgL9ZZ7Mje+kcYfNBiI4uaG1uV9x59R7sZ3x/3mLBGlZ+76N5ERfpkhB1i83eNWdlmnvy/3/ouWb5UM0oxCZsGk3nt1GBOoi1XnnQiKdwb0fQnjdWFwH62lDV7nPs72KGqgBUKn6W0/H9ZIZuUySc52dXaonvmwLI9Q== 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)(47076005)(7696005)(4326008)(508600001)(426003)(2616005)(2906002)(8676002)(1076003)(70586007)(70206006)(6286002)(336012)(83380400001)(186003)(16526019)(55016002)(36860700001)(5660300002)(7636003)(54906003)(6666004)(356005)(36756003)(6636002)(26005)(8936002)(316002)(86362001)(82310400003)(36906005)(110136005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2021 06:31:16.6889 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d6fb346-8183-458d-2b0f-08d99d01358d 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: BYAPR12MB3063 Subject: [dpdk-dev] [PATCH 1/2] net/mlx5: fix age 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 age action with flows creation could be supported on the multiple threads. The age pools were created to manage the age resources, if there is no room in the current pool then resize the age pool to the new pool size and free the old one. There's a race condition while one thread resizes the age pool and the old pool resource be freed, and another thread query the age action value of the old pool so the queried value is invalid. This patch uses the 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 | 2 +- drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_flow.c | 5 ++++- drivers/net/mlx5/mlx5_flow_aso.c | 8 ++++---- drivers/net/mlx5/mlx5_flow_dv.c | 6 +++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 4fe7e34578..b90752c56d 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -450,7 +450,7 @@ mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh) mlx5_free(sh->aso_age_mng); return -1; } - rte_spinlock_init(&sh->aso_age_mng->resize_sl); + rte_rwlock_init(&sh->aso_age_mng->resize_rwl); rte_spinlock_init(&sh->aso_age_mng->free_sl); LIST_INIT(&sh->aso_age_mng->free); return 0; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index a3b2a3d8e5..5e88dfcfea 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -549,7 +549,7 @@ struct mlx5_aso_age_mng { struct mlx5_aso_age_pool **pools; uint16_t n; /* Total number of pools. */ uint16_t next; /* Number of pools in use, index of next free pool. */ - rte_spinlock_t resize_sl; /* Lock for resize objects. */ + rte_rwlock_t resize_rwl; /* Lock for resize objects. */ rte_spinlock_t free_sl; /* Lock for free list access. */ struct aso_age_list free; /* Free age actions list - ready to use. */ struct mlx5_aso_sq aso_sq; /* ASO queue objects. */ diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index d222914cf5..d5ed673891 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -3675,8 +3675,11 @@ flow_aso_age_get_by_idx(struct rte_eth_dev *dev, uint32_t age_idx) uint16_t offset = (age_idx >> 16) & UINT16_MAX; struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_aso_age_mng *mng = priv->sh->aso_age_mng; - struct mlx5_aso_age_pool *pool = mng->pools[pool_idx]; + struct mlx5_aso_age_pool *pool; + rte_rwlock_read_lock(&mng->resize_rwl); + pool = mng->pools[pool_idx]; + rte_rwlock_read_unlock(&mng->resize_rwl); return &pool->actions[offset - 1]; } diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c index 1fc1000b01..bcdad31330 100644 --- a/drivers/net/mlx5/mlx5_flow_aso.c +++ b/drivers/net/mlx5/mlx5_flow_aso.c @@ -417,9 +417,9 @@ mlx5_aso_sq_enqueue_burst(struct mlx5_aso_age_mng *mng, uint16_t n) wqe = &sq->sq_obj.aso_wqes[sq->head & mask]; rte_prefetch0(&sq->sq_obj.aso_wqes[(sq->head + 1) & mask]); /* Fill next WQE. */ - rte_spinlock_lock(&mng->resize_sl); + rte_rwlock_read_lock(&mng->resize_rwl); pool = mng->pools[sq->next]; - rte_spinlock_unlock(&mng->resize_sl); + rte_rwlock_read_unlock(&mng->resize_rwl); sq->elts[sq->head & mask].pool = pool; wqe->general_cseg.misc = rte_cpu_to_be_32(((struct mlx5_devx_obj *) @@ -635,9 +635,9 @@ mlx5_flow_aso_alarm(void *arg) uint32_t us = 100u; uint16_t n; - rte_spinlock_lock(&sh->aso_age_mng->resize_sl); + rte_rwlock_read_lock(&sh->aso_age_mng->resize_rwl); n = sh->aso_age_mng->next; - rte_spinlock_unlock(&sh->aso_age_mng->resize_sl); + rte_rwlock_read_unlock(&sh->aso_age_mng->resize_rwl); mlx5_aso_completion_handle(sh); if (sq->next == n) { /* End of loop: wait 1 second. */ diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 8529930897..22081dddd3 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -11857,18 +11857,18 @@ flow_dv_age_pool_create(struct rte_eth_dev *dev, } pool->flow_hit_aso_obj = obj; pool->time_of_last_age_check = MLX5_CURR_TIME_SEC; - rte_spinlock_lock(&mng->resize_sl); + rte_rwlock_write_lock(&mng->resize_rwl); pool->index = mng->next; /* Resize pools array if there is no room for the new pool in it. */ if (pool->index == mng->n && flow_dv_aso_age_pools_resize(dev)) { claim_zero(mlx5_devx_cmd_destroy(obj)); mlx5_free(pool); - rte_spinlock_unlock(&mng->resize_sl); + rte_rwlock_write_unlock(&mng->resize_rwl); return NULL; } mng->pools[pool->index] = pool; mng->next++; - rte_spinlock_unlock(&mng->resize_sl); + rte_rwlock_write_unlock(&mng->resize_rwl); /* Assign the first action in the new pool, the rest go to free list. */ *age_free = &pool->actions[0]; for (i = 1; i < MLX5_ASO_AGE_ACTIONS_PER_POOL; i++) { -- 2.18.1