diff options
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/i386/conf/LOCKDOC | 12 | ||||
| -rw-r--r-- | sys/arch/i386/conf/files.i386 | 3 | ||||
| -rw-r--r-- | sys/kern/kern_mutex.c | 3 | ||||
| -rw-r--r-- | sys/lockdoc/log.c | 3 | ||||
| -rw-r--r-- | sys/sys/Makefile | 2 | ||||
| -rw-r--r-- | sys/sys/lockdoc.h | 36 | ||||
| -rw-r--r-- | sys/sys/lockdoc_event.h | 57 |
7 files changed, 109 insertions, 7 deletions
diff --git a/sys/arch/i386/conf/LOCKDOC b/sys/arch/i386/conf/LOCKDOC index a5f8b4c5ce9..955fa29fec2 100644 --- a/sys/arch/i386/conf/LOCKDOC +++ b/sys/arch/i386/conf/LOCKDOC @@ -111,21 +111,21 @@ options BUFQ_PRIOCSCAN # Diagnostic/debugging support options #options DIAGNOSTIC # inexpensive kernel consistency checks # XXX to be commented out on release branch -#options DEBUG # expensive debugging checks/support -#options LOCKDEBUG # expensive locking checks/support -options DDB # in-kernel debugger +options DEBUG # expensive debugging checks/support +options LOCKDEBUG # expensive locking checks/support. Also triggers LOCKDOC experiments +#options DDB # in-kernel debugger #options DDB_ONPANIC=1 # see also sysctl(7): `ddb.onpanic' -options DDB_HISTORY_SIZE=512 # enable history editing in DDB +#options DDB_HISTORY_SIZE=512 # enable history editing in DDB #options DDB_VERBOSE_HELP #options KGDB # remote debugger #options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600 -#makeoptions DEBUG="-g" # compile full symbol table +makeoptions DEBUG="-g" # compile full symbol table #options KUBSAN # Kernel Undefined Behavior Sanitizer (kUBSan) #options UBSAN_ALWAYS_FATAL # (optional) Panic on all kUBSan reports #options SYSCALL_STATS # per syscall counts #options SYSCALL_TIMES # per syscall times #options SYSCALL_TIMES_HASCOUNTER # use 'broken' rdtsc (soekris) -options KDTRACE_HOOKS # kernel DTrace hooks +#options KDTRACE_HOOKS # kernel DTrace hooks # Kernel Code Coverage Driver. makeoptions KCOV=1 diff --git a/sys/arch/i386/conf/files.i386 b/sys/arch/i386/conf/files.i386 index e6321081a00..628d792929a 100644 --- a/sys/arch/i386/conf/files.i386 +++ b/sys/arch/i386/conf/files.i386 @@ -47,6 +47,9 @@ defparam opt_beep.h BEEP_ONHALT_COUNT=3 defparam opt_beep.h BEEP_ONHALT_PITCH=1500 defparam opt_beep.h BEEP_ONHALT_PERIOD=250 + +file lockdoc/log.c lockdebug + # Multiboot support defflag opt_multiboot.h MULTIBOOT obsolete defparam MULTIBOOT_SYMTAB_SPACE diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 7fb68cf2d8f..beb40f8a368 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -56,6 +56,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.79.2.1 2020/03/08 11:21:29 martin E #include <sys/types.h> #include <sys/cpu.h> #include <sys/pserialize.h> +#include <sys/lockdoc.h> #include <dev/lockstat.h> @@ -893,6 +894,7 @@ mutex_tryenter(kmutex_t *mtx) if (MUTEX_SPINBIT_LOCK_TRY(mtx)) { MUTEX_WANTLOCK(mtx); MUTEX_LOCKED(mtx); + log_lock(P_WRITE, mtx, __FILE__, __LINE__, LOCK_NONE); return 1; } MUTEX_SPIN_SPLRESTORE(mtx); @@ -909,6 +911,7 @@ mutex_tryenter(kmutex_t *mtx) MUTEX_LOCKED(mtx); MUTEX_DASSERT(mtx, MUTEX_OWNER(mtx->mtx_owner) == curthread); + log_lock(P_WRITE, mtx, __FILE__, __LINE__, LOCK_NONE); return 1; } } diff --git a/sys/lockdoc/log.c b/sys/lockdoc/log.c new file mode 100644 index 00000000000..e2d49c76090 --- /dev/null +++ b/sys/lockdoc/log.c @@ -0,0 +1,3 @@ +#include <sys/lockdoc.h> + +struct log_action la_buffer; diff --git a/sys/sys/Makefile b/sys/sys/Makefile index 9be88b08cc6..00b64960abb 100644 --- a/sys/sys/Makefile +++ b/sys/sys/Makefile @@ -26,7 +26,7 @@ INCS= acct.h agpio.h aio.h ansi.h aout_mids.h ataio.h atomic.h \ ioctl_compat.h iostat.h ipc.h ipmi.h \ joystick.h \ kcore.h kcov.h kcpuset.h kgdb.h kmem.h ksem.h ksyms.h ktrace.h \ - localcount.h localedef.h lock.h lockf.h lua.h lwp.h lwpctl.h \ + localcount.h localedef.h lock.h lockdoc.h lockdoc_event.h lockf.h lua.h lwp.h lwpctl.h \ malloc.h mallocvar.h mbuf.h md4.h md5.h midiio.h \ mman.h module.h mount.h mqueue.h msg.h msgbuf.h mtio.h mutex.h \ namei.h null.h \ diff --git a/sys/sys/lockdoc.h b/sys/sys/lockdoc.h new file mode 100644 index 00000000000..ee9ffdb8820 --- /dev/null +++ b/sys/sys/lockdoc.h @@ -0,0 +1,36 @@ +#if !defined(__LOCKDOC_H__) && !defined(__ASSEMBLER__) +#define __LOCKDOC_H__ + +#include <sys/types.h> +#include <sys/lockdoc_event.h> + +#define DELIMITER "#" +#define DELIMITER_CHAR '#' +#define PING_CHAR 'p' +#define MK_STRING(x) #x +#define IO_PORT_LOG (0x00e9) + +#ifdef LOCKDEBUG + +extern struct log_action la_buffer; + +/* Basic port I/O */ +static inline void outb_(u_int8_t v, u_int16_t port) +{ + __asm __volatile("outb %0,%1" : : "a" (v), "dN" (port)); +} + +static inline void log_memory(int alloc, const char *datatype, const void *ptr, size_t size) { + +} + +static inline void log_lock(int lock_op, const kmutex_t* ptr, const char *file, int line, int irq_sync) { + memset(&la_buffer,0,sizeof(la_buffer)); + outb_(PING_CHAR,IO_PORT_LOG); +} +#else +#define log_lock(a, b, c, d, e) + +#endif // !LOCKDEBUG + +#endif // __LOCKDOC_H__ diff --git a/sys/sys/lockdoc_event.h b/sys/sys/lockdoc_event.h new file mode 100644 index 00000000000..5dc402cf435 --- /dev/null +++ b/sys/sys/lockdoc_event.h @@ -0,0 +1,57 @@ +#ifndef __LOCKDOC_EVENT_H__ +#define __LOCKDOC_EVENT_H__ + +#define LOG_CHAR_BUFFER_LEN 100 +#define PSEUDOLOCK_ADDR_RCU 0x42 +#define PSEUDOLOCK_ADDR_PREEMPT 0x43 +#define PSEUDOLOCK_ADDR_SOFTIRQ 0x45 +#define PSEUDOLOCK_ADDR_HARDIRQ 0x44 +#define PSEUDOLOCK_NAME_RCU "rcu" +#define PSEUDOLOCK_NAME_HARDIRQ "hardirq" +#define PSEUDOLOCK_NAME_SOFTIRQ "softirq" +#define PSEUDOLOCK_NAME_PREEMPT "preempt" +#define PSEUDOLOCK_VAR "static" +#define PSEUDOLOCK_VAR_RCU PSEUDOLOCK_VAR +#define PSEUDOLOCK_VAR_HARDIRQ PSEUDOLOCK_VAR +#define PSEUDOLOCK_VAR_SOFTIRQ PSEUDOLOCK_VAR +#define PSEUDOLOCK_VAR_PREEMPT PSEUDOLOCK_VAR + +// Lock flags +#define LOCK_FLAGS_RECURSIVE 0x1 + +/* + * When altered, this file + * has to be copied to the according fail experiment + * as well as to convert! + */ + +enum LOCK_OP { + P_READ = 0, + P_WRITE, + V_READ, + V_WRITE +}; + +enum IRQ_SYNC { + LOCK_NONE = 0, + LOCK_IRQ, + LOCK_IRQ_NESTED, /* aka irqsave and irqrestore */ + LOCK_BH +}; + +struct log_action { + char action; + uint32_t lock_op; + uint32_t ptr; + uint32_t size; + char type[LOG_CHAR_BUFFER_LEN]; // allocated data_type or lock type + char lock_member[LOG_CHAR_BUFFER_LEN]; + char file[LOG_CHAR_BUFFER_LEN]; + int32_t line; + char function[LOG_CHAR_BUFFER_LEN]; + int32_t preempt_count; + int32_t irq_sync; + int32_t flags; +}__attribute__((packed)); + +#endif /* __LOCKDOC_EVENT_H__ */ |
