summaryrefslogtreecommitdiff
path: root/sys/arch/amd64
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2013-06-02 01:55:53 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2013-06-02 01:55:53 +0000
commit8548005f6f3ae2fb7743ffb9cef7ba71af182b0c (patch)
tree8b1ac8d3ae2fa3b754b0912a1408776350283751 /sys/arch/amd64
parent790bcce67ee4aaa4961fb54a5d22b8369c8b6e1f (diff)
To prevent lock ordering problems with the kernel lock, we need to make sure
we block all interrupts that can grab the kernel lock. The simplest way to achieve this is to make sure mutexes always raise the ipl to the highest level that has interrupts that grab the kernel lock. This will allow us to have "mpsafe" interrupt handlers at lower priority levels. No change for non-MULTIPROCESSOR kernels. discussed with many ok mpi@, tedu@
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r--sys/arch/amd64/amd64/mutex.S4
-rw-r--r--sys/arch/amd64/include/mutex.h22
2 files changed, 22 insertions, 4 deletions
diff --git a/sys/arch/amd64/amd64/mutex.S b/sys/arch/amd64/amd64/mutex.S
index 4e12d8c96e6..052fab2508f 100644
--- a/sys/arch/amd64/amd64/mutex.S
+++ b/sys/arch/amd64/amd64/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.8 2010/09/24 13:21:30 matthew Exp $ */
+/* $OpenBSD: mutex.S,v 1.9 2013/06/02 01:55:52 kettenis Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -38,7 +38,7 @@
* Yeah, we don't really need to implement mtx_init here, but let's keep
* all the functions in the same place.
*/
-ENTRY(mtx_init)
+ENTRY(__mtx_init)
movl %esi, MTX_WANTIPL(%rdi)
movl $0, MTX_OLDIPL(%rdi)
movq $0, MTX_OWNER(%rdi)
diff --git a/sys/arch/amd64/include/mutex.h b/sys/arch/amd64/include/mutex.h
index 6ce401c8f34..9866051db66 100644
--- a/sys/arch/amd64/include/mutex.h
+++ b/sys/arch/amd64/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.4 2011/03/23 16:54:34 pirofti Exp $ */
+/* $OpenBSD: mutex.h,v 1.5 2013/06/02 01:55:52 kettenis Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -33,7 +33,25 @@ struct mutex {
__volatile void *mtx_owner;
};
-#define MUTEX_INITIALIZER(ipl) { (ipl), 0, NULL }
+
+/*
+ * To prevent lock ordering problems with the kernel lock, we need to
+ * make sure we block all interrupts that can grab the kernel lock.
+ * The simplest way to achieve this is to make sure mutexes always
+ * raise the interrupt ptiority level to the highest level that has
+ * interrupts that grab the kernel lock.
+ */
+#ifdef MULTIPROCESSOR
+#define __MUTEX_IPL(ipl) \
+ (((ipl) > IPL_NONE && (ipl) < IPL_AUDIO) ? IPL_AUDIO : (ipl))
+#else
+#define __MUTEX_IPL(ipl) (ipl)
+#endif
+
+#define MUTEX_INITIALIZER(ipl) { __MUTEX_IPL((ipl)), 0, NULL }
+
+void __mtx_init(struct mutex *, int);
+#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#define MUTEX_ASSERT_LOCKED(mtx) do { \
if ((mtx)->mtx_owner != curcpu()) \