liblockdep: userspace lockdep
cover liblockdep: userspace lockdep
liblockdep is a tiny wrapper built around kernel/lockdep.c. The aim is to provide the same functionality the kernel gets from lockdep to userspace.
The bulk of the code here is the LD_PRELOAD support which provides users an easy way to test their code without having to integrate liblockdep into said code. Simply doing:
lockdep my_app
Would provide lockdep support to my_app.
There is also a small test suite to test both mutexes and rwlocks, it's based on the tests in lib/locking-selftest.c.
This entire patch series was reviewed by lockdep maintainers and accepted to the tip tree previously. It was pulled out so that the potential merge of liblockdep won't delay the rest of the commits in the tip locking tree.
For some more background about this entire thing, the folks at LWN did an awesome overview: http://lwn.net/Articles/536363/
Sasha Levin (9):
lockdep: Be nice about building from userspace
liblockdep: Wrap kernel/lockdep.c to allow usage from userspace
liblockdep: Add public headers for pthread_mutex_t implementation
liblockdep: Add pthread_mutex_t test suite
liblockdep: Add public headers for pthread_rwlock_t implementation
liblockdep: Add pthread_rwlock_t test suite
liblockdep: Support using LD_PRELOAD
liblockdep: Add the 'lockdep' user-space utility
liblockdep: Add a MAINTAINERS entry
MAINTAINERS | 5 + kernel/lockdep.c | 4 + tools/lib/lockdep/Makefile | 251 ++++++++++++++ tools/lib/lockdep/common.c | 33 ++ tools/lib/lockdep/include/liblockdep/common.h | 43 +++ tools/lib/lockdep/include/liblockdep/mutex.h | 73 ++++ tools/lib/lockdep/include/liblockdep/rwlock.h | 91 +++++ tools/lib/lockdep/lockdep | 3 + tools/lib/lockdep/lockdep.c | 2 + tools/lib/lockdep/lockdep_internals.h | 1 + tools/lib/lockdep/lockdep_states.h | 1 + tools/lib/lockdep/preload.c | 386 +++++++++++++++++++++ tools/lib/lockdep/rbtree.c | 1 + tools/lib/lockdep/run_tests.sh | 27 ++ tools/lib/lockdep/tests/AA.c | 13 + tools/lib/lockdep/tests/ABBA.c | 13 + tools/lib/lockdep/tests/ABBCCA.c | 15 + tools/lib/lockdep/tests/ABBCCDDA.c | 17 + tools/lib/lockdep/tests/ABCABC.c | 15 + tools/lib/lockdep/tests/ABCDBCDA.c | 17 + tools/lib/lockdep/tests/ABCDBDDA.c | 17 + tools/lib/lockdep/tests/WW.c | 13 + tools/lib/lockdep/tests/common.h | 12 + tools/lib/lockdep/tests/unlock_balance.c | 12 + tools/lib/lockdep/uinclude/asm/hweight.h | 0 tools/lib/lockdep/uinclude/asm/sections.h | 0 tools/lib/lockdep/uinclude/linux/bitops.h | 0 tools/lib/lockdep/uinclude/linux/compiler.h | 7 + tools/lib/lockdep/uinclude/linux/debug_locks.h | 12 + tools/lib/lockdep/uinclude/linux/delay.h | 0 tools/lib/lockdep/uinclude/linux/export.h | 7 + tools/lib/lockdep/uinclude/linux/ftrace.h | 0 tools/lib/lockdep/uinclude/linux/gfp.h | 0 tools/lib/lockdep/uinclude/linux/hardirq.h | 11 + tools/lib/lockdep/uinclude/linux/hash.h | 1 + tools/lib/lockdep/uinclude/linux/interrupt.h | 0 tools/lib/lockdep/uinclude/linux/irqflags.h | 38 ++ tools/lib/lockdep/uinclude/linux/kallsyms.h | 32 ++ tools/lib/lockdep/uinclude/linux/kernel.h | 36 ++ tools/lib/lockdep/uinclude/linux/kmemcheck.h | 8 + tools/lib/lockdep/uinclude/linux/linkage.h | 0 tools/lib/lockdep/uinclude/linux/list.h | 1 + tools/lib/lockdep/uinclude/linux/lockdep.h | 58 ++++ tools/lib/lockdep/uinclude/linux/mm_types.h | 0 tools/lib/lockdep/uinclude/linux/module.h | 6 + tools/lib/lockdep/uinclude/linux/mutex.h | 0 tools/lib/lockdep/uinclude/linux/poison.h | 1 + tools/lib/lockdep/uinclude/linux/prefetch.h | 6 + tools/lib/lockdep/uinclude/linux/proc_fs.h | 0 tools/lib/lockdep/uinclude/linux/rbtree.h | 1 + .../lib/lockdep/uinclude/linux/rbtree_augmented.h | 2 + tools/lib/lockdep/uinclude/linux/rcu.h | 16 + tools/lib/lockdep/uinclude/linux/seq_file.h | 0 tools/lib/lockdep/uinclude/linux/spinlock.h | 25 ++ tools/lib/lockdep/uinclude/linux/stacktrace.h | 32 ++ tools/lib/lockdep/uinclude/linux/stringify.h | 7 + tools/lib/lockdep/uinclude/linux/system.h | 0 tools/lib/lockdep/uinclude/linux/types.h | 58 ++++ tools/lib/lockdep/uinclude/linux/util.h | 0 tools/lib/lockdep/uinclude/trace/events/lock.h | 0 60 files changed, 1430 insertions(+) create mode 100644 tools/lib/lockdep/Makefile create mode 100644 tools/lib/lockdep/common.c create mode 100644 tools/lib/lockdep/include/liblockdep/common.h create mode 100644 tools/lib/lockdep/include/liblockdep/mutex.h create mode 100644 tools/lib/lockdep/include/liblockdep/rwlock.h create mode 100755 tools/lib/lockdep/lockdep create mode 100644 tools/lib/lockdep/lockdep.c create mode 100644 tools/lib/lockdep/lockdep_internals.h create mode 100644 tools/lib/lockdep/lockdep_states.h create mode 100644 tools/lib/lockdep/preload.c create mode 100644 tools/lib/lockdep/rbtree.c create mode 100755 tools/lib/lockdep/run_tests.sh create mode 100644 tools/lib/lockdep/tests/AA.c create mode 100644 tools/lib/lockdep/tests/ABBA.c create mode 100644 tools/lib/lockdep/tests/ABBCCA.c create mode 100644 tools/lib/lockdep/tests/ABBCCDDA.c create mode 100644 tools/lib/lockdep/tests/ABCABC.c create mode 100644 tools/lib/lockdep/tests/ABCDBCDA.c create mode 100644 tools/lib/lockdep/tests/ABCDBDDA.c create mode 100644 tools/lib/lockdep/tests/WW.c create mode 100644 tools/lib/lockdep/tests/common.h create mode 100644 tools/lib/lockdep/tests/unlock_balance.c create mode 100644 tools/lib/lockdep/uinclude/asm/hweight.h create mode 100644 tools/lib/lockdep/uinclude/asm/sections.h create mode 100644 tools/lib/lockdep/uinclude/linux/bitops.h create mode 100644 tools/lib/lockdep/uinclude/linux/compiler.h create mode 100644 tools/lib/lockdep/uinclude/linux/debug_locks.h create mode 100644 tools/lib/lockdep/uinclude/linux/delay.h create mode 100644 tools/lib/lockdep/uinclude/linux/export.h create mode 100644 tools/lib/lockdep/uinclude/linux/ftrace.h create mode 100644 tools/lib/lockdep/uinclude/linux/gfp.h create mode 100644 tools/lib/lockdep/uinclude/linux/hardirq.h create mode 100644 tools/lib/lockdep/uinclude/linux/hash.h create mode 100644 tools/lib/lockdep/uinclude/linux/interrupt.h create mode 100644 tools/lib/lockdep/uinclude/linux/irqflags.h create mode 100644 tools/lib/lockdep/uinclude/linux/kallsyms.h create mode 100644 tools/lib/lockdep/uinclude/linux/kernel.h create mode 100644 tools/lib/lockdep/uinclude/linux/kmemcheck.h create mode 100644 tools/lib/lockdep/uinclude/linux/linkage.h create mode 100644 tools/lib/lockdep/uinclude/linux/list.h create mode 100644 tools/lib/lockdep/uinclude/linux/lockdep.h create mode 100644 tools/lib/lockdep/uinclude/linux/mm_types.h create mode 100644 tools/lib/lockdep/uinclude/linux/module.h create mode 100644 tools/lib/lockdep/uinclude/linux/mutex.h create mode 100644 tools/lib/lockdep/uinclude/linux/poison.h create mode 100644 tools/lib/lockdep/uinclude/linux/prefetch.h create mode 100644 tools/lib/lockdep/uinclude/linux/proc_fs.h create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree.h create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree_augmented.h create mode 100644 tools/lib/lockdep/uinclude/linux/rcu.h create mode 100644 tools/lib/lockdep/uinclude/linux/seq_file.h create mode 100644 tools/lib/lockdep/uinclude/linux/spinlock.h create mode 100644 tools/lib/lockdep/uinclude/linux/stacktrace.h create mode 100644 tools/lib/lockdep/uinclude/linux/stringify.h create mode 100644 tools/lib/lockdep/uinclude/linux/system.h create mode 100644 tools/lib/lockdep/uinclude/linux/types.h create mode 100644 tools/lib/lockdep/uinclude/linux/util.h create mode 100644 tools/lib/lockdep/uinclude/trace/events/lock.h
Signature · 1 line
1.8.2.1
PATCH 1/9 lockdep: Be nice about building from userspace
Lockdep is an awesome piece of code which detects locking issues which are relevant both to userspace and kernelspace. We can easily make lockdep work in userspace since there is really no kernel spacific magic going on in the code.
All we need is to wrap two functions which are used by lockdep and are very kernel specific.
Doing that will allow tools located in tools/ to easily utilize lockdep's code for their own use.
--- kernel/lockdep.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/lockdep.c +4 -0
@@ -584,6 +584,7 @@ static int very_verbose(struct lock_class *class)/* * Is this the address of a static object: */ +#ifdef __KERNEL__static int static_obj (void *obj) { unsigned long start = (unsigned long) &_stext,
@@ -610,6 +611,7 @@ static int static_obj(void *obj)*/ return is_module_address(addr) || is_module_percpu_address(addr); } +#endif /* * To make lock name printouts unique, we calculate a unique
@@ -4114,6 +4116,7 @@ void debug_check_no_locks_held(struct task_struct *task)print_held_locks_bug (task); } +#ifdef __KERNEL__void debug_show_all_locks (void ) {struct task_struct *g, *p;
@@ -4171,6 +4174,7 @@ retry: read_unlock(&tasklist_lock); }EXPORT_SYMBOL_GPL (debug_show_all_locks); +#endif /* * Careful: only use this function if you are sure that
Signature · 1 line
1.8.2.1
PATCH 2/9 liblockdep: Wrap kernel/lockdep.c to allow usage from userspace
In reply to Sasha Levinkernel/lockdep.c deals with validating locking scenarios for various architectures supported by the kernel. There isn't anything kernel specific going on in lockdep, and when we compare userspace to other architectures that don't have to deal with irqs such as s390, they become all too similar.
We wrap kernel/lockdep.c and include/linux/lockdep.h with several headers which allow us to build and use lockdep from userspace. We don't touch the kernel code itself which means that any work done on lockdep in the kernel will automatically benefit userspace lockdep as well!
--- tools/lib/lockdep/Makefile | 251 +++++++++++++++++++++ tools/lib/lockdep/common.c | 33 +++ tools/lib/lockdep/lockdep.c | 2 + tools/lib/lockdep/lockdep_internals.h | 1 + tools/lib/lockdep/lockdep_states.h | 1 + tools/lib/lockdep/rbtree.c | 1 + tools/lib/lockdep/uinclude/asm/hweight.h | 0 tools/lib/lockdep/uinclude/asm/sections.h | 0 tools/lib/lockdep/uinclude/linux/bitops.h | 0 tools/lib/lockdep/uinclude/linux/compiler.h | 7 + tools/lib/lockdep/uinclude/linux/debug_locks.h | 12 + tools/lib/lockdep/uinclude/linux/delay.h | 0 tools/lib/lockdep/uinclude/linux/export.h | 7 + tools/lib/lockdep/uinclude/linux/ftrace.h | 0 tools/lib/lockdep/uinclude/linux/gfp.h | 0 tools/lib/lockdep/uinclude/linux/hardirq.h | 11 + tools/lib/lockdep/uinclude/linux/hash.h | 1 + tools/lib/lockdep/uinclude/linux/interrupt.h | 0 tools/lib/lockdep/uinclude/linux/irqflags.h | 38 ++++ tools/lib/lockdep/uinclude/linux/kallsyms.h | 32 +++ tools/lib/lockdep/uinclude/linux/kernel.h | 36 +++ tools/lib/lockdep/uinclude/linux/kmemcheck.h | 8 + tools/lib/lockdep/uinclude/linux/linkage.h | 0 tools/lib/lockdep/uinclude/linux/list.h | 1 + tools/lib/lockdep/uinclude/linux/lockdep.h | 58 +++++ tools/lib/lockdep/uinclude/linux/mm_types.h | 0 tools/lib/lockdep/uinclude/linux/module.h | 6 + tools/lib/lockdep/uinclude/linux/mutex.h | 0 tools/lib/lockdep/uinclude/linux/poison.h | 1 + tools/lib/lockdep/uinclude/linux/prefetch.h | 6 + tools/lib/lockdep/uinclude/linux/proc_fs.h | 0 tools/lib/lockdep/uinclude/linux/rbtree.h | 1 + .../lib/lockdep/uinclude/linux/rbtree_augmented.h | 2 + tools/lib/lockdep/uinclude/linux/rcu.h | 16 ++ tools/lib/lockdep/uinclude/linux/seq_file.h | 0 tools/lib/lockdep/uinclude/linux/spinlock.h | 25 ++ tools/lib/lockdep/uinclude/linux/stacktrace.h | 32 +++ tools/lib/lockdep/uinclude/linux/stringify.h | 7 + tools/lib/lockdep/uinclude/linux/system.h | 0 tools/lib/lockdep/uinclude/linux/types.h | 58 +++++ tools/lib/lockdep/uinclude/linux/util.h | 0 tools/lib/lockdep/uinclude/trace/events/lock.h | 0 42 files changed, 654 insertions(+) create mode 100644 tools/lib/lockdep/Makefile create mode 100644 tools/lib/lockdep/common.c create mode 100644 tools/lib/lockdep/lockdep.c create mode 100644 tools/lib/lockdep/lockdep_internals.h create mode 100644 tools/lib/lockdep/lockdep_states.h create mode 100644 tools/lib/lockdep/rbtree.c create mode 100644 tools/lib/lockdep/uinclude/asm/hweight.h create mode 100644 tools/lib/lockdep/uinclude/asm/sections.h create mode 100644 tools/lib/lockdep/uinclude/linux/bitops.h create mode 100644 tools/lib/lockdep/uinclude/linux/compiler.h create mode 100644 tools/lib/lockdep/uinclude/linux/debug_locks.h create mode 100644 tools/lib/lockdep/uinclude/linux/delay.h create mode 100644 tools/lib/lockdep/uinclude/linux/export.h create mode 100644 tools/lib/lockdep/uinclude/linux/ftrace.h create mode 100644 tools/lib/lockdep/uinclude/linux/gfp.h create mode 100644 tools/lib/lockdep/uinclude/linux/hardirq.h create mode 100644 tools/lib/lockdep/uinclude/linux/hash.h create mode 100644 tools/lib/lockdep/uinclude/linux/interrupt.h create mode 100644 tools/lib/lockdep/uinclude/linux/irqflags.h create mode 100644 tools/lib/lockdep/uinclude/linux/kallsyms.h create mode 100644 tools/lib/lockdep/uinclude/linux/kernel.h create mode 100644 tools/lib/lockdep/uinclude/linux/kmemcheck.h create mode 100644 tools/lib/lockdep/uinclude/linux/linkage.h create mode 100644 tools/lib/lockdep/uinclude/linux/list.h create mode 100644 tools/lib/lockdep/uinclude/linux/lockdep.h create mode 100644 tools/lib/lockdep/uinclude/linux/mm_types.h create mode 100644 tools/lib/lockdep/uinclude/linux/module.h create mode 100644 tools/lib/lockdep/uinclude/linux/mutex.h create mode 100644 tools/lib/lockdep/uinclude/linux/poison.h create mode 100644 tools/lib/lockdep/uinclude/linux/prefetch.h create mode 100644 tools/lib/lockdep/uinclude/linux/proc_fs.h create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree.h create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree_augmented.h create mode 100644 tools/lib/lockdep/uinclude/linux/rcu.h create mode 100644 tools/lib/lockdep/uinclude/linux/seq_file.h create mode 100644 tools/lib/lockdep/uinclude/linux/spinlock.h create mode 100644 tools/lib/lockdep/uinclude/linux/stacktrace.h create mode 100644 tools/lib/lockdep/uinclude/linux/stringify.h create mode 100644 tools/lib/lockdep/uinclude/linux/system.h create mode 100644 tools/lib/lockdep/uinclude/linux/types.h create mode 100644 tools/lib/lockdep/uinclude/linux/util.h create mode 100644 tools/lib/lockdep/uinclude/trace/events/lock.h
tools/lib/lockdep/Makefile new file +251 -0
@@ -0,0 +1,251 @@ +# liblockdep version +LL_VERSION = 0 +LL_PATCHLEVEL = 0 +LL_EXTRAVERSION = 1 + +# file format version +FILE_VERSION = 1 + +MAKEFLAGS += --no-print-directory + + +# Makefiles suck: This macro sets a default value of $(2) for the +# variable named by $(1), unless the variable has been set by +# environment or command line. This is necessary for CC and AR +# because make sets default values, so the simpler ?= approach +# won't work as expected. +define allow-override + $(if $(or $(findstring environment,$(origin $(1))),\ + $(findstring command line,$(origin $(1)))),,\ + $(eval $(1) = $(2))) +endef + +# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. +$(call allow-override,CC,$(CROSS_COMPILE)gcc) +$(call allow-override,AR,$(CROSS_COMPILE)ar) + +INSTALL = install + +# Use DESTDIR for installing into a different root directory. +# This is useful for building a package. The program will be +# installed in this directory as if it was the root directory. +# Then the build tool can move it later. +DESTDIR ?= +DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' + +prefix ?= /usr/local +libdir_relative = lib +libdir = $(prefix)/$(libdir_relative) +bindir_relative = bin +bindir = $(prefix)/$(bindir_relative) + +export DESTDIR DESTDIR_SQ INSTALL + +# copy a bit from Linux kbuild + +ifeq ("$(origin V)", "command line") + VERBOSE = $(V) +endif +ifndef VERBOSE + VERBOSE = 0 +endif + +ifeq ("$(origin O)", "command line") + BUILD_OUTPUT := $(O) +endif + +ifeq ($(BUILD_SRC),) +ifneq ($(BUILD_OUTPUT),) + +define build_output + $(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT) \ + BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1 +endef + +saved-output := $(BUILD_OUTPUT) +BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd) +$(if $(BUILD_OUTPUT),, \ + $(error output directory "$(saved-output)" does not exist)) + +all: sub-make + +gui: force + $(call build_output, all_cmd) + +$(filter-out gui,$(MAKECMDGOALS)): sub-make + +sub-make: force + $(call build_output, $(MAKECMDGOALS)) + + +# Leave processing to above invocation of make +skip-makefile := 1 + +endif # BUILD_OUTPUT +endif # BUILD_SRC + +# We process the rest of the Makefile if this is the final invocation of make +ifeq ($(skip-makefile),) + +srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)) +objtree := $(CURDIR) +src := $(srctree) +obj := $(objtree) + +export prefix libdir bindir src obj + +# Shell quotes +libdir_SQ = $(subst ','\'',$(libdir)) +bindir_SQ = $(subst ','\'',$(bindir)) + +LIB_FILE = liblockdep.a liblockdep.so +BIN_FILE = lockdep + +CONFIG_INCLUDES = +CONFIG_LIBS = +CONFIG_FLAGS = + +OBJ = $@ +N = + +export Q VERBOSE + +LIBLOCKDEP_VERSION = $(LL_VERSION).$(LL_PATCHLEVEL).$(LL_EXTRAVERSION) + +INCLUDES = -I. -I/usr/local/include -I./uinclude $(CONFIG_INCLUDES) + +# Set compile option CFLAGS if not set elsewhere +CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g + +override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) + +ifeq ($(VERBOSE),1) + Q = + print_compile = + print_app_build = + print_fpic_compile = + print_shared_lib_compile = + print_install = +else + Q = @ + print_compile = echo ' CC '$(OBJ); + print_app_build = echo ' BUILD '$(OBJ); + print_fpic_compile = echo ' CC FPIC '$(OBJ); + print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ); + print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ); + print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2'; +endif + +do_fpic_compile = \ + ($(print_fpic_compile) \ + $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@) + +do_app_build = \ + ($(print_app_build) \ + $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS)) + +do_compile_shared_library = \ + ($(print_shared_lib_compile) \ + $(CC) --shared -ldl $^ -o $@) + +do_build_static_lib = \ + ($(print_static_lib_build) \ + $(RM) $@; $(AR) rcs $@ $^) + + +define do_compile + $(print_compile) \ + $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@; +endef + +$(obj)/%.o: $(src)/%.c + $(Q)$(call do_compile) + +%.o: $(src)/%.c + $(Q)$(call do_compile) + +PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o + +ALL_OBJS = $(PEVENT_LIB_OBJS) + +CMD_TARGETS = $(LIB_FILE) + +TARGETS = $(CMD_TARGETS) + + +all: all_cmd + +all_cmd: $(CMD_TARGETS) + +liblockdep.so: $(PEVENT_LIB_OBJS) + $(Q)$(do_compile_shared_library) + +liblockdep.a: $(PEVENT_LIB_OBJS) + $(Q)$(do_build_static_lib) + +$(PEVENT_LIB_OBJS): %.o: $(src)/%.c + $(Q)$(do_fpic_compile) + +## make deps + +all_objs := $(sort $(ALL_OBJS)) +all_deps := $(all_objs:%.o=.%.d) + +# let .d file also depends on the source and header files +define check_deps + @set -e; $(RM) $@; \ + $(CC) -MM $(CFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + $(RM) $@.$$$$ +endef + +$(all_deps): .%.d: $(src)/%.c + $(Q)$(call check_deps) + +$(all_objs) : %.o : .%.d + +dep_includes := $(wildcard $(all_deps)) + +ifneq ($(dep_includes),) + include $(dep_includes) +endif + +### Detect environment changes +TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE) + +tags: force + $(RM) tags + find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ + --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' + +TAGS: force + $(RM) TAGS + find . -name '*.[ch]' | xargs etags \ + --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' + +define do_install + $(print_install) \ + if [ ! -d '$(DESTDIR_SQ)$2' ]; then \ + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \ + fi; \ + $(INSTALL) $1 '$(DESTDIR_SQ)$2' +endef + +install_lib: all_cmd + $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ)) + $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ)) + +install: install_lib + +clean: + $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d + $(RM) tags TAGS + +endif # skip-makefile + +PHONY += force +force: + +# Declare the contents of the .PHONY variable as phony. We keep that +# information in a variable so we can use it in if_changed and friends. +.PHONY: $(PHONY)
tools/lib/lockdep/common.c new file +33 -0
@@ -0,0 +1,33 @@ +#include <stddef.h> +#include <stdbool.h> +#include <linux/compiler.h> +#include <linux/lockdep.h> +#include <unistd.h> +#include <sys/syscall.h> + +static struct task_struct current_obj; + +/* lockdep wants these */ +bool debug_locks = true; +bool debug_locks_silent; + +__attribute__((constructor))static void liblockdep_init (void ) +{ +lockdep_init (); +} + +__attribute__((destructor))static void liblockdep_exit (void ) +{ +debug_check_no_locks_held (¤t_obj); +} + +struct task_struct *__curr (void ) +{ +if (current_obj.pid ==0 ) { +/* Makes lockdep output pretty */ +prctl (PR_GET_NAME , current_obj.comm); + current_obj.pid =syscall (__NR_gettid); + } + +return ¤t_obj; +}
tools/lib/lockdep/lockdep.c new file +2 -0
@@ -0,0 +1,2 @@ +#include <linux/lockdep.h> +#include "../../../kernel/lockdep.c"
tools/lib/lockdep/lockdep_internals.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../kernel/lockdep_internals.h"
tools/lib/lockdep/lockdep_states.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../kernel/lockdep_states.h"
tools/lib/lockdep/rbtree.c new file +1 -0
@@ -0,0 +1 @@ +#include "../../../lib/rbtree.c"
tools/lib/lockdep/uinclude/asm/hweight.h new file +0 -0
tools/lib/lockdep/uinclude/asm/sections.h new file +0 -0
tools/lib/lockdep/uinclude/linux/bitops.h new file +0 -0
tools/lib/lockdep/uinclude/linux/compiler.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _LIBLOCKDEP_LINUX_COMPILER_H_ +#define _LIBLOCKDEP_LINUX_COMPILER_H_ + +#define __used __attribute__((__unused__)) +#define unlikely + +#endif
tools/lib/lockdep/uinclude/linux/debug_locks.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LIBLOCKDEP_DEBUG_LOCKS_H_ +#define _LIBLOCKDEP_DEBUG_LOCKS_H_ + +#include <stddef.h> +#include <linux/compiler.h> + +#define DEBUG_LOCKS_WARN_ON (x) (x) + +extern bool debug_locks; +extern bool debug_locks_silent; + +#endif
tools/lib/lockdep/uinclude/linux/delay.h new file +0 -0
tools/lib/lockdep/uinclude/linux/export.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _LIBLOCKDEP_LINUX_EXPORT_H_ +#define _LIBLOCKDEP_LINUX_EXPORT_H_ + +#define EXPORT_SYMBOL (sym) +#define EXPORT_SYMBOL_GPL (sym) + +#endif
tools/lib/lockdep/uinclude/linux/ftrace.h new file +0 -0
tools/lib/lockdep/uinclude/linux/gfp.h new file +0 -0
tools/lib/lockdep/uinclude/linux/hardirq.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _LIBLOCKDEP_LINUX_HARDIRQ_H_ +#define _LIBLOCKDEP_LINUX_HARDIRQ_H_ + +#define SOFTIRQ_BITS 0UL +#define HARDIRQ_BITS 0UL +#define SOFTIRQ_SHIFT 0UL +#define HARDIRQ_SHIFT 0UL +#define hardirq_count () 0UL +#define softirq_count () 0UL + +#endif
tools/lib/lockdep/uinclude/linux/hash.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../include/linux/hash.h"
tools/lib/lockdep/uinclude/linux/interrupt.h new file +0 -0
tools/lib/lockdep/uinclude/linux/irqflags.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef _LIBLOCKDEP_LINUX_TRACE_IRQFLAGS_H_ +#define _LIBLOCKDEP_LINUX_TRACE_IRQFLAGS_H_ + +# define trace_hardirq_context (p) 0 +# define trace_softirq_context (p) 0 +# define trace_hardirqs_enabled (p) 0 +# define trace_softirqs_enabled (p) 0 +# define trace_hardirq_enter () do { } while (0) +# define trace_hardirq_exit () do { } while (0) +# define lockdep_softirq_enter () do { } while (0) +# define lockdep_softirq_exit () do { } while (0) +# define INIT_TRACE_IRQFLAGS + +# define stop_critical_timings () do { } while (0) +# define start_critical_timings () do { } while (0) + +#define raw_local_irq_disable () do { } while (0) +#define raw_local_irq_enable () do { } while (0) +#define raw_local_irq_save (flags) ((flags) = 0) +#define raw_local_irq_restore (flags) do { } while (0) +#define raw_local_save_flags (flags) ((flags) = 0) +#define raw_irqs_disabled_flags (flags) do { } while (0) +#define raw_irqs_disabled () 0 +#define raw_safe_halt () + +#define local_irq_enable () do { } while (0) +#define local_irq_disable () do { } while (0) +#define local_irq_save (flags) ((flags) = 0) +#define local_irq_restore (flags) do { } while (0) +#define local_save_flags (flags) ((flags) = 0) +#define irqs_disabled () (1) +#define irqs_disabled_flags (flags) (0) +#define safe_halt () do { } while (0) + +#define trace_lock_release (x, y) +#define trace_lock_acquire (a, b, c, d, e, f, g) + +#endif
tools/lib/lockdep/uinclude/linux/kallsyms.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef _LIBLOCKDEP_LINUX_KALLSYMS_H_ +#define _LIBLOCKDEP_LINUX_KALLSYMS_H_ + +#include <linux/kernel.h> +#include <stdio.h> + +#define KSYM_NAME_LEN 128 + +struct module ; + +static inline const char *kallsyms_lookup (unsigned long addr, +unsigned long *symbolsize, +unsigned long *offset, +char **modname,char *namebuf) +{ +return NULL ; +} + +#include <execinfo.h> +#include <stdlib.h> +static inline void print_ip_sym (unsigned long ip) +{ +char **name; + + name =backtrace_symbols ((void **)&ip,1 ); + +printf ("%s\n" , *name); + +free (name); +} + +#endif
tools/lib/lockdep/uinclude/linux/kernel.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef _LIBLOCKDEP_LINUX_KERNEL_H_ +#define _LIBLOCKDEP_LINUX_KERNEL_H_ + +#include <linux/export.h> +#include <linux/types.h> +#include <linux/rcu.h> +#include <linux/hardirq.h> + +#ifndef container_of +#define container_of (ptr, type, member) ({ \ + const typeof(((type *)0)->member) * __mptr = (ptr); \ + (type *)((char *)__mptr - offsetof(type, member)); }) +#endif + +#define max (x, y) ({ \ + typeof(x) _max1 = (x); \ + typeof(y) _max2 = (y); \ + (void) (&_max1 == &_max2); \ + _max1 > _max2 ? _max1 : _max2; }) + +#define BUILD_BUG_ON (condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#define WARN_ON (x) (x) +#define WARN_ON_ONCE (x) (x) +#define likely (x) (x) +#define WARN (x, y, z) (x) +#define uninitialized_var (x) x +#define __init +#define noinline +#define list_add_tail_rcu list_add_tail + +#ifndef CALLER_ADDR0 +#define _THIS_IP_ CALLER_ADDR0 +#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) +#endif + +#endif
tools/lib/lockdep/uinclude/linux/kmemcheck.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef _LIBLOCKDEP_LINUX_KMEMCHECK_H_ +#define _LIBLOCKDEP_LINUX_KMEMCHECK_H_ + +static inline void kmemcheck_mark_initialized (void *address,unsigned int n) +{ +} + +#endif
tools/lib/lockdep/uinclude/linux/linkage.h new file +0 -0
tools/lib/lockdep/uinclude/linux/list.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../include/linux/list.h"
tools/lib/lockdep/uinclude/linux/lockdep.h new file +58 -0
58 lines not on this page · raw message
tools/lib/lockdep/uinclude/linux/mm_types.h new file +0 -0
tools/lib/lockdep/uinclude/linux/module.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LIBLOCKDEP_LINUX_MODULE_H_ +#define _LIBLOCKDEP_LINUX_MODULE_H_ + +#define module_param (name, type, perm) + +#endif
tools/lib/lockdep/uinclude/linux/mutex.h new file +0 -0
tools/lib/lockdep/uinclude/linux/poison.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../include/linux/poison.h"
tools/lib/lockdep/uinclude/linux/prefetch.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LIBLOCKDEP_LINUX_PREFETCH_H_ +#define _LIBLOCKDEP_LINUX_PREFETCH_H + +static inline void prefetch (void *a __attribute__((unused))) { } + +#endif
tools/lib/lockdep/uinclude/linux/proc_fs.h new file +0 -0
tools/lib/lockdep/uinclude/linux/rbtree.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../../include/linux/rbtree.h"
tools/lib/lockdep/uinclude/linux/rbtree_augmented.h new file +2 -0
@@ -0,0 +1,2 @@ +#define __always_inline +#include "../../../include/linux/rbtree_augmented.h"
tools/lib/lockdep/uinclude/linux/rcu.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef _LIBLOCKDEP_RCU_H_ +#define _LIBLOCKDEP_RCU_H_ + +int rcu_scheduler_active; + +static inline int rcu_lockdep_current_cpu_online (void ) +{ +return 1 ; +} + +static inline int rcu_is_cpu_idle (void ) +{ +return 1 ; +} + +#endif
tools/lib/lockdep/uinclude/linux/seq_file.h new file +0 -0
tools/lib/lockdep/uinclude/linux/spinlock.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef _LIBLOCKDEP_SPINLOCK_H_ +#define _LIBLOCKDEP_SPINLOCK_H_ + +#include <pthread.h> +#include <stdbool.h> + +#define arch_spinlock_t pthread_mutex_t +#define __ARCH_SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER + +static inline void arch_spin_lock (arch_spinlock_t *mutex) +{ +pthread_mutex_lock (mutex); +} + +static inline void arch_spin_unlock (arch_spinlock_t *mutex) +{ +pthread_mutex_unlock (mutex); +} + +static inline bool arch_spin_is_locked (arch_spinlock_t *mutex) +{ +return true; +} + +#endif
tools/lib/lockdep/uinclude/linux/stacktrace.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef _LIBLOCKDEP_LINUX_STACKTRACE_H_ +#define _LIBLOCKDEP_LINUX_STACKTRACE_H_ + +#include <execinfo.h> + +struct stack_trace { +unsigned int nr_entries, max_entries; +unsigned long *entries; +int skip; +}; + +static inline void print_stack_trace (struct stack_trace *trace,int spaces) +{ +backtrace_symbols_fd ((void **)trace->entries, trace->nr_entries,1 ); +} + +#define save_stack_trace (trace) \ + ((trace)->nr_entries = \ + backtrace((void **)(trace)->entries, (trace)->max_entries)) + +static inline int dump_stack (void ) +{ +void *array[64 ]; +size_t size; + + size =backtrace (array,64 ); +backtrace_symbols_fd (array, size,1 ); + +return 0 ; +} + +#endif
tools/lib/lockdep/uinclude/linux/stringify.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _LIBLOCKDEP_LINUX_STRINGIFY_H_ +#define _LIBLOCKDEP_LINUX_STRINGIFY_H_ + +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) + +#endif
tools/lib/lockdep/uinclude/linux/system.h new file +0 -0
tools/lib/lockdep/uinclude/linux/types.h new file +58 -0
58 lines not on this page · raw message
tools/lib/lockdep/uinclude/linux/util.h new file +0 -0
tools/lib/lockdep/uinclude/trace/events/lock.h new file +0 -0
Signature · 1 line
1.8.2.1
Re: [PATCH 2/9] liblockdep: Wrap kernel/lockdep.c to allow usage from userspace
Quoted 94 lines · Sasha Levin
tools/lib/lockdep/common.c new file +33
-0@@ -0,0 +1,33 @@ +#include <stddef.h> +#include <stdbool.h> +#include <linux/compiler.h> +#include <linux/lockdep.h> +#include <unistd.h> +#include <sys/syscall.h> + +static struct task_struct current_obj; + +/* lockdep wants these */ +bool debug_locks = true; +bool debug_locks_silent; + +__attribute__((constructor))static void liblockdep_init (void ) +{ +lockdep_init (); +} + +__attribute__((destructor))static void liblockdep_exit (void ) +{ +debug_check_no_locks_held (¤t_obj); +} + +struct task_struct *__curr (void ) +{ +if (current_obj.pid ==0 ) { +/* Makes lockdep output pretty */ +prctl (PR_GET_NAME , current_obj.comm); + current_obj.pid =syscall (__NR_gettid); + } + +return ¤t_obj; +}tools/lib/lockdep/uinclude/linux/lockdep.h new file +48
-0@@ -0,0 +1,58 @@ +#ifndef _LIBLOCKDEP_LOCKDEP_H_ +#define _LIBLOCKDEP_LOCKDEP_H_ + +#include <sys/prctl.h> +#include <sys/syscall.h> +#include <string.h> +#include <limits.h> +#include <linux/utsname.h> + + +#define MAX_LOCK_DEPTH 2000UL + +#include "../../../include/linux/lockdep.h" + +struct task_struct { +u64 curr_chain_key; +int lockdep_depth; +unsigned int lockdep_recursion; +struct held_lock held_locks[MAX_LOCK_DEPTH ]; +gfp_t lockdep_reclaim_gfp; +int pid; +char comm[17 ]; +}; + +extern struct task_struct *__curr (void ); + +#define current (__curr()) + +#define debug_locks_off () 1 +#define task_pid_nr (tsk) ((tsk)->pid) + +#define KSYM_NAME_LEN 128 +#define printk printf + +#define KERN_ERR +#define KERN_CONT + +#define list_del_rcu list_del + +#define atomic_t unsigned long +#define atomic_inc (x) ((*(x))++) + +static struct new_utsname *init_utsname (void ) +{ +static struct new_utsname n = (struct new_utsname ) { + .release ="liblockdep" , + .version =LIBLOCKDEP_VERSION , + };
tools/lib/lockdep/uinclude/linux/lockdep.h line 58
Quoted 10 lines
tools/lib/lockdep/uinclude/linux/lockdep.h new file +10
-0+ + return &n; +} + +#define print_tainted () "" +#define static_obj (x) 1 + +#define debug_show_all_locks () + +#endif
I don't see how this could possible work for threaded programs; you only have a single task_struct instance. Wouldn't you need something like the below?
---
static int (*pthread_create_orig)(pthread_t *__restrict,
__const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict) = NULL;
static __thread struct task_struct __current;
#define current (&__current)
static void sched_fork(void)
{
/* init __current */
}__attribute__((constructor)) static void sched_init(void)
{
pthread_create_orig = dlsym(RTLD_NEXT, "pthread_create");
if (!pthread_create_orig) {
char *error = dlerror();
if (!error)
error = "pthread_create is NULL";
die("%s\n", error);
}
sched_fork(); /* main thread */
}__attribute__((destructor)) static void sched_exit(void)
{
/* */
}struct tramp_data {
void *(*func)(void *); void *arg; pthread_mutex_t lock; pthread_cond_t wait; };
static void *tramp_func(void *data)
{
struct tramp_data *tramp_data = data;
void *(*func)(void *) = tramp_data->func;
void *arg = tramp_data->arg;
sched_fork();
pthread_mutex_lock(&tramp_data->lock);
pthread_cond_signal(&tramp_data->wait);
pthread_mutex_unlock(&tramp_data->lock);
return func(arg);
}/* hijack pthread_create() */
int pthread_create(pthread_t *__restrict thread,
__const pthread_attr_t *__restrict attr, void *(*func)(void *),
void *__restrict arg)
{
struct tramp_data tramp_data = {
.func = func,
.arg = arg,
};
int ret;
pthread_cond_init(&tramp_data.wait, NULL);
pthread_mutex_init(&tramp_data.lock, NULL);
pthread_mutex_lock(&tramp_data.lock);
ret = pthread_create_orig(thread, attr, &tramp_func, &tramp_data);
if (!ret)
pthread_cond_wait(&tramp_data.wait, &tramp_data.lock);
pthread_mutex_unlock(&tramp_data.lock);
pthread_mutex_destroy(&tramp_data.lock);
pthread_cond_destroy(&tramp_data.wait);
return ret;
} Re: [PATCH 2/9] liblockdep: Wrap kernel/lockdep.c to allow usage from userspace
Quoted 100 lines · Peter Zijlstra
Quoted 99 lines · Sasha Levin
tools/lib/lockdep/common.c new file +33
-0@@ -0,0 +1,33 @@ +#include <stddef.h> +#include <stdbool.h> +#include <linux/compiler.h> +#include <linux/lockdep.h> +#include <unistd.h> +#include <sys/syscall.h> + +static struct task_struct current_obj; + +/* lockdep wants these */ +bool debug_locks = true; +bool debug_locks_silent; + +__attribute__((constructor))static void liblockdep_init (void ) +{ +lockdep_init (); +} + +__attribute__((destructor))static void liblockdep_exit (void ) +{ +debug_check_no_locks_held (¤t_obj); +} + +struct task_struct *__curr (void ) +{ +if (current_obj.pid ==0 ) { +/* Makes lockdep output pretty */ +prctl (PR_GET_NAME , current_obj.comm); + current_obj.pid =syscall (__NR_gettid); + } + +return ¤t_obj; +}tools/lib/lockdep/uinclude/linux/lockdep.h new file +53
-0@@ -0,0 +1,58 @@ +#ifndef _LIBLOCKDEP_LOCKDEP_H_ +#define _LIBLOCKDEP_LOCKDEP_H_ + +#include <sys/prctl.h> +#include <sys/syscall.h> +#include <string.h> +#include <limits.h> +#include <linux/utsname.h> + + +#define MAX_LOCK_DEPTH 2000UL + +#include "../../../include/linux/lockdep.h" + +struct task_struct { +u64 curr_chain_key; +int lockdep_depth; +unsigned int lockdep_recursion; +struct held_lock held_locks[MAX_LOCK_DEPTH ]; +gfp_t lockdep_reclaim_gfp; +int pid; +char comm[17 ]; +}; + +extern struct task_struct *__curr (void ); + +#define current (__curr()) + +#define debug_locks_off () 1 +#define task_pid_nr (tsk) ((tsk)->pid) + +#define KSYM_NAME_LEN 128 +#define printk printf + +#define KERN_ERR +#define KERN_CONT + +#define list_del_rcu list_del + +#define atomic_t unsigned long +#define atomic_inc (x) ((*(x))++) + +static struct new_utsname *init_utsname (void ) +{ +static struct new_utsname n = (struct new_utsname ) { + .release ="liblockdep" , + .version =LIBLOCKDEP_VERSION , + }; + +return &n; +} + +#define print_tainted () ""
Quoted 8 lines
tools/lib/lockdep/uinclude/linux/lockdep.h line 58
Quoted 5 lines
tools/lib/lockdep/uinclude/linux/lockdep.h new file +5
-0+#define static_obj (x) 1 + +#define debug_show_all_locks () + +#endif I don't see how this could possible work for threaded programs; you only have a single
task_structinstance. Wouldn't you need something like the below?
[snip]
Hi Peter,
You're right - I broke multithreading for some odd reason (mostly me being stupid) after having it working :/
It's enough to set the __thread flag on current_obj:
diff --git a/tools/lib/lockdep/common.c b/tools/lib/lockdep/common.c index eb5e481..8ef602f 100644 --- a/tools/lib/lockdep/common.c +++ b/tools/lib/lockdep/common.c @@ -5,7 +5,7 @@ #include <unistd.h> #include <sys/syscall.h> -static struct task_struct current_obj; +static __thread struct task_struct current_obj; /* lockdep wants these */ bool debug_locks = true;
Since we don't need any special initialization of the struct at any point. This means that the patch above is enough and we don't need to hook pthread_create.
I've tested it by adding the following test to the tests dir:
#include <pthread.h>
#include <liblockdep/mutex.h>
#include "common.h"
pthread_mutex_t a, b;
static void *thread_a(void *arg)
{
LOCK_UNLOCK_2(a, b);
return NULL;
}
static void *thread_b(void *arg)
{
LOCK_UNLOCK_2(b, a);
return NULL;
}
void main(void)
{
pthread_t ta, tb;
pthread_mutex_init(&a, NULL);
pthread_mutex_init(&b, NULL);
pthread_create(&ta, NULL, thread_a, NULL);
pthread_create(&tb, NULL, thread_b, NULL);
pthread_join(ta, NULL);
pthread_join(tb, NULL);
}Which, as expected, produced the following spew:
======================================================
[ INFO: possible circular locking dependency detected ] liblockdep 0.0.1
-------------------------------------------------------
ABBA_MT/30105 is trying to acquire lock:
(&a){......}, at: /lib64/libpthread.so.0(+0x8f3b) [0x7ffa7d2f1f3b]
but task is already holding lock:
(&b){......}, at: /lib64/libpthread.so.0(+0x8f3b) [0x7ffa7d2f1f3b]
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&b){......}:
tests/ABBA_MT[0x4017e4]
tests/ABBA_MT[0x403381]
tests/ABBA_MT[0x40361b]
tests/ABBA_MT[0x403cb1]
tests/ABBA_MT[0x40476e]
tests/ABBA_MT[0x40522d]
tests/ABBA_MT[0x4012d2]
/lib64/libpthread.so.0(+0x8f3b)[0x7ffa7d2f1f3b]
/lib64/libc.so.6(clone+0x6d)[0x7ffa7d02d26d]
-> #0 (&a){......}:
tests/ABBA_MT[0x4017e4]
tests/ABBA_MT[0x402c95]
tests/ABBA_MT[0x403267]
tests/ABBA_MT[0x40361b]
tests/ABBA_MT[0x403cb1]
tests/ABBA_MT[0x40476e]
tests/ABBA_MT[0x40522d]
tests/ABBA_MT[0x401372]
/lib64/libpthread.so.0(+0x8f3b)[0x7ffa7d2f1f3b]
/lib64/libc.so.6(clone+0x6d)[0x7ffa7d02d26d]
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&b);
lock(&a);
lock(&b); lock(&a);
*** DEADLOCK ***
1 lock held by ABBA_MT/30105:
#0: (&b){......}, at: /lib64/libpthread.so.0(+0x8f3b) [0x7ffa7d2f1f3b]
stack backtrace:
tests/ABBA_MT[0x401518]
tests/ABBA_MT[0x402d4f]
tests/ABBA_MT[0x403267]
tests/ABBA_MT[0x40361b]
tests/ABBA_MT[0x403cb1]
tests/ABBA_MT[0x40476e]
tests/ABBA_MT[0x40522d]
tests/ABBA_MT[0x401372]
/lib64/libpthread.so.0(+0x8f3b)[0x7ffa7d2f1f3b]
/lib64/libc.so.6(clone+0x6d)[0x7ffa7d02d26d]
Thanks,
Sasha
Re: [PATCH 2/9] liblockdep: Wrap kernel/lockdep.c to allow usage from userspace
Quoted 23 lines · Sasha Levin
[snip]
Hi Peter,
You're right - I broke multithreading for some odd reason (mostly me being stupid) after having it working :/
It's enough to set the
__threadflag oncurrent_obj:diff --git a/tools/lib/lockdep/common.c b/tools/lib/lockdep/common.c index eb5e481..8ef602f 100644 --- a/tools/lib/lockdep/common.c +++ b/tools/lib/lockdep/common.c @@ -5,7 +5,7 @@ #include <unistd.h> #include <sys/syscall.h> -static struct task_struct current_obj; +static __thread struct task_struct current_obj; /* lockdep wants these */ bool debug_locks = true;
Quoted 3 lines
Since we don't need any special initialization of the struct at any point. This means that the patch above is enough and we don't need to hook
pthread_create.
I tried googling but failed to find the TLS initialization rules. Are they zero'd for each thread or copied about or what? And is this documented or implementation behaviour?
If its consistently zero'd then I suppose you're right and we can get away with just adding __thread; *phew*.
Re: [PATCH 2/9] liblockdep: Wrap kernel/lockdep.c to allow usage from userspace
Quoted 28 lines · Peter Zijlstra
Quoted 23 lines · Sasha Levin
[snip]
Hi Peter,
You're right - I broke multithreading for some odd reason (mostly me being stupid) after having it working :/
It's enough to set the
__threadflag oncurrent_obj:diff --git a/tools/lib/lockdep/common.c b/tools/lib/lockdep/common.c index eb5e481..8ef602f 100644 --- a/tools/lib/lockdep/common.c +++ b/tools/lib/lockdep/common.c @@ -5,7 +5,7 @@ #include <unistd.h> #include <sys/syscall.h> -static struct task_struct current_obj; +static __thread struct task_struct current_obj; /* lockdep wants these */ bool debug_locks = true;Quoted 3 lines
Since we don't need any special initialization of the struct at any point. This means that the patch above is enough and we don't need to hook
pthread_create.
Quoted 6 lines
I tried googling but failed to find the TLS initialization rules. Are they zero'd for each thread or copied about or what? And is this documented or implementation behaviour?
If its consistently zero'd then I suppose you're right and we can get away with just adding
__thread; *phew*.
I assumed that they are zero'd because it is a global variable, and those are supposed to be zero'd.
Running a quick test confirmed that they are indeed zero'd for each thread, so we're safe to just add that __thread.
Thanks,
Sasha
PATCH 3/9 liblockdep: Add public headers for pthread_mutex_t implementation
In reply to Sasha LevinThese headers provide the same API as their pthread mutex counterparts.
The design here is to allow to easily switch to liblockdep lock validation just by adding a "liblockdep_" to pthread_mutex_*() calls, which means that it's easy to integrate liblockdep into existing codebases.
--- tools/lib/lockdep/include/liblockdep/common.h | 43 ++++++++++++++++ tools/lib/lockdep/include/liblockdep/mutex.h | 73 +++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 tools/lib/lockdep/include/liblockdep/common.h create mode 100644 tools/lib/lockdep/include/liblockdep/mutex.h
tools/lib/lockdep/include/liblockdep/common.h new file +43 -0
@@ -0,0 +1,43 @@ +#ifndef _LIBLOCKDEP_COMMON_H +#define _LIBLOCKDEP_COMMON_H + +#include <pthread.h> + +#ifndef CALLER_ADDR0 +#define CALLER_ADDR0 (__builtin_return_address(0)) +#define _THIS_IP_ CALLER_ADDR0 +#endif + +#define NR_LOCKDEP_CACHING_CLASSES 2 +#define MAX_LOCKDEP_SUBCLASSES 8UL + +struct lockdep_subclass_key { +char __one_byte; +}; + +struct lock_class_key { +struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES ]; +}; + +struct lockdep_map { +struct lock_class_key *key; +struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES ]; +const char *name; +#ifdef CONFIG_LOCK_STAT +int cpu; +unsigned long ip; +#endif +}; + +void lockdep_init_map (struct lockdep_map *lock,const char *name, +struct lock_class_key *key,int subclass); +void lock_acquire (struct lockdep_map *lock,unsigned int subclass, +int trylock,int read,int check, +struct lockdep_map *nest_lock,unsigned long ip); +void lock_release (struct lockdep_map *lock,int nested, +unsigned long ip); + +#define STATIC_LOCKDEP_MAP_INIT (_name, _key) \ + { .name = (_name), .key = (void *)(_key), } + +#endif
tools/lib/lockdep/include/liblockdep/mutex.h new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
1.8.2.1
PATCH 4/9 liblockdep: Add pthread_mutex_t test suite
In reply to Sasha LevinThis is a rather simple and basic test suite to test common locking issues.
Beyond tests, it also shows how to use the library.
--- tools/lib/lockdep/run_tests.sh | 27 +++++++++++++++++++++++++++ tools/lib/lockdep/tests/AA.c | 13 +++++++++++++ tools/lib/lockdep/tests/ABBA.c | 13 +++++++++++++ tools/lib/lockdep/tests/ABBCCA.c | 15 +++++++++++++++ tools/lib/lockdep/tests/ABBCCDDA.c | 17 +++++++++++++++++ tools/lib/lockdep/tests/ABCABC.c | 15 +++++++++++++++ tools/lib/lockdep/tests/ABCDBCDA.c | 17 +++++++++++++++++ tools/lib/lockdep/tests/ABCDBDDA.c | 17 +++++++++++++++++ tools/lib/lockdep/tests/common.h | 12 ++++++++++++ tools/lib/lockdep/tests/unlock_balance.c | 12 ++++++++++++ 10 files changed, 158 insertions(+) create mode 100755 tools/lib/lockdep/run_tests.sh create mode 100644 tools/lib/lockdep/tests/AA.c create mode 100644 tools/lib/lockdep/tests/ABBA.c create mode 100644 tools/lib/lockdep/tests/ABBCCA.c create mode 100644 tools/lib/lockdep/tests/ABBCCDDA.c create mode 100644 tools/lib/lockdep/tests/ABCABC.c create mode 100644 tools/lib/lockdep/tests/ABCDBCDA.c create mode 100644 tools/lib/lockdep/tests/ABCDBDDA.c create mode 100644 tools/lib/lockdep/tests/common.h create mode 100644 tools/lib/lockdep/tests/unlock_balance.c
tools/lib/lockdep/run_tests.sh new file +27 -0
@@ -0,0 +1,27 @@ +#! /bin/bash + +make &> /dev/null + +for i in `ls tests/*.c`; do + testname=$(basename -s .c "$i") + gcc -o tests/$testname -lpthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null + echo -ne "$testname... " + if [ $(timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then + echo "PASSED!" + else + echo "FAILED!" + fi + rm tests/$testname +done + +for i in `ls tests/*.c`; do + testname=$(basename -s .c "$i") + gcc -o tests/$testname -lpthread -Iinclude $i &> /dev/null + echo -ne "(PRELOAD) $testname... " + if [ $(timeout 1 ./lockdep ./tests/$testname | wc -l) -gt 0 ]; then + echo "PASSED!" + else + echo "FAILED!" + fi + rm tests/$testname +done
tools/lib/lockdep/tests/AA.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <liblockdep/mutex.h> + +void main (void ) +{ +pthread_mutex_t a, b; + +pthread_mutex_init (&a,NULL ); +pthread_mutex_init (&b,NULL ); + +pthread_mutex_lock (&a); +pthread_mutex_lock (&b); +pthread_mutex_lock (&a); +}
tools/lib/lockdep/tests/ABBA.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <liblockdep/mutex.h> +#include "common.h" + +void main (void ) +{ +pthread_mutex_t a, b; + +pthread_mutex_init (&a,NULL ); +pthread_mutex_init (&b,NULL ); + +LOCK_UNLOCK_2 (a, b); +LOCK_UNLOCK_2 (b, a); +}
tools/lib/lockdep/tests/ABBCCA.c new file +15 -0
@@ -0,0 +1,15 @@ +#include <liblockdep/mutex.h> +#include "common.h" + +void main (void ) +{ +pthread_mutex_t a, b, c; + +pthread_mutex_init (&a,NULL ); +pthread_mutex_init (&b,NULL ); +pthread_mutex_init (&c,NULL ); + +LOCK_UNLOCK_2 (a, b); +LOCK_UNLOCK_2 (b, c); +LOCK_UNLOCK_2 (c, a); +}
tools/lib/lockdep/tests/ABBCCDDA.c new file +17 -0
@@ -0,0 +1,17 @@ +#include <liblockdep/mutex.h> +#include "common.h" + +void main (void ) +{ +pthread_mutex_t a, b, c, d; + +pthread_mutex_init (&a,NULL ); +pthread_mutex_init (&b,NULL ); +pthread_mutex_init (&c,NULL ); +pthread_mutex_init (&d,NULL ); + +LOCK_UNLOCK_2 (a, b); +LOCK_UNLOCK_2 (b, c); +LOCK_UNLOCK_2 (c, d); +LOCK_UNLOCK_2 (d, a); +}
tools/lib/lockdep/tests/ABCABC.c new file +15 -0
@@ -0,0 +1,15 @@ +#include <liblockdep/mutex.h> +#include "common.h" + +void main (void ) +{ +pthread_mutex_t a, b, c; + +pthread_mutex_init (&a,NULL ); +pthread_mutex_init (&b,NULL ); +pthread_mutex_init (&c,NULL ); + +LOCK_UNLOCK_2 (a, b); +LOCK_UNLOCK_2 (c, a); +LOCK_UNLOCK_2 (b, c); +}
tools/lib/lockdep/tests/ABCDBCDA.c new file +17 -0
@@ -0,0 +1,17 @@ +#include <liblockdep/mutex.h> +#include "common.h" + +void main (void ) +{ +pthread_mutex_t a, b, c, d; + +pthread_mutex_init (&a,NULL ); +pthread_mutex_init (&b,NULL ); +pthread_mutex_init (&c,NULL ); +pthread_mutex_init (&d,NULL ); + +LOCK_UNLOCK_2 (a, b); +LOCK_UNLOCK_2 (c, d); +LOCK_UNLOCK_2 (b, c); +LOCK_UNLOCK_2 (d, a); +}
tools/lib/lockdep/tests/ABCDBDDA.c new file +17 -0
@@ -0,0 +1,17 @@ +#include <liblockdep/mutex.h> +#include "common.h" + +void main (void ) +{ +pthread_mutex_t a, b, c, d; + +pthread_mutex_init (&a,NULL ); +pthread_mutex_init (&b,NULL ); +pthread_mutex_init (&c,NULL ); +pthread_mutex_init (&d,NULL ); + +LOCK_UNLOCK_2 (a, b); +LOCK_UNLOCK_2 (c, d); +LOCK_UNLOCK_2 (b, d); +LOCK_UNLOCK_2 (d, a); +}
tools/lib/lockdep/tests/common.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LIBLOCKDEP_TEST_COMMON_H +#define _LIBLOCKDEP_TEST_COMMON_H + +#define LOCK_UNLOCK_2 (a, b) \ + do { \ + pthread_mutex_lock(&(a)); \ + pthread_mutex_lock(&(b)); \ + pthread_mutex_unlock(&(b)); \ + pthread_mutex_unlock(&(a)); \ + } while(0) + +#endif
tools/lib/lockdep/tests/unlock_balance.c new file +12 -0
@@ -0,0 +1,12 @@ +#include <liblockdep/mutex.h> + +void main (void ) +{ +pthread_mutex_t a; + +pthread_mutex_init (&a,NULL ); + +pthread_mutex_lock (&a); +pthread_mutex_unlock (&a); +pthread_mutex_unlock (&a); +}
Signature · 1 line
1.8.2.1
PATCH 5/9 liblockdep: Add public headers for pthread_rwlock_t implementation
In reply to Sasha LevinBoth pthreads and lockdep support dealing with rwlocks, so here's the liblockdep implementation for those.
--- tools/lib/lockdep/include/liblockdep/rwlock.h | 91 +++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tools/lib/lockdep/include/liblockdep/rwlock.h
tools/lib/lockdep/include/liblockdep/rwlock.h new file +91 -0
@@ -0,0 +1,91 @@ +#ifndef _LIBLOCKDEP_RWLOCK_H +#define _LIBLOCKDEP_RWLOCK_H + +#include <pthread.h> +#include "common.h" + +struct liblockdep_pthread_rwlock { +pthread_rwlock_t rwlock; +struct lockdep_map dep_map; +}; + +typedef struct liblockdep_pthread_rwlock liblockdep_pthread_rwlock_t ; + +#define LIBLOCKDEP_PTHREAD_RWLOCK_INITIALIZER (rwl) \ + (struct liblockdep_pthread_rwlock) { \ + .rwlock = PTHREAD_RWLOCK_INITIALIZER, \ + .dep_map = STATIC_LOCKDEP_MAP_INIT(#rwl, &((&(rwl))->dep_map)), \ +} + +static inline int __rwlock_init (liblockdep_pthread_rwlock_t *lock, +const char *name, +struct lock_class_key *key, +const pthread_rwlockattr_t *attr) +{ +lockdep_init_map (&lock->dep_map, name, key,0 ); + +return pthread_rwlock_init (&lock->rwlock, attr); +} + +#define liblockdep_pthread_rwlock_init (lock, attr) \ +({ \ + static struct lock_class_key __key; \ + \ + __rwlock_init((lock), #lock, &__key, (attr)); \ +}) + +static inline int liblockdep_pthread_rwlock_rdlock (liblockdep_pthread_rwlock_t *lock) +{ +void *ip = _THIS_IP_; +lock_acquire (&lock->dep_map,0 ,0 ,2 ,2 ,NULL , (unsigned long )ip); +return pthread_rwlock_rdlock (&lock->rwlock); + +} + +static inline int liblockdep_pthread_rwlock_unlock (liblockdep_pthread_rwlock_t *lock) +{ +void *ip = _THIS_IP_; +lock_release (&lock->dep_map,0 , (unsigned long )ip); +return pthread_rwlock_unlock (&lock->rwlock); +} + +static inline int liblockdep_pthread_rwlock_wrlock (liblockdep_pthread_rwlock_t *lock) +{ +void *ip = _THIS_IP_; +lock_acquire (&lock->dep_map,0 ,0 ,0 ,2 ,NULL , (unsigned long )ip); +return pthread_rwlock_wrlock (&lock->rwlock); +} + +static inline int liblockdep_pthread_rwlock_tryrdlock (liblockdep_pthread_rwlock_t *lock) +{ +void *ip = _THIS_IP_; +lock_acquire (&lock->dep_map,0 ,1 ,2 ,2 ,NULL , (unsigned long )ip); +return pthread_rwlock_tryrdlock (&lock->rwlock) ==0 ?1 :0 ; +} + +static inline int liblockdep_pthread_rwlock_trywlock (liblockdep_pthread_rwlock_t *lock) +{ +void *ip = _THIS_IP_; +lock_acquire (&lock->dep_map,0 ,1 ,0 ,2 ,NULL , (unsigned long )ip); +return pthread_rwlock_trywlock (&lock->rwlock) ==0 ?1 :0 ; +} + +static inline int liblockdep_rwlock_destroy (liblockdep_pthread_rwlock_t *lock) +{ +return pthread_rwlock_destroy (&lock->rwlock); +} + +#ifdef __USE_LIBLOCKDEP + +#define pthread_rwlock_t liblockdep_pthread_rwlock_t +#define pthread_rwlock_init liblockdep_pthread_rwlock_init +#define pthread_rwlock_rdlock liblockdep_pthread_rwlock_rdlock +#define pthread_rwlock_unlock liblockdep_pthread_rwlock_unlock +#define pthread_rwlock_wrlock liblockdep_pthread_rwlock_wrlock +#define pthread_rwlock_tryrdlock liblockdep_pthread_rwlock_tryrdlock +#define pthread_rwlock_trywlock liblockdep_pthread_rwlock_trywlock +#define pthread_rwlock_destroy liblockdep_rwlock_destroy + +#endif + +#endif
Signature · 1 line
1.8.2.1
PATCH 6/9 liblockdep: Add pthread_rwlock_t test suite
In reply to Sasha LevinA simple test to make sure we handle rwlocks correctly.
--- tools/lib/lockdep/tests/WW.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tools/lib/lockdep/tests/WW.c
tools/lib/lockdep/tests/WW.c new file +13 -0
@@ -0,0 +1,13 @@ +#include <liblockdep/rwlock.h> + +void main (void ) +{ +pthread_rwlock_t a, b; + +pthread_rwlock_init (&a,NULL ); +pthread_rwlock_init (&b,NULL ); + +pthread_rwlock_wrlock (&a); +pthread_rwlock_rdlock (&b); +pthread_rwlock_wrlock (&a); +}
Signature · 1 line
1.8.2.1
PATCH 7/9 liblockdep: Support using LD_PRELOAD
In reply to Sasha LevinThis allows lockdep to be used without being compiled in the original program.
Usage is quite simple:
LD_PRELOAD=/path/to/liblockdep.so /path/to/my/program
And magically, you'll have lockdep checking in your program!
--- tools/lib/lockdep/preload.c | 386 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 386 insertions(+) create mode 100644 tools/lib/lockdep/preload.c
tools/lib/lockdep/preload.c new file +386 -0
@@ -0,0 +1,386 @@ +#define _GNU_SOURCE +#include <pthread.h> +#include <stdio.h> +#include <dlfcn.h> +#include <stdlib.h> +#include "include/liblockdep/mutex.h" +#include "../../../include/linux/rbtree.h" + +/** +* struct lock_lookup - liblockdep's view of a single unique lock +* @orig: pointer to the original pthread lock, used for lookups +* @dep_map: lockdep's dep_map structure +* @key: lockdep's key structure +* @node: rb-tree node used to store the lock in a global tree +* @name: a unique name for the lock +*/ +struct lock_lookup { +void *orig;/* Original pthread lock, used for lookups */ +struct lockdep_map dep_map;/* Since all locks are dynamic, we need +* a dep_map and a key for each lock */ +struct lock_class_key key; +struct rb_node node; +#define LIBLOCKDEP_MAX_LOCK_NAME 22 +char name[LIBLOCKDEP_MAX_LOCK_NAME ]; +}; + +/* This is where we store our locks */ +static struct rb_root locks =RB_ROOT ; +static pthread_rwlock_t locks_rwlock =PTHREAD_RWLOCK_INITIALIZER ; + +/* pthread mutex API */ +static int (*ll_pthread_mutex_init)(pthread_mutex_t *mutex, +const pthread_mutexattr_t *attr); +static int (*ll_pthread_mutex_lock)(pthread_mutex_t *mutex); +static int (*ll_pthread_mutex_trylock)(pthread_mutex_t *mutex); +static int (*ll_pthread_mutex_unlock)(pthread_mutex_t *mutex); +static int (*ll_pthread_mutex_destroy)(pthread_mutex_t *mutex); + +/* pthread rwlock API */ +static int (*ll_pthread_rwlock_init)(pthread_rwlock_t *rwlock, +const pthread_rwlockattr_t *attr); +static int (*ll_pthread_rwlock_destroy)(pthread_rwlock_t *rwlock); +static int (*ll_pthread_rwlock_rdlock)(pthread_rwlock_t *rwlock); +static int (*ll_pthread_rwlock_tryrdlock)(pthread_rwlock_t *rwlock); +static int (*ll_pthread_rwlock_trywrlock)(pthread_rwlock_t *rwlock); +static int (*ll_pthread_rwlock_wrlock)(pthread_rwlock_t *rwlock); +static int (*ll_pthread_rwlock_unlock)(pthread_rwlock_t *rwlock); + +static bool preload_done; +static void init_preload (void ); +static void try_init_preload (void ) +{ +if (!preload_done) +init_preload (); +} + +static struct rb_node **__get_lock_node (void *lock,struct rb_node **parent) +{ +struct rb_node **node = &locks.rb_node; +struct lock_lookup *l; + + *parent =NULL ; + +while (*node) { + l = rb_entry(*node, struct lock_lookup, node); + + *parent = *node; +if (lock < l->orig) + node = &l->node.rb_left; +else if (lock > l->orig) + node = &l->node.rb_right; +else +return node; + } + +return node; +} + +/** +* __get_lock - find or create a lock instance +* @lock: pointer to a pthread lock function +* +* Try to find an existing lock in the rbtree using the provided pointer. If +* one wasn't found - create it. +*/ +static struct lock_lookup *__get_lock (void *lock) +{ +struct rb_node **node, *parent; +struct lock_lookup *l; + +ll_pthread_rwlock_rdlock (&locks_rwlock); + node =__get_lock_node (lock, &parent); +ll_pthread_rwlock_unlock (&locks_rwlock); +if (*node) { + return rb_entry(*node, struct lock_lookup, node); + } + +/* We didn't find the lock, let's create it */ + l =malloc (sizeof (*l)); +if (l ==NULL ) +return NULL ; + + l->orig = lock; +/* +* Currently the name of the lock is the ptr value of the pthread lock, +* while not optimal, it makes debugging a bit easier. +* +* TODO: Get the real name of the lock using libdwarf +*/ +sprintf (l->name,"%p" , lock); +lockdep_init_map (&l->dep_map, l->name, &l->key,0 ); + +ll_pthread_rwlock_wrlock (&locks_rwlock); +/* This might have changed since the last time we fetched it */ + node =__get_lock_node (lock, &parent); +rb_link_node (&l->node, parent, node); +rb_insert_color (&l->node, &locks); +ll_pthread_rwlock_unlock (&locks_rwlock); + +return l; +} + +int pthread_mutex_init (pthread_mutex_t *mutex, +const pthread_mutexattr_t *attr) +{ +int r; + +/* +* We keep trying to init our preload module because there might be +* code in init sections that tries to touch locks before we are +* initialized, in that case we'll need to manually call preload +* to get us going. +* +* Funny enough, kernel's lockdep had the same issue, and used +* (almost) the same solution. See look_up_lock_class() in +* kernel/lockdep.c for details. +*/ +try_init_preload (); + + r =ll_pthread_mutex_init (mutex, attr); +if (r ==0 ) +/* +* We do a dummy initialization here so that lockdep could +* warn us if something fishy is going on - such as +* initializing a held lock. +*/ +__get_lock (mutex); + +return r; +} + +int pthread_mutex_lock (pthread_mutex_t *mutex) +{ +int r; + +try_init_preload (); + +lock_acquire (&__get_lock (mutex)->dep_map,0 ,0 ,0 ,2 ,NULL , + (unsigned long )_THIS_IP_); +/* +* Here's the thing with pthread mutexes: unlike the kernel variant, +* they can fail. +* +* This means that the behaviour here is a bit different from what's +* going on in the kernel: there we just tell lockdep that we took the +* lock before actually taking it, but here we must deal with the case +* that locking failed. +* +* To do that we'll "release" the lock if locking failed - this way +* we'll get lockdep doing the correct checks when we try to take +* the lock, and if that fails - we'll be back to the correct +* state by releasing it. +*/ + r =ll_pthread_mutex_lock (mutex); +if (r) +lock_release (&__get_lock (mutex)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_mutex_trylock (pthread_mutex_t *mutex) +{ +int r; + +try_init_preload (); + +lock_acquire (&__get_lock (mutex)->dep_map,0 ,1 ,0 ,2 ,NULL , (unsigned long )_THIS_IP_); + r =ll_pthread_mutex_trylock (mutex); +if (r) +lock_release (&__get_lock (mutex)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_mutex_unlock (pthread_mutex_t *mutex) +{ +int r; + +try_init_preload (); + +lock_release (&__get_lock (mutex)->dep_map,0 , (unsigned long )_THIS_IP_); +/* +* Just like taking a lock, only in reverse! +* +* If we fail releasing the lock, tell lockdep we're holding it again. +*/ + r =ll_pthread_mutex_unlock (mutex); +if (r) +lock_acquire (&__get_lock (mutex)->dep_map,0 ,0 ,0 ,2 ,NULL , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_mutex_destroy (pthread_mutex_t *mutex) +{ +struct lock_lookup *l =__get_lock (mutex); + +try_init_preload (); + +/* +* Let's see if we're releasing a lock that's held. +* +* TODO: Hook into free() and add that check there as well. +*/ +debug_check_no_locks_freed (mutex, mutex +sizeof (*mutex)); +ll_pthread_rwlock_wrlock (&locks_rwlock); +rb_erase (&l->node, &locks); +ll_pthread_rwlock_unlock (&locks_rwlock); +free (l); +return ll_pthread_mutex_destroy (mutex); +} + +/* This is the rwlock part, very similar to what happened with mutex above */ +int pthread_rwlock_init (pthread_rwlock_t *rwlock, +const pthread_rwlockattr_t *attr) +{ +int r; + +try_init_preload (); + + r =ll_pthread_rwlock_init (rwlock, attr); +if (r ==0 ) +__get_lock (rwlock); + +return r; +} + +int pthread_rwlock_destroy (pthread_rwlock_t *rwlock) +{ +struct lock_lookup *l =__get_lock (rwlock); + +try_init_preload (); + +debug_check_no_locks_freed (rwlock, rwlock +sizeof (*rwlock)); +ll_pthread_rwlock_wrlock (&locks_rwlock); +rb_erase (&l->node, &locks); +ll_pthread_rwlock_unlock (&locks_rwlock); +free (l); +return ll_pthread_rwlock_destroy (rwlock); +} + +int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) +{ +int r; + +init_preload (); + +lock_acquire (&__get_lock (rwlock)->dep_map,0 ,0 ,2 ,2 ,NULL , (unsigned long )_THIS_IP_); + r =ll_pthread_rwlock_rdlock (rwlock); +if (r) +lock_release (&__get_lock (rwlock)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock) +{ +int r; + +init_preload (); + +lock_acquire (&__get_lock (rwlock)->dep_map,0 ,1 ,2 ,2 ,NULL , (unsigned long )_THIS_IP_); + r =ll_pthread_rwlock_tryrdlock (rwlock); +if (r) +lock_release (&__get_lock (rwlock)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock) +{ +int r; + +init_preload (); + +lock_acquire (&__get_lock (rwlock)->dep_map,0 ,1 ,0 ,2 ,NULL , (unsigned long )_THIS_IP_); + r =ll_pthread_rwlock_trywrlock (rwlock); +if (r) +lock_release (&__get_lock (rwlock)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) +{ +int r; + +init_preload (); + +lock_acquire (&__get_lock (rwlock)->dep_map,0 ,0 ,0 ,2 ,NULL , (unsigned long )_THIS_IP_); + r =ll_pthread_rwlock_wrlock (rwlock); +if (r) +lock_release (&__get_lock (rwlock)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_rwlock_unlock (pthread_rwlock_t *rwlock) +{ +int r; + +init_preload (); + +lock_release (&__get_lock (rwlock)->dep_map,0 , (unsigned long )_THIS_IP_); + r =ll_pthread_rwlock_unlock (rwlock); +if (r) +lock_acquire (&__get_lock (rwlock)->dep_map,0 ,0 ,0 ,2 ,NULL , (unsigned long )_THIS_IP_); + +return r; +} + +__attribute__((constructor))static void init_preload (void ) +{ +static bool preload_started; + +if (preload_done) +return ; + +/* +* Some programs attempt to initialize and use locks in their +* allocation path. This means that a call to malloc() would +* result in locks being initialized and locked. +* +* Why is it an issue for us? dlsym() below will try allocating to +* give us the original function. Since this allocation will result +* in a locking operations, we have to let pthread deal with it, +* but we can't! we don't have the pointer to the original API +* since we're inside dlsym() trying to get it :( +* +* We can work around it by telling the program that locking was +* really okay, and just initialize those locks when we're fully +* up and running (this is ok because this all happens during +* initialization phase, when we have just one thread). But +* this is a big TODO at this point. +*/ +if (preload_started) { +printf ( +"LOCKDEP error: It seems that the program you are trying to " +"debug is initializing locks in it's allocation path.\n" +"This means that liblockdep cannot reliably analyze this " +"program since we need the allocator to work before we can " +"debug locks.\nSorry!\n" ); + +exit (1 ); + } + + preload_started = true; + + ll_pthread_mutex_init =dlsym (RTLD_NEXT ,"pthread_mutex_init" ); + ll_pthread_mutex_lock =dlsym (RTLD_NEXT ,"pthread_mutex_lock" ); + ll_pthread_mutex_trylock =dlsym (RTLD_NEXT ,"pthread_mutex_trylock" ); + ll_pthread_mutex_unlock =dlsym (RTLD_NEXT ,"pthread_mutex_unlock" ); + ll_pthread_mutex_destroy =dlsym (RTLD_NEXT ,"pthread_mutex_destroy" ); + + ll_pthread_rwlock_init =dlsym (RTLD_NEXT ,"pthread_rwlock_init" ); + ll_pthread_rwlock_destroy =dlsym (RTLD_NEXT ,"pthread_rwlock_destroy" ); + ll_pthread_rwlock_rdlock =dlsym (RTLD_NEXT ,"pthread_rwlock_rdlock" ); + ll_pthread_rwlock_tryrdlock =dlsym (RTLD_NEXT ,"pthread_rwlock_tryrdlock" ); + ll_pthread_rwlock_wrlock =dlsym (RTLD_NEXT ,"pthread_rwlock_wrlock" ); + ll_pthread_rwlock_trywrlock =dlsym (RTLD_NEXT ,"pthread_rwlock_trywrlock" ); + ll_pthread_rwlock_unlock =dlsym (RTLD_NEXT ,"pthread_rwlock_unlock" ); + +lockdep_init (); + + preload_done = true; +}
Signature · 1 line
1.8.2.1
Re: [PATCH 7/9] liblockdep: Support using LD_PRELOAD
Quoted 7 lines · Sasha Levin
tools/lib/lockdep/preload.c new file +6
-0+ +static struct rb_node **__get_lock_node (void *lock,struct rb_node **parent) +{ +} + +/**
tools/lib/lockdep/preload.c line 96
Quoted 10 lines
tools/lib/lockdep/preload.c new file +9
-0+* __get_lock - find or create a lock instance +* @lock: pointer to a pthread lock function +* +* Try to find an existing lock in the rbtree using the provided pointer. If +* one wasn't found - create it. +*/ +static struct lock_lookup *__get_lock (void *lock) +{ +}
This needs something like:
static void __del_lock(void *lock);
Since now you're repeating yourself in pthread_{rwlock,mutex}_destroy() :-)
tools/lib/lockdep/preload.c line 156
Quoted 5 lines
tools/lib/lockdep/preload.c new file +5
-0+int pthread_mutex_lock (pthread_mutex_t *mutex) +{ +int r; + +try_init_preload ();
You seem consistently whitespace challenged on this line.
tools/lib/lockdep/preload.c line 167
Quoted 11 lines
tools/lib/lockdep/preload.c new file +11
-0+ +lock_acquire (&__get_lock (mutex)->dep_map,0 ,0 ,0 ,2 ,NULL , + (unsigned long )_THIS_IP_); +/* +* Here's the thing with pthread mutexes: unlike the kernel variant, +* they can fail. +* +* This means that the behaviour here is a bit different from what's +* going on in the kernel: there we just tell lockdep that we took the +* lock before actually taking it, but here we must deal with the case +* that locking failed.
mutex_lock_{interruptible,killable}() could be argued to be able to fail too. And if you look at __mutex_lock_common() you'll see that it does the exact same thing -- that is release on fail.
Quoted 7 lines
tools/lib/lockdep/preload.c new file +7
-0+* To do that we'll "release" the lock if locking failed - this way +* we'll get lockdep doing the correct checks when we try to take +* the lock, and if that fails - we'll be back to the correct +* state by releasing it. +*/ + r =ll_pthread_mutex_lock (mutex); +if (r)
tools/lib/lockdep/preload.c line 185
Quoted 10 lines
tools/lib/lockdep/preload.c new file +10
-0+lock_release (&__get_lock (mutex)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} + +int pthread_mutex_trylock (pthread_mutex_t *mutex) +{ +int r; + +try_init_preload ();
See..
Quoted 22 lines
tools/lib/lockdep/preload.c new file +21
-0+lock_acquire (&__get_lock (mutex)->dep_map,0 ,1 ,0 ,2 ,NULL , (unsigned long )_THIS_IP_); + r =ll_pthread_mutex_trylock (mutex); +if (r) +lock_release (&__get_lock (mutex)->dep_map,0 , (unsigned long )_THIS_IP_); + +return r; +} +__attribute__((constructor))static void init_preload (void ) +{ +static bool preload_started; + +if (preload_done) +return ; + +/* +* Some programs attempt to initialize and use locks in their +* allocation path. This means that a call to malloc() would +* result in locks being initialized and locked. +* +* Why is it an issue for us? dlsym() below will try allocating to +* give us the original function. Since this allocation will result
tools/lib/lockdep/preload.c line 355
Quoted 10 lines
tools/lib/lockdep/preload.c new file +10
-0+* in a locking operations, we have to let pthread deal with it, +* but we can't! we don't have the pointer to the original API +* since we're inside dlsym() trying to get it :( +* +* We can work around it by telling the program that locking was +* really okay, and just initialize those locks when we're fully +* up and running (this is ok because this all happens during +* initialization phase, when we have just one thread). But +* this is a big TODO at this point. +*/
Fun.. got any example programs that trigger this?
Quoted 31 lines
tools/lib/lockdep/preload.c new file +31
-0+if (preload_started) { +printf ( +"LOCKDEP error: It seems that the program you are trying to " +"debug is initializing locks in it's allocation path.\n" +"This means that liblockdep cannot reliably analyze this " +"program since we need the allocator to work before we can " +"debug locks.\nSorry!\n" ); + +exit (1 ); + } + + preload_started = true; + + ll_pthread_mutex_init =dlsym (RTLD_NEXT ,"pthread_mutex_init" ); + ll_pthread_mutex_lock =dlsym (RTLD_NEXT ,"pthread_mutex_lock" ); + ll_pthread_mutex_trylock =dlsym (RTLD_NEXT ,"pthread_mutex_trylock" ); + ll_pthread_mutex_unlock =dlsym (RTLD_NEXT ,"pthread_mutex_unlock" ); + ll_pthread_mutex_destroy =dlsym (RTLD_NEXT ,"pthread_mutex_destroy" ); + + ll_pthread_rwlock_init =dlsym (RTLD_NEXT ,"pthread_rwlock_init" ); + ll_pthread_rwlock_destroy =dlsym (RTLD_NEXT ,"pthread_rwlock_destroy" ); + ll_pthread_rwlock_rdlock =dlsym (RTLD_NEXT ,"pthread_rwlock_rdlock" ); + ll_pthread_rwlock_tryrdlock =dlsym (RTLD_NEXT ,"pthread_rwlock_tryrdlock" ); + ll_pthread_rwlock_wrlock =dlsym (RTLD_NEXT ,"pthread_rwlock_wrlock" ); + ll_pthread_rwlock_trywrlock =dlsym (RTLD_NEXT ,"pthread_rwlock_trywrlock" ); + ll_pthread_rwlock_unlock =dlsym (RTLD_NEXT ,"pthread_rwlock_unlock" ); + +lockdep_init (); + + preload_done = true; +}
Re: [PATCH 7/9] liblockdep: Support using LD_PRELOAD
Peter,
Thanks for your comments! I'll address them and re-send the patch series.
Quoted 10 lines · Peter Zijlstra
Quoted 10 lines
(quoted diff) +1
-0+ /*Quoted 9 lines
tools/lib/lockdep/preload.c new file +9
-0+* Some programs attempt to initialize and use locks in their +* allocation path. This means that a call to malloc() would +* result in locks being initialized and locked. +* +* Why is it an issue for us? dlsym() below will try allocating to +* give us the original function. Since this allocation will result +* in a locking operations, we have to let pthread deal with it, +* but we can't! we don't have the pointer to the original API +* since we're inside dlsym() trying to get it :(
Quoted 8 lines
Quoted 7 lines
tools/lib/lockdep/preload.c line 355
Quoted 7 lines
tools/lib/lockdep/preload.c new file +7
-0+* +* We can work around it by telling the program that locking was +* really okay, and just initialize those locks when we're fully +* up and running (this is ok because this all happens during +* initialization phase, when we have just one thread). But +* this is a big TODO at this point. +*/ Fun.. got any example programs that trigger this?
firefox.
The problem there is that it uses jemalloc, which tries to do what I've described in the blurb above.
Thanks,
Sasha
PATCH 8/9 liblockdep: Add the 'lockdep' user-space utility
In reply to Sasha LevinThis is a simple wrapper to make using liblockdep on existing applications much easier.
After running 'make && make install', it becomes quite simple to test things with liblockdep. For example, to try it on perf:
lockdep perf
No other integration required.
--- tools/lib/lockdep/lockdep | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 tools/lib/lockdep/lockdep
tools/lib/lockdep/lockdep new file +3 -0
@@ -0,0 +1,3 @@ +#! /bin/bash + +LD_PRELOAD="liblockdep.so $LD_PRELOAD" "$@"
Signature · 1 line
1.8.2.1
PATCH 9/9 liblockdep: Add a MAINTAINERS entry
In reply to Sasha Levin--- MAINTAINERS | 5 +++++ 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
@@ -4784,6 +4784,11 @@ F: drivers/lguest/ F: include/linux/lguest*.h F: tools/lguest/ +LIBLOCK +M: Sasha Levin <[email protected]> +S: Maintained +F: tools/lib/lockdep/ + LINUX FOR IBM pSERIES (RS/6000) M: Paul Mackerras <[email protected]> W: http://www.ibm.com/linux/ltc/projects/ppc
Signature · 1 line
1.8.2.1
Ping?
Thanks,
Sasha
Quoted 153 lines · Sasha Levin
liblockdep is a tiny wrapper built around
kernel/lockdep.c. The aim is to provide the same functionality the kernel gets from lockdep to userspace.The bulk of the code here is the
LD_PRELOADsupport which provides users an easy way to test their code without having to integrate liblockdep into said code. Simply doing:lockdep
my_appWould provide lockdep support to
my_app.There is also a small test suite to test both mutexes and rwlocks, it's based on the tests in
lib/locking-selftest.c.This entire patch series was reviewed by lockdep maintainers and accepted to the tip tree previously. It was pulled out so that the potential merge of liblockdep won't delay the rest of the commits in the tip locking tree.
For some more background about this entire thing, the folks at LWN did an awesome overview: http://lwn.net/Articles/536363/
Sasha Levin (9):
lockdep: Be nice about building from userspace
liblockdep: Wrapkernel/lockdep.cto allow usage from userspace
liblockdep: Add public headers forpthread_mutex_timplementation
liblockdep: Addpthread_mutex_ttest suite
liblockdep: Add public headers forpthread_rwlock_timplementation
liblockdep: Addpthread_rwlock_ttest suite
liblockdep: Support usingLD_PRELOAD
liblockdep: Add the 'lockdep' user-space utility
liblockdep: Add aMAINTAINERSentryMAINTAINERS | 5 + kernel/lockdep.c | 4 + tools/lib/lockdep/Makefile | 251 ++++++++++++++ tools/lib/lockdep/common.c | 33 ++ tools/lib/lockdep/include/liblockdep/common.h | 43 +++ tools/lib/lockdep/include/liblockdep/mutex.h | 73 ++++ tools/lib/lockdep/include/liblockdep/rwlock.h | 91 +++++ tools/lib/lockdep/lockdep | 3 + tools/lib/lockdep/lockdep.c | 2 + tools/lib/lockdep/lockdep_internals.h | 1 + tools/lib/lockdep/lockdep_states.h | 1 + tools/lib/lockdep/preload.c | 386 +++++++++++++++++++++ tools/lib/lockdep/rbtree.c | 1 + tools/lib/lockdep/run_tests.sh | 27 ++ tools/lib/lockdep/tests/AA.c | 13 + tools/lib/lockdep/tests/ABBA.c | 13 + tools/lib/lockdep/tests/ABBCCA.c | 15 + tools/lib/lockdep/tests/ABBCCDDA.c | 17 + tools/lib/lockdep/tests/ABCABC.c | 15 + tools/lib/lockdep/tests/ABCDBCDA.c | 17 + tools/lib/lockdep/tests/ABCDBDDA.c | 17 + tools/lib/lockdep/tests/WW.c | 13 + tools/lib/lockdep/tests/common.h | 12 + tools/lib/lockdep/tests/unlock_balance.c | 12 + tools/lib/lockdep/uinclude/asm/hweight.h | 0 tools/lib/lockdep/uinclude/asm/sections.h | 0 tools/lib/lockdep/uinclude/linux/bitops.h | 0 tools/lib/lockdep/uinclude/linux/compiler.h | 7 + tools/lib/lockdep/uinclude/linux/debug_locks.h | 12 + tools/lib/lockdep/uinclude/linux/delay.h | 0 tools/lib/lockdep/uinclude/linux/export.h | 7 + tools/lib/lockdep/uinclude/linux/ftrace.h | 0 tools/lib/lockdep/uinclude/linux/gfp.h | 0 tools/lib/lockdep/uinclude/linux/hardirq.h | 11 + tools/lib/lockdep/uinclude/linux/hash.h | 1 + tools/lib/lockdep/uinclude/linux/interrupt.h | 0 tools/lib/lockdep/uinclude/linux/irqflags.h | 38 ++ tools/lib/lockdep/uinclude/linux/kallsyms.h | 32 ++ tools/lib/lockdep/uinclude/linux/kernel.h | 36 ++ tools/lib/lockdep/uinclude/linux/kmemcheck.h | 8 + tools/lib/lockdep/uinclude/linux/linkage.h | 0 tools/lib/lockdep/uinclude/linux/list.h | 1 + tools/lib/lockdep/uinclude/linux/lockdep.h | 58 ++++ tools/lib/lockdep/uinclude/linux/mm_types.h | 0 tools/lib/lockdep/uinclude/linux/module.h | 6 + tools/lib/lockdep/uinclude/linux/mutex.h | 0 tools/lib/lockdep/uinclude/linux/poison.h | 1 + tools/lib/lockdep/uinclude/linux/prefetch.h | 6 + tools/lib/lockdep/uinclude/linux/proc_fs.h | 0 tools/lib/lockdep/uinclude/linux/rbtree.h | 1 + .../lib/lockdep/uinclude/linux/rbtree_augmented.h | 2 + tools/lib/lockdep/uinclude/linux/rcu.h | 16 + tools/lib/lockdep/uinclude/linux/seq_file.h | 0 tools/lib/lockdep/uinclude/linux/spinlock.h | 25 ++ tools/lib/lockdep/uinclude/linux/stacktrace.h | 32 ++ tools/lib/lockdep/uinclude/linux/stringify.h | 7 + tools/lib/lockdep/uinclude/linux/system.h | 0 tools/lib/lockdep/uinclude/linux/types.h | 58 ++++ tools/lib/lockdep/uinclude/linux/util.h | 0 tools/lib/lockdep/uinclude/trace/events/lock.h | 0 60 files changed, 1430 insertions(+) create mode 100644 tools/lib/lockdep/Makefile create mode 100644 tools/lib/lockdep/common.c create mode 100644 tools/lib/lockdep/include/liblockdep/common.h create mode 100644 tools/lib/lockdep/include/liblockdep/mutex.h create mode 100644 tools/lib/lockdep/include/liblockdep/rwlock.h create mode 100755 tools/lib/lockdep/lockdep create mode 100644 tools/lib/lockdep/lockdep.c create mode 100644 tools/lib/lockdep/lockdep_internals.h create mode 100644 tools/lib/lockdep/lockdep_states.h create mode 100644 tools/lib/lockdep/preload.c create mode 100644 tools/lib/lockdep/rbtree.c create mode 100755 tools/lib/lockdep/run_tests.sh create mode 100644 tools/lib/lockdep/tests/AA.c create mode 100644 tools/lib/lockdep/tests/ABBA.c create mode 100644 tools/lib/lockdep/tests/ABBCCA.c create mode 100644 tools/lib/lockdep/tests/ABBCCDDA.c create mode 100644 tools/lib/lockdep/tests/ABCABC.c create mode 100644 tools/lib/lockdep/tests/ABCDBCDA.c create mode 100644 tools/lib/lockdep/tests/ABCDBDDA.c create mode 100644 tools/lib/lockdep/tests/WW.c create mode 100644 tools/lib/lockdep/tests/common.h create mode 100644 tools/lib/lockdep/tests/unlock_balance.c create mode 100644 tools/lib/lockdep/uinclude/asm/hweight.h create mode 100644 tools/lib/lockdep/uinclude/asm/sections.h create mode 100644 tools/lib/lockdep/uinclude/linux/bitops.h create mode 100644 tools/lib/lockdep/uinclude/linux/compiler.h create mode 100644 tools/lib/lockdep/uinclude/linux/debug_locks.h create mode 100644 tools/lib/lockdep/uinclude/linux/delay.h create mode 100644 tools/lib/lockdep/uinclude/linux/export.h create mode 100644 tools/lib/lockdep/uinclude/linux/ftrace.h create mode 100644 tools/lib/lockdep/uinclude/linux/gfp.h create mode 100644 tools/lib/lockdep/uinclude/linux/hardirq.h create mode 100644 tools/lib/lockdep/uinclude/linux/hash.h create mode 100644 tools/lib/lockdep/uinclude/linux/interrupt.h create mode 100644 tools/lib/lockdep/uinclude/linux/irqflags.h create mode 100644 tools/lib/lockdep/uinclude/linux/kallsyms.h create mode 100644 tools/lib/lockdep/uinclude/linux/kernel.h create mode 100644 tools/lib/lockdep/uinclude/linux/kmemcheck.h create mode 100644 tools/lib/lockdep/uinclude/linux/linkage.h create mode 100644 tools/lib/lockdep/uinclude/linux/list.h create mode 100644 tools/lib/lockdep/uinclude/linux/lockdep.h create mode 100644 tools/lib/lockdep/uinclude/linux/mm_types.h create mode 100644 tools/lib/lockdep/uinclude/linux/module.h create mode 100644 tools/lib/lockdep/uinclude/linux/mutex.h create mode 100644 tools/lib/lockdep/uinclude/linux/poison.h create mode 100644 tools/lib/lockdep/uinclude/linux/prefetch.h create mode 100644 tools/lib/lockdep/uinclude/linux/proc_fs.h create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree.h create mode 100644 tools/lib/lockdep/uinclude/linux/rbtree_augmented.h create mode 100644 tools/lib/lockdep/uinclude/linux/rcu.h create mode 100644 tools/lib/lockdep/uinclude/linux/seq_file.h create mode 100644 tools/lib/lockdep/uinclude/linux/spinlock.h create mode 100644 tools/lib/lockdep/uinclude/linux/stacktrace.h create mode 100644 tools/lib/lockdep/uinclude/linux/stringify.h create mode 100644 tools/lib/lockdep/uinclude/linux/system.h create mode 100644 tools/lib/lockdep/uinclude/linux/types.h create mode 100644 tools/lib/lockdep/uinclude/linux/util.h create mode 100644 tools/lib/lockdep/uinclude/trace/events/lock.h