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 7BA6742ECF for ; Thu, 20 Jul 2023 17:34:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 78D7B40685; Thu, 20 Jul 2023 17:34:05 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 68CCB42D31 for ; Thu, 20 Jul 2023 17:34:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689867243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eGbCmVWyRHRrpUpA1U4BGmCGf3Bnvt8dOivvbKfqJ4s=; b=GxGlIgb0ZDiPUxg2DvPz2T7Si7MOg6AZotxqN7m3e3yntGmmZ7PIpmN0l4erqz4Gi/yfjV 7Vj/GUsZtwHEgeXWpr2+jo8Ahnlmig4FVWzkLvLKEewFl+yBgbwRDy2tw8q431L7053hhm 4UyK+inY9C5oPF0vKYnD660SiPPfMxo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-250-kLpY6ZtfPySNpquZlIaxrw-1; Thu, 20 Jul 2023 11:24:05 -0400 X-MC-Unique: kLpY6ZtfPySNpquZlIaxrw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72C6410504CC; Thu, 20 Jul 2023 15:23:09 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0442A492C13; Thu, 20 Jul 2023 15:23:07 +0000 (UTC) From: Kevin Traynor To: Gregory Etelson Cc: David Marchand , Bing Zhao , Matan Azrad , dpdk stable Subject: patch 'net/mlx5: fix flow workspace destruction' has been queued to stable release 21.11.5 Date: Thu, 20 Jul 2023 16:19:17 +0100 Message-ID: <20230720151942.262154-126-ktraynor@redhat.com> In-Reply-To: <20230720151942.262154-1-ktraynor@redhat.com> References: <20230720151942.262154-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 21.11.5 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 07/25/23. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable/commit/cd2b1999eb8c504f0d669e2022518b93c71085a0 Thanks. Kevin --- >From cd2b1999eb8c504f0d669e2022518b93c71085a0 Mon Sep 17 00:00:00 2001 From: Gregory Etelson Date: Mon, 3 Jul 2023 12:50:52 +0300 Subject: [PATCH] net/mlx5: fix flow workspace destruction [ upstream commit dc7c5e0aa905b675c56a66b2014b01b7f5ae8a1d ] PMD uses pthread key to allocate and access per thread flow workspace memory buffers. PMD registered a key destructor function to clean up flow workspace buffers. However, the key destructor was not called by the pthread library. The patch keeps track of per-thread flow workspaces in PMD. Flow workspaces memory release is activated from PMD destructor. In the meanwhile, workspace buffer and RSS queues array are allocated in a single memory chunk with this patch. The maximal number of queues RTE_ETH_RSS_RETA_SIZE_512 is chosen. Then the workspace adjustment can be removed to reduce the software hiccup: 1. realloc and content copy 2. spinlock acquire and release Bugzilla ID: 1255 Fixes: 5d55a494f4e6 ("net/mlx5: split multi-thread flow handling per OS") Reported-by: David Marchand Signed-off-by: Gregory Etelson Signed-off-by: Bing Zhao Acked-by: Matan Azrad --- drivers/net/mlx5/linux/mlx5_flow_os.c | 2 +- drivers/net/mlx5/mlx5.c | 1 + drivers/net/mlx5/mlx5_flow.c | 77 +++++++++++---------------- drivers/net/mlx5/mlx5_flow.h | 4 +- 4 files changed, 36 insertions(+), 48 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_flow_os.c b/drivers/net/mlx5/linux/mlx5_flow_os.c index a5956c255a..08337a9b24 100644 --- a/drivers/net/mlx5/linux/mlx5_flow_os.c +++ b/drivers/net/mlx5/linux/mlx5_flow_os.c @@ -13,5 +13,5 @@ int mlx5_flow_os_init_workspace_once(void) { - if (rte_thread_key_create(&key_workspace, flow_release_workspace)) { + if (rte_thread_key_create(&key_workspace, NULL)) { DRV_LOG(ERR, "Can't create flow workspace data thread key."); rte_errno = ENOMEM; diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index c5f2db1e4a..5645e8656c 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1328,4 +1328,5 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) mlx5_os_net_cleanup(); mlx5_flow_os_release_workspace(); + mlx5_flow_workspace_gc_release(); } pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex); diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 192e2d7718..133dca5dcf 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -6527,34 +6527,4 @@ flow_tunnel_from_rule(const struct mlx5_flow *flow) } -/** - * Adjust flow RSS workspace if needed. - * - * @param wks - * Pointer to thread flow work space. - * @param rss_desc - * Pointer to RSS descriptor. - * @param[in] nrssq_num - * New RSS queue number. - * - * @return - * 0 on success, -1 otherwise and rte_errno is set. - */ -static int -flow_rss_workspace_adjust(struct mlx5_flow_workspace *wks, - struct mlx5_flow_rss_desc *rss_desc, - uint32_t nrssq_num) -{ - if (likely(nrssq_num <= wks->rssq_num)) - return 0; - rss_desc->queue = realloc(rss_desc->queue, - sizeof(*rss_desc->queue) * RTE_ALIGN(nrssq_num, 2)); - if (!rss_desc->queue) { - rte_errno = ENOMEM; - return -1; - } - wks->rssq_num = RTE_ALIGN(nrssq_num, 2); - return 0; -} - /** * Create a flow and add it to @p list. @@ -6674,6 +6644,5 @@ flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type, rss = flow_get_rss_action(dev, p_actions_rx); if (rss) { - if (flow_rss_workspace_adjust(wks, rss_desc, rss->queue_num)) - return 0; + MLX5_ASSERT(rss->queue_num <= RTE_ETH_RSS_RETA_SIZE_512); /* * The following information is required by @@ -7108,5 +7077,4 @@ flow_release_workspace(void *data) while (wks) { next = wks->next; - free(wks->rss_desc.queue); free(wks); wks = next; @@ -7114,4 +7082,27 @@ flow_release_workspace(void *data) } +static struct mlx5_flow_workspace *gc_head; +static rte_spinlock_t mlx5_flow_workspace_lock = RTE_SPINLOCK_INITIALIZER; + +static void +mlx5_flow_workspace_gc_add(struct mlx5_flow_workspace *ws) +{ + rte_spinlock_lock(&mlx5_flow_workspace_lock); + ws->gc = gc_head; + gc_head = ws; + rte_spinlock_unlock(&mlx5_flow_workspace_lock); +} + +void +mlx5_flow_workspace_gc_release(void) +{ + while (gc_head) { + struct mlx5_flow_workspace *wks = gc_head; + + gc_head = wks->gc; + flow_release_workspace(wks); + } +} + /** * Get thread specific current flow workspace. @@ -7139,22 +7130,15 @@ static struct mlx5_flow_workspace* flow_alloc_thread_workspace(void) { - struct mlx5_flow_workspace *data = calloc(1, sizeof(*data)); + size_t data_size = RTE_ALIGN(sizeof(struct mlx5_flow_workspace), sizeof(long)); + size_t rss_queue_array_size = sizeof(uint16_t) * RTE_ETH_RSS_RETA_SIZE_512; + struct mlx5_flow_workspace *data = calloc(1, data_size + + rss_queue_array_size); if (!data) { - DRV_LOG(ERR, "Failed to allocate flow workspace " - "memory."); + DRV_LOG(ERR, "Failed to allocate flow workspace memory."); return NULL; } - data->rss_desc.queue = calloc(1, - sizeof(uint16_t) * MLX5_RSSQ_DEFAULT_NUM); - if (!data->rss_desc.queue) - goto err; - data->rssq_num = MLX5_RSSQ_DEFAULT_NUM; + data->rss_desc.queue = RTE_PTR_ADD(data, data_size); return data; -err: - if (data->rss_desc.queue) - free(data->rss_desc.queue); - free(data); - return NULL; } @@ -7177,4 +7161,5 @@ mlx5_flow_push_thread_workspace(void) if (!data) return NULL; + mlx5_flow_workspace_gc_add(data); } else if (!curr->inuse) { data = curr; diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 8ad8e63205..8a571f977e 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -1099,8 +1099,8 @@ struct mlx5_flow_workspace { struct mlx5_flow_workspace *prev; struct mlx5_flow_workspace *next; + struct mlx5_flow_workspace *gc; uint32_t inuse; /* can't create new flow with current. */ struct mlx5_flow flows[MLX5_NUM_MAX_DEV_FLOWS]; struct mlx5_flow_rss_desc rss_desc; - uint32_t rssq_num; /* Allocated queue num in rss_desc. */ uint32_t flow_idx; /* Intermediate device flow index. */ struct mlx5_flow_meter_info *fm; /* Pointer to the meter in flow. */ @@ -1305,4 +1305,6 @@ struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void); void mlx5_flow_pop_thread_workspace(void); struct mlx5_flow_workspace *mlx5_flow_get_thread_workspace(void); +void mlx5_flow_workspace_gc_release(void); + __extension__ struct flow_grp_info { -- 2.41.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-07-20 16:18:10.154319379 +0100 +++ 0126-net-mlx5-fix-flow-workspace-destruction.patch 2023-07-20 16:17:55.178752619 +0100 @@ -1 +1 @@ -From dc7c5e0aa905b675c56a66b2014b01b7f5ae8a1d Mon Sep 17 00:00:00 2001 +From cd2b1999eb8c504f0d669e2022518b93c71085a0 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit dc7c5e0aa905b675c56a66b2014b01b7f5ae8a1d ] + @@ -25 +26,0 @@ -Cc: stable@dpdk.org @@ -34 +35 @@ - drivers/net/mlx5/mlx5_flow.c | 76 +++++++++++---------------- + drivers/net/mlx5/mlx5_flow.c | 77 +++++++++++---------------- @@ -36 +37 @@ - 4 files changed, 36 insertions(+), 47 deletions(-) + 4 files changed, 36 insertions(+), 48 deletions(-) @@ -39 +40 @@ -index 3c9a823edf..b139bb75b9 100644 +index a5956c255a..08337a9b24 100644 @@ -42 +43 @@ -@@ -52,5 +52,5 @@ int +@@ -13,5 +13,5 @@ int @@ -50 +51 @@ -index 5f0aa296ba..fd9b76027d 100644 +index c5f2db1e4a..5645e8656c 100644 @@ -53 +54 @@ -@@ -1839,4 +1839,5 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) +@@ -1328,4 +1328,5 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) @@ -60 +61 @@ -index abb86241fc..1071ef0c3e 100644 +index 192e2d7718..133dca5dcf 100644 @@ -63 +64 @@ -@@ -7156,34 +7156,4 @@ flow_tunnel_from_rule(const struct mlx5_flow *flow) +@@ -6527,34 +6527,4 @@ flow_tunnel_from_rule(const struct mlx5_flow *flow) @@ -98 +99 @@ -@@ -7304,6 +7274,5 @@ flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type, +@@ -6674,6 +6644,5 @@ flow_list_create(struct rte_eth_dev *dev, enum mlx5_flow_type type, @@ -106 +107 @@ -@@ -8073,5 +8042,4 @@ flow_release_workspace(void *data) +@@ -7108,5 +7077,4 @@ flow_release_workspace(void *data) @@ -112 +113 @@ -@@ -8079,4 +8047,27 @@ flow_release_workspace(void *data) +@@ -7114,4 +7082,27 @@ flow_release_workspace(void *data) @@ -140 +141 @@ -@@ -8104,21 +8095,15 @@ static struct mlx5_flow_workspace* +@@ -7139,22 +7130,15 @@ static struct mlx5_flow_workspace* @@ -163 +164,2 @@ -- free(data->rss_desc.queue); +- if (data->rss_desc.queue) +- free(data->rss_desc.queue); @@ -168 +170 @@ -@@ -8141,4 +8126,5 @@ mlx5_flow_push_thread_workspace(void) +@@ -7177,4 +7161,5 @@ mlx5_flow_push_thread_workspace(void) @@ -175 +177 @@ -index 003e7da3a6..62789853ab 100644 +index 8ad8e63205..8a571f977e 100644 @@ -178 +180 @@ -@@ -1497,8 +1497,8 @@ struct mlx5_flow_workspace { +@@ -1099,8 +1099,8 @@ struct mlx5_flow_workspace { @@ -188 +190 @@ -@@ -2023,4 +2023,6 @@ struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void); +@@ -1305,4 +1305,6 @@ struct mlx5_flow_workspace *mlx5_flow_push_thread_workspace(void);