Re: [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation

From
netdev-bot+sashiko@kernel.org
Date
2026-11-20 05:35:20
Also in
linux-rdma, lkml
Reply to
Tariq Toukan, 2026-11-18
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message for "net/mlx5: HWS, Handle NULL in vport
  destination action creation" describes only part of what the bug did.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the same
  caller, mlx5_fs_fte_get_hws_actions() in…

--

net/mlx5: HWS, Handle NULL in vport destination action creation

This patch makes mlx5_fs_get_dest_action_vport() return NULL as soon as
mlx5hws_action_create_dest_vport() fails. A NULL entry is therefore never
inserted into the vport destination xarray. Before this change, inserting
NULL could later cause a NULL dereference in hws_action_destroy_hws().
The next mlx5hws_action_create_dest_vport() failure will try to
insert NULL again, but xa_insert() will return -EBUSY, because
we already have NULL entry. In such case the code will go into
error flow of action creation, and eventually will cause NULL
dereference at hws_action_destroy_hws().
[Severity: Low]
This isn't a bug, but does this describe the whole impact? The text covers
a later creation for the same idx failing again. What about a later
creation that succeeds?

When the entry is NULL, __xa_insert() stores XA_ZERO_ENTRY instead:

lib/xarray.c:__xa_insert() {
    ...
	if (!entry)
		entry = XA_ZERO_ENTRY;
    ...
}

xa_load() turns that back into NULL. The slot looks empty but stays
reserved.

Suppose a later mlx5hws_action_create_dest_vport() call succeeds, for
example once a transient kzalloc or STC pool failure has cleared. The old
code then appears to loop:

mlx5_fs_get_dest_action_vport()
  dest_load:
    xa_load() returns NULL
    mlx5hws_action_create_dest_vport() returns a valid action
    xa_insert() returns -EBUSY
    mlx5hws_action_destroy(dest)
    goto dest_load

Wouldn't this spin forever and hang rule insertion for that vport?

The fix covers both outcomes, since NULL is never inserted now. Could the
commit message also mention the livelock?
quoted hunk ↗ jump to hunk
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
index cbcbc2b62809d..de22e7279a312 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
@@ -441,6 +441,8 @@ mlx5_fs_get_dest_action_vport(struct mlx5_fs_hws_context *fs_ctx,
 
 	dest = mlx5hws_action_create_dest_vport(ctx, vport_num,	vhca_id_valid,
 						dest_attr->vport.vhca_id, flags);
+	if (!dest)
+		return NULL;
 
 	err = xa_insert(dests_xa, idx, dest, GFP_KERNEL);
 	if (err) {
[Severity: High]
This is a pre-existing issue, but can the same caller,
mlx5_fs_fte_get_hws_actions(), still oops on a NULL action in other
destination cases?

In three cases the result goes into fs_actions[] and is counted before
the NULL check. These are FLOW_TABLE_NUM (when the action has to be
created), RANGE and FLOW_SAMPLER:

drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c:mlx5_fs_fte_get_hws_actions() {
    ...
				dest_action = mlx5_fs_create_dest_action_table_num(fs_ctx,
										   dst);
				fs_actions[num_fs_actions++].action = dest_action;
				break;
			case MLX5_FLOW_DESTINATION_TYPE_RANGE:
				dest_action = mlx5_fs_create_dest_action_range(ctx, dst);
				fs_actions[num_fs_actions++].action = dest_action;
				break;
    ...
			case MLX5_FLOW_DESTINATION_TYPE_FLOW_SAMPLER:
				dest_action =
					mlx5_fs_get_dest_action_sampler(fs_ctx,
									dst);
				fs_actions[num_fs_actions].action = dest_action;
				fs_actions[num_fs_actions++].sampler_id =
							dst->dest_attr.sampler_id;
				break;
    ...
			if (!dest_action) {
				err = -ENOMEM;
				goto free_actions;
			}
    ...
}

Each of these can return NULL:

  mlx5hws_action_create_dest_table_num(): allocation failure or STC pool
  exhaustion

  mlx5hws_action_create_dest_match_range(): invalid range parameters, or
  allocation, definer or STC failure

  mlx5_fs_get_dest_action_sampler(): GFP_ATOMIC allocation or
  __xa_insert() failure, or failure to create the sampler action

The free_actions path then calls teardown on every counted entry:

mlx5_fs_destroy_fs_actions()
  mlx5_fs_destroy_fs_action()
    mlx5hws_action_get_type(fs_action->action)
      return action->type;   <-- NULL dereference

The other patch in this series, "net/mlx5: DR, Fix out-of-bounds write
when sync to HW fails", only touches sws/dr_icm_pool.c and does not fix
this.

Could dest_action be checked before it goes into fs_actions[]?
Alternatively, mlx5_fs_destroy_fs_actions() could skip NULL entries.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118173227.1957670-1-tariqt%40nvidia.com
Thread (7 messages) 7 messages, 4 authors, last reply 19h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help