Skip to content

Commit 410bd75

Browse files
eranbe-nbuSaeed Mahameed
authored andcommitted
net/mlx5: Add retry mechanism to the command entry index allocation
It is possible that new command entry index allocation will temporarily fail. The new command holds the semaphore, so it means that a free entry should be ready soon. Add one second retry mechanism before returning an error. Patch "net/mlx5: Avoid possible free of command entry while timeout comp handler" increase the possibility to bump into this temporarily failure as it delays the entry index release for non-callback commands. Fixes: e126ba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Signed-off-by: Eran Ben Elisha <eranbe@nvidia.com> Reviewed-by: Moshe Shemesh <moshe@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent 1d5558b commit 410bd75

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

  • drivers/net/ethernet/mellanox/mlx5/core

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,25 @@ static bool opcode_allowed(struct mlx5_cmd *cmd, u16 opcode)
883883
return cmd->allowed_opcode == opcode;
884884
}
885885

886+
static int cmd_alloc_index_retry(struct mlx5_cmd *cmd)
887+
{
888+
unsigned long alloc_end = jiffies + msecs_to_jiffies(1000);
889+
int idx;
890+
891+
retry:
892+
idx = cmd_alloc_index(cmd);
893+
if (idx < 0 && time_before(jiffies, alloc_end)) {
894+
/* Index allocation can fail on heavy load of commands. This is a temporary
895+
* situation as the current command already holds the semaphore, meaning that
896+
* another command completion is being handled and it is expected to release
897+
* the entry index soon.
898+
*/
899+
cpu_relax();
900+
goto retry;
901+
}
902+
return idx;
903+
}
904+
886905
static void cmd_work_handler(struct work_struct *work)
887906
{
888907
struct mlx5_cmd_work_ent *ent = container_of(work, struct mlx5_cmd_work_ent, work);
@@ -900,7 +919,7 @@ static void cmd_work_handler(struct work_struct *work)
900919
sem = ent->page_queue ? &cmd->pages_sem : &cmd->sem;
901920
down(sem);
902921
if (!ent->page_queue) {
903-
alloc_ret = cmd_alloc_index(cmd);
922+
alloc_ret = cmd_alloc_index_retry(cmd);
904923
if (alloc_ret < 0) {
905924
mlx5_core_err_rl(dev, "failed to allocate command entry\n");
906925
if (ent->callback) {

0 commit comments

Comments
 (0)