FAILED: patch "[PATCH] net/mlx5: HWS, fix matcher leak on resize target setup" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x bb09d0e64ecaa0aa0f7d1133a1696ed74dead295
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072123-treason-bush-df20@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From bb09d0e64ecaa0aa0f7d1133a1696ed74dead295 Mon Sep 17 00:00:00 2001
From: Dawei Feng <[email protected]>
Date: Mon, 29 Jun 2026 14:40:49 +0800
Subject: [PATCH] net/mlx5: HWS, fix matcher leak on resize target setup
failure
hws_bwc_matcher_move() allocates a replacement matcher before setting it as the resize target. If mlx5hws_matcher_resize_set_target() fails, the replacement matcher is not attached anywhere and is leaked.
Fix the leak by destroying the replacement matcher before returning from the resize-target failure path.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1.1.
An x86_64 allyesconfig build showed no new warnings. As we do not have a mlx5 HWS-capable device to test with, no runtime testing was able to be performed.
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.c +1 -0
@@ -205,6 +205,7 @@ static int hws_bwc_matcher_move(struct mlx5hws_bwc_matcher *bwc_matcher) ret =mlx5hws_matcher_resize_set_target (old_matcher, new_matcher);if (ret) {mlx5hws_err (ctx,"Rehash error: failed setting resize target\n" ); +mlx5hws_matcher_destroy (new_matcher);return ret; }
Sasha Levin
maintainerPATCH 1/2 net/mlx5: HWS, Rearrange to prevent forward declaration
From: Yevgeny Kliteynik <[email protected]>
[ Upstream commit 29063103f864fb63f7f7c436e670c5804df1b55b ]
As a preparation for the following patch that will add support for shrinking empty matchers, rearrange the code to prevent forward declaration of functions.
Stable-dep-of: bb09d0e64eca ("net/mlx5: HWS, fix matcher leak on resize target setup failure")
--- .../mlx5/core/steering/hws/mlx5hws_bwc.c | 354 +++++++++--------- 1 file changed, 177 insertions(+), 177 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc.c +177 -177
@@ -63,6 +63,183 @@ static void hws_bwc_matcher_init_attr(struct mlx5hws_matcher_attr *attr, attr->max_num_of_at_attach =MLX5HWS_BWC_MATCHER_ATTACH_AT_NUM ; } +static int hws_bwc_queue_poll (struct mlx5hws_context *ctx, +u16 queue_id, +u32 *pending_rules, +bool drain) +{ +struct mlx5hws_flow_op_result comp[MLX5HWS_BWC_MATCHER_REHASH_BURST_TH ]; +u16 burst_th =hws_bwc_get_burst_th (ctx, queue_id); +bool got_comp = *pending_rules >= burst_th; +bool queue_full; +int err =0 ; +int ret; +int i; + +/* Check if there are any completions at all */ +if (!got_comp && !drain) +return 0 ; + + queue_full =mlx5hws_send_engine_full (&ctx->send_queue[queue_id]); +while (queue_full || ((got_comp || drain) && *pending_rules)) { + ret =mlx5hws_send_queue_poll (ctx, queue_id, comp, burst_th); +if (unlikely (ret <0 )) { +mlx5hws_err (ctx,"BWC poll error: polling queue %d returned %d\n" , + queue_id, ret); +return -EINVAL ; + } + +if (ret) { + (*pending_rules) -= ret; +for (i =0 ; i < ret; i++) { +if (unlikely (comp[i].status !=MLX5HWS_FLOW_OP_SUCCESS )) { +mlx5hws_err (ctx, +"BWC poll error: polling queue %d returned completion with error\n" , + queue_id); + err = -EINVAL ; + } + } + queue_full = false; + } + + got_comp = !!ret; + } + +return err; +} + +static int hws_bwc_matcher_move_all_simple (struct mlx5hws_bwc_matcher *bwc_matcher) +{ +struct mlx5hws_context *ctx = bwc_matcher->matcher->tbl->ctx; +u16 bwc_queues =mlx5hws_bwc_queues (ctx); +struct mlx5hws_bwc_rule **bwc_rules; +struct mlx5hws_rule_attr rule_attr; +u32 *pending_rules; +int i, j, ret =0 ; +bool all_done; +u16 burst_th; + +mlx5hws_bwc_rule_fill_attr (bwc_matcher,0 ,0 , &rule_attr); + + pending_rules =kcalloc (bwc_queues,sizeof (*pending_rules),GFP_KERNEL ); +if (!pending_rules) +return -ENOMEM ; + + bwc_rules =kcalloc (bwc_queues,sizeof (*bwc_rules),GFP_KERNEL ); +if (!bwc_rules) { + ret = -ENOMEM ; + goto free_pending_rules; + } + +for (i =0 ; i < bwc_queues; i++) { +if (list_empty (&bwc_matcher->rules[i])) + bwc_rules[i] =NULL ; +else + bwc_rules[i] =list_first_entry (&bwc_matcher->rules[i], + struct mlx5hws_bwc_rule, + list_node); + } + +do { + all_done = true; + +for (i =0 ; i < bwc_queues; i++) { + rule_attr.queue_id =mlx5hws_bwc_get_queue_id (ctx, i); + burst_th =hws_bwc_get_burst_th (ctx, rule_attr.queue_id); + +for (j =0 ; j < burst_th && bwc_rules[i]; j++) { + rule_attr.burst = !!((j +1 ) % burst_th); + ret =mlx5hws_matcher_resize_rule_move (bwc_matcher->matcher, + bwc_rules[i]->rule, + &rule_attr); +if (unlikely (ret)) { +mlx5hws_err (ctx, +"Moving BWC rule failed during rehash (%d)\n" , + ret); + goto free_bwc_rules; + } + + all_done = false; + pending_rules[i]++; + bwc_rules[i] =list_is_last (&bwc_rules[i]->list_node, + &bwc_matcher->rules[i]) ? +NULL :list_next_entry (bwc_rules[i], list_node); + + ret =hws_bwc_queue_poll (ctx, rule_attr.queue_id, + &pending_rules[i], false); +if (unlikely (ret)) + goto free_bwc_rules; + } + } + }while (!all_done); + +/* drain all the bwc queues */ +for (i =0 ; i < bwc_queues; i++) { +if (pending_rules[i]) { +u16 queue_id =mlx5hws_bwc_get_queue_id (ctx, i); + +mlx5hws_send_engine_flush_queue (&ctx->send_queue[queue_id]); + ret =hws_bwc_queue_poll (ctx, queue_id, + &pending_rules[i], true); +if (unlikely (ret)) + goto free_bwc_rules; + } + } + +free_bwc_rules: +kfree (bwc_rules); +free_pending_rules: +kfree (pending_rules); + +return ret; +} + +static int hws_bwc_matcher_move_all (struct mlx5hws_bwc_matcher *bwc_matcher) +{ +return hws_bwc_matcher_move_all_simple (bwc_matcher); +} + +static int hws_bwc_matcher_move (struct mlx5hws_bwc_matcher *bwc_matcher) +{ +struct mlx5hws_context *ctx = bwc_matcher->matcher->tbl->ctx; +struct mlx5hws_matcher_attr matcher_attr = {0 }; +struct mlx5hws_matcher *old_matcher; +struct mlx5hws_matcher *new_matcher; +int ret; + +hws_bwc_matcher_init_attr (&matcher_attr, + bwc_matcher->priority, + bwc_matcher->size_log); + + old_matcher = bwc_matcher->matcher; + new_matcher =mlx5hws_matcher_create (old_matcher->tbl, + &bwc_matcher->mt,1 , + bwc_matcher->at, + bwc_matcher->num_of_at, + &matcher_attr); +if (!new_matcher) { +mlx5hws_err (ctx,"Rehash error: matcher creation failed\n" ); +return -ENOMEM ; + } + + ret =mlx5hws_matcher_resize_set_target (old_matcher, new_matcher); +if (ret) { +mlx5hws_err (ctx,"Rehash error: failed setting resize target\n" ); +return ret; + } + + ret =hws_bwc_matcher_move_all (bwc_matcher); +if (ret) { +mlx5hws_err (ctx,"Rehash error: moving rules failed\n" ); +return -ENOMEM ; + } + + bwc_matcher->matcher = new_matcher; +mlx5hws_matcher_destroy (old_matcher); + +return 0 ; +} + int mlx5hws_bwc_matcher_create_simple(struct mlx5hws_bwc_matcher *bwc_matcher, struct mlx5hws_table *table, u32 priority,
@@ -210,51 +387,6 @@ int mlx5hws_bwc_matcher_destroy(struct mlx5hws_bwc_matcher *bwc_matcher)return 0 ; } -static int hws_bwc_queue_poll (struct mlx5hws_context *ctx, -u16 queue_id, -u32 *pending_rules, -bool drain) -{ -struct mlx5hws_flow_op_result comp[MLX5HWS_BWC_MATCHER_REHASH_BURST_TH ]; -u16 burst_th =hws_bwc_get_burst_th (ctx, queue_id); -bool got_comp = *pending_rules >= burst_th; -bool queue_full; -int err =0 ; -int ret; -int i; - -/* Check if there are any completions at all */ -if (!got_comp && !drain) -return 0 ; - - queue_full =mlx5hws_send_engine_full (&ctx->send_queue[queue_id]); -while (queue_full || ((got_comp || drain) && *pending_rules)) { - ret =mlx5hws_send_queue_poll (ctx, queue_id, comp, burst_th); -if (unlikely (ret <0 )) { -mlx5hws_err (ctx,"BWC poll error: polling queue %d returned %d\n" , - queue_id, ret); -return -EINVAL ; - } - -if (ret) { - (*pending_rules) -= ret; -for (i =0 ; i < ret; i++) { -if (unlikely (comp[i].status !=MLX5HWS_FLOW_OP_SUCCESS )) { -mlx5hws_err (ctx, -"BWC poll error: polling queue %d returned completion with error\n" , - queue_id); - err = -EINVAL ; - } - } - queue_full = false; - } - - got_comp = !!ret; - } - -return err; -} - void mlx5hws_bwc_rule_fill_attr(struct mlx5hws_bwc_matcher *bwc_matcher, u16 bwc_queue_idx,
@@ -556,138 +688,6 @@ hws_bwc_matcher_find_at(struct mlx5hws_bwc_matcher *bwc_matcher,return -1 ; } -static int hws_bwc_matcher_move_all_simple (struct mlx5hws_bwc_matcher *bwc_matcher) -{ -struct mlx5hws_context *ctx = bwc_matcher->matcher->tbl->ctx; -u16 bwc_queues =mlx5hws_bwc_queues (ctx); -struct mlx5hws_bwc_rule **bwc_rules; -struct mlx5hws_rule_attr rule_attr; -u32 *pending_rules; -int i, j, ret =0 ; -bool all_done; -u16 burst_th; - -mlx5hws_bwc_rule_fill_attr (bwc_matcher,0 ,0 , &rule_attr); - - pending_rules =kcalloc (bwc_queues,sizeof (*pending_rules),GFP_KERNEL ); -if (!pending_rules) -return -ENOMEM ; - - bwc_rules =kcalloc (bwc_queues,sizeof (*bwc_rules),GFP_KERNEL ); -if (!bwc_rules) { - ret = -ENOMEM ; - goto free_pending_rules; - } - -for (i =0 ; i < bwc_queues; i++) { -if (list_empty (&bwc_matcher->rules[i])) - bwc_rules[i] =NULL ; -else - bwc_rules[i] =list_first_entry (&bwc_matcher->rules[i], - struct mlx5hws_bwc_rule, - list_node); - } - -do { - all_done = true; - -for (i =0 ; i < bwc_queues; i++) { - rule_attr.queue_id =mlx5hws_bwc_get_queue_id (ctx, i); - burst_th =hws_bwc_get_burst_th (ctx, rule_attr.queue_id); - -for (j =0 ; j < burst_th && bwc_rules[i]; j++) { - rule_attr.burst = !!((j +1 ) % burst_th); - ret =mlx5hws_matcher_resize_rule_move (bwc_matcher->matcher, - bwc_rules[i]->rule, - &rule_attr); -if (unlikely (ret)) { -mlx5hws_err (ctx, -"Moving BWC rule failed during rehash (%d)\n" , - ret); - goto free_bwc_rules; - } - - all_done = false; - pending_rules[i]++; - bwc_rules[i] =list_is_last (&bwc_rules[i]->list_node, - &bwc_matcher->rules[i]) ? -NULL :list_next_entry (bwc_rules[i], list_node); - - ret =hws_bwc_queue_poll (ctx, rule_attr.queue_id, - &pending_rules[i], false); -if (unlikely (ret)) - goto free_bwc_rules; - } - } - }while (!all_done); - -/* drain all the bwc queues */ -for (i =0 ; i < bwc_queues; i++) { -if (pending_rules[i]) { -u16 queue_id =mlx5hws_bwc_get_queue_id (ctx, i); - -mlx5hws_send_engine_flush_queue (&ctx->send_queue[queue_id]); - ret =hws_bwc_queue_poll (ctx, queue_id, - &pending_rules[i], true); -if (unlikely (ret)) - goto free_bwc_rules; - } - } - -free_bwc_rules: -kfree (bwc_rules); -free_pending_rules: -kfree (pending_rules); - -return ret; -} - -static int hws_bwc_matcher_move_all (struct mlx5hws_bwc_matcher *bwc_matcher) -{ -return hws_bwc_matcher_move_all_simple (bwc_matcher); -} - -static int hws_bwc_matcher_move (struct mlx5hws_bwc_matcher *bwc_matcher) -{ -struct mlx5hws_context *ctx = bwc_matcher->matcher->tbl->ctx; -struct mlx5hws_matcher_attr matcher_attr = {0 }; -struct mlx5hws_matcher *old_matcher; -struct mlx5hws_matcher *new_matcher; -int ret; - -hws_bwc_matcher_init_attr (&matcher_attr, - bwc_matcher->priority, - bwc_matcher->size_log); - - old_matcher = bwc_matcher->matcher; - new_matcher =mlx5hws_matcher_create (old_matcher->tbl, - &bwc_matcher->mt,1 , - bwc_matcher->at, - bwc_matcher->num_of_at, - &matcher_attr); -if (!new_matcher) { -mlx5hws_err (ctx,"Rehash error: matcher creation failed\n" ); -return -ENOMEM ; - } - - ret =mlx5hws_matcher_resize_set_target (old_matcher, new_matcher); -if (ret) { -mlx5hws_err (ctx,"Rehash error: failed setting resize target\n" ); -return ret; - } - - ret =hws_bwc_matcher_move_all (bwc_matcher); -if (ret) { -mlx5hws_err (ctx,"Rehash error: moving rules failed\n" ); -return -ENOMEM ; - } - - bwc_matcher->matcher = new_matcher; -mlx5hws_matcher_destroy (old_matcher); - -return 0 ; -} -static int hws_bwc_matcher_rehash_size (struct mlx5hws_bwc_matcher *bwc_matcher) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 net/mlx5: HWS, fix matcher leak on resize target setup failure
From: Dawei Feng <[email protected]>
[ Upstream commit bb09d0e64ecaa0aa0f7d1133a1696ed74dead295 ]
hws_bwc_matcher_move() allocates a replacement matcher before setting it as the resize target. If mlx5hws_matcher_resize_set_target() fails, the replacement matcher is not attached anywhere and is leaked.
Fix the leak by destroying the replacement matcher before returning from the resize-target failure path.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1.1.
An x86_64 allyesconfig build showed no new warnings. As we do not have a mlx5 HWS-capable device to test with, no runtime testing was able to be performed.
--- .../net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_bwc.c +1 -0
@@ -225,6 +225,7 @@ static int hws_bwc_matcher_move(struct mlx5hws_bwc_matcher *bwc_matcher) ret =mlx5hws_matcher_resize_set_target (old_matcher, new_matcher);if (ret) {mlx5hws_err (ctx,"Rehash error: failed setting resize target\n" ); +mlx5hws_matcher_destroy (new_matcher);return ret; }
Signature · 1 line
2.53.0