Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (2004) Linus Torvalds |
| 3 | * |
| 4 | * Author: Zwane Mwaikambo <zwane@fsmlabs.com> |
| 5 | * |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 6 | * Copyright (2004, 2005) Ingo Molnar |
| 7 | * |
| 8 | * This file contains the spinlock/rwlock implementations for the |
| 9 | * SMP and the DEBUG_SPINLOCK cases. (UP-nondebug inlines them) |
Andi Kleen | 0cb91a2 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 10 | * |
| 11 | * Note that some architectures have special knowledge about the |
| 12 | * stack frames of these functions in their profile_pc. If you |
| 13 | * change anything significant here that could change the stack |
| 14 | * frame contact the architecture maintainers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/linkage.h> |
| 18 | #include <linux/preempt.h> |
| 19 | #include <linux/spinlock.h> |
| 20 | #include <linux/interrupt.h> |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 21 | #include <linux/debug_locks.h> |
Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 24 | /* |
| 25 | * If lockdep is enabled then we use the non-preemption spin-ops |
| 26 | * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are |
| 27 | * not re-enabled during lock-acquire (which the preempt-spin-ops do): |
| 28 | */ |
| 29 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) |
| 30 | /* |
| 31 | * The __lock_function inlines are taken from |
| 32 | * include/linux/spinlock_api_smp.h |
| 33 | */ |
| 34 | #else |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 35 | #define raw_read_can_lock(l) read_can_lock(l) |
| 36 | #define raw_write_can_lock(l) write_can_lock(l) |
Will Deacon | c14c338 | 2013-09-11 14:23:23 -0700 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Some architectures can relax in favour of the CPU owning the lock. |
| 40 | */ |
| 41 | #ifndef arch_read_relax |
| 42 | # define arch_read_relax(l) cpu_relax() |
| 43 | #endif |
| 44 | #ifndef arch_write_relax |
| 45 | # define arch_write_relax(l) cpu_relax() |
| 46 | #endif |
| 47 | #ifndef arch_spin_relax |
| 48 | # define arch_spin_relax(l) cpu_relax() |
| 49 | #endif |
| 50 | |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 51 | /* |
| 52 | * We build the __lock_function inlines here. They are too large for |
| 53 | * inlining all over the place, but here is only one user per function |
| 54 | * which embedds them into the calling _lock_function below. |
| 55 | * |
| 56 | * This could be a long-held lock. We both prepare to spin for a long |
| 57 | * time (making _this_ CPU preemptable if possible), and we also signal |
| 58 | * towards that other CPU that it should break the lock ASAP. |
| 59 | */ |
| 60 | #define BUILD_LOCK_OPS(op, locktype) \ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 61 | void __lockfunc __raw_##op##_lock(locktype##_t *lock) \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 62 | { \ |
| 63 | for (;;) { \ |
| 64 | preempt_disable(); \ |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 65 | if (likely(do_raw_##op##_trylock(lock))) \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 66 | break; \ |
| 67 | preempt_enable(); \ |
| 68 | \ |
| 69 | if (!(lock)->break_lock) \ |
| 70 | (lock)->break_lock = 1; \ |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 71 | while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 72 | arch_##op##_relax(&lock->raw_lock); \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 73 | } \ |
| 74 | (lock)->break_lock = 0; \ |
| 75 | } \ |
| 76 | \ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 77 | unsigned long __lockfunc __raw_##op##_lock_irqsave(locktype##_t *lock) \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 78 | { \ |
| 79 | unsigned long flags; \ |
| 80 | \ |
| 81 | for (;;) { \ |
| 82 | preempt_disable(); \ |
| 83 | local_irq_save(flags); \ |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 84 | if (likely(do_raw_##op##_trylock(lock))) \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 85 | break; \ |
| 86 | local_irq_restore(flags); \ |
| 87 | preempt_enable(); \ |
| 88 | \ |
| 89 | if (!(lock)->break_lock) \ |
| 90 | (lock)->break_lock = 1; \ |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 91 | while (!raw_##op##_can_lock(lock) && (lock)->break_lock)\ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 92 | arch_##op##_relax(&lock->raw_lock); \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 93 | } \ |
| 94 | (lock)->break_lock = 0; \ |
| 95 | return flags; \ |
| 96 | } \ |
| 97 | \ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 98 | void __lockfunc __raw_##op##_lock_irq(locktype##_t *lock) \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 99 | { \ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 100 | _raw_##op##_lock_irqsave(lock); \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 101 | } \ |
| 102 | \ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 103 | void __lockfunc __raw_##op##_lock_bh(locktype##_t *lock) \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 104 | { \ |
| 105 | unsigned long flags; \ |
| 106 | \ |
| 107 | /* */ \ |
| 108 | /* Careful: we must exclude softirqs too, hence the */ \ |
| 109 | /* irq-disabling. We use the generic preemption-aware */ \ |
| 110 | /* function: */ \ |
| 111 | /**/ \ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 112 | flags = _raw_##op##_lock_irqsave(lock); \ |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 113 | local_bh_disable(); \ |
| 114 | local_irq_restore(flags); \ |
| 115 | } \ |
| 116 | |
| 117 | /* |
| 118 | * Build preemption-friendly versions of the following |
| 119 | * lock-spinning functions: |
| 120 | * |
| 121 | * __[spin|read|write]_lock() |
| 122 | * __[spin|read|write]_lock_irq() |
| 123 | * __[spin|read|write]_lock_irqsave() |
| 124 | * __[spin|read|write]_lock_bh() |
| 125 | */ |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 126 | BUILD_LOCK_OPS(spin, raw_spinlock); |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 127 | BUILD_LOCK_OPS(read, rwlock); |
| 128 | BUILD_LOCK_OPS(write, rwlock); |
| 129 | |
| 130 | #endif |
| 131 | |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 132 | #ifndef CONFIG_INLINE_SPIN_TRYLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 133 | int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 134 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 135 | return __raw_spin_trylock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 136 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 137 | EXPORT_SYMBOL(_raw_spin_trylock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 138 | #endif |
| 139 | |
| 140 | #ifndef CONFIG_INLINE_SPIN_TRYLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 141 | int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 142 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 143 | return __raw_spin_trylock_bh(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 144 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 145 | EXPORT_SYMBOL(_raw_spin_trylock_bh); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 146 | #endif |
| 147 | |
| 148 | #ifndef CONFIG_INLINE_SPIN_LOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 149 | void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 150 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 151 | __raw_spin_lock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 152 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 153 | EXPORT_SYMBOL(_raw_spin_lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 154 | #endif |
| 155 | |
| 156 | #ifndef CONFIG_INLINE_SPIN_LOCK_IRQSAVE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 157 | unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 158 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 159 | return __raw_spin_lock_irqsave(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 160 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 161 | EXPORT_SYMBOL(_raw_spin_lock_irqsave); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 162 | #endif |
| 163 | |
| 164 | #ifndef CONFIG_INLINE_SPIN_LOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 165 | void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 166 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 167 | __raw_spin_lock_irq(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 168 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 169 | EXPORT_SYMBOL(_raw_spin_lock_irq); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 170 | #endif |
| 171 | |
| 172 | #ifndef CONFIG_INLINE_SPIN_LOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 173 | void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 174 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 175 | __raw_spin_lock_bh(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 176 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 177 | EXPORT_SYMBOL(_raw_spin_lock_bh); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 178 | #endif |
| 179 | |
Raghavendra K T | e335e3e | 2012-03-22 15:25:08 +0530 | [diff] [blame] | 180 | #ifdef CONFIG_UNINLINE_SPIN_UNLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 181 | void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 182 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 183 | __raw_spin_unlock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 184 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 185 | EXPORT_SYMBOL(_raw_spin_unlock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 186 | #endif |
| 187 | |
| 188 | #ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 189 | void __lockfunc _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 190 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 191 | __raw_spin_unlock_irqrestore(lock, flags); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 192 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 193 | EXPORT_SYMBOL(_raw_spin_unlock_irqrestore); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 194 | #endif |
| 195 | |
| 196 | #ifndef CONFIG_INLINE_SPIN_UNLOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 197 | void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 198 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 199 | __raw_spin_unlock_irq(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 200 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 201 | EXPORT_SYMBOL(_raw_spin_unlock_irq); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 202 | #endif |
| 203 | |
| 204 | #ifndef CONFIG_INLINE_SPIN_UNLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 205 | void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 206 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 207 | __raw_spin_unlock_bh(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 208 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 209 | EXPORT_SYMBOL(_raw_spin_unlock_bh); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 210 | #endif |
| 211 | |
| 212 | #ifndef CONFIG_INLINE_READ_TRYLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 213 | int __lockfunc _raw_read_trylock(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 214 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 215 | return __raw_read_trylock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 216 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 217 | EXPORT_SYMBOL(_raw_read_trylock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 218 | #endif |
| 219 | |
| 220 | #ifndef CONFIG_INLINE_READ_LOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 221 | void __lockfunc _raw_read_lock(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 222 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 223 | __raw_read_lock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 224 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 225 | EXPORT_SYMBOL(_raw_read_lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 226 | #endif |
| 227 | |
| 228 | #ifndef CONFIG_INLINE_READ_LOCK_IRQSAVE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 229 | unsigned long __lockfunc _raw_read_lock_irqsave(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 230 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 231 | return __raw_read_lock_irqsave(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 232 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 233 | EXPORT_SYMBOL(_raw_read_lock_irqsave); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 234 | #endif |
| 235 | |
| 236 | #ifndef CONFIG_INLINE_READ_LOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 237 | void __lockfunc _raw_read_lock_irq(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 238 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 239 | __raw_read_lock_irq(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 240 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 241 | EXPORT_SYMBOL(_raw_read_lock_irq); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 242 | #endif |
| 243 | |
| 244 | #ifndef CONFIG_INLINE_READ_LOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 245 | void __lockfunc _raw_read_lock_bh(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 246 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 247 | __raw_read_lock_bh(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 248 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 249 | EXPORT_SYMBOL(_raw_read_lock_bh); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 250 | #endif |
| 251 | |
| 252 | #ifndef CONFIG_INLINE_READ_UNLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 253 | void __lockfunc _raw_read_unlock(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 254 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 255 | __raw_read_unlock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 256 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 257 | EXPORT_SYMBOL(_raw_read_unlock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 258 | #endif |
| 259 | |
| 260 | #ifndef CONFIG_INLINE_READ_UNLOCK_IRQRESTORE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 261 | void __lockfunc _raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 262 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 263 | __raw_read_unlock_irqrestore(lock, flags); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 264 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 265 | EXPORT_SYMBOL(_raw_read_unlock_irqrestore); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 266 | #endif |
| 267 | |
| 268 | #ifndef CONFIG_INLINE_READ_UNLOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 269 | void __lockfunc _raw_read_unlock_irq(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 270 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 271 | __raw_read_unlock_irq(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 272 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 273 | EXPORT_SYMBOL(_raw_read_unlock_irq); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 274 | #endif |
| 275 | |
| 276 | #ifndef CONFIG_INLINE_READ_UNLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 277 | void __lockfunc _raw_read_unlock_bh(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 278 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 279 | __raw_read_unlock_bh(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 280 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 281 | EXPORT_SYMBOL(_raw_read_unlock_bh); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 282 | #endif |
| 283 | |
| 284 | #ifndef CONFIG_INLINE_WRITE_TRYLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 285 | int __lockfunc _raw_write_trylock(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 286 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 287 | return __raw_write_trylock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 288 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 289 | EXPORT_SYMBOL(_raw_write_trylock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 290 | #endif |
| 291 | |
| 292 | #ifndef CONFIG_INLINE_WRITE_LOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 293 | void __lockfunc _raw_write_lock(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 294 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 295 | __raw_write_lock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 296 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 297 | EXPORT_SYMBOL(_raw_write_lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 298 | #endif |
| 299 | |
| 300 | #ifndef CONFIG_INLINE_WRITE_LOCK_IRQSAVE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 301 | unsigned long __lockfunc _raw_write_lock_irqsave(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 302 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 303 | return __raw_write_lock_irqsave(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 304 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 305 | EXPORT_SYMBOL(_raw_write_lock_irqsave); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 306 | #endif |
| 307 | |
| 308 | #ifndef CONFIG_INLINE_WRITE_LOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 309 | void __lockfunc _raw_write_lock_irq(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 310 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 311 | __raw_write_lock_irq(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 312 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 313 | EXPORT_SYMBOL(_raw_write_lock_irq); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 314 | #endif |
| 315 | |
| 316 | #ifndef CONFIG_INLINE_WRITE_LOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 317 | void __lockfunc _raw_write_lock_bh(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 318 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 319 | __raw_write_lock_bh(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 320 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 321 | EXPORT_SYMBOL(_raw_write_lock_bh); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 322 | #endif |
| 323 | |
| 324 | #ifndef CONFIG_INLINE_WRITE_UNLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 325 | void __lockfunc _raw_write_unlock(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 326 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 327 | __raw_write_unlock(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 328 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 329 | EXPORT_SYMBOL(_raw_write_unlock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 330 | #endif |
| 331 | |
| 332 | #ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 333 | void __lockfunc _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 334 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 335 | __raw_write_unlock_irqrestore(lock, flags); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 336 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 337 | EXPORT_SYMBOL(_raw_write_unlock_irqrestore); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 338 | #endif |
| 339 | |
| 340 | #ifndef CONFIG_INLINE_WRITE_UNLOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 341 | void __lockfunc _raw_write_unlock_irq(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 342 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 343 | __raw_write_unlock_irq(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 344 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 345 | EXPORT_SYMBOL(_raw_write_unlock_irq); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 346 | #endif |
| 347 | |
| 348 | #ifndef CONFIG_INLINE_WRITE_UNLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 349 | void __lockfunc _raw_write_unlock_bh(rwlock_t *lock) |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 350 | { |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 351 | __raw_write_unlock_bh(lock); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 352 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 353 | EXPORT_SYMBOL(_raw_write_unlock_bh); |
Thomas Gleixner | b7b40ad | 2009-11-09 21:01:59 +0100 | [diff] [blame] | 354 | #endif |
| 355 | |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 356 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 357 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 358 | void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass) |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 359 | { |
| 360 | preempt_disable(); |
| 361 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 362 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 363 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 364 | EXPORT_SYMBOL(_raw_spin_lock_nested); |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 365 | |
Thomas Graf | 113948d | 2015-01-02 23:00:19 +0100 | [diff] [blame] | 366 | void __lockfunc _raw_spin_lock_bh_nested(raw_spinlock_t *lock, int subclass) |
| 367 | { |
| 368 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
| 369 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); |
| 370 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
| 371 | } |
| 372 | EXPORT_SYMBOL(_raw_spin_lock_bh_nested); |
| 373 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 374 | unsigned long __lockfunc _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock, |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 375 | int subclass) |
| 376 | { |
| 377 | unsigned long flags; |
| 378 | |
| 379 | local_irq_save(flags); |
| 380 | preempt_disable(); |
| 381 | spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 382 | LOCK_CONTENDED_FLAGS(lock, do_raw_spin_trylock, do_raw_spin_lock, |
| 383 | do_raw_spin_lock_flags, &flags); |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 384 | return flags; |
| 385 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 386 | EXPORT_SYMBOL(_raw_spin_lock_irqsave_nested); |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 387 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 388 | void __lockfunc _raw_spin_lock_nest_lock(raw_spinlock_t *lock, |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 389 | struct lockdep_map *nest_lock) |
| 390 | { |
| 391 | preempt_disable(); |
| 392 | spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 393 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 394 | } |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 395 | EXPORT_SYMBOL(_raw_spin_lock_nest_lock); |
Thomas Gleixner | 8e13c7b | 2009-11-09 15:21:41 +0000 | [diff] [blame] | 396 | |
| 397 | #endif |
| 398 | |
Steven Rostedt | 0764d23 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 399 | notrace int in_lock_functions(unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
| 401 | /* Linker adds these: start and end of __lockfunc functions */ |
| 402 | extern char __lock_text_start[], __lock_text_end[]; |
| 403 | |
| 404 | return addr >= (unsigned long)__lock_text_start |
| 405 | && addr < (unsigned long)__lock_text_end; |
| 406 | } |
| 407 | EXPORT_SYMBOL(in_lock_functions); |