netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net V1] mlx4_core: fix race on comm channel
@ 2012-03-18 14:32 Yevgeny Petrilin
  2012-03-19 22:06 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Yevgeny Petrilin @ 2012-03-18 14:32 UTC (permalink / raw)
  To: davem; +Cc: netdev, yevgenyp, eugenia

From: Eugenia Emantayev <eugenia@mellanox.co.il>


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 <eugenia@mellanox.co.il>
---
Diff from V0:
 Fixed comments style

 drivers/net/ethernet/mellanox/mlx4/cmd.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index eaf09d4..6037d36 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;
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-19 22:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-18 14:32 [PATCH net V1] mlx4_core: fix race on comm channel Yevgeny Petrilin
2012-03-19 22:06 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).