summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorck142721 <none@none>2008-05-12 15:28:50 -0700
committerck142721 <none@none>2008-05-12 15:28:50 -0700
commit7f30f4919f1fad98a5e3032e69aedcbac81d59b4 (patch)
tree508b6338d3561eee6bc7cc23f6d92ce31a21bd19 /usr/src
parent479ac37569625bae44ffb80071d4bc865fc710ed (diff)
downloadillumos-gate-7f30f4919f1fad98a5e3032e69aedcbac81d59b4.tar.gz
6691488 Solaris should warn about mis-aligned mutexes
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/uts/common/os/mutex.c32
-rw-r--r--usr/src/uts/intel/sys/mutex_impl.h3
2 files changed, 35 insertions, 0 deletions
diff --git a/usr/src/uts/common/os/mutex.c b/usr/src/uts/common/os/mutex.c
index 762ec2c184..873b91f6f4 100644
--- a/usr/src/uts/common/os/mutex.c
+++ b/usr/src/uts/common/os/mutex.c
@@ -577,7 +577,39 @@ mutex_init(kmutex_t *mp, char *name, kmutex_type_t type, void *ibc)
LOCK_INIT_HELD(&lp->m_spin.m_dummylock);
lp->m_spin.m_minspl = (int)(intptr_t)ibc;
} else {
+#ifdef MUTEX_ALIGN
+ static int misalign_cnt = 0;
+
+ if (((uintptr_t)lp & (uintptr_t)(MUTEX_ALIGN - 1)) &&
+ (misalign_cnt < MUTEX_ALIGN_WARNINGS)) {
+ /*
+ * The mutex is not aligned and may cross a cache line.
+ * This is not supported and may cause a panic.
+ * Show a warning that the mutex is not aligned
+ * and attempt to identify the origin.
+ * Unaligned mutexes are not (supposed to be)
+ * possible on SPARC.
+ */
+ char *funcname;
+ ulong_t offset = 0;
+
+ funcname = modgetsymname((uintptr_t)caller(), &offset);
+ cmn_err(CE_WARN, "mutex_init: %p is not %d byte "
+ "aligned; caller %s+%lx in module %s. "
+ "This is unsupported and may cause a panic. "
+ "Please report this to the kernel module supplier.",
+ lp, MUTEX_ALIGN,
+ funcname ? funcname : "unknown", offset,
+ mod_containing_pc(caller()));
+ misalign_cnt++;
+ if (misalign_cnt >= MUTEX_ALIGN_WARNINGS) {
+ cmn_err(CE_WARN, "mutex_init: further unaligned"
+ " mutex warnings will be suppressed.");
+ }
+ }
+#endif /* MUTEX_ALIGN */
ASSERT(type != MUTEX_SPIN);
+
MUTEX_SET_TYPE(lp, MUTEX_ADAPTIVE);
MUTEX_CLEAR_LOCK_AND_WAITERS(lp);
}
diff --git a/usr/src/uts/intel/sys/mutex_impl.h b/usr/src/uts/intel/sys/mutex_impl.h
index c8cff15c2a..843c50b19d 100644
--- a/usr/src/uts/intel/sys/mutex_impl.h
+++ b/usr/src/uts/intel/sys/mutex_impl.h
@@ -73,6 +73,9 @@ typedef union mutex_impl {
#define m_owner m_adaptive._m_owner
+#define MUTEX_ALIGN _LONG_ALIGNMENT
+#define MUTEX_ALIGN_WARNINGS 10 /* num of warnings to issue */
+
#define MUTEX_WAITERS 0x1
#define MUTEX_DEAD 0x6
#define MUTEX_THREAD (-0x8)