Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern - DIAGNOSTIC: check for leaked kernel_lock in mi_sw...
details: https://anonhg.NetBSD.org/src/rev/13f8f5572377
branches: trunk
changeset: 848252:13f8f5572377
user: ad <ad%NetBSD.org@localhost>
date: Wed Jan 22 13:19:33 2020 +0000
description:
- DIAGNOSTIC: check for leaked kernel_lock in mi_switch().
- Now that ci_biglock_wanted is set later, explicitly disable preemption
while acquiring kernel_lock. It was blocked in a roundabout way
previously.
Reported-by: syzbot+43111d810160fb4b978b%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+f5b871bd00089bf97286%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+cd1f15eee5b1b6d20078%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+fb945a331dabd0b6ba9e%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+53a0c2342b361db25240%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+552222a952814dede7d1%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+c7104a72172b0f9093a4%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+efbd30c6ca0f7d8440e8%syzkaller.appspotmail.com@localhost
Reported-by: syzbot+330a421bd46794d8b750%syzkaller.appspotmail.com@localhost
diffstat:
sys/kern/kern_lock.c | 14 ++++++++++----
sys/kern/kern_synch.c | 8 ++++----
2 files changed, 14 insertions(+), 8 deletions(-)
diffs (79 lines):
diff -r 0cdc55781c2f -r 13f8f5572377 sys/kern/kern_lock.c
--- a/sys/kern/kern_lock.c Wed Jan 22 12:44:54 2020 +0000
+++ b/sys/kern/kern_lock.c Wed Jan 22 13:19:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_lock.c,v 1.165 2020/01/17 20:26:22 ad Exp $ */
+/* $NetBSD: kern_lock.c,v 1.166 2020/01/22 13:19:33 ad Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008, 2009, 2020 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.165 2020/01/17 20:26:22 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.166 2020/01/22 13:19:33 ad Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@@ -212,9 +212,10 @@
owant = ci->ci_biglock_wanted;
/*
- * Spin until we acquire the lock. Once we have it, record the
- * time spent with lockstat.
+ * Stay pinned to the CPU and spin until we acquire the lock. Once
+ * we have it, record the time spent with lockstat.
*/
+ l->l_nopreempt++;
LOCKSTAT_ENTER(lsflag);
LOCKSTAT_START_TIMER(lsflag, spintime);
@@ -238,6 +239,11 @@
s = splvm();
} while (!__cpu_simple_lock_try(kernel_lock));
+ /*
+ * Got it; not re-enable preemption, although we now can't do a
+ * preemption as kernel_lock is held!
+ */
+ l->l_nopreempt--;
ci->ci_biglock_count = nlocks;
l->l_blcnt = nlocks;
splx(s);
diff -r 0cdc55781c2f -r 13f8f5572377 sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c Wed Jan 22 12:44:54 2020 +0000
+++ b/sys/kern/kern_synch.c Wed Jan 22 13:19:33 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_synch.c,v 1.336 2020/01/09 16:35:03 ad Exp $ */
+/* $NetBSD: kern_synch.c,v 1.337 2020/01/22 13:19:33 ad Exp $ */
/*-
* Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009, 2019
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.336 2020/01/09 16:35:03 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.337 2020/01/22 13:19:33 ad Exp $");
#include "opt_kstack.h"
#include "opt_dtrace.h"
@@ -353,8 +353,7 @@
break;
}
s = splsched();
- if (__predict_false(l->l_blcnt != 0 ||
- curcpu()->ci_biglock_wanted != NULL)) {
+ if (__predict_false(l->l_blcnt != 0)) {
/* Hold or want kernel_lock, code is not MT safe. */
splx(s);
if ((dop & DOPREEMPT_COUNTED) == 0) {
@@ -531,6 +530,7 @@
KASSERT(lwp_locked(l, NULL));
KASSERT(kpreempt_disabled());
KASSERT(mutex_owned(curcpu()->ci_schedstate.spc_mutex));
+ KASSERTMSG(l->l_blcnt == 0, "kernel_lock leaked");
kstack_check_magic(l);
Home |
Main Index |
Thread Index |
Old Index