summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/kern_rwlock.c19
-rw-r--r--sys/lockdoc/log.c17
-rw-r--r--sys/sys/lockdoc.h18
-rw-r--r--sys/sys/rwlock.h8
-rwxr-xr-xupdate_system.sh2
5 files changed, 46 insertions, 18 deletions
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index 5b52af91e71..b000eb00c86 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -778,6 +778,25 @@ rw_lock_held(krwlock_t *rw)
return (rw->rw_owner & RW_THREAD) != 0;
}
+#ifdef LOCKDOC
+/*
+ * Helper function to get a lock type (backported from NetBSD 10.0-STABLE)
+ * the #ifdef is here just in case.
+ */
+
+ /*
+ * rw_lock_op:
+ *
+ * For a rwlock that is known to be held by the caller, return
+ * RW_READER or RW_WRITER to describe the hold type.
+ */
+krw_t
+rw_lock_op(krwlock_t *rw)
+{
+ return (rw->rw_owner & RW_WRITE_LOCKED) != 0 ? RW_WRITER : RW_READER;
+}
+#endif
+
/*
* rw_owner:
*
diff --git a/sys/lockdoc/log.c b/sys/lockdoc/log.c
index db86defac17..4781d6570e7 100644
--- a/sys/lockdoc/log.c
+++ b/sys/lockdoc/log.c
@@ -9,6 +9,7 @@ struct log_action la_buffer;
#define LOCK_TYPE "kmutex_t"
+// Mutexes are always considered write locks
inline void __mutex_enter(kmutex_t * lock, const char* file, int line, const char* func) {
_mutex_enter(lock);
lockdoc_log_lock(P_WRITE, lock, file, line, func, LOCK_TYPE, LOCK_NONE);
@@ -75,11 +76,15 @@ inline int __rw_tryenter(krwlock_t * lock, const krw_t type, const char* file, i
}
inline void __rw_exit(krwlock_t * lock, const char* file, int line, const char* func) {
- _rw_exit(lock);
- if((lock->rw_owner & 0x04UL) != 0)
+ /*
+ * See sys/sys/rwlock.h
+ * We cannot include this directly due to circular dependencies.
+ */
+ if(rw_lock_op(lock) == RW_WRITER)
lockdoc_log_lock(V_WRITE, lock, file, line, func, LOCK_TYPE, LOCK_NONE);
else
lockdoc_log_lock(V_READ, lock, file, line, func, LOCK_TYPE, LOCK_NONE);
+ _rw_exit(lock);
}
#undef LOCK_TYPE
@@ -158,7 +163,7 @@ void trace_irqs_on(struct trapframe *frame) {
u_long cur_eflags;
cur_eflags = x86_read_flags();
if ((frame->tf_eflags & (1 << 9)) && !(cur_eflags & (1 << 9))) {
- lockdoc_log_lock(V_WRITE, (struct lock_object*)PSEUDOLOCK_ADDR_HARDIRQ, __FILE__, __LINE__, "dummy", "dummy", LOCK_NONE);
+ lockdoc_log_lock(V_WRITE, (void *)PSEUDOLOCK_ADDR_HARDIRQ, __FILE__, __LINE__, "dummy", "dummy", LOCK_NONE);
}
}
@@ -166,7 +171,7 @@ void trace_irqs_off(struct trapframe *frame) {
u_long cur_eflags;
cur_eflags = x86_read_flags();
if ((frame->tf_eflags & (1 << 9)) && !(cur_eflags & (1 << 9))) {
- lockdoc_log_lock(P_WRITE, (struct lock_object*)PSEUDOLOCK_ADDR_HARDIRQ, __FILE__, __LINE__, "dummy", "dummy", frame->tf_trapno);
+ lockdoc_log_lock(P_WRITE, (void *)PSEUDOLOCK_ADDR_HARDIRQ, __FILE__, __LINE__, "dummy", "dummy", frame->tf_trapno);
}
}
@@ -175,7 +180,7 @@ void __x86_disable_intr(const char *file, int line, const char *func){
eflags = x86_read_flags();
if (eflags & (1 << 9)){ // Check if interrupts were enabled in the first place
- lockdoc_log_lock(P_WRITE, (void*)PSEUDOLOCK_ADDR_HARDIRQ, file, line, "dummy", "dummy", LOCK_NONE);
+ lockdoc_log_lock(P_WRITE, (void *)PSEUDOLOCK_ADDR_HARDIRQ, file, line, "dummy", "dummy", LOCK_NONE);
}
lockdoc_x86_disable_intr();
}
@@ -194,7 +199,7 @@ void __x86_enable_intr(const char *file, int line, const char *func){
eflags = x86_read_flags();
if (!(eflags & (1 << 9))){ // Check if interrupts were disabled in the first place
- lockdoc_log_lock(V_WRITE, (void*)PSEUDOLOCK_ADDR_HARDIRQ, file, line, "dummy", "dummy", LOCK_NONE);
+ lockdoc_log_lock(V_WRITE, (void *)PSEUDOLOCK_ADDR_HARDIRQ, file, line, "dummy", "dummy", LOCK_NONE);
}
lockdoc_x86_enable_intr();
}
diff --git a/sys/sys/lockdoc.h b/sys/sys/lockdoc.h
index 65919b58a00..8e96d7cf719 100644
--- a/sys/sys/lockdoc.h
+++ b/sys/sys/lockdoc.h
@@ -52,6 +52,11 @@ extern struct log_action la_buffer;
#define rw_tryenter(lock, type) __rw_tryenter(lock, type, __FILE__, __LINE__, __func__)
#define rw_exit(lock) __rw_exit(lock, __FILE__, __LINE__, __func__)
+/*
+ * Helper function to get a lock type (backported from NetBSD 10.0-STABLE)
+ */
+krw_t rw_lock_op(krwlock_t *rw);
+
/* Basic port I/O */
static inline void outb_(u_int8_t v, u_int16_t port)
{
@@ -85,15 +90,6 @@ static inline void lockdoc_log_memory(int alloc, const char *datatype, const voi
lockdoc_x86_restore_intr(flags);
}
-/*
- * TODO: Check for different lock types. We can *not*:
- * - Copy the FreeBSD approach with the embedded struct (since it just doesn't exist)
- * - Copy the Linux approach with __same_type (doesn't exist either)
- *
- * Possible solutions:
- * - Pass an enum that is statically set in the macro, different in each function (similar to Linux)
- *
- */
static inline void lockdoc_log_lock(int lock_op, const volatile void* ptr, const char *file, int line, const char* func, const char* lock_type, int irq_sync) {
u_long eflags;
eflags = x86_read_psl();
@@ -151,8 +147,8 @@ void lockdoc_send_pid_offset(void);
void lockdoc_send_kernel_version(void);
#else
-#define log_memory(a, b, c, d)
-#define log_lock(a, b, c, d, e)
+#define lockdoc_log_memory(a, b, c, d)
+#define lockdoc_log_lock(a, b, c, d, e)
#endif /* LOCKDOC */
diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h
index afa80d36ebc..8e2de10e767 100644
--- a/sys/sys/rwlock.h
+++ b/sys/sys/rwlock.h
@@ -123,6 +123,14 @@ int rw_read_held(krwlock_t *);
int rw_write_held(krwlock_t *);
int rw_lock_held(krwlock_t *);
+#ifdef LOCKDOC
+/*
+ * Helper function to get a lock type (backported from NetBSD 10.0-STABLE)
+ * the #ifdef is here just in case.
+ */
+krw_t rw_lock_op(krwlock_t *);
+#endif
+
#ifndef LOCKDOC
void rw_enter(krwlock_t *, const krw_t);
void rw_exit(krwlock_t *);
diff --git a/update_system.sh b/update_system.sh
index daadecb0cd0..88e5fc46ab6 100755
--- a/update_system.sh
+++ b/update_system.sh
@@ -1,7 +1,7 @@
#!/bin/sh
set -xeu
-NETBSD_IP=10.0.20.246
+NETBSD_IP=192.168.122.211
./build.sh -U -O ./obj -j$(nproc) -m i386 -a i386 -u kernel=LOCKDOC
scp etc/rc root@$NETBSD_IP:/etc/rc