diff options
-rw-r--r-- | include/linux/preempt_mask.h | 15 | ||||
-rw-r--r-- | include/linux/rwlock_api_smp.h | 12 | ||||
-rw-r--r-- | include/linux/spinlock_api_smp.h | 12 | ||||
-rw-r--r-- | include/linux/spinlock_api_up.h | 16 | ||||
-rw-r--r-- | kernel/softirq.c | 4 |
5 files changed, 36 insertions, 23 deletions
diff --git a/include/linux/preempt_mask.h b/include/linux/preempt_mask.h index d169820203dd..b8d96bca4357 100644 --- a/include/linux/preempt_mask.h +++ b/include/linux/preempt_mask.h | |||
@@ -79,6 +79,21 @@ | |||
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | /* | 81 | /* |
82 | * The preempt_count offset needed for things like: | ||
83 | * | ||
84 | * spin_lock_bh() | ||
85 | * | ||
86 | * Which need to disable both preemption (CONFIG_PREEMPT_COUNT) and | ||
87 | * softirqs, such that unlock sequences of: | ||
88 | * | ||
89 | * spin_unlock(); | ||
90 | * local_bh_enable(); | ||
91 | * | ||
92 | * Work as expected. | ||
93 | */ | ||
94 | #define SOFTIRQ_LOCK_OFFSET (SOFTIRQ_DISABLE_OFFSET + PREEMPT_CHECK_OFFSET) | ||
95 | |||
96 | /* | ||
82 | * Are we running in atomic context? WARNING: this macro cannot | 97 | * Are we running in atomic context? WARNING: this macro cannot |
83 | * always detect atomic context; in particular, it cannot know about | 98 | * always detect atomic context; in particular, it cannot know about |
84 | * held spinlocks in non-preemptible kernels. Thus it should not be | 99 | * held spinlocks in non-preemptible kernels. Thus it should not be |
diff --git a/include/linux/rwlock_api_smp.h b/include/linux/rwlock_api_smp.h index 9c9f0495d37c..5b9b84b20407 100644 --- a/include/linux/rwlock_api_smp.h +++ b/include/linux/rwlock_api_smp.h | |||
@@ -172,8 +172,7 @@ static inline void __raw_read_lock_irq(rwlock_t *lock) | |||
172 | 172 | ||
173 | static inline void __raw_read_lock_bh(rwlock_t *lock) | 173 | static inline void __raw_read_lock_bh(rwlock_t *lock) |
174 | { | 174 | { |
175 | local_bh_disable(); | 175 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
176 | preempt_disable(); | ||
177 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); | 176 | rwlock_acquire_read(&lock->dep_map, 0, 0, _RET_IP_); |
178 | LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock); | 177 | LOCK_CONTENDED(lock, do_raw_read_trylock, do_raw_read_lock); |
179 | } | 178 | } |
@@ -200,8 +199,7 @@ static inline void __raw_write_lock_irq(rwlock_t *lock) | |||
200 | 199 | ||
201 | static inline void __raw_write_lock_bh(rwlock_t *lock) | 200 | static inline void __raw_write_lock_bh(rwlock_t *lock) |
202 | { | 201 | { |
203 | local_bh_disable(); | 202 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
204 | preempt_disable(); | ||
205 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); | 203 | rwlock_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
206 | LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock); | 204 | LOCK_CONTENDED(lock, do_raw_write_trylock, do_raw_write_lock); |
207 | } | 205 | } |
@@ -250,8 +248,7 @@ static inline void __raw_read_unlock_bh(rwlock_t *lock) | |||
250 | { | 248 | { |
251 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 249 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
252 | do_raw_read_unlock(lock); | 250 | do_raw_read_unlock(lock); |
253 | preempt_enable_no_resched(); | 251 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
254 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
255 | } | 252 | } |
256 | 253 | ||
257 | static inline void __raw_write_unlock_irqrestore(rwlock_t *lock, | 254 | static inline void __raw_write_unlock_irqrestore(rwlock_t *lock, |
@@ -275,8 +272,7 @@ static inline void __raw_write_unlock_bh(rwlock_t *lock) | |||
275 | { | 272 | { |
276 | rwlock_release(&lock->dep_map, 1, _RET_IP_); | 273 | rwlock_release(&lock->dep_map, 1, _RET_IP_); |
277 | do_raw_write_unlock(lock); | 274 | do_raw_write_unlock(lock); |
278 | preempt_enable_no_resched(); | 275 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
279 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
280 | } | 276 | } |
281 | 277 | ||
282 | #endif /* __LINUX_RWLOCK_API_SMP_H */ | 278 | #endif /* __LINUX_RWLOCK_API_SMP_H */ |
diff --git a/include/linux/spinlock_api_smp.h b/include/linux/spinlock_api_smp.h index bdb9993f0fda..42dfab89e740 100644 --- a/include/linux/spinlock_api_smp.h +++ b/include/linux/spinlock_api_smp.h | |||
@@ -131,8 +131,7 @@ static inline void __raw_spin_lock_irq(raw_spinlock_t *lock) | |||
131 | 131 | ||
132 | static inline void __raw_spin_lock_bh(raw_spinlock_t *lock) | 132 | static inline void __raw_spin_lock_bh(raw_spinlock_t *lock) |
133 | { | 133 | { |
134 | local_bh_disable(); | 134 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
135 | preempt_disable(); | ||
136 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); | 135 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
137 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); | 136 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
138 | } | 137 | } |
@@ -174,20 +173,17 @@ static inline void __raw_spin_unlock_bh(raw_spinlock_t *lock) | |||
174 | { | 173 | { |
175 | spin_release(&lock->dep_map, 1, _RET_IP_); | 174 | spin_release(&lock->dep_map, 1, _RET_IP_); |
176 | do_raw_spin_unlock(lock); | 175 | do_raw_spin_unlock(lock); |
177 | preempt_enable_no_resched(); | 176 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
178 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
179 | } | 177 | } |
180 | 178 | ||
181 | static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock) | 179 | static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock) |
182 | { | 180 | { |
183 | local_bh_disable(); | 181 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
184 | preempt_disable(); | ||
185 | if (do_raw_spin_trylock(lock)) { | 182 | if (do_raw_spin_trylock(lock)) { |
186 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); | 183 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
187 | return 1; | 184 | return 1; |
188 | } | 185 | } |
189 | preempt_enable_no_resched(); | 186 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
190 | local_bh_enable_ip((unsigned long)__builtin_return_address(0)); | ||
191 | return 0; | 187 | return 0; |
192 | } | 188 | } |
193 | 189 | ||
diff --git a/include/linux/spinlock_api_up.h b/include/linux/spinlock_api_up.h index af1f47229e70..d0d188861ad6 100644 --- a/include/linux/spinlock_api_up.h +++ b/include/linux/spinlock_api_up.h | |||
@@ -24,11 +24,14 @@ | |||
24 | * flags straight, to suppress compiler warnings of unused lock | 24 | * flags straight, to suppress compiler warnings of unused lock |
25 | * variables, and to add the proper checker annotations: | 25 | * variables, and to add the proper checker annotations: |
26 | */ | 26 | */ |
27 | #define ___LOCK(lock) \ | ||
28 | do { __acquire(lock); (void)(lock); } while (0) | ||
29 | |||
27 | #define __LOCK(lock) \ | 30 | #define __LOCK(lock) \ |
28 | do { preempt_disable(); __acquire(lock); (void)(lock); } while (0) | 31 | do { preempt_disable(); ___LOCK(lock); } while (0) |
29 | 32 | ||
30 | #define __LOCK_BH(lock) \ | 33 | #define __LOCK_BH(lock) \ |
31 | do { local_bh_disable(); __LOCK(lock); } while (0) | 34 | do { __local_bh_disable_ip(_THIS_IP_, SOFTIRQ_LOCK_OFFSET); ___LOCK(lock); } while (0) |
32 | 35 | ||
33 | #define __LOCK_IRQ(lock) \ | 36 | #define __LOCK_IRQ(lock) \ |
34 | do { local_irq_disable(); __LOCK(lock); } while (0) | 37 | do { local_irq_disable(); __LOCK(lock); } while (0) |
@@ -36,12 +39,15 @@ | |||
36 | #define __LOCK_IRQSAVE(lock, flags) \ | 39 | #define __LOCK_IRQSAVE(lock, flags) \ |
37 | do { local_irq_save(flags); __LOCK(lock); } while (0) | 40 | do { local_irq_save(flags); __LOCK(lock); } while (0) |
38 | 41 | ||
42 | #define ___UNLOCK(lock) \ | ||
43 | do { __release(lock); (void)(lock); } while (0) | ||
44 | |||
39 | #define __UNLOCK(lock) \ | 45 | #define __UNLOCK(lock) \ |
40 | do { preempt_enable(); __release(lock); (void)(lock); } while (0) | 46 | do { preempt_enable(); ___UNLOCK(lock); } while (0) |
41 | 47 | ||
42 | #define __UNLOCK_BH(lock) \ | 48 | #define __UNLOCK_BH(lock) \ |
43 | do { preempt_enable_no_resched(); local_bh_enable(); \ | 49 | do { __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_LOCK_OFFSET); \ |
44 | __release(lock); (void)(lock); } while (0) | 50 | ___UNLOCK(lock); } while (0) |
45 | 51 | ||
46 | #define __UNLOCK_IRQ(lock) \ | 52 | #define __UNLOCK_IRQ(lock) \ |
47 | do { local_irq_enable(); __UNLOCK(lock); } while (0) | 53 | do { local_irq_enable(); __UNLOCK(lock); } while (0) |
diff --git a/kernel/softirq.c b/kernel/softirq.c index 11025ccc06dd..7500cce1ebfd 100644 --- a/kernel/softirq.c +++ b/kernel/softirq.c | |||
@@ -107,7 +107,7 @@ static void __local_bh_disable(unsigned long ip, unsigned int cnt) | |||
107 | /* | 107 | /* |
108 | * Were softirqs turned off above: | 108 | * Were softirqs turned off above: |
109 | */ | 109 | */ |
110 | if (softirq_count() == cnt) | 110 | if (softirq_count() == (cnt & SOFTIRQ_MASK)) |
111 | trace_softirqs_off(ip); | 111 | trace_softirqs_off(ip); |
112 | raw_local_irq_restore(flags); | 112 | raw_local_irq_restore(flags); |
113 | 113 | ||
@@ -133,7 +133,7 @@ static void __local_bh_enable(unsigned int cnt) | |||
133 | { | 133 | { |
134 | WARN_ON_ONCE(!irqs_disabled()); | 134 | WARN_ON_ONCE(!irqs_disabled()); |
135 | 135 | ||
136 | if (softirq_count() == cnt) | 136 | if (softirq_count() == (cnt & SOFTIRQ_MASK)) |
137 | trace_softirqs_on(_RET_IP_); | 137 | trace_softirqs_on(_RET_IP_); |
138 | preempt_count_sub(cnt); | 138 | preempt_count_sub(cnt); |
139 | } | 139 | } |