aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-07-03 15:14:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-03 15:14:18 -0400
commit892ad5acca0b2ddb514fae63fa4686bf726d2471 (patch)
tree9945b41e6552c0b6b9b1b5b0ffb77f2f15857671
parent162b246eb420d2ca2002a50917c897b10c9aba09 (diff)
parent5d6dec6fba38c3e2d408df108bb92ef4ac201f18 (diff)
Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking updates from Ingo Molnar: "The main changes in this cycle were: - Add CONFIG_REFCOUNT_FULL=y to allow the disabling of the 'full' (robustness checked) refcount_t implementation with slightly lower runtime overhead. (Kees Cook) The lighter weight variant is the default. The two variants use the same API. Having this variant was a precondition by some maintainers to merge refcount_t cleanups. - Add lockdep support for rtmutexes (Peter Zijlstra) - liblockdep fixes and improvements (Sasha Levin, Ben Hutchings) - ... misc fixes and improvements" * 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (30 commits) locking/refcount: Remove the half-implemented refcount_sub() API locking/refcount: Create unchecked atomic_t implementation locking/rtmutex: Don't initialize lockdep when not required locking/selftest: Add RT-mutex support locking/selftest: Remove the bad unlock ordering test rt_mutex: Add lockdep annotations MAINTAINERS: Claim atomic*_t maintainership locking/x86: Remove the unused atomic_inc_short() methd tools/lib/lockdep: Remove private kernel headers tools/lib/lockdep: Hide liblockdep output from test results tools/lib/lockdep: Add dummy current_gfp_context() tools/include: Add IS_ERR_OR_NULL to err.h tools/lib/lockdep: Add empty __is_[module,kernel]_percpu_address tools/lib/lockdep: Include err.h tools/include: Add (mostly) empty include/linux/sched/mm.h tools/lib/lockdep: Use LDFLAGS tools/lib/lockdep: Remove double-quotes from soname tools/lib/lockdep: Fix object file paths used in an out-of-tree build tools/lib/lockdep: Fix compilation for 4.11 tools/lib/lockdep: Don't mix fd-based and stream IO ...
-rw-r--r--MAINTAINERS11
-rw-r--r--arch/Kconfig9
-rw-r--r--arch/tile/lib/atomic_asm_32.S3
-rw-r--r--arch/x86/include/asm/atomic.h13
-rw-r--r--include/linux/refcount.h38
-rw-r--r--include/linux/rtmutex.h25
-rw-r--r--kernel/locking/rtmutex-debug.c6
-rw-r--r--kernel/locking/rtmutex-debug.h2
-rw-r--r--kernel/locking/rtmutex.c37
-rw-r--r--kernel/locking/rtmutex.h2
-rw-r--r--lib/Kconfig.debug3
-rw-r--r--lib/locking-selftest-rtmutex.h11
-rw-r--r--lib/locking-selftest.c133
-rw-r--r--lib/refcount.c3
-rw-r--r--tools/Makefile8
-rw-r--r--tools/include/asm/sections.h4
-rw-r--r--tools/include/linux/bitops.h10
-rw-r--r--tools/include/linux/compiler.h12
-rw-r--r--tools/include/linux/debug_locks.h (renamed from tools/lib/lockdep/uinclude/linux/debug_locks.h)3
-rw-r--r--tools/include/linux/delay.h4
-rw-r--r--tools/include/linux/err.h5
-rw-r--r--tools/include/linux/ftrace.h4
-rw-r--r--tools/include/linux/gfp.h4
-rw-r--r--tools/include/linux/hardirq.h (renamed from tools/lib/lockdep/uinclude/linux/hardirq.h)0
-rw-r--r--tools/include/linux/interrupt.h4
-rw-r--r--tools/include/linux/irqflags.h (renamed from tools/lib/lockdep/uinclude/linux/irqflags.h)8
-rw-r--r--tools/include/linux/jhash.h175
-rw-r--r--tools/include/linux/kallsyms.h (renamed from tools/lib/lockdep/uinclude/linux/kallsyms.h)3
-rw-r--r--tools/include/linux/kern_levels.h (renamed from tools/lib/lockdep/uinclude/linux/kern_levels.h)0
-rw-r--r--tools/include/linux/kernel.h4
-rw-r--r--tools/include/linux/kmemcheck.h (renamed from tools/lib/lockdep/uinclude/linux/kmemcheck.h)0
-rw-r--r--tools/include/linux/linkage.h4
-rw-r--r--tools/include/linux/lockdep.h (renamed from tools/lib/lockdep/uinclude/linux/lockdep.h)34
-rw-r--r--tools/include/linux/module.h (renamed from tools/lib/lockdep/uinclude/linux/module.h)5
-rw-r--r--tools/include/linux/mutex.h4
-rw-r--r--tools/include/linux/proc_fs.h4
-rw-r--r--tools/include/linux/rcu.h (renamed from tools/lib/lockdep/uinclude/linux/rcu.h)3
-rw-r--r--tools/include/linux/sched/clock.h4
-rw-r--r--tools/include/linux/sched/mm.h4
-rw-r--r--tools/include/linux/sched/task.h4
-rw-r--r--tools/include/linux/seq_file.h4
-rw-r--r--tools/include/linux/spinlock.h26
-rw-r--r--tools/include/linux/stacktrace.h (renamed from tools/lib/lockdep/uinclude/linux/stacktrace.h)0
-rw-r--r--tools/include/linux/unaligned/packed_struct.h46
-rw-r--r--tools/include/trace/events/lock.h4
-rw-r--r--tools/lib/lockdep/Makefile9
-rw-r--r--tools/lib/lockdep/lockdep.c19
-rw-r--r--tools/lib/lockdep/preload.c5
-rw-r--r--tools/lib/lockdep/rbtree.c2
-rwxr-xr-xtools/lib/lockdep/run_tests.sh8
-rw-r--r--tools/lib/lockdep/uinclude/asm/hash.h6
-rw-r--r--tools/lib/lockdep/uinclude/asm/hweight.h3
-rw-r--r--tools/lib/lockdep/uinclude/asm/sections.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/bitops.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/compiler.h10
-rw-r--r--tools/lib/lockdep/uinclude/linux/delay.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/ftrace.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/gfp.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/hash.h1
-rw-r--r--tools/lib/lockdep/uinclude/linux/interrupt.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/kernel.h47
-rw-r--r--tools/lib/lockdep/uinclude/linux/linkage.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/list.h1
-rw-r--r--tools/lib/lockdep/uinclude/linux/mutex.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/poison.h1
-rw-r--r--tools/lib/lockdep/uinclude/linux/prefetch.h6
-rw-r--r--tools/lib/lockdep/uinclude/linux/proc_fs.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/rbtree_augmented.h2
-rw-r--r--tools/lib/lockdep/uinclude/linux/seq_file.h3
-rw-r--r--tools/lib/lockdep/uinclude/linux/spinlock.h25
-rw-r--r--tools/lib/lockdep/uinclude/linux/stringify.h7
-rw-r--r--tools/lib/lockdep/uinclude/trace/events/lock.h3
72 files changed, 641 insertions, 234 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 503f80a43bec..d357695ee4fe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2322,6 +2322,15 @@ F: Documentation/devicetree/bindings/input/atmel,maxtouch.txt
2322F: drivers/input/touchscreen/atmel_mxt_ts.c 2322F: drivers/input/touchscreen/atmel_mxt_ts.c
2323F: include/linux/platform_data/atmel_mxt_ts.h 2323F: include/linux/platform_data/atmel_mxt_ts.h
2324 2324
2325ATOMIC INFRASTRUCTURE
2326M: Will Deacon <will.deacon@arm.com>
2327M: Peter Zijlstra <peterz@infradead.org>
2328R: Boqun Feng <boqun.feng@gmail.com>
2329L: linux-kernel@vger.kernel.org
2330S: Maintained
2331F: arch/*/include/asm/atomic*.h
2332F: include/*/atomic*.h
2333
2325ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER 2334ATTO EXPRESSSAS SAS/SATA RAID SCSI DRIVER
2326M: Bradley Grove <linuxdrivers@attotech.com> 2335M: Bradley Grove <linuxdrivers@attotech.com>
2327L: linux-scsi@vger.kernel.org 2336L: linux-scsi@vger.kernel.org
@@ -7555,7 +7564,7 @@ S: Maintained
7555F: drivers/ata/sata_promise.* 7564F: drivers/ata/sata_promise.*
7556 7565
7557LIBLOCKDEP 7566LIBLOCKDEP
7558M: Sasha Levin <sasha.levin@oracle.com> 7567M: Sasha Levin <alexander.levin@verizon.com>
7559S: Maintained 7568S: Maintained
7560F: tools/lib/lockdep/ 7569F: tools/lib/lockdep/
7561 7570
diff --git a/arch/Kconfig b/arch/Kconfig
index 6c00e5b00f8b..f76b214cf7ad 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -867,4 +867,13 @@ config STRICT_MODULE_RWX
867config ARCH_WANT_RELAX_ORDER 867config ARCH_WANT_RELAX_ORDER
868 bool 868 bool
869 869
870config REFCOUNT_FULL
871 bool "Perform full reference count validation at the expense of speed"
872 help
873 Enabling this switches the refcounting infrastructure from a fast
874 unchecked atomic_t implementation to a fully state checked
875 implementation, which can be (slightly) slower but provides protections
876 against various use-after-free conditions that can be used in
877 security flaw exploits.
878
870source "kernel/gcov/Kconfig" 879source "kernel/gcov/Kconfig"
diff --git a/arch/tile/lib/atomic_asm_32.S b/arch/tile/lib/atomic_asm_32.S
index 1a70e6c0f259..94709ab41ed8 100644
--- a/arch/tile/lib/atomic_asm_32.S
+++ b/arch/tile/lib/atomic_asm_32.S
@@ -24,8 +24,7 @@
24 * has an opportunity to return -EFAULT to the user if needed. 24 * has an opportunity to return -EFAULT to the user if needed.
25 * The 64-bit routines just return a "long long" with the value, 25 * The 64-bit routines just return a "long long" with the value,
26 * since they are only used from kernel space and don't expect to fault. 26 * since they are only used from kernel space and don't expect to fault.
27 * Support for 16-bit ops is included in the framework but we don't provide 27 * Support for 16-bit ops is included in the framework but we don't provide any.
28 * any (x86_64 has an atomic_inc_short(), so we might want to some day).
29 * 28 *
30 * Note that the caller is advised to issue a suitable L1 or L2 29 * Note that the caller is advised to issue a suitable L1 or L2
31 * prefetch on the address being manipulated to avoid extra stalls. 30 * prefetch on the address being manipulated to avoid extra stalls.
diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index caa5798c92f4..33380b871463 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -246,19 +246,6 @@ static __always_inline int __atomic_add_unless(atomic_t *v, int a, int u)
246 return c; 246 return c;
247} 247}
248 248
249/**
250 * atomic_inc_short - increment of a short integer
251 * @v: pointer to type int
252 *
253 * Atomically adds 1 to @v
254 * Returns the new value of @u
255 */
256static __always_inline short int atomic_inc_short(short int *v)
257{
258 asm(LOCK_PREFIX "addw $1, %0" : "+m" (*v));
259 return *v;
260}
261
262#ifdef CONFIG_X86_32 249#ifdef CONFIG_X86_32
263# include <asm/atomic64_32.h> 250# include <asm/atomic64_32.h>
264#else 251#else
diff --git a/include/linux/refcount.h b/include/linux/refcount.h
index b34aa649d204..591792c8e5b0 100644
--- a/include/linux/refcount.h
+++ b/include/linux/refcount.h
@@ -41,6 +41,7 @@ static inline unsigned int refcount_read(const refcount_t *r)
41 return atomic_read(&r->refs); 41 return atomic_read(&r->refs);
42} 42}
43 43
44#ifdef CONFIG_REFCOUNT_FULL
44extern __must_check bool refcount_add_not_zero(unsigned int i, refcount_t *r); 45extern __must_check bool refcount_add_not_zero(unsigned int i, refcount_t *r);
45extern void refcount_add(unsigned int i, refcount_t *r); 46extern void refcount_add(unsigned int i, refcount_t *r);
46 47
@@ -48,10 +49,45 @@ extern __must_check bool refcount_inc_not_zero(refcount_t *r);
48extern void refcount_inc(refcount_t *r); 49extern void refcount_inc(refcount_t *r);
49 50
50extern __must_check bool refcount_sub_and_test(unsigned int i, refcount_t *r); 51extern __must_check bool refcount_sub_and_test(unsigned int i, refcount_t *r);
51extern void refcount_sub(unsigned int i, refcount_t *r);
52 52
53extern __must_check bool refcount_dec_and_test(refcount_t *r); 53extern __must_check bool refcount_dec_and_test(refcount_t *r);
54extern void refcount_dec(refcount_t *r); 54extern void refcount_dec(refcount_t *r);
55#else
56static inline __must_check bool refcount_add_not_zero(unsigned int i, refcount_t *r)
57{
58 return atomic_add_unless(&r->refs, i, 0);
59}
60
61static inline void refcount_add(unsigned int i, refcount_t *r)
62{
63 atomic_add(i, &r->refs);
64}
65
66static inline __must_check bool refcount_inc_not_zero(refcount_t *r)
67{
68 return atomic_add_unless(&r->refs, 1, 0);
69}
70
71static inline void refcount_inc(refcount_t *r)
72{
73 atomic_inc(&r->refs);
74}
75
76static inline __must_check bool refcount_sub_and_test(unsigned int i, refcount_t *r)
77{
78 return atomic_sub_and_test(i, &r->refs);
79}
80
81static inline __must_check bool refcount_dec_and_test(refcount_t *r)
82{
83 return atomic_dec_and_test(&r->refs);
84}
85
86static inline void refcount_dec(refcount_t *r)
87{
88 atomic_dec(&r->refs);
89}
90#endif /* CONFIG_REFCOUNT_FULL */
55 91
56extern __must_check bool refcount_dec_if_one(refcount_t *r); 92extern __must_check bool refcount_dec_if_one(refcount_t *r);
57extern __must_check bool refcount_dec_not_one(refcount_t *r); 93extern __must_check bool refcount_dec_not_one(refcount_t *r);
diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h
index 1abba5ce2a2f..44fd002f7cd5 100644
--- a/include/linux/rtmutex.h
+++ b/include/linux/rtmutex.h
@@ -37,6 +37,9 @@ struct rt_mutex {
37 int line; 37 int line;
38 void *magic; 38 void *magic;
39#endif 39#endif
40#ifdef CONFIG_DEBUG_LOCK_ALLOC
41 struct lockdep_map dep_map;
42#endif
40}; 43};
41 44
42struct rt_mutex_waiter; 45struct rt_mutex_waiter;
@@ -58,19 +61,33 @@ struct hrtimer_sleeper;
58#ifdef CONFIG_DEBUG_RT_MUTEXES 61#ifdef CONFIG_DEBUG_RT_MUTEXES
59# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \ 62# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
60 , .name = #mutexname, .file = __FILE__, .line = __LINE__ 63 , .name = #mutexname, .file = __FILE__, .line = __LINE__
61# define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__) 64
65# define rt_mutex_init(mutex) \
66do { \
67 static struct lock_class_key __key; \
68 __rt_mutex_init(mutex, __func__, &__key); \
69} while (0)
70
62 extern void rt_mutex_debug_task_free(struct task_struct *tsk); 71 extern void rt_mutex_debug_task_free(struct task_struct *tsk);
63#else 72#else
64# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) 73# define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
65# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL) 74# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL, NULL)
66# define rt_mutex_debug_task_free(t) do { } while (0) 75# define rt_mutex_debug_task_free(t) do { } while (0)
67#endif 76#endif
68 77
78#ifdef CONFIG_DEBUG_LOCK_ALLOC
79#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \
80 , .dep_map = { .name = #mutexname }
81#else
82#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)
83#endif
84
69#define __RT_MUTEX_INITIALIZER(mutexname) \ 85#define __RT_MUTEX_INITIALIZER(mutexname) \
70 { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \ 86 { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
71 , .waiters = RB_ROOT \ 87 , .waiters = RB_ROOT \
72 , .owner = NULL \ 88 , .owner = NULL \
73 __DEBUG_RT_MUTEX_INITIALIZER(mutexname)} 89 __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
90 __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname)}
74 91
75#define DEFINE_RT_MUTEX(mutexname) \ 92#define DEFINE_RT_MUTEX(mutexname) \
76 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname) 93 struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
@@ -86,7 +103,7 @@ static inline int rt_mutex_is_locked(struct rt_mutex *lock)
86 return lock->owner != NULL; 103 return lock->owner != NULL;
87} 104}
88 105
89extern void __rt_mutex_init(struct rt_mutex *lock, const char *name); 106extern void __rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
90extern void rt_mutex_destroy(struct rt_mutex *lock); 107extern void rt_mutex_destroy(struct rt_mutex *lock);
91 108
92extern void rt_mutex_lock(struct rt_mutex *lock); 109extern void rt_mutex_lock(struct rt_mutex *lock);
diff --git a/kernel/locking/rtmutex-debug.c b/kernel/locking/rtmutex-debug.c
index 58e366ad36f4..ac35e648b0e5 100644
--- a/kernel/locking/rtmutex-debug.c
+++ b/kernel/locking/rtmutex-debug.c
@@ -166,12 +166,16 @@ void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
166 memset(waiter, 0x22, sizeof(*waiter)); 166 memset(waiter, 0x22, sizeof(*waiter));
167} 167}
168 168
169void debug_rt_mutex_init(struct rt_mutex *lock, const char *name) 169void debug_rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key)
170{ 170{
171 /* 171 /*
172 * Make sure we are not reinitializing a held lock: 172 * Make sure we are not reinitializing a held lock:
173 */ 173 */
174 debug_check_no_locks_freed((void *)lock, sizeof(*lock)); 174 debug_check_no_locks_freed((void *)lock, sizeof(*lock));
175 lock->name = name; 175 lock->name = name;
176
177#ifdef CONFIG_DEBUG_LOCK_ALLOC
178 lockdep_init_map(&lock->dep_map, name, key, 0);
179#endif
176} 180}
177 181
diff --git a/kernel/locking/rtmutex-debug.h b/kernel/locking/rtmutex-debug.h
index b585af9a1b50..5078c6ddf4a5 100644
--- a/kernel/locking/rtmutex-debug.h
+++ b/kernel/locking/rtmutex-debug.h
@@ -11,7 +11,7 @@
11 11
12extern void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter); 12extern void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter);
13extern void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter); 13extern void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter);
14extern void debug_rt_mutex_init(struct rt_mutex *lock, const char *name); 14extern void debug_rt_mutex_init(struct rt_mutex *lock, const char *name, struct lock_class_key *key);
15extern void debug_rt_mutex_lock(struct rt_mutex *lock); 15extern void debug_rt_mutex_lock(struct rt_mutex *lock);
16extern void debug_rt_mutex_unlock(struct rt_mutex *lock); 16extern void debug_rt_mutex_unlock(struct rt_mutex *lock);
17extern void debug_rt_mutex_proxy_lock(struct rt_mutex *lock, 17extern void debug_rt_mutex_proxy_lock(struct rt_mutex *lock,
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 28cd09e635ed..78069895032a 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1481,6 +1481,7 @@ void __sched rt_mutex_lock(struct rt_mutex *lock)
1481{ 1481{
1482 might_sleep(); 1482 might_sleep();
1483 1483
1484 mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
1484 rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock); 1485 rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
1485} 1486}
1486EXPORT_SYMBOL_GPL(rt_mutex_lock); 1487EXPORT_SYMBOL_GPL(rt_mutex_lock);
@@ -1496,9 +1497,16 @@ EXPORT_SYMBOL_GPL(rt_mutex_lock);
1496 */ 1497 */
1497int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock) 1498int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
1498{ 1499{
1500 int ret;
1501
1499 might_sleep(); 1502 might_sleep();
1500 1503
1501 return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock); 1504 mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
1505 ret = rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
1506 if (ret)
1507 mutex_release(&lock->dep_map, 1, _RET_IP_);
1508
1509 return ret;
1502} 1510}
1503EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible); 1511EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
1504 1512
@@ -1526,11 +1534,18 @@ int __sched rt_mutex_futex_trylock(struct rt_mutex *lock)
1526int 1534int
1527rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout) 1535rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
1528{ 1536{
1537 int ret;
1538
1529 might_sleep(); 1539 might_sleep();
1530 1540
1531 return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout, 1541 mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
1542 ret = rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
1532 RT_MUTEX_MIN_CHAINWALK, 1543 RT_MUTEX_MIN_CHAINWALK,
1533 rt_mutex_slowlock); 1544 rt_mutex_slowlock);
1545 if (ret)
1546 mutex_release(&lock->dep_map, 1, _RET_IP_);
1547
1548 return ret;
1534} 1549}
1535EXPORT_SYMBOL_GPL(rt_mutex_timed_lock); 1550EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
1536 1551
@@ -1547,10 +1562,16 @@ EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
1547 */ 1562 */
1548int __sched rt_mutex_trylock(struct rt_mutex *lock) 1563int __sched rt_mutex_trylock(struct rt_mutex *lock)
1549{ 1564{
1565 int ret;
1566
1550 if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq())) 1567 if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq()))
1551 return 0; 1568 return 0;
1552 1569
1553 return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock); 1570 ret = rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
1571 if (ret)
1572 mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
1573
1574 return ret;
1554} 1575}
1555EXPORT_SYMBOL_GPL(rt_mutex_trylock); 1576EXPORT_SYMBOL_GPL(rt_mutex_trylock);
1556 1577
@@ -1561,6 +1582,7 @@ EXPORT_SYMBOL_GPL(rt_mutex_trylock);
1561 */ 1582 */
1562void __sched rt_mutex_unlock(struct rt_mutex *lock) 1583void __sched rt_mutex_unlock(struct rt_mutex *lock)
1563{ 1584{
1585 mutex_release(&lock->dep_map, 1, _RET_IP_);
1564 rt_mutex_fastunlock(lock, rt_mutex_slowunlock); 1586 rt_mutex_fastunlock(lock, rt_mutex_slowunlock);
1565} 1587}
1566EXPORT_SYMBOL_GPL(rt_mutex_unlock); 1588EXPORT_SYMBOL_GPL(rt_mutex_unlock);
@@ -1620,7 +1642,6 @@ void rt_mutex_destroy(struct rt_mutex *lock)
1620 lock->magic = NULL; 1642 lock->magic = NULL;
1621#endif 1643#endif
1622} 1644}
1623
1624EXPORT_SYMBOL_GPL(rt_mutex_destroy); 1645EXPORT_SYMBOL_GPL(rt_mutex_destroy);
1625 1646
1626/** 1647/**
@@ -1632,14 +1653,16 @@ EXPORT_SYMBOL_GPL(rt_mutex_destroy);
1632 * 1653 *
1633 * Initializing of a locked rt lock is not allowed 1654 * Initializing of a locked rt lock is not allowed
1634 */ 1655 */
1635void __rt_mutex_init(struct rt_mutex *lock, const char *name) 1656void __rt_mutex_init(struct rt_mutex *lock, const char *name,
1657 struct lock_class_key *key)
1636{ 1658{
1637 lock->owner = NULL; 1659 lock->owner = NULL;
1638 raw_spin_lock_init(&lock->wait_lock); 1660 raw_spin_lock_init(&lock->wait_lock);
1639 lock->waiters = RB_ROOT; 1661 lock->waiters = RB_ROOT;
1640 lock->waiters_leftmost = NULL; 1662 lock->waiters_leftmost = NULL;
1641 1663
1642 debug_rt_mutex_init(lock, name); 1664 if (name && key)
1665 debug_rt_mutex_init(lock, name, key);
1643} 1666}
1644EXPORT_SYMBOL_GPL(__rt_mutex_init); 1667EXPORT_SYMBOL_GPL(__rt_mutex_init);
1645 1668
@@ -1660,7 +1683,7 @@ EXPORT_SYMBOL_GPL(__rt_mutex_init);
1660void rt_mutex_init_proxy_locked(struct rt_mutex *lock, 1683void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
1661 struct task_struct *proxy_owner) 1684 struct task_struct *proxy_owner)
1662{ 1685{
1663 __rt_mutex_init(lock, NULL); 1686 __rt_mutex_init(lock, NULL, NULL);
1664 debug_rt_mutex_proxy_lock(lock, proxy_owner); 1687 debug_rt_mutex_proxy_lock(lock, proxy_owner);
1665 rt_mutex_set_owner(lock, proxy_owner); 1688 rt_mutex_set_owner(lock, proxy_owner);
1666} 1689}
diff --git a/kernel/locking/rtmutex.h b/kernel/locking/rtmutex.h
index 6607802efa8b..5c253caffe91 100644
--- a/kernel/locking/rtmutex.h
+++ b/kernel/locking/rtmutex.h
@@ -17,7 +17,7 @@
17#define debug_rt_mutex_proxy_lock(l,p) do { } while (0) 17#define debug_rt_mutex_proxy_lock(l,p) do { } while (0)
18#define debug_rt_mutex_proxy_unlock(l) do { } while (0) 18#define debug_rt_mutex_proxy_unlock(l) do { } while (0)
19#define debug_rt_mutex_unlock(l) do { } while (0) 19#define debug_rt_mutex_unlock(l) do { } while (0)
20#define debug_rt_mutex_init(m, n) do { } while (0) 20#define debug_rt_mutex_init(m, n, k) do { } while (0)
21#define debug_rt_mutex_deadlock(d, a ,l) do { } while (0) 21#define debug_rt_mutex_deadlock(d, a ,l) do { } while (0)
22#define debug_rt_mutex_print_deadlock(w) do { } while (0) 22#define debug_rt_mutex_print_deadlock(w) do { } while (0)
23#define debug_rt_mutex_reset_waiter(w) do { } while (0) 23#define debug_rt_mutex_reset_waiter(w) do { } while (0)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index a7a751a75cfd..9c5d40a50930 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1052,6 +1052,7 @@ config DEBUG_LOCK_ALLOC
1052 depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT 1052 depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
1053 select DEBUG_SPINLOCK 1053 select DEBUG_SPINLOCK
1054 select DEBUG_MUTEXES 1054 select DEBUG_MUTEXES
1055 select DEBUG_RT_MUTEXES if RT_MUTEXES
1055 select LOCKDEP 1056 select LOCKDEP
1056 help 1057 help
1057 This feature will check whether any held lock (spinlock, rwlock, 1058 This feature will check whether any held lock (spinlock, rwlock,
@@ -1067,6 +1068,7 @@ config PROVE_LOCKING
1067 select LOCKDEP 1068 select LOCKDEP
1068 select DEBUG_SPINLOCK 1069 select DEBUG_SPINLOCK
1069 select DEBUG_MUTEXES 1070 select DEBUG_MUTEXES
1071 select DEBUG_RT_MUTEXES if RT_MUTEXES
1070 select DEBUG_LOCK_ALLOC 1072 select DEBUG_LOCK_ALLOC
1071 select TRACE_IRQFLAGS 1073 select TRACE_IRQFLAGS
1072 default n 1074 default n
@@ -1121,6 +1123,7 @@ config LOCK_STAT
1121 select LOCKDEP 1123 select LOCKDEP
1122 select DEBUG_SPINLOCK 1124 select DEBUG_SPINLOCK
1123 select DEBUG_MUTEXES 1125 select DEBUG_MUTEXES
1126 select DEBUG_RT_MUTEXES if RT_MUTEXES
1124 select DEBUG_LOCK_ALLOC 1127 select DEBUG_LOCK_ALLOC
1125 default n 1128 default n
1126 help 1129 help
diff --git a/lib/locking-selftest-rtmutex.h b/lib/locking-selftest-rtmutex.h
new file mode 100644
index 000000000000..e3cb83989d16
--- /dev/null
+++ b/lib/locking-selftest-rtmutex.h
@@ -0,0 +1,11 @@
1#undef LOCK
2#define LOCK RTL
3
4#undef UNLOCK
5#define UNLOCK RTU
6
7#undef RLOCK
8#undef WLOCK
9
10#undef INIT
11#define INIT RTI
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index f3a217ea0388..6f2b135dc5e8 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/debug_locks.h> 22#include <linux/debug_locks.h>
23#include <linux/irqflags.h> 23#include <linux/irqflags.h>
24#include <linux/rtmutex.h>
24 25
25/* 26/*
26 * Change this to 1 if you want to see the failure printouts: 27 * Change this to 1 if you want to see the failure printouts:
@@ -46,6 +47,7 @@ __setup("debug_locks_verbose=", setup_debug_locks_verbose);
46#define LOCKTYPE_MUTEX 0x4 47#define LOCKTYPE_MUTEX 0x4
47#define LOCKTYPE_RWSEM 0x8 48#define LOCKTYPE_RWSEM 0x8
48#define LOCKTYPE_WW 0x10 49#define LOCKTYPE_WW 0x10
50#define LOCKTYPE_RTMUTEX 0x20
49 51
50static struct ww_acquire_ctx t, t2; 52static struct ww_acquire_ctx t, t2;
51static struct ww_mutex o, o2, o3; 53static struct ww_mutex o, o2, o3;
@@ -74,6 +76,15 @@ static DECLARE_RWSEM(rwsem_B);
74static DECLARE_RWSEM(rwsem_C); 76static DECLARE_RWSEM(rwsem_C);
75static DECLARE_RWSEM(rwsem_D); 77static DECLARE_RWSEM(rwsem_D);
76 78
79#ifdef CONFIG_RT_MUTEXES
80
81static DEFINE_RT_MUTEX(rtmutex_A);
82static DEFINE_RT_MUTEX(rtmutex_B);
83static DEFINE_RT_MUTEX(rtmutex_C);
84static DEFINE_RT_MUTEX(rtmutex_D);
85
86#endif
87
77/* 88/*
78 * Locks that we initialize dynamically as well so that 89 * Locks that we initialize dynamically as well so that
79 * e.g. X1 and X2 becomes two instances of the same class, 90 * e.g. X1 and X2 becomes two instances of the same class,
@@ -108,6 +119,17 @@ static DECLARE_RWSEM(rwsem_Y2);
108static DECLARE_RWSEM(rwsem_Z1); 119static DECLARE_RWSEM(rwsem_Z1);
109static DECLARE_RWSEM(rwsem_Z2); 120static DECLARE_RWSEM(rwsem_Z2);
110 121
122#ifdef CONFIG_RT_MUTEXES
123
124static DEFINE_RT_MUTEX(rtmutex_X1);
125static DEFINE_RT_MUTEX(rtmutex_X2);
126static DEFINE_RT_MUTEX(rtmutex_Y1);
127static DEFINE_RT_MUTEX(rtmutex_Y2);
128static DEFINE_RT_MUTEX(rtmutex_Z1);
129static DEFINE_RT_MUTEX(rtmutex_Z2);
130
131#endif
132
111/* 133/*
112 * non-inlined runtime initializers, to let separate locks share 134 * non-inlined runtime initializers, to let separate locks share
113 * the same lock-class: 135 * the same lock-class:
@@ -129,6 +151,17 @@ INIT_CLASS_FUNC(Z)
129 151
130static void init_shared_classes(void) 152static void init_shared_classes(void)
131{ 153{
154#ifdef CONFIG_RT_MUTEXES
155 static struct lock_class_key rt_X, rt_Y, rt_Z;
156
157 __rt_mutex_init(&rtmutex_X1, __func__, &rt_X);
158 __rt_mutex_init(&rtmutex_X2, __func__, &rt_X);
159 __rt_mutex_init(&rtmutex_Y1, __func__, &rt_Y);
160 __rt_mutex_init(&rtmutex_Y2, __func__, &rt_Y);
161 __rt_mutex_init(&rtmutex_Z1, __func__, &rt_Z);
162 __rt_mutex_init(&rtmutex_Z2, __func__, &rt_Z);
163#endif
164
132 init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1); 165 init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1);
133 init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2); 166 init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2);
134 167
@@ -193,6 +226,10 @@ static void init_shared_classes(void)
193#define MU(x) mutex_unlock(&mutex_##x) 226#define MU(x) mutex_unlock(&mutex_##x)
194#define MI(x) mutex_init(&mutex_##x) 227#define MI(x) mutex_init(&mutex_##x)
195 228
229#define RTL(x) rt_mutex_lock(&rtmutex_##x)
230#define RTU(x) rt_mutex_unlock(&rtmutex_##x)
231#define RTI(x) rt_mutex_init(&rtmutex_##x)
232
196#define WSL(x) down_write(&rwsem_##x) 233#define WSL(x) down_write(&rwsem_##x)
197#define WSU(x) up_write(&rwsem_##x) 234#define WSU(x) up_write(&rwsem_##x)
198 235
@@ -264,6 +301,11 @@ GENERATE_TESTCASE(AA_wsem)
264#include "locking-selftest-rsem.h" 301#include "locking-selftest-rsem.h"
265GENERATE_TESTCASE(AA_rsem) 302GENERATE_TESTCASE(AA_rsem)
266 303
304#ifdef CONFIG_RT_MUTEXES
305#include "locking-selftest-rtmutex.h"
306GENERATE_TESTCASE(AA_rtmutex);
307#endif
308
267#undef E 309#undef E
268 310
269/* 311/*
@@ -345,6 +387,11 @@ GENERATE_TESTCASE(ABBA_wsem)
345#include "locking-selftest-rsem.h" 387#include "locking-selftest-rsem.h"
346GENERATE_TESTCASE(ABBA_rsem) 388GENERATE_TESTCASE(ABBA_rsem)
347 389
390#ifdef CONFIG_RT_MUTEXES
391#include "locking-selftest-rtmutex.h"
392GENERATE_TESTCASE(ABBA_rtmutex);
393#endif
394
348#undef E 395#undef E
349 396
350/* 397/*
@@ -373,6 +420,11 @@ GENERATE_TESTCASE(ABBCCA_wsem)
373#include "locking-selftest-rsem.h" 420#include "locking-selftest-rsem.h"
374GENERATE_TESTCASE(ABBCCA_rsem) 421GENERATE_TESTCASE(ABBCCA_rsem)
375 422
423#ifdef CONFIG_RT_MUTEXES
424#include "locking-selftest-rtmutex.h"
425GENERATE_TESTCASE(ABBCCA_rtmutex);
426#endif
427
376#undef E 428#undef E
377 429
378/* 430/*
@@ -401,6 +453,11 @@ GENERATE_TESTCASE(ABCABC_wsem)
401#include "locking-selftest-rsem.h" 453#include "locking-selftest-rsem.h"
402GENERATE_TESTCASE(ABCABC_rsem) 454GENERATE_TESTCASE(ABCABC_rsem)
403 455
456#ifdef CONFIG_RT_MUTEXES
457#include "locking-selftest-rtmutex.h"
458GENERATE_TESTCASE(ABCABC_rtmutex);
459#endif
460
404#undef E 461#undef E
405 462
406/* 463/*
@@ -430,6 +487,11 @@ GENERATE_TESTCASE(ABBCCDDA_wsem)
430#include "locking-selftest-rsem.h" 487#include "locking-selftest-rsem.h"
431GENERATE_TESTCASE(ABBCCDDA_rsem) 488GENERATE_TESTCASE(ABBCCDDA_rsem)
432 489
490#ifdef CONFIG_RT_MUTEXES
491#include "locking-selftest-rtmutex.h"
492GENERATE_TESTCASE(ABBCCDDA_rtmutex);
493#endif
494
433#undef E 495#undef E
434 496
435/* 497/*
@@ -458,6 +520,11 @@ GENERATE_TESTCASE(ABCDBDDA_wsem)
458#include "locking-selftest-rsem.h" 520#include "locking-selftest-rsem.h"
459GENERATE_TESTCASE(ABCDBDDA_rsem) 521GENERATE_TESTCASE(ABCDBDDA_rsem)
460 522
523#ifdef CONFIG_RT_MUTEXES
524#include "locking-selftest-rtmutex.h"
525GENERATE_TESTCASE(ABCDBDDA_rtmutex);
526#endif
527
461#undef E 528#undef E
462 529
463/* 530/*
@@ -486,6 +553,11 @@ GENERATE_TESTCASE(ABCDBCDA_wsem)
486#include "locking-selftest-rsem.h" 553#include "locking-selftest-rsem.h"
487GENERATE_TESTCASE(ABCDBCDA_rsem) 554GENERATE_TESTCASE(ABCDBCDA_rsem)
488 555
556#ifdef CONFIG_RT_MUTEXES
557#include "locking-selftest-rtmutex.h"
558GENERATE_TESTCASE(ABCDBCDA_rtmutex);
559#endif
560
489#undef E 561#undef E
490 562
491/* 563/*
@@ -513,33 +585,10 @@ GENERATE_TESTCASE(double_unlock_wsem)
513#include "locking-selftest-rsem.h" 585#include "locking-selftest-rsem.h"
514GENERATE_TESTCASE(double_unlock_rsem) 586GENERATE_TESTCASE(double_unlock_rsem)
515 587
516#undef E 588#ifdef CONFIG_RT_MUTEXES
517 589#include "locking-selftest-rtmutex.h"
518/* 590GENERATE_TESTCASE(double_unlock_rtmutex);
519 * Bad unlock ordering: 591#endif
520 */
521#define E() \
522 \
523 LOCK(A); \
524 LOCK(B); \
525 UNLOCK(A); /* fail */ \
526 UNLOCK(B);
527
528/*
529 * 6 testcases:
530 */
531#include "locking-selftest-spin.h"
532GENERATE_TESTCASE(bad_unlock_order_spin)
533#include "locking-selftest-wlock.h"
534GENERATE_TESTCASE(bad_unlock_order_wlock)
535#include "locking-selftest-rlock.h"
536GENERATE_TESTCASE(bad_unlock_order_rlock)
537#include "locking-selftest-mutex.h"
538GENERATE_TESTCASE(bad_unlock_order_mutex)
539#include "locking-selftest-wsem.h"
540GENERATE_TESTCASE(bad_unlock_order_wsem)
541#include "locking-selftest-rsem.h"
542GENERATE_TESTCASE(bad_unlock_order_rsem)
543 592
544#undef E 593#undef E
545 594
@@ -567,6 +616,11 @@ GENERATE_TESTCASE(init_held_wsem)
567#include "locking-selftest-rsem.h" 616#include "locking-selftest-rsem.h"
568GENERATE_TESTCASE(init_held_rsem) 617GENERATE_TESTCASE(init_held_rsem)
569 618
619#ifdef CONFIG_RT_MUTEXES
620#include "locking-selftest-rtmutex.h"
621GENERATE_TESTCASE(init_held_rtmutex);
622#endif
623
570#undef E 624#undef E
571 625
572/* 626/*
@@ -916,6 +970,9 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft)
916# define I_MUTEX(x) lockdep_reset_lock(&mutex_##x.dep_map) 970# define I_MUTEX(x) lockdep_reset_lock(&mutex_##x.dep_map)
917# define I_RWSEM(x) lockdep_reset_lock(&rwsem_##x.dep_map) 971# define I_RWSEM(x) lockdep_reset_lock(&rwsem_##x.dep_map)
918# define I_WW(x) lockdep_reset_lock(&x.dep_map) 972# define I_WW(x) lockdep_reset_lock(&x.dep_map)
973#ifdef CONFIG_RT_MUTEXES
974# define I_RTMUTEX(x) lockdep_reset_lock(&rtmutex_##x.dep_map)
975#endif
919#else 976#else
920# define I_SPINLOCK(x) 977# define I_SPINLOCK(x)
921# define I_RWLOCK(x) 978# define I_RWLOCK(x)
@@ -924,12 +981,23 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft)
924# define I_WW(x) 981# define I_WW(x)
925#endif 982#endif
926 983
984#ifndef I_RTMUTEX
985# define I_RTMUTEX(x)
986#endif
987
988#ifdef CONFIG_RT_MUTEXES
989#define I2_RTMUTEX(x) rt_mutex_init(&rtmutex_##x)
990#else
991#define I2_RTMUTEX(x)
992#endif
993
927#define I1(x) \ 994#define I1(x) \
928 do { \ 995 do { \
929 I_SPINLOCK(x); \ 996 I_SPINLOCK(x); \
930 I_RWLOCK(x); \ 997 I_RWLOCK(x); \
931 I_MUTEX(x); \ 998 I_MUTEX(x); \
932 I_RWSEM(x); \ 999 I_RWSEM(x); \
1000 I_RTMUTEX(x); \
933 } while (0) 1001 } while (0)
934 1002
935#define I2(x) \ 1003#define I2(x) \
@@ -938,6 +1006,7 @@ GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft)
938 rwlock_init(&rwlock_##x); \ 1006 rwlock_init(&rwlock_##x); \
939 mutex_init(&mutex_##x); \ 1007 mutex_init(&mutex_##x); \
940 init_rwsem(&rwsem_##x); \ 1008 init_rwsem(&rwsem_##x); \
1009 I2_RTMUTEX(x); \
941 } while (0) 1010 } while (0)
942 1011
943static void reset_locks(void) 1012static void reset_locks(void)
@@ -1013,6 +1082,12 @@ static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
1013 reset_locks(); 1082 reset_locks();
1014} 1083}
1015 1084
1085#ifdef CONFIG_RT_MUTEXES
1086#define dotest_rt(fn, e, m) dotest((fn), (e), (m))
1087#else
1088#define dotest_rt(fn, e, m)
1089#endif
1090
1016static inline void print_testname(const char *testname) 1091static inline void print_testname(const char *testname)
1017{ 1092{
1018 printk("%33s:", testname); 1093 printk("%33s:", testname);
@@ -1050,6 +1125,7 @@ static inline void print_testname(const char *testname)
1050 dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \ 1125 dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
1051 dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \ 1126 dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
1052 dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \ 1127 dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
1128 dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
1053 pr_cont("\n"); 1129 pr_cont("\n");
1054 1130
1055#define DO_TESTCASE_6_SUCCESS(desc, name) \ 1131#define DO_TESTCASE_6_SUCCESS(desc, name) \
@@ -1060,6 +1136,7 @@ static inline void print_testname(const char *testname)
1060 dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX); \ 1136 dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX); \
1061 dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM); \ 1137 dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM); \
1062 dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \ 1138 dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM); \
1139 dotest_rt(name##_rtmutex, SUCCESS, LOCKTYPE_RTMUTEX); \
1063 pr_cont("\n"); 1140 pr_cont("\n");
1064 1141
1065/* 1142/*
@@ -1073,6 +1150,7 @@ static inline void print_testname(const char *testname)
1073 dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \ 1150 dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX); \
1074 dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \ 1151 dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM); \
1075 dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \ 1152 dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM); \
1153 dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX); \
1076 pr_cont("\n"); 1154 pr_cont("\n");
1077 1155
1078#define DO_TESTCASE_2I(desc, name, nr) \ 1156#define DO_TESTCASE_2I(desc, name, nr) \
@@ -1825,7 +1903,6 @@ void locking_selftest(void)
1825 DO_TESTCASE_6R("A-B-C-D-B-C-D-A deadlock", ABCDBCDA); 1903 DO_TESTCASE_6R("A-B-C-D-B-C-D-A deadlock", ABCDBCDA);
1826 DO_TESTCASE_6("double unlock", double_unlock); 1904 DO_TESTCASE_6("double unlock", double_unlock);
1827 DO_TESTCASE_6("initialize held", init_held); 1905 DO_TESTCASE_6("initialize held", init_held);
1828 DO_TESTCASE_6_SUCCESS("bad unlock order", bad_unlock_order);
1829 1906
1830 printk(" --------------------------------------------------------------------------\n"); 1907 printk(" --------------------------------------------------------------------------\n");
1831 print_testname("recursive read-lock"); 1908 print_testname("recursive read-lock");
diff --git a/lib/refcount.c b/lib/refcount.c
index 9f906783987e..5d0582a9480c 100644
--- a/lib/refcount.c
+++ b/lib/refcount.c
@@ -37,6 +37,8 @@
37#include <linux/refcount.h> 37#include <linux/refcount.h>
38#include <linux/bug.h> 38#include <linux/bug.h>
39 39
40#ifdef CONFIG_REFCOUNT_FULL
41
40/** 42/**
41 * refcount_add_not_zero - add a value to a refcount unless it is 0 43 * refcount_add_not_zero - add a value to a refcount unless it is 0
42 * @i: the value to add to the refcount 44 * @i: the value to add to the refcount
@@ -225,6 +227,7 @@ void refcount_dec(refcount_t *r)
225 WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); 227 WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n");
226} 228}
227EXPORT_SYMBOL(refcount_dec); 229EXPORT_SYMBOL(refcount_dec);
230#endif /* CONFIG_REFCOUNT_FULL */
228 231
229/** 232/**
230 * refcount_dec_if_one - decrement a refcount if it is 1 233 * refcount_dec_if_one - decrement a refcount if it is 1
diff --git a/tools/Makefile b/tools/Makefile
index c8a90d01dd8e..221e1ce78b06 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -19,6 +19,7 @@ help:
19 @echo ' kvm_stat - top-like utility for displaying kvm statistics' 19 @echo ' kvm_stat - top-like utility for displaying kvm statistics'
20 @echo ' leds - LEDs tools' 20 @echo ' leds - LEDs tools'
21 @echo ' lguest - a minimal 32-bit x86 hypervisor' 21 @echo ' lguest - a minimal 32-bit x86 hypervisor'
22 @echo ' liblockdep - user-space wrapper for kernel locking-validator'
22 @echo ' net - misc networking tools' 23 @echo ' net - misc networking tools'
23 @echo ' perf - Linux performance measurement and analysis tool' 24 @echo ' perf - Linux performance measurement and analysis tool'
24 @echo ' selftests - various kernel selftests' 25 @echo ' selftests - various kernel selftests'
@@ -89,7 +90,7 @@ freefall: FORCE
89kvm_stat: FORCE 90kvm_stat: FORCE
90 $(call descend,kvm/$@) 91 $(call descend,kvm/$@)
91 92
92all: acpi cgroup cpupower gpio hv firewire lguest \ 93all: acpi cgroup cpupower gpio hv firewire lguest liblockdep \
93 perf selftests turbostat usb \ 94 perf selftests turbostat usb \
94 virtio vm net x86_energy_perf_policy \ 95 virtio vm net x86_energy_perf_policy \
95 tmon freefall objtool kvm_stat 96 tmon freefall objtool kvm_stat
@@ -103,6 +104,9 @@ cpupower_install:
103cgroup_install firewire_install gpio_install hv_install lguest_install perf_install usb_install virtio_install vm_install net_install objtool_install: 104cgroup_install firewire_install gpio_install hv_install lguest_install perf_install usb_install virtio_install vm_install net_install objtool_install:
104 $(call descend,$(@:_install=),install) 105 $(call descend,$(@:_install=),install)
105 106
107liblockdep_install:
108 $(call descend,lib/lockdep,install)
109
106selftests_install: 110selftests_install:
107 $(call descend,testing/$(@:_install=),install) 111 $(call descend,testing/$(@:_install=),install)
108 112
@@ -119,7 +123,7 @@ kvm_stat_install:
119 $(call descend,kvm/$(@:_install=),install) 123 $(call descend,kvm/$(@:_install=),install)
120 124
121install: acpi_install cgroup_install cpupower_install gpio_install \ 125install: acpi_install cgroup_install cpupower_install gpio_install \
122 hv_install firewire_install lguest_install \ 126 hv_install firewire_install lguest_install liblockdep_install \
123 perf_install selftests_install turbostat_install usb_install \ 127 perf_install selftests_install turbostat_install usb_install \
124 virtio_install vm_install net_install x86_energy_perf_policy_install \ 128 virtio_install vm_install net_install x86_energy_perf_policy_install \
125 tmon_install freefall_install objtool_install kvm_stat_install 129 tmon_install freefall_install objtool_install kvm_stat_install
diff --git a/tools/include/asm/sections.h b/tools/include/asm/sections.h
new file mode 100644
index 000000000000..a80643d7a7f1
--- /dev/null
+++ b/tools/include/asm/sections.h
@@ -0,0 +1,4 @@
1#ifndef __TOOLS_INCLUDE_LINUX_ASM_SECTIONS_H
2#define __TOOLS_INCLUDE_LINUX_ASM_SECTIONS_H
3
4#endif /* __TOOLS_INCLUDE_LINUX_ASM_SECTIONS_H */
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index 1aecad369af5..969db1981868 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -61,4 +61,14 @@ static inline unsigned fls_long(unsigned long l)
61 return fls64(l); 61 return fls64(l);
62} 62}
63 63
64/**
65 * rol32 - rotate a 32-bit value left
66 * @word: value to rotate
67 * @shift: bits to roll
68 */
69static inline __u32 rol32(__u32 word, unsigned int shift)
70{
71 return (word << shift) | (word >> ((-shift) & 31));
72}
73
64#endif 74#endif
diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 23299d7e7160..ef6ab908a42f 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -45,6 +45,10 @@
45# define __maybe_unused __attribute__((unused)) 45# define __maybe_unused __attribute__((unused))
46#endif 46#endif
47 47
48#ifndef __used
49# define __used __attribute__((__unused__))
50#endif
51
48#ifndef __packed 52#ifndef __packed
49# define __packed __attribute__((__packed__)) 53# define __packed __attribute__((__packed__))
50#endif 54#endif
@@ -65,6 +69,14 @@
65# define unlikely(x) __builtin_expect(!!(x), 0) 69# define unlikely(x) __builtin_expect(!!(x), 0)
66#endif 70#endif
67 71
72#ifndef __init
73# define __init
74#endif
75
76#ifndef noinline
77# define noinline
78#endif
79
68#define uninitialized_var(x) x = *(&(x)) 80#define uninitialized_var(x) x = *(&(x))
69 81
70#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) 82#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
diff --git a/tools/lib/lockdep/uinclude/linux/debug_locks.h b/tools/include/linux/debug_locks.h
index f38eb64df794..61cc7f501168 100644
--- a/tools/lib/lockdep/uinclude/linux/debug_locks.h
+++ b/tools/include/linux/debug_locks.h
@@ -3,8 +3,9 @@
3 3
4#include <stddef.h> 4#include <stddef.h>
5#include <linux/compiler.h> 5#include <linux/compiler.h>
6#include <asm/bug.h>
6 7
7#define DEBUG_LOCKS_WARN_ON(x) (x) 8#define DEBUG_LOCKS_WARN_ON(x) WARN_ON(x)
8 9
9extern bool debug_locks; 10extern bool debug_locks;
10extern bool debug_locks_silent; 11extern bool debug_locks_silent;
diff --git a/tools/include/linux/delay.h b/tools/include/linux/delay.h
new file mode 100644
index 000000000000..55aa4173af1f
--- /dev/null
+++ b/tools/include/linux/delay.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_DELAY_H
2#define _TOOLS_INCLUDE_LINUX_DELAY_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_DELAY_H */
diff --git a/tools/include/linux/err.h b/tools/include/linux/err.h
index bdc3dd8131d4..abf0478a8fb2 100644
--- a/tools/include/linux/err.h
+++ b/tools/include/linux/err.h
@@ -46,4 +46,9 @@ static inline bool __must_check IS_ERR(__force const void *ptr)
46 return IS_ERR_VALUE((unsigned long)ptr); 46 return IS_ERR_VALUE((unsigned long)ptr);
47} 47}
48 48
49static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
50{
51 return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
52}
53
49#endif /* _LINUX_ERR_H */ 54#endif /* _LINUX_ERR_H */
diff --git a/tools/include/linux/ftrace.h b/tools/include/linux/ftrace.h
new file mode 100644
index 000000000000..949f541ce11e
--- /dev/null
+++ b/tools/include/linux/ftrace.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_FTRACE_H
2#define _TOOLS_INCLUDE_LINUX_FTRACE_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_FTRACE_H */
diff --git a/tools/include/linux/gfp.h b/tools/include/linux/gfp.h
new file mode 100644
index 000000000000..22030756fbc0
--- /dev/null
+++ b/tools/include/linux/gfp.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_GFP_H
2#define _TOOLS_INCLUDE_LINUX_GFP_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_GFP_H */
diff --git a/tools/lib/lockdep/uinclude/linux/hardirq.h b/tools/include/linux/hardirq.h
index c8f3f8f58729..c8f3f8f58729 100644
--- a/tools/lib/lockdep/uinclude/linux/hardirq.h
+++ b/tools/include/linux/hardirq.h
diff --git a/tools/include/linux/interrupt.h b/tools/include/linux/interrupt.h
new file mode 100644
index 000000000000..6be25bbdca9e
--- /dev/null
+++ b/tools/include/linux/interrupt.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_INTERRUPT_H
2#define _TOOLS_INCLUDE_LINUX_INTERRUPT_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_INTERRUPT_H */
diff --git a/tools/lib/lockdep/uinclude/linux/irqflags.h b/tools/include/linux/irqflags.h
index 6cc296f0fad0..df77669cfe1c 100644
--- a/tools/lib/lockdep/uinclude/linux/irqflags.h
+++ b/tools/include/linux/irqflags.h
@@ -17,19 +17,19 @@
17#define raw_local_irq_disable() do { } while (0) 17#define raw_local_irq_disable() do { } while (0)
18#define raw_local_irq_enable() do { } while (0) 18#define raw_local_irq_enable() do { } while (0)
19#define raw_local_irq_save(flags) ((flags) = 0) 19#define raw_local_irq_save(flags) ((flags) = 0)
20#define raw_local_irq_restore(flags) do { } while (0) 20#define raw_local_irq_restore(flags) ((void)(flags))
21#define raw_local_save_flags(flags) ((flags) = 0) 21#define raw_local_save_flags(flags) ((flags) = 0)
22#define raw_irqs_disabled_flags(flags) do { } while (0) 22#define raw_irqs_disabled_flags(flags) ((void)(flags))
23#define raw_irqs_disabled() 0 23#define raw_irqs_disabled() 0
24#define raw_safe_halt() 24#define raw_safe_halt()
25 25
26#define local_irq_enable() do { } while (0) 26#define local_irq_enable() do { } while (0)
27#define local_irq_disable() do { } while (0) 27#define local_irq_disable() do { } while (0)
28#define local_irq_save(flags) ((flags) = 0) 28#define local_irq_save(flags) ((flags) = 0)
29#define local_irq_restore(flags) do { } while (0) 29#define local_irq_restore(flags) ((void)(flags))
30#define local_save_flags(flags) ((flags) = 0) 30#define local_save_flags(flags) ((flags) = 0)
31#define irqs_disabled() (1) 31#define irqs_disabled() (1)
32#define irqs_disabled_flags(flags) (0) 32#define irqs_disabled_flags(flags) ((void)(flags), 0)
33#define safe_halt() do { } while (0) 33#define safe_halt() do { } while (0)
34 34
35#define trace_lock_release(x, y) 35#define trace_lock_release(x, y)
diff --git a/tools/include/linux/jhash.h b/tools/include/linux/jhash.h
new file mode 100644
index 000000000000..348c6f47e4cc
--- /dev/null
+++ b/tools/include/linux/jhash.h
@@ -0,0 +1,175 @@
1#ifndef _LINUX_JHASH_H
2#define _LINUX_JHASH_H
3
4/* jhash.h: Jenkins hash support.
5 *
6 * Copyright (C) 2006. Bob Jenkins (bob_jenkins@burtleburtle.net)
7 *
8 * http://burtleburtle.net/bob/hash/
9 *
10 * These are the credits from Bob's sources:
11 *
12 * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
13 *
14 * These are functions for producing 32-bit hashes for hash table lookup.
15 * hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
16 * are externally useful functions. Routines to test the hash are included
17 * if SELF_TEST is defined. You can use this free for any purpose. It's in
18 * the public domain. It has no warranty.
19 *
20 * Copyright (C) 2009-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
21 *
22 * I've modified Bob's hash to be useful in the Linux kernel, and
23 * any bugs present are my fault.
24 * Jozsef
25 */
26#include <linux/bitops.h>
27#include <linux/unaligned/packed_struct.h>
28
29/* Best hash sizes are of power of two */
30#define jhash_size(n) ((u32)1<<(n))
31/* Mask the hash value, i.e (value & jhash_mask(n)) instead of (value % n) */
32#define jhash_mask(n) (jhash_size(n)-1)
33
34/* __jhash_mix -- mix 3 32-bit values reversibly. */
35#define __jhash_mix(a, b, c) \
36{ \
37 a -= c; a ^= rol32(c, 4); c += b; \
38 b -= a; b ^= rol32(a, 6); a += c; \
39 c -= b; c ^= rol32(b, 8); b += a; \
40 a -= c; a ^= rol32(c, 16); c += b; \
41 b -= a; b ^= rol32(a, 19); a += c; \
42 c -= b; c ^= rol32(b, 4); b += a; \
43}
44
45/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
46#define __jhash_final(a, b, c) \
47{ \
48 c ^= b; c -= rol32(b, 14); \
49 a ^= c; a -= rol32(c, 11); \
50 b ^= a; b -= rol32(a, 25); \
51 c ^= b; c -= rol32(b, 16); \
52 a ^= c; a -= rol32(c, 4); \
53 b ^= a; b -= rol32(a, 14); \
54 c ^= b; c -= rol32(b, 24); \
55}
56
57/* An arbitrary initial parameter */
58#define JHASH_INITVAL 0xdeadbeef
59
60/* jhash - hash an arbitrary key
61 * @k: sequence of bytes as key
62 * @length: the length of the key
63 * @initval: the previous hash, or an arbitray value
64 *
65 * The generic version, hashes an arbitrary sequence of bytes.
66 * No alignment or length assumptions are made about the input key.
67 *
68 * Returns the hash value of the key. The result depends on endianness.
69 */
70static inline u32 jhash(const void *key, u32 length, u32 initval)
71{
72 u32 a, b, c;
73 const u8 *k = key;
74
75 /* Set up the internal state */
76 a = b = c = JHASH_INITVAL + length + initval;
77
78 /* All but the last block: affect some 32 bits of (a,b,c) */
79 while (length > 12) {
80 a += __get_unaligned_cpu32(k);
81 b += __get_unaligned_cpu32(k + 4);
82 c += __get_unaligned_cpu32(k + 8);
83 __jhash_mix(a, b, c);
84 length -= 12;
85 k += 12;
86 }
87 /* Last block: affect all 32 bits of (c) */
88 /* All the case statements fall through */
89 switch (length) {
90 case 12: c += (u32)k[11]<<24;
91 case 11: c += (u32)k[10]<<16;
92 case 10: c += (u32)k[9]<<8;
93 case 9: c += k[8];
94 case 8: b += (u32)k[7]<<24;
95 case 7: b += (u32)k[6]<<16;
96 case 6: b += (u32)k[5]<<8;
97 case 5: b += k[4];
98 case 4: a += (u32)k[3]<<24;
99 case 3: a += (u32)k[2]<<16;
100 case 2: a += (u32)k[1]<<8;
101 case 1: a += k[0];
102 __jhash_final(a, b, c);
103 case 0: /* Nothing left to add */
104 break;
105 }
106
107 return c;
108}
109
110/* jhash2 - hash an array of u32's
111 * @k: the key which must be an array of u32's
112 * @length: the number of u32's in the key
113 * @initval: the previous hash, or an arbitray value
114 *
115 * Returns the hash value of the key.
116 */
117static inline u32 jhash2(const u32 *k, u32 length, u32 initval)
118{
119 u32 a, b, c;
120
121 /* Set up the internal state */
122 a = b = c = JHASH_INITVAL + (length<<2) + initval;
123
124 /* Handle most of the key */
125 while (length > 3) {
126 a += k[0];
127 b += k[1];
128 c += k[2];
129 __jhash_mix(a, b, c);
130 length -= 3;
131 k += 3;
132 }
133
134 /* Handle the last 3 u32's: all the case statements fall through */
135 switch (length) {
136 case 3: c += k[2];
137 case 2: b += k[1];
138 case 1: a += k[0];
139 __jhash_final(a, b, c);
140 case 0: /* Nothing left to add */
141 break;
142 }
143
144 return c;
145}
146
147
148/* __jhash_nwords - hash exactly 3, 2 or 1 word(s) */
149static inline u32 __jhash_nwords(u32 a, u32 b, u32 c, u32 initval)
150{
151 a += initval;
152 b += initval;
153 c += initval;
154
155 __jhash_final(a, b, c);
156
157 return c;
158}
159
160static inline u32 jhash_3words(u32 a, u32 b, u32 c, u32 initval)
161{
162 return __jhash_nwords(a, b, c, initval + JHASH_INITVAL + (3 << 2));
163}
164
165static inline u32 jhash_2words(u32 a, u32 b, u32 initval)
166{
167 return __jhash_nwords(a, b, 0, initval + JHASH_INITVAL + (2 << 2));
168}
169
170static inline u32 jhash_1word(u32 a, u32 initval)
171{
172 return __jhash_nwords(a, 0, 0, initval + JHASH_INITVAL + (1 << 2));
173}
174
175#endif /* _LINUX_JHASH_H */
diff --git a/tools/lib/lockdep/uinclude/linux/kallsyms.h b/tools/include/linux/kallsyms.h
index b0f2dbdf1a15..582cc1e5f3a4 100644
--- a/tools/lib/lockdep/uinclude/linux/kallsyms.h
+++ b/tools/include/linux/kallsyms.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5#include <stdio.h> 5#include <stdio.h>
6#include <unistd.h>
6 7
7#define KSYM_NAME_LEN 128 8#define KSYM_NAME_LEN 128
8 9
@@ -24,7 +25,7 @@ static inline void print_ip_sym(unsigned long ip)
24 25
25 name = backtrace_symbols((void **)&ip, 1); 26 name = backtrace_symbols((void **)&ip, 1);
26 27
27 printf("%s\n", *name); 28 dprintf(STDOUT_FILENO, "%s\n", *name);
28 29
29 free(name); 30 free(name);
30} 31}
diff --git a/tools/lib/lockdep/uinclude/linux/kern_levels.h b/tools/include/linux/kern_levels.h
index 3b9bade28698..3b9bade28698 100644
--- a/tools/lib/lockdep/uinclude/linux/kern_levels.h
+++ b/tools/include/linux/kern_levels.h
diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 73ccc48126bb..801b927499f2 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -32,6 +32,7 @@
32 (type *)((char *)__mptr - offsetof(type, member)); }) 32 (type *)((char *)__mptr - offsetof(type, member)); })
33#endif 33#endif
34 34
35#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
35#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 36#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
36 37
37#ifndef max 38#ifndef max
@@ -89,4 +90,7 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...);
89#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 90#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
90#define round_down(x, y) ((x) & ~__round_mask(x, y)) 91#define round_down(x, y) ((x) & ~__round_mask(x, y))
91 92
93#define current_gfp_context(k) 0
94#define synchronize_sched()
95
92#endif 96#endif
diff --git a/tools/lib/lockdep/uinclude/linux/kmemcheck.h b/tools/include/linux/kmemcheck.h
index 94d598bc6abe..94d598bc6abe 100644
--- a/tools/lib/lockdep/uinclude/linux/kmemcheck.h
+++ b/tools/include/linux/kmemcheck.h
diff --git a/tools/include/linux/linkage.h b/tools/include/linux/linkage.h
new file mode 100644
index 000000000000..bc763d500262
--- /dev/null
+++ b/tools/include/linux/linkage.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_LINKAGE_H
2#define _TOOLS_INCLUDE_LINUX_LINKAGE_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_LINKAGE_H */
diff --git a/tools/lib/lockdep/uinclude/linux/lockdep.h b/tools/include/linux/lockdep.h
index c808c7d02d21..8da3e8effafa 100644
--- a/tools/lib/lockdep/uinclude/linux/lockdep.h
+++ b/tools/include/linux/lockdep.h
@@ -7,8 +7,15 @@
7#include <limits.h> 7#include <limits.h>
8#include <linux/utsname.h> 8#include <linux/utsname.h>
9#include <linux/compiler.h> 9#include <linux/compiler.h>
10#include <linux/export.h>
11#include <linux/kern_levels.h>
12#include <linux/err.h>
13#include <linux/rcu.h>
14#include <linux/list.h>
15#include <linux/hardirq.h>
16#include <unistd.h>
10 17
11#define MAX_LOCK_DEPTH 2000UL 18#define MAX_LOCK_DEPTH 63UL
12 19
13#define asmlinkage 20#define asmlinkage
14#define __visible 21#define __visible
@@ -29,31 +36,32 @@ extern struct task_struct *__curr(void);
29 36
30#define current (__curr()) 37#define current (__curr())
31 38
32#define debug_locks_off() 1 39static inline int debug_locks_off(void)
40{
41 return 1;
42}
43
33#define task_pid_nr(tsk) ((tsk)->pid) 44#define task_pid_nr(tsk) ((tsk)->pid)
34 45
35#define KSYM_NAME_LEN 128 46#define KSYM_NAME_LEN 128
36#define printk printf 47#define printk(...) dprintf(STDOUT_FILENO, __VA_ARGS__)
48#define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
49#define pr_warn pr_err
37 50
38#define list_del_rcu list_del 51#define list_del_rcu list_del
39 52
40#define atomic_t unsigned long 53#define atomic_t unsigned long
41#define atomic_inc(x) ((*(x))++) 54#define atomic_inc(x) ((*(x))++)
42 55
43static struct new_utsname *init_utsname(void)
44{
45 static struct new_utsname n = (struct new_utsname) {
46 .release = "liblockdep",
47 .version = LIBLOCKDEP_VERSION,
48 };
49
50 return &n;
51}
52
53#define print_tainted() "" 56#define print_tainted() ""
54#define static_obj(x) 1 57#define static_obj(x) 1
55 58
56#define debug_show_all_locks() 59#define debug_show_all_locks()
57extern void debug_check_no_locks_held(void); 60extern void debug_check_no_locks_held(void);
58 61
62static __used bool __is_kernel_percpu_address(unsigned long addr, void *can_addr)
63{
64 return false;
65}
66
59#endif 67#endif
diff --git a/tools/lib/lockdep/uinclude/linux/module.h b/tools/include/linux/module.h
index 09c7a7be8ccc..07055db296f3 100644
--- a/tools/lib/lockdep/uinclude/linux/module.h
+++ b/tools/include/linux/module.h
@@ -3,4 +3,9 @@
3 3
4#define module_param(name, type, perm) 4#define module_param(name, type, perm)
5 5
6static inline bool __is_module_percpu_address(unsigned long addr, unsigned long *can_addr)
7{
8 return false;
9}
10
6#endif 11#endif
diff --git a/tools/include/linux/mutex.h b/tools/include/linux/mutex.h
new file mode 100644
index 000000000000..a8180d25f2fc
--- /dev/null
+++ b/tools/include/linux/mutex.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_MUTEX_H
2#define _TOOLS_INCLUDE_LINUX_MUTEX_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_MUTEX_H */
diff --git a/tools/include/linux/proc_fs.h b/tools/include/linux/proc_fs.h
new file mode 100644
index 000000000000..8b3b03b64fda
--- /dev/null
+++ b/tools/include/linux/proc_fs.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_PROC_FS_H
2#define _TOOLS_INCLUDE_LINUX_PROC_FS_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_PROC_FS_H */
diff --git a/tools/lib/lockdep/uinclude/linux/rcu.h b/tools/include/linux/rcu.h
index 042ee8e463c9..5080649dad04 100644
--- a/tools/lib/lockdep/uinclude/linux/rcu.h
+++ b/tools/include/linux/rcu.h
@@ -18,4 +18,7 @@ static inline bool rcu_is_watching(void)
18 return false; 18 return false;
19} 19}
20 20
21#define rcu_assign_pointer(p, v) ((p) = (v))
22#define RCU_INIT_POINTER(p, v) p=(v)
23
21#endif 24#endif
diff --git a/tools/include/linux/sched/clock.h b/tools/include/linux/sched/clock.h
new file mode 100644
index 000000000000..5837d17c4182
--- /dev/null
+++ b/tools/include/linux/sched/clock.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_PERF_LINUX_SCHED_CLOCK_H
2#define _TOOLS_PERF_LINUX_SCHED_CLOCK_H
3
4#endif /* _TOOLS_PERF_LINUX_SCHED_CLOCK_H */
diff --git a/tools/include/linux/sched/mm.h b/tools/include/linux/sched/mm.h
new file mode 100644
index 000000000000..c8d9f19c1f35
--- /dev/null
+++ b/tools/include/linux/sched/mm.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_PERF_LINUX_SCHED_MM_H
2#define _TOOLS_PERF_LINUX_SCHED_MM_H
3
4#endif /* _TOOLS_PERF_LINUX_SCHED_MM_H */
diff --git a/tools/include/linux/sched/task.h b/tools/include/linux/sched/task.h
new file mode 100644
index 000000000000..a97890eca110
--- /dev/null
+++ b/tools/include/linux/sched/task.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_PERF_LINUX_SCHED_TASK_H
2#define _TOOLS_PERF_LINUX_SCHED_TASK_H
3
4#endif /* _TOOLS_PERF_LINUX_SCHED_TASK_H */
diff --git a/tools/include/linux/seq_file.h b/tools/include/linux/seq_file.h
new file mode 100644
index 000000000000..102fd9217f1f
--- /dev/null
+++ b/tools/include/linux/seq_file.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_LINUX_SEQ_FILE_H
2#define _TOOLS_INCLUDE_LINUX_SEQ_FILE_H
3
4#endif /* _TOOLS_INCLUDE_LINUX_SEQ_FILE_H */
diff --git a/tools/include/linux/spinlock.h b/tools/include/linux/spinlock.h
index 58397dcb19d6..417cda4f793f 100644
--- a/tools/include/linux/spinlock.h
+++ b/tools/include/linux/spinlock.h
@@ -1,5 +1,31 @@
1#ifndef __LINUX_SPINLOCK_H_
2#define __LINUX_SPINLOCK_H_
3
4#include <pthread.h>
5#include <stdbool.h>
6
1#define spinlock_t pthread_mutex_t 7#define spinlock_t pthread_mutex_t
2#define DEFINE_SPINLOCK(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER; 8#define DEFINE_SPINLOCK(x) pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
3 9
4#define spin_lock_irqsave(x, f) (void)f, pthread_mutex_lock(x) 10#define spin_lock_irqsave(x, f) (void)f, pthread_mutex_lock(x)
5#define spin_unlock_irqrestore(x, f) (void)f, pthread_mutex_unlock(x) 11#define spin_unlock_irqrestore(x, f) (void)f, pthread_mutex_unlock(x)
12
13#define arch_spinlock_t pthread_mutex_t
14#define __ARCH_SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER
15
16static inline void arch_spin_lock(arch_spinlock_t *mutex)
17{
18 pthread_mutex_lock(mutex);
19}
20
21static inline void arch_spin_unlock(arch_spinlock_t *mutex)
22{
23 pthread_mutex_unlock(mutex);
24}
25
26static inline bool arch_spin_is_locked(arch_spinlock_t *mutex)
27{
28 return true;
29}
30
31#endif
diff --git a/tools/lib/lockdep/uinclude/linux/stacktrace.h b/tools/include/linux/stacktrace.h
index 39aecc6b19d1..39aecc6b19d1 100644
--- a/tools/lib/lockdep/uinclude/linux/stacktrace.h
+++ b/tools/include/linux/stacktrace.h
diff --git a/tools/include/linux/unaligned/packed_struct.h b/tools/include/linux/unaligned/packed_struct.h
new file mode 100644
index 000000000000..c0d817de4df2
--- /dev/null
+++ b/tools/include/linux/unaligned/packed_struct.h
@@ -0,0 +1,46 @@
1#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
2#define _LINUX_UNALIGNED_PACKED_STRUCT_H
3
4#include <linux/kernel.h>
5
6struct __una_u16 { u16 x; } __packed;
7struct __una_u32 { u32 x; } __packed;
8struct __una_u64 { u64 x; } __packed;
9
10static inline u16 __get_unaligned_cpu16(const void *p)
11{
12 const struct __una_u16 *ptr = (const struct __una_u16 *)p;
13 return ptr->x;
14}
15
16static inline u32 __get_unaligned_cpu32(const void *p)
17{
18 const struct __una_u32 *ptr = (const struct __una_u32 *)p;
19 return ptr->x;
20}
21
22static inline u64 __get_unaligned_cpu64(const void *p)
23{
24 const struct __una_u64 *ptr = (const struct __una_u64 *)p;
25 return ptr->x;
26}
27
28static inline void __put_unaligned_cpu16(u16 val, void *p)
29{
30 struct __una_u16 *ptr = (struct __una_u16 *)p;
31 ptr->x = val;
32}
33
34static inline void __put_unaligned_cpu32(u32 val, void *p)
35{
36 struct __una_u32 *ptr = (struct __una_u32 *)p;
37 ptr->x = val;
38}
39
40static inline void __put_unaligned_cpu64(u64 val, void *p)
41{
42 struct __una_u64 *ptr = (struct __una_u64 *)p;
43 ptr->x = val;
44}
45
46#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */
diff --git a/tools/include/trace/events/lock.h b/tools/include/trace/events/lock.h
new file mode 100644
index 000000000000..5b15fd5ee1af
--- /dev/null
+++ b/tools/include/trace/events/lock.h
@@ -0,0 +1,4 @@
1#ifndef _TOOLS_INCLUDE_TRACE_EVENTS_LOCK_H
2#define _TOOLS_INCLUDE_TRACE_EVENTS_LOCK_H
3
4#endif /* _TOOLS_INCLUDE_TRACE_EVENTS_LOCK_H */
diff --git a/tools/lib/lockdep/Makefile b/tools/lib/lockdep/Makefile
index 3bc0ef9f8923..ed9ace59d112 100644
--- a/tools/lib/lockdep/Makefile
+++ b/tools/lib/lockdep/Makefile
@@ -79,6 +79,7 @@ INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
79# Set compile option CFLAGS if not set elsewhere 79# Set compile option CFLAGS if not set elsewhere
80CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g 80CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
81CFLAGS += -fPIC 81CFLAGS += -fPIC
82CFLAGS += -Wall
82 83
83override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 84override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
84 85
@@ -100,7 +101,7 @@ include $(srctree)/tools/build/Makefile.include
100 101
101do_compile_shared_library = \ 102do_compile_shared_library = \
102 ($(print_shared_lib_compile) \ 103 ($(print_shared_lib_compile) \
103 $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -sf $@ liblockdep.so)) 104 $(CC) $(LDFLAGS) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='$(@F)';$(shell ln -sf $(@F) $(@D)/liblockdep.so))
104 105
105do_build_static_lib = \ 106do_build_static_lib = \
106 ($(print_static_lib_build) \ 107 ($(print_static_lib_build) \
@@ -118,10 +119,10 @@ all_cmd: $(CMD_TARGETS)
118$(LIB_IN): force 119$(LIB_IN): force
119 $(Q)$(MAKE) $(build)=liblockdep 120 $(Q)$(MAKE) $(build)=liblockdep
120 121
121liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN) 122$(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
122 $(Q)$(do_compile_shared_library) 123 $(Q)$(do_compile_shared_library)
123 124
124liblockdep.a: $(LIB_IN) 125$(OUTPUT)liblockdep.a: $(LIB_IN)
125 $(Q)$(do_build_static_lib) 126 $(Q)$(do_build_static_lib)
126 127
127tags: force 128tags: force
@@ -149,7 +150,7 @@ install_lib: all_cmd
149install: install_lib 150install: install_lib
150 151
151clean: 152clean:
152 $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d .*.cmd 153 $(RM) $(OUTPUT)*.o *~ $(TARGETS) $(OUTPUT)*.a $(OUTPUT)*liblockdep*.so* $(VERSION_FILES) $(OUTPUT).*.d $(OUTPUT).*.cmd
153 $(RM) tags TAGS 154 $(RM) tags TAGS
154 155
155PHONY += force 156PHONY += force
diff --git a/tools/lib/lockdep/lockdep.c b/tools/lib/lockdep/lockdep.c
index a0a2e3a266af..ced6d7443cea 100644
--- a/tools/lib/lockdep/lockdep.c
+++ b/tools/lib/lockdep/lockdep.c
@@ -1,8 +1,27 @@
1#include <linux/lockdep.h> 1#include <linux/lockdep.h>
2#include <stdlib.h>
2 3
3/* Trivial API wrappers, we don't (yet) have RCU in user-space: */ 4/* Trivial API wrappers, we don't (yet) have RCU in user-space: */
4#define hlist_for_each_entry_rcu hlist_for_each_entry 5#define hlist_for_each_entry_rcu hlist_for_each_entry
5#define hlist_add_head_rcu hlist_add_head 6#define hlist_add_head_rcu hlist_add_head
6#define hlist_del_rcu hlist_del 7#define hlist_del_rcu hlist_del
8#define list_for_each_entry_rcu list_for_each_entry
9#define list_add_tail_rcu list_add_tail
10
11u32 prandom_u32(void)
12{
13 /* Used only by lock_pin_lock() which is dead code */
14 abort();
15}
16
17static struct new_utsname *init_utsname(void)
18{
19 static struct new_utsname n = (struct new_utsname) {
20 .release = "liblockdep",
21 .version = LIBLOCKDEP_VERSION,
22 };
23
24 return &n;
25}
7 26
8#include "../../../kernel/locking/lockdep.c" 27#include "../../../kernel/locking/lockdep.c"
diff --git a/tools/lib/lockdep/preload.c b/tools/lib/lockdep/preload.c
index 52844847569c..6a2d3c5d4e92 100644
--- a/tools/lib/lockdep/preload.c
+++ b/tools/lib/lockdep/preload.c
@@ -4,6 +4,7 @@
4#include <dlfcn.h> 4#include <dlfcn.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <sysexits.h> 6#include <sysexits.h>
7#include <unistd.h>
7#include "include/liblockdep/mutex.h" 8#include "include/liblockdep/mutex.h"
8#include "../../include/linux/rbtree.h" 9#include "../../include/linux/rbtree.h"
9 10
@@ -122,8 +123,6 @@ static struct rb_node **__get_lock_node(void *lock, struct rb_node **parent)
122#define LIBLOCKDEP_STATIC_ENTRIES 1024 123#define LIBLOCKDEP_STATIC_ENTRIES 1024
123#endif 124#endif
124 125
125#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
126
127static struct lock_lookup __locks[LIBLOCKDEP_STATIC_ENTRIES]; 126static struct lock_lookup __locks[LIBLOCKDEP_STATIC_ENTRIES];
128static int __locks_nr; 127static int __locks_nr;
129 128
@@ -149,7 +148,7 @@ static struct lock_lookup *alloc_lock(void)
149 148
150 int idx = __locks_nr++; 149 int idx = __locks_nr++;
151 if (idx >= ARRAY_SIZE(__locks)) { 150 if (idx >= ARRAY_SIZE(__locks)) {
152 fprintf(stderr, 151 dprintf(STDERR_FILENO,
153 "LOCKDEP error: insufficient LIBLOCKDEP_STATIC_ENTRIES\n"); 152 "LOCKDEP error: insufficient LIBLOCKDEP_STATIC_ENTRIES\n");
154 exit(EX_UNAVAILABLE); 153 exit(EX_UNAVAILABLE);
155 } 154 }
diff --git a/tools/lib/lockdep/rbtree.c b/tools/lib/lockdep/rbtree.c
index f7f43033c8b7..297c304571f8 100644
--- a/tools/lib/lockdep/rbtree.c
+++ b/tools/lib/lockdep/rbtree.c
@@ -1 +1 @@
#include "../../../lib/rbtree.c" #include "../../lib/rbtree.c"
diff --git a/tools/lib/lockdep/run_tests.sh b/tools/lib/lockdep/run_tests.sh
index 1069d96248c1..f9b94098fc98 100755
--- a/tools/lib/lockdep/run_tests.sh
+++ b/tools/lib/lockdep/run_tests.sh
@@ -4,9 +4,9 @@ make &> /dev/null
4 4
5for i in `ls tests/*.c`; do 5for i in `ls tests/*.c`; do
6 testname=$(basename "$i" .c) 6 testname=$(basename "$i" .c)
7 gcc -o tests/$testname -pthread -lpthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null 7 gcc -o tests/$testname -pthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null
8 echo -ne "$testname... " 8 echo -ne "$testname... "
9 if [ $(timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then 9 if [ $(timeout 1 ./tests/$testname 2>&1 | wc -l) -gt 0 ]; then
10 echo "PASSED!" 10 echo "PASSED!"
11 else 11 else
12 echo "FAILED!" 12 echo "FAILED!"
@@ -18,9 +18,9 @@ done
18 18
19for i in `ls tests/*.c`; do 19for i in `ls tests/*.c`; do
20 testname=$(basename "$i" .c) 20 testname=$(basename "$i" .c)
21 gcc -o tests/$testname -pthread -lpthread -Iinclude $i &> /dev/null 21 gcc -o tests/$testname -pthread -Iinclude $i &> /dev/null
22 echo -ne "(PRELOAD) $testname... " 22 echo -ne "(PRELOAD) $testname... "
23 if [ $(timeout 1 ./lockdep ./tests/$testname | wc -l) -gt 0 ]; then 23 if [ $(timeout 1 ./lockdep ./tests/$testname 2>&1 | wc -l) -gt 0 ]; then
24 echo "PASSED!" 24 echo "PASSED!"
25 else 25 else
26 echo "FAILED!" 26 echo "FAILED!"
diff --git a/tools/lib/lockdep/uinclude/asm/hash.h b/tools/lib/lockdep/uinclude/asm/hash.h
deleted file mode 100644
index d82b170bb216..000000000000
--- a/tools/lib/lockdep/uinclude/asm/hash.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef __ASM_GENERIC_HASH_H
2#define __ASM_GENERIC_HASH_H
3
4/* Stub */
5
6#endif /* __ASM_GENERIC_HASH_H */
diff --git a/tools/lib/lockdep/uinclude/asm/hweight.h b/tools/lib/lockdep/uinclude/asm/hweight.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/asm/hweight.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/asm/sections.h b/tools/lib/lockdep/uinclude/asm/sections.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/asm/sections.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/bitops.h b/tools/lib/lockdep/uinclude/linux/bitops.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/bitops.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/compiler.h b/tools/lib/lockdep/uinclude/linux/compiler.h
deleted file mode 100644
index fd3e56a83fc2..000000000000
--- a/tools/lib/lockdep/uinclude/linux/compiler.h
+++ /dev/null
@@ -1,10 +0,0 @@
1#ifndef _LIBLOCKDEP_LINUX_COMPILER_H_
2#define _LIBLOCKDEP_LINUX_COMPILER_H_
3
4#define __used __attribute__((__unused__))
5#define unlikely
6#define READ_ONCE(x) (x)
7#define WRITE_ONCE(x, val) x=(val)
8#define RCU_INIT_POINTER(p, v) p=(v)
9
10#endif
diff --git a/tools/lib/lockdep/uinclude/linux/delay.h b/tools/lib/lockdep/uinclude/linux/delay.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/delay.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/ftrace.h b/tools/lib/lockdep/uinclude/linux/ftrace.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/ftrace.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/gfp.h b/tools/lib/lockdep/uinclude/linux/gfp.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/gfp.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/hash.h b/tools/lib/lockdep/uinclude/linux/hash.h
deleted file mode 100644
index 0f8479858dc0..000000000000
--- a/tools/lib/lockdep/uinclude/linux/hash.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../../include/linux/hash.h"
diff --git a/tools/lib/lockdep/uinclude/linux/interrupt.h b/tools/lib/lockdep/uinclude/linux/interrupt.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/interrupt.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/kernel.h b/tools/lib/lockdep/uinclude/linux/kernel.h
deleted file mode 100644
index 276c7a8b2ed1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/kernel.h
+++ /dev/null
@@ -1,47 +0,0 @@
1#ifndef _LIBLOCKDEP_LINUX_KERNEL_H_
2#define _LIBLOCKDEP_LINUX_KERNEL_H_
3
4#include <linux/export.h>
5#include <linux/types.h>
6#include <linux/rcu.h>
7#include <linux/hardirq.h>
8#include <linux/kern_levels.h>
9
10#ifndef container_of
11#define container_of(ptr, type, member) ({ \
12 const typeof(((type *)0)->member) * __mptr = (ptr); \
13 (type *)((char *)__mptr - offsetof(type, member)); })
14#endif
15
16#define max(x, y) ({ \
17 typeof(x) _max1 = (x); \
18 typeof(y) _max2 = (y); \
19 (void) (&_max1 == &_max2); \
20 _max1 > _max2 ? _max1 : _max2; })
21
22#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
23#define WARN_ON(x) (x)
24#define WARN_ON_ONCE(x) (x)
25#define likely(x) (x)
26#define WARN(x, y...) (x)
27#define uninitialized_var(x) x
28#define __init
29#define noinline
30#define list_add_tail_rcu list_add_tail
31#define list_for_each_entry_rcu list_for_each_entry
32#define barrier()
33#define synchronize_sched()
34
35#ifndef CALLER_ADDR0
36#define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
37#endif
38
39#ifndef _RET_IP_
40#define _RET_IP_ CALLER_ADDR0
41#endif
42
43#ifndef _THIS_IP_
44#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
45#endif
46
47#endif
diff --git a/tools/lib/lockdep/uinclude/linux/linkage.h b/tools/lib/lockdep/uinclude/linux/linkage.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/linkage.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/list.h b/tools/lib/lockdep/uinclude/linux/list.h
deleted file mode 100644
index 6e9ef31ed82e..000000000000
--- a/tools/lib/lockdep/uinclude/linux/list.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../../include/linux/list.h"
diff --git a/tools/lib/lockdep/uinclude/linux/mutex.h b/tools/lib/lockdep/uinclude/linux/mutex.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/mutex.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/poison.h b/tools/lib/lockdep/uinclude/linux/poison.h
deleted file mode 100644
index 0c27bdf14233..000000000000
--- a/tools/lib/lockdep/uinclude/linux/poison.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../../include/linux/poison.h"
diff --git a/tools/lib/lockdep/uinclude/linux/prefetch.h b/tools/lib/lockdep/uinclude/linux/prefetch.h
deleted file mode 100644
index d73fe6f850ac..000000000000
--- a/tools/lib/lockdep/uinclude/linux/prefetch.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef _LIBLOCKDEP_LINUX_PREFETCH_H_
2#define _LIBLOCKDEP_LINUX_PREFETCH_H
3
4static inline void prefetch(void *a __attribute__((unused))) { }
5
6#endif
diff --git a/tools/lib/lockdep/uinclude/linux/proc_fs.h b/tools/lib/lockdep/uinclude/linux/proc_fs.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/proc_fs.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/rbtree_augmented.h b/tools/lib/lockdep/uinclude/linux/rbtree_augmented.h
deleted file mode 100644
index c3759477379c..000000000000
--- a/tools/lib/lockdep/uinclude/linux/rbtree_augmented.h
+++ /dev/null
@@ -1,2 +0,0 @@
1#define __always_inline
2#include "../../../include/linux/rbtree_augmented.h"
diff --git a/tools/lib/lockdep/uinclude/linux/seq_file.h b/tools/lib/lockdep/uinclude/linux/seq_file.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/linux/seq_file.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3
diff --git a/tools/lib/lockdep/uinclude/linux/spinlock.h b/tools/lib/lockdep/uinclude/linux/spinlock.h
deleted file mode 100644
index 68c1aa2bcba5..000000000000
--- a/tools/lib/lockdep/uinclude/linux/spinlock.h
+++ /dev/null
@@ -1,25 +0,0 @@
1#ifndef _LIBLOCKDEP_SPINLOCK_H_
2#define _LIBLOCKDEP_SPINLOCK_H_
3
4#include <pthread.h>
5#include <stdbool.h>
6
7#define arch_spinlock_t pthread_mutex_t
8#define __ARCH_SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER
9
10static inline void arch_spin_lock(arch_spinlock_t *mutex)
11{
12 pthread_mutex_lock(mutex);
13}
14
15static inline void arch_spin_unlock(arch_spinlock_t *mutex)
16{
17 pthread_mutex_unlock(mutex);
18}
19
20static inline bool arch_spin_is_locked(arch_spinlock_t *mutex)
21{
22 return true;
23}
24
25#endif
diff --git a/tools/lib/lockdep/uinclude/linux/stringify.h b/tools/lib/lockdep/uinclude/linux/stringify.h
deleted file mode 100644
index 05dfcd1ac118..000000000000
--- a/tools/lib/lockdep/uinclude/linux/stringify.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef _LIBLOCKDEP_LINUX_STRINGIFY_H_
2#define _LIBLOCKDEP_LINUX_STRINGIFY_H_
3
4#define __stringify_1(x...) #x
5#define __stringify(x...) __stringify_1(x)
6
7#endif
diff --git a/tools/lib/lockdep/uinclude/trace/events/lock.h b/tools/lib/lockdep/uinclude/trace/events/lock.h
deleted file mode 100644
index fab00ff936d1..000000000000
--- a/tools/lib/lockdep/uinclude/trace/events/lock.h
+++ /dev/null
@@ -1,3 +0,0 @@
1
2/* empty file */
3