svn commit: r197453 - in stable/7/sys: . contrib/pf kern

Attilio Rao attilio at FreeBSD.org
Thu Sep 24 09:08:23 UTC 2009


Author: attilio
Date: Thu Sep 24 09:08:22 2009
New Revision: 197453
URL: http://svn.freebsd.org/changeset/base/197453

Log:
  MFC r197223:
  Fix a deadlock in sched_switch_migrate given by the runqueues being not
  locked at once together when doing the switch.

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/kern/sched_ule.c

Modified: stable/7/sys/kern/sched_ule.c
==============================================================================
--- stable/7/sys/kern/sched_ule.c	Thu Sep 24 08:35:17 2009	(r197452)
+++ stable/7/sys/kern/sched_ule.c	Thu Sep 24 09:08:22 2009	(r197453)
@@ -1822,18 +1822,24 @@ sched_switch_migrate(struct tdq *tdq, st
 	 */
 	spinlock_enter();
 	thread_block_switch(td);	/* This releases the lock on tdq. */
-	TDQ_LOCK(tdn);
-	tdq_add(tdn, td, flags);
-	tdq_notify(td->td_sched);
-	/*
-	 * After we unlock tdn the new cpu still can't switch into this
-	 * thread until we've unblocked it in cpu_switch().  The lock
-	 * pointers may match in the case of HTT cores.  Don't unlock here
-	 * or we can deadlock when the other CPU runs the IPI handler.
+
+	/*
+	 * Acquire both run-queue locks before placing the thread on the new
+	 * run-queue to avoid deadlocks created by placing a thread with a
+	 * blocked lock on the run-queue of a remote processor.  The deadlock
+	 * occurs when a third processor attempts to lock the two queues in
+	 * question while the target processor is spinning with its own
+	 * run-queue lock held while waiting for the blocked lock to clear.
 	 */
-	if (TDQ_LOCKPTR(tdn) != TDQ_LOCKPTR(tdq)) {
-		TDQ_UNLOCK(tdn);
+	if (TDQ_LOCKPTR(tdn) == TDQ_LOCKPTR(tdq)) {
 		TDQ_LOCK(tdq);
+		tdq_add(tdn, td, flags);
+		tdq_notify(td->td_sched);
+	} else {
+		tdq_lock_pair(tdn, tdq);
+		tdq_add(tdn, td, flags);
+		tdq_notify(td->td_sched);
+		TDQ_UNLOCK(tdn);
 	}
 	spinlock_exit();
 #endif


More information about the svn-src-all mailing list