From: Eugenia Emantayev Date: Sun, 18 Mar 2012 04:32:08 +0000 (+0000) Subject: mlx4_core: fix race on comm channel X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=58a3de0592454c216c68427fa3c31a34823f5115;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git mlx4_core: fix race on comm channel Prevent race condition between commands on comm channel. Happened while unloading the driver when switching from event to polling mode. VF got completion on the last command before switching to polling mode, but toggle was not changed. After the fix - VF will not write the next command before toggle is updated. Signed-off-by: Eugenia Emantayev Signed-off-by: David S. Miller --- diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c index 48d5c48d7ce..773c70ea3f6 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c @@ -239,6 +239,7 @@ static int mlx4_comm_cmd_wait(struct mlx4_dev *dev, u8 op, { struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd; struct mlx4_cmd_context *context; + unsigned long end; int err = 0; down(&cmd->event_sem); @@ -268,6 +269,14 @@ static int mlx4_comm_cmd_wait(struct mlx4_dev *dev, u8 op, } out: + /* wait for comm channel ready + * this is necessary for prevention the race + * when switching between event to polling mode + */ + end = msecs_to_jiffies(timeout) + jiffies; + while (comm_pending(dev) && time_before(jiffies, end)) + cond_resched(); + spin_lock(&cmd->context_lock); context->next = cmd->free_head; cmd->free_head = context - cmd->context;