Skip to content

Commit 8e715cd

Browse files
mosheshemesh2Saeed Mahameed
authored andcommitted
net/mlx5: Set command entry semaphore up once got index free
Avoid a race where command work handler may fail to allocate command entry index, by holding the command semaphore down till command entry index is being freed. Fixes: 410bd75 ("net/mlx5: Add retry mechanism to the command entry index allocation") Signed-off-by: Moshe Shemesh <[email protected]> Reviewed-by: Eran Ben Elisha <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 07f6dc4 commit 8e715cd

File tree

1 file changed

+6
-9
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+6
-9
lines changed

drivers/net/ethernet/mellanox/mlx5/core/cmd.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ static void cmd_ent_put(struct mlx5_cmd_work_ent *ent)
148148
if (!refcount_dec_and_test(&ent->refcnt))
149149
return;
150150

151-
if (ent->idx >= 0)
152-
cmd_free_index(ent->cmd, ent->idx);
151+
if (ent->idx >= 0) {
152+
struct mlx5_cmd *cmd = ent->cmd;
153+
154+
cmd_free_index(cmd, ent->idx);
155+
up(ent->page_queue ? &cmd->pages_sem : &cmd->sem);
156+
}
153157

154158
cmd_free_ent(ent);
155159
}
@@ -1602,8 +1606,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force
16021606
vector = vec & 0xffffffff;
16031607
for (i = 0; i < (1 << cmd->log_sz); i++) {
16041608
if (test_bit(i, &vector)) {
1605-
struct semaphore *sem;
1606-
16071609
ent = cmd->ent_arr[i];
16081610

16091611
/* if we already completed the command, ignore it */
@@ -1626,10 +1628,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force
16261628
dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR)
16271629
cmd_ent_put(ent);
16281630

1629-
if (ent->page_queue)
1630-
sem = &cmd->pages_sem;
1631-
else
1632-
sem = &cmd->sem;
16331631
ent->ts2 = ktime_get_ns();
16341632
memcpy(ent->out->first.data, ent->lay->out, sizeof(ent->lay->out));
16351633
dump_command(dev, ent, 0);
@@ -1683,7 +1681,6 @@ static void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec, bool force
16831681
*/
16841682
complete(&ent->done);
16851683
}
1686-
up(sem);
16871684
}
16881685
}
16891686
}

0 commit comments

Comments
 (0)