It makes sense to have witness(4) on uniprocessor systems, too. Lock-order
violations are not an MP-only thing. Since UP kernels do not have the kernel
lock, wrap the code in appropriate ifdefs.
---
sys/kern/subr_witness.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c
index 2f785d3a3d0..761494cdbea 100644
--- a/sys/kern/subr_witness.c
+++ b/sys/kern/subr_witness.c
@@ -94,7 +94,9 @@ __FBSDID("$FreeBSD: head/sys/kern/subr_witness.c 313261
2017-02-05 02:27:04Z mar
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
+#ifdef MULTIPROCESSOR
#include <sys/mplock.h>
+#endif
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/sched.h>
@@ -571,6 +573,20 @@ witness_init(struct lock_object *lock, const struct
lock_type *type)
lock->lo_witness = enroll(type, lock->lo_name, class);
}
+#ifdef MULTIPROCESSOR
+static inline int
+is_kernel_lock(const struct lock_object *lock)
+{
+ return (lock == &kernel_lock.mpl_lock_obj);
+}
+#else
+static inline int
+is_kernel_lock(const struct lock_object *lock)
+{
+ return (0);
+}
+#endif
+
#ifdef DDB
static void
witness_ddb_compute_levels(void)
@@ -924,7 +940,7 @@ witness_checkorder(struct lock_object *lock, int flags,
const char *file,
* lock, then skip it.
*/
if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0 &&
- lock == &kernel_lock.mpl_lock_obj)
+ is_kernel_lock(lock))
continue;
/*
@@ -932,7 +948,7 @@ witness_checkorder(struct lock_object *lock, int flags,
const char *file,
* is Giant, then skip it.
*/
if ((lock->lo_flags & LO_SLEEPABLE) != 0 &&
- lock1->li_lock == &kernel_lock.mpl_lock_obj)
+ is_kernel_lock(lock1->li_lock))
continue;
/*
@@ -950,7 +966,7 @@ witness_checkorder(struct lock_object *lock, int flags,
const char *file,
* lock, then treat it as a reversal.
*/
if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0 &&
- lock == &kernel_lock.mpl_lock_obj)
+ is_kernel_lock(lock))
goto reversal;
/*
@@ -994,7 +1010,7 @@ witness_checkorder(struct lock_object *lock, int flags,
const char *file,
printf("lock order reversal: "
"(sleepable after non-sleepable)\n");
else if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0
- && lock == &kernel_lock.mpl_lock_obj)
+ && is_kernel_lock(lock))
printf("lock order reversal: "
"(Giant after non-sleepable)\n");
else
@@ -1087,7 +1103,7 @@ witness_checkorder(struct lock_object *lock, int flags,
const char *file,
* always come before Giant.
*/
if (flags & LOP_NEWORDER &&
- !(plock->li_lock == &kernel_lock.mpl_lock_obj &&
+ !(is_kernel_lock(plock->li_lock) &&
(lock->lo_flags & LO_SLEEPABLE) != 0))
itismychild(plock->li_lock->lo_witness, w);
out:
@@ -1407,7 +1423,7 @@ witness_warn(int flags, struct lock_object *lock, const
char *fmt, ...)
if (lock1->li_lock == lock)
continue;
if (flags & WARN_KERNELOK &&
- lock1->li_lock == &kernel_lock.mpl_lock_obj)
+ is_kernel_lock(lock1->li_lock))
continue;
if (flags & WARN_SLEEPOK &&
(lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0)
--
2.17.1