Skip to content

Commit 5682aad

Browse files
kliteyngregkh
authored andcommitted
net/mlx5: HWS, change error flow on matcher disconnect
commit 1ce840c upstream. Currently, when firmware failure occurs during matcher disconnect flow, the error flow of the function reconnects the matcher back and returns an error, which continues running the calling function and eventually frees the matcher that is being disconnected. This leads to a case where we have a freed matcher on the matchers list, which in turn leads to use-after-free and eventual crash. This patch fixes that by not trying to reconnect the matcher back when some FW command fails during disconnect. Note that we're dealing here with FW error. We can't overcome this problem. This might lead to bad steering state (e.g. wrong connection between matchers), and will also lead to resource leakage, as it is the case with any other error handling during resource destruction. However, the goal here is to allow the driver to continue and not crash the machine with use-after-free error. Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com> Signed-off-by: Itamar Gozlan <igozlan@nvidia.com> Reviewed-by: Mark Bloch <mbloch@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20250102181415.1477316-7-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Jan Alexander Preissler <akendo@akendo.eu> Signed-off-by: Sujana Subramaniam <sujana.subramaniam@sap.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 464a33c commit 5682aad

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

drivers/net/ethernet/mellanox/mlx5/core/steering/hws/mlx5hws_matcher.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,42 +165,34 @@ static int hws_matcher_disconnect(struct mlx5hws_matcher *matcher)
165165
next->match_ste.rtc_0_id,
166166
next->match_ste.rtc_1_id);
167167
if (ret) {
168-
mlx5hws_err(tbl->ctx, "Failed to disconnect matcher\n");
169-
goto matcher_reconnect;
168+
mlx5hws_err(tbl->ctx, "Fatal error, failed to disconnect matcher\n");
169+
return ret;
170170
}
171171
} else {
172172
ret = mlx5hws_table_connect_to_miss_table(tbl, tbl->default_miss.miss_tbl);
173173
if (ret) {
174-
mlx5hws_err(tbl->ctx, "Failed to disconnect last matcher\n");
175-
goto matcher_reconnect;
174+
mlx5hws_err(tbl->ctx, "Fatal error, failed to disconnect last matcher\n");
175+
return ret;
176176
}
177177
}
178178

179179
/* Removing first matcher, update connected miss tables if exists */
180180
if (prev_ft_id == tbl->ft_id) {
181181
ret = mlx5hws_table_update_connected_miss_tables(tbl);
182182
if (ret) {
183-
mlx5hws_err(tbl->ctx, "Fatal error, failed to update connected miss table\n");
184-
goto matcher_reconnect;
183+
mlx5hws_err(tbl->ctx,
184+
"Fatal error, failed to update connected miss table\n");
185+
return ret;
185186
}
186187
}
187188

188189
ret = mlx5hws_table_ft_set_default_next_ft(tbl, prev_ft_id);
189190
if (ret) {
190191
mlx5hws_err(tbl->ctx, "Fatal error, failed to restore matcher ft default miss\n");
191-
goto matcher_reconnect;
192+
return ret;
192193
}
193194

194195
return 0;
195-
196-
matcher_reconnect:
197-
if (list_empty(&tbl->matchers_list) || !prev)
198-
list_add(&matcher->list_node, &tbl->matchers_list);
199-
else
200-
/* insert after prev matcher */
201-
list_add(&matcher->list_node, &prev->list_node);
202-
203-
return ret;
204196
}
205197

206198
static void hws_matcher_set_rtc_attr_sz(struct mlx5hws_matcher *matcher,

0 commit comments

Comments
 (0)