From 0ec9835421b7844e9244a78ce3d27bf21984963e Mon Sep 17 00:00:00 2001 From: cperciva Date: Sat, 27 Feb 2010 10:55:43 +0000 Subject: [PATCH] MFC r197223: Fix a deadlock in the ULE scheduler. Approved by: so (cperciva) Errata: FreeBSD-EN-10:02.sched_ule git-svn-id: svn://svn.freebsd.org/base/releng/7.2@204409 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- UPDATING | 3 +++ sys/conf/newvers.sh | 2 +- sys/kern/sched_ule.c | 24 +++++++++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/UPDATING b/UPDATING index 4bbe4308..f6e94bf8 100644 --- a/UPDATING +++ b/UPDATING @@ -8,6 +8,9 @@ Items affecting the ports and packages system can be found in /usr/ports/UPDATING. Please read that file before running portupgrade. +20100227: p7 FreeBSD-EN-10:02.sched_ule + Fix a deadlock in the ULE scheduler. + 20100106: p6 FreeBSD-SA-10:01.bind, FreeBSD-SA-10:02.ntpd, FreeBSD-SA-10:03.zfs Fix BIND named(8) cache poisoning with DNSSEC validation. diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh index 87371582..80aa476f 100644 --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -32,7 +32,7 @@ TYPE="FreeBSD" REVISION="7.2" -BRANCH="RELEASE-p6" +BRANCH="RELEASE-p7" if [ "X${BRANCH_OVERRIDE}" != "X" ]; then BRANCH=${BRANCH_OVERRIDE} fi diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index a9d4e447..0340a35c 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -1822,18 +1822,24 @@ sched_switch_migrate(struct tdq *tdq, struct thread *td, int flags) */ 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 -- 2.45.0