summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2017-07-16 22:48:38 +0000
committerguenther <guenther@openbsd.org>2017-07-16 22:48:38 +0000
commit9856cad4bb3ce7f15871dcd139ecc536da111ffb (patch)
tree24dd4088eed857a35812f6b601a9d893038af6ee
parentAdd comments to the definitions of iwm(4) driver-private flags. (diff)
downloadwireguard-openbsd-9856cad4bb3ce7f15871dcd139ecc536da111ffb.tar.xz
wireguard-openbsd-9856cad4bb3ce7f15871dcd139ecc536da111ffb.zip
Add WITNESS support
ok visa@ kettenis@
-rw-r--r--sys/arch/hppa/hppa/db_interface.c25
-rw-r--r--sys/arch/hppa/hppa/lock_machdep.c44
-rw-r--r--sys/arch/hppa/include/mplock.h44
3 files changed, 96 insertions, 17 deletions
diff --git a/sys/arch/hppa/hppa/db_interface.c b/sys/arch/hppa/hppa/db_interface.c
index c7eabf3ba7e..44d8afaa222 100644
--- a/sys/arch/hppa/hppa/db_interface.c
+++ b/sys/arch/hppa/hppa/db_interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_interface.c,v 1.40 2017/05/30 15:39:04 mpi Exp $ */
+/* $OpenBSD: db_interface.c,v 1.41 2017/07/16 22:48:38 guenther Exp $ */
/*
* Copyright (c) 1999-2003 Michael Shalayeff
@@ -311,3 +311,26 @@ db_stack_trace_print(db_expr_t addr, int have_addr, db_expr_t count,
(*pr)(":\n");
}
}
+
+void
+db_save_stack_trace(struct db_stack_trace *st)
+{
+ register_t *fp, pc, rp;
+ int i;
+
+ fp = (register_t *)__builtin_frame_address(0);
+ pc = 0;
+ rp = fp[-5];
+
+ for (i = 0; i < DB_STACK_TRACE_MAX; i++) {
+ st->st_pc[st->st_count++] = rp;
+
+ /* next frame */
+ pc = rp;
+ if (!fp[0] || USERMODE(pc))
+ break;
+
+ rp = fp[-5];
+ fp = (register_t *)fp[0];
+ }
+}
diff --git a/sys/arch/hppa/hppa/lock_machdep.c b/sys/arch/hppa/hppa/lock_machdep.c
index 972b5bb8886..605a54f3420 100644
--- a/sys/arch/hppa/hppa/lock_machdep.c
+++ b/sys/arch/hppa/hppa/lock_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock_machdep.c,v 1.11 2017/05/29 14:19:49 mpi Exp $ */
+/* $OpenBSD: lock_machdep.c,v 1.12 2017/07/16 22:48:38 guenther Exp $ */
/*
* Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -18,6 +18,8 @@
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/witness.h>
+#include <sys/_lock.h>
#include <machine/atomic.h>
#include <machine/intr.h>
@@ -54,7 +56,7 @@ __cpu_cas(struct __mp_lock *mpl, volatile unsigned long *addr,
}
void
-__mp_lock_init(struct __mp_lock *lock)
+___mp_lock_init(struct __mp_lock *lock)
{
lock->mpl_lock[0] = MPL_UNLOCKED;
lock->mpl_lock[1] = MPL_UNLOCKED;
@@ -93,10 +95,16 @@ __mp_lock_spin(struct __mp_lock *mpl)
}
void
-__mp_lock(struct __mp_lock *mpl)
+___mp_lock(struct __mp_lock *mpl LOCK_FL_VARS)
{
int s;
+#ifdef WITNESS
+ if (!__mp_lock_held(mpl))
+ WITNESS_CHECKORDER(&mpl->mpl_lock_obj,
+ LOP_EXCLUSIVE | LOP_NEWORDER, file, line, NULL);
+#endif
+
/*
* Please notice that mpl_count gets incremented twice for the
* first lock. This is on purpose. The way we release the lock
@@ -124,10 +132,12 @@ __mp_lock(struct __mp_lock *mpl)
__mp_lock_spin(mpl);
}
+
+ WITNESS_LOCK(&mpl->mpl_lock_obj, LOP_EXCLUSIVE, file, line);
}
void
-__mp_unlock(struct __mp_lock *mpl)
+___mp_unlock(struct __mp_lock *mpl LOCK_FL_VARS)
{
int s;
@@ -139,6 +149,8 @@ __mp_unlock(struct __mp_lock *mpl)
}
#endif
+ WITNESS_UNLOCK(&mpl->mpl_lock_obj, LOP_EXCLUSIVE, file, line);
+
s = hppa_intr_disable();
if (--mpl->mpl_count == 1) {
mpl->mpl_cpu = NULL;
@@ -149,10 +161,13 @@ __mp_unlock(struct __mp_lock *mpl)
}
int
-__mp_release_all(struct __mp_lock *mpl)
+___mp_release_all(struct __mp_lock *mpl LOCK_FL_VARS)
{
int rv = mpl->mpl_count - 1;
int s;
+#ifdef WITNESS
+ int i;
+#endif
#ifdef MP_LOCKDEBUG
if (mpl->mpl_cpu != curcpu()) {
@@ -162,6 +177,11 @@ __mp_release_all(struct __mp_lock *mpl)
}
#endif
+#ifdef WITNESS
+ for (i = 0; i < rv; i++)
+ WITNESS_UNLOCK(&mpl->mpl_lock_obj, LOP_EXCLUSIVE, file, line);
+#endif
+
s = hppa_intr_disable();
mpl->mpl_cpu = NULL;
__asm volatile("sync" ::: "memory");
@@ -172,9 +192,12 @@ __mp_release_all(struct __mp_lock *mpl)
}
int
-__mp_release_all_but_one(struct __mp_lock *mpl)
+___mp_release_all_but_one(struct __mp_lock *mpl LOCK_FL_VARS)
{
int rv = mpl->mpl_count - 2;
+#ifdef WITNESS
+ int i;
+#endif
#ifdef MP_LOCKDEBUG
if (mpl->mpl_cpu != curcpu()) {
@@ -184,16 +207,21 @@ __mp_release_all_but_one(struct __mp_lock *mpl)
}
#endif
+#ifdef WITNESS
+ for (i = 0; i < rv; i++)
+ WITNESS_UNLOCK(&mpl->mpl_lock_obj, LOP_EXCLUSIVE, file, line);
+#endif
+
mpl->mpl_count = 2;
return (rv);
}
void
-__mp_acquire_count(struct __mp_lock *mpl, int count)
+___mp_acquire_count(struct __mp_lock *mpl, int count LOCK_FL_VARS)
{
while (count--)
- __mp_lock(mpl);
+ ___mp_lock(mpl LOCK_FL_ARGS);
}
int
diff --git a/sys/arch/hppa/include/mplock.h b/sys/arch/hppa/include/mplock.h
index ec5bb03c16d..331542434fe 100644
--- a/sys/arch/hppa/include/mplock.h
+++ b/sys/arch/hppa/include/mplock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mplock.h,v 1.1 2010/03/25 14:26:21 jsing Exp $ */
+/* $OpenBSD: mplock.h,v 1.2 2017/07/16 22:48:38 guenther Exp $ */
/*
* Copyright (c) 2004 Niklas Hallqvist. All rights reserved.
@@ -39,17 +39,45 @@ struct __mp_lock {
volatile int mpl_lock[4];
volatile struct cpu_info *mpl_cpu;
volatile long mpl_count;
+#ifdef WITNESS
+ struct lock_object mpl_lock_obj;
+#endif
};
#ifndef _LOCORE
-void __mp_lock_init(struct __mp_lock *);
-void __mp_lock(struct __mp_lock *);
-void __mp_unlock(struct __mp_lock *);
-int __mp_release_all(struct __mp_lock *);
-int __mp_release_all_but_one(struct __mp_lock *);
-void __mp_acquire_count(struct __mp_lock *, int);
-int __mp_lock_held(struct __mp_lock *);
+void ___mp_lock_init(struct __mp_lock *);
+void ___mp_lock(struct __mp_lock * LOCK_FL_VARS);
+void ___mp_unlock(struct __mp_lock * LOCK_FL_VARS);
+int ___mp_release_all(struct __mp_lock * LOCK_FL_VARS);
+int ___mp_release_all_but_one(struct __mp_lock * LOCK_FL_VARS);
+void ___mp_acquire_count(struct __mp_lock *, int LOCK_FL_VARS);
+int __mp_lock_held(struct __mp_lock *);
+
+#ifdef WITNESS
+
+void _mp_lock_init(struct __mp_lock *, struct lock_type *);
+
+#define __mp_lock_init(mpl) do { \
+ static struct lock_type __lock_type = { .lt_name = #mpl }; \
+ _mp_lock_init((mpl), &__lock_type); \
+} while (0)
+
+#else /* WITNESS */
+
+#define __mp_lock_init ___mp_lock_init
+
+#endif /* WITNESS */
+
+#define __mp_lock(mpl) ___mp_lock((mpl) LOCK_FILE_LINE)
+#define __mp_unlock(mpl) ___mp_unlock((mpl) LOCK_FILE_LINE)
+
+#define __mp_release_all(mpl) \
+ ___mp_release_all((mpl) LOCK_FILE_LINE)
+#define __mp_release_all_but_one(mpl) \
+ ___mp_release_all_but_one((mpl) LOCK_FILE_LINE)
+#define __mp_acquire_count(mpl, count) \
+ ___mp_acquire_count((mpl), (count) LOCK_FILE_LINE)
#endif