diff options
author | 2018-03-27 08:32:29 +0000 | |
---|---|---|
committer | 2018-03-27 08:32:29 +0000 | |
commit | 1bb039c847b6dea01b519a8eea6248ec332aedae (patch) | |
tree | 3db9a7923de3356b51be2a605881eef15f506df2 | |
parent | Use a goto to merge multiple error blocks in sosplice(). (diff) | |
download | wireguard-openbsd-1bb039c847b6dea01b519a8eea6248ec332aedae.tar.xz wireguard-openbsd-1bb039c847b6dea01b519a8eea6248ec332aedae.zip |
Try harder to execute code protected by mutexes after entering ddb(4).
Should prevent a panic after panic reported by mlarkin@.
ok mlarkin@, visa@
-rw-r--r-- | sys/kern/kern_lock.c | 14 | ||||
-rw-r--r-- | sys/sys/mutex.h | 6 |
2 files changed, 16 insertions, 4 deletions
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index f108c7393e9..01e0a567b82 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_lock.c,v 1.60 2018/03/20 15:45:32 mpi Exp $ */ +/* $OpenBSD: kern_lock.c,v 1.61 2018/03/27 08:32:29 mpi Exp $ */ /* * Copyright (c) 2017 Visa Hankala @@ -262,6 +262,10 @@ __mtx_enter(struct mutex *mtx) int nticks = __mp_lock_spinout; #endif + /* Avoid deadlocks after panic or in DDB */ + if (panicstr || db_active) + return; + while (__mtx_enter_try(mtx) == 0) { CPU_BUSY_CYCLE(); @@ -310,6 +314,10 @@ __mtx_enter(struct mutex *mtx) { struct cpu_info *ci = curcpu(); + /* Avoid deadlocks after panic or in DDB */ + if (panicstr || db_active) + return; + #ifdef DIAGNOSTIC if (__predict_false(mtx->mtx_owner == ci)) panic("mtx %p: locking against myself", mtx); @@ -338,6 +346,10 @@ __mtx_leave(struct mutex *mtx) { int s; + /* Avoid deadlocks after panic or in DDB */ + if (panicstr || db_active) + return; + MUTEX_ASSERT_LOCKED(mtx); #ifdef DIAGNOSTIC diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h index f64d6da634f..3cc61b39a8a 100644 --- a/sys/sys/mutex.h +++ b/sys/sys/mutex.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.h,v 1.13 2018/02/10 12:53:22 mpi Exp $ */ +/* $OpenBSD: mutex.h,v 1.14 2018/03/27 08:32:29 mpi Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -75,12 +75,12 @@ void __mtx_init(struct mutex *, int); #ifdef DIAGNOSTIC #define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_owner != curcpu()) \ + if (((mtx)->mtx_owner != curcpu()) && !(panicstr || db_active)) \ panic("mutex %p not held in %s", (mtx), __func__); \ } while (0) #define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_owner == curcpu()) \ + if (((mtx)->mtx_owner == curcpu()) && !(panicstr || db_active)) \ panic("mutex %p held in %s", (mtx), __func__); \ } while (0) #else |