Fix lockuninit

Nuno Antunes nuno.antunes at gmail.com
Sun Dec 30 08:04:01 PST 2007


lockuninit was acquiring the spinlock embedded in struct lock, thus
incrementing the per-thread spinlock count. However, spin_uninit does
not decrement the count, resulting in a panic when trying to sleep
("lwkt_switch: still holding %d exclusive spinlocks!"). From now on,
require that the caller already holds the struct lock in question so
that lockuninit can rely on it being the sole owner of the lock.

Lots of help from: corecode@, aggelos

Comment from Aggelos: "That's what you get when commiting code without
any in-tree users."

diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index c945ef5..5ae8c30 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -518,12 +518,18 @@ lockreinit(struct lock *lkp, char *wmesg, int
timo, int flags)
 	spin_unlock_wr(&lkp->lk_spinlock);
 }

+/*
+ * Requires that the caller is the exclusive owner of this lock.
+ */
 void
 lockuninit(struct lock *l)
 {
-	spin_lock_wr(&l->lk_spinlock);
+	/*
+	 * At this point we should have removed all the references to this lock
+	 * so there can't be anyone waiting on it.
+	 */
 	KKASSERT(l->lk_waitcount == 0);
-	l->lk_wmesg = "BUG";
+
 	spin_uninit(&l->lk_spinlock);
 }





More information about the Submit mailing list