From owner-svn-src-stable@FreeBSD.ORG Tue Sep 15 19:14:25 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A9FCB106566C; Tue, 15 Sep 2009 19:14:25 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7F24D8FC1D; Tue, 15 Sep 2009 19:14:25 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n8FJEPXs000118; Tue, 15 Sep 2009 19:14:25 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n8FJEPGw000116; Tue, 15 Sep 2009 19:14:25 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <200909151914.n8FJEPGw000116@svn.freebsd.org> From: Attilio Rao Date: Tue, 15 Sep 2009 19:14:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r197226 - stable/8/sys/kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Sep 2009 19:14:25 -0000 Author: attilio Date: Tue Sep 15 19:14:25 2009 New Revision: 197226 URL: http://svn.freebsd.org/changeset/base/197226 Log: MFC r197223: Fix sched_switch_migrate() by assuming locks cannot be shared and a deadlock between 3 different threads by acquiring both runqueue locks when doing the migration. Please note that this is a special condition as we want this fix in before RC1 as we assume it is critical and so it has been handled as an instant-merge. For the STABLE_7 branch, 1 week before the MFC is assumed. Approved by: re (kib) Modified: stable/8/sys/kern/sched_ule.c Modified: stable/8/sys/kern/sched_ule.c ============================================================================== --- stable/8/sys/kern/sched_ule.c Tue Sep 15 18:39:27 2009 (r197225) +++ stable/8/sys/kern/sched_ule.c Tue Sep 15 19:14:25 2009 (r197226) @@ -1749,19 +1749,19 @@ 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(tdn, td); + /* - * 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); - TDQ_LOCK(tdq); - } + tdq_lock_pair(tdn, tdq); + tdq_add(tdn, td, flags); + tdq_notify(tdn, td); + TDQ_UNLOCK(tdn); spinlock_exit(); #endif return (TDQ_LOCKPTR(tdn));