diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-03-27 08:32:30 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2018-03-27 08:32:30 +0000 |
commit | fefc9a1fda9d3eb539e7bd74d437fdf3c1c6c0de (patch) | |
tree | b2e8819357afbe6c9800becbe4a2ef05747a2072 | |
parent | 3b253fe05a77c304d42deb92b622a8e45e7d2c2e (diff) |
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 |