[openib-general] [PATCH] fix race condition in mthca event code

Sean Hefty mshefty at ichips.intel.com
Thu Dec 9 10:43:17 PST 2004


This patch fixed my problem hitting the BUG_ON code in mthca_cmd, line 328.  It
moves releasing the semaphore to after freeing the event entry.

- Sean

Index: hw/mthca/mthca_cmd.c
===================================================================
--- hw/mthca/mthca_cmd.c	(revision 1316)
+++ hw/mthca/mthca_cmd.c	(working copy)
@@ -293,12 +293,6 @@
 	complete(&context->done);
 }
 
-void mthca_cmd_complete(struct mthca_dev *dev, int ncomp)
-{
-	while (ncomp--)
-		up(&dev->cmd.event_sem);
-}
-
 static void event_timeout(unsigned long context_ptr)
 {
 	struct mthca_cmd_context *context =
@@ -362,7 +356,7 @@
 	context->next = dev->cmd.free_head;
 	dev->cmd.free_head = context - dev->cmd.context;
 	spin_unlock(&dev->cmd.context_lock);
-
+	up(&dev->cmd.event_sem);
 	return err;
 }
 
Index: hw/mthca/mthca_eq.c
===================================================================
--- hw/mthca/mthca_eq.c	(revision 1316)
+++ hw/mthca/mthca_eq.c	(working copy)
@@ -219,7 +219,6 @@
 	struct mthca_eqe *eqe;
 	int disarm_cqn;
 	int work = 0;
-	int ncmd = 0;
 
 	while (1) {
 		if (!next_eqe_sw(eq))
@@ -275,7 +274,6 @@
 					be16_to_cpu(eqe->event.cmd.token),
 					eqe->event.cmd.status,
 					be64_to_cpu(eqe->event.cmd.out_param));
-			++ncmd;
 			break;
 
 		case MTHCA_EVENT_TYPE_PORT_CHANGE:
@@ -314,9 +312,6 @@
 		set_eq_ci(dev, eq->eqn, eq->cons_index);
 	}
 
-	if (ncmd)
-		mthca_cmd_complete(dev, ncmd);
-
 	eq_req_not(dev, eq->eqn);
 }
 
Index: hw/mthca/mthca_cmd.h
===================================================================
--- hw/mthca/mthca_cmd.h	(revision 1316)
+++ hw/mthca/mthca_cmd.h	(working copy)
@@ -205,7 +205,6 @@
 void mthca_cmd_use_polling(struct mthca_dev *dev);
 void mthca_cmd_event(struct mthca_dev *dev, u16 token,
 		     u8  status, u64 out_param);
-void mthca_cmd_complete(struct mthca_dev *dev, int ncomp);
 
 int mthca_SYS_EN(struct mthca_dev *dev, u8 *status);
 int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status);



More information about the general mailing list