Skip to content

Commit 776edb5

Browse files
committed
Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into next
Pull core locking updates from Ingo Molnar: "The main changes in this cycle were: - reduced/streamlined smp_mb__*() interface that allows more usecases and makes the existing ones less buggy, especially in rarer architectures - add rwsem implementation comments - bump up lockdep limits" * 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (33 commits) rwsem: Add comments to explain the meaning of the rwsem's count field lockdep: Increase static allocations arch: Mass conversion of smp_mb__*() arch,doc: Convert smp_mb__*() arch,xtensa: Convert smp_mb__*() arch,x86: Convert smp_mb__*() arch,tile: Convert smp_mb__*() arch,sparc: Convert smp_mb__*() arch,sh: Convert smp_mb__*() arch,score: Convert smp_mb__*() arch,s390: Convert smp_mb__*() arch,powerpc: Convert smp_mb__*() arch,parisc: Convert smp_mb__*() arch,openrisc: Convert smp_mb__*() arch,mn10300: Convert smp_mb__*() arch,mips: Convert smp_mb__*() arch,metag: Convert smp_mb__*() arch,m68k: Convert smp_mb__*() arch,m32r: Convert smp_mb__*() arch,ia64: Convert smp_mb__*() ...
2 parents 59a3d4c + 3cf2f34 commit 776edb5

185 files changed

Lines changed: 549 additions & 650 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/atomic_ops.txt‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,13 @@ If a caller requires memory barrier semantics around an atomic_t
285285
operation which does not return a value, a set of interfaces are
286286
defined which accomplish this:
287287

288-
void smp_mb__before_atomic_dec(void);
289-
void smp_mb__after_atomic_dec(void);
290-
void smp_mb__before_atomic_inc(void);
291-
void smp_mb__after_atomic_inc(void);
288+
void smp_mb__before_atomic(void);
289+
void smp_mb__after_atomic(void);
292290

293-
For example, smp_mb__before_atomic_dec() can be used like so:
291+
For example, smp_mb__before_atomic() can be used like so:
294292

295293
obj->dead = 1;
296-
smp_mb__before_atomic_dec();
294+
smp_mb__before_atomic();
297295
atomic_dec(&obj->ref_count);
298296

299297
It makes sure that all memory operations preceding the atomic_dec()
@@ -302,15 +300,10 @@ operation. In the above example, it guarantees that the assignment of
302300
"1" to obj->dead will be globally visible to other cpus before the
303301
atomic counter decrement.
304302

305-
Without the explicit smp_mb__before_atomic_dec() call, the
303+
Without the explicit smp_mb__before_atomic() call, the
306304
implementation could legally allow the atomic counter update visible
307305
to other cpus before the "obj->dead = 1;" assignment.
308306

309-
The other three interfaces listed are used to provide explicit
310-
ordering with respect to memory operations after an atomic_dec() call
311-
(smp_mb__after_atomic_dec()) and around atomic_inc() calls
312-
(smp_mb__{before,after}_atomic_inc()).
313-
314307
A missing memory barrier in the cases where they are required by the
315308
atomic_t implementation above can have disastrous results. Here is
316309
an example, which follows a pattern occurring frequently in the Linux
@@ -487,26 +480,26 @@ Finally there is the basic operation:
487480
Which returns a boolean indicating if bit "nr" is set in the bitmask
488481
pointed to by "addr".
489482

490-
If explicit memory barriers are required around clear_bit() (which
491-
does not return a value, and thus does not need to provide memory
492-
barrier semantics), two interfaces are provided:
483+
If explicit memory barriers are required around {set,clear}_bit() (which do
484+
not return a value, and thus does not need to provide memory barrier
485+
semantics), two interfaces are provided:
493486

494-
void smp_mb__before_clear_bit(void);
495-
void smp_mb__after_clear_bit(void);
487+
void smp_mb__before_atomic(void);
488+
void smp_mb__after_atomic(void);
496489

497490
They are used as follows, and are akin to their atomic_t operation
498491
brothers:
499492

500493
/* All memory operations before this call will
501494
* be globally visible before the clear_bit().
502495
*/
503-
smp_mb__before_clear_bit();
496+
smp_mb__before_atomic();
504497
clear_bit( ... );
505498

506499
/* The clear_bit() will be visible before all
507500
* subsequent memory operations.
508501
*/
509-
smp_mb__after_clear_bit();
502+
smp_mb__after_atomic();
510503

511504
There are two special bitops with lock barrier semantics (acquire/release,
512505
same as spinlocks). These operate in the same way as their non-_lock/unlock

‎Documentation/memory-barriers.txt‎

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,20 +1583,21 @@ There are some more advanced barrier functions:
15831583
insert anything more than a compiler barrier in a UP compilation.
15841584

15851585

1586-
(*) smp_mb__before_atomic_dec();
1587-
(*) smp_mb__after_atomic_dec();
1588-
(*) smp_mb__before_atomic_inc();
1589-
(*) smp_mb__after_atomic_inc();
1586+
(*) smp_mb__before_atomic();
1587+
(*) smp_mb__after_atomic();
15901588

1591-
These are for use with atomic add, subtract, increment and decrement
1592-
functions that don't return a value, especially when used for reference
1593-
counting. These functions do not imply memory barriers.
1589+
These are for use with atomic (such as add, subtract, increment and
1590+
decrement) functions that don't return a value, especially when used for
1591+
reference counting. These functions do not imply memory barriers.
1592+
1593+
These are also used for atomic bitop functions that do not return a
1594+
value (such as set_bit and clear_bit).
15941595

15951596
As an example, consider a piece of code that marks an object as being dead
15961597
and then decrements the object's reference count:
15971598

15981599
obj->dead = 1;
1599-
smp_mb__before_atomic_dec();
1600+
smp_mb__before_atomic();
16001601
atomic_dec(&obj->ref_count);
16011602

16021603
This makes sure that the death mark on the object is perceived to be set
@@ -1606,27 +1607,6 @@ There are some more advanced barrier functions:
16061607
operations" subsection for information on where to use these.
16071608

16081609

1609-
(*) smp_mb__before_clear_bit(void);
1610-
(*) smp_mb__after_clear_bit(void);
1611-
1612-
These are for use similar to the atomic inc/dec barriers. These are
1613-
typically used for bitwise unlocking operations, so care must be taken as
1614-
there are no implicit memory barriers here either.
1615-
1616-
Consider implementing an unlock operation of some nature by clearing a
1617-
locking bit. The clear_bit() would then need to be barriered like this:
1618-
1619-
smp_mb__before_clear_bit();
1620-
clear_bit( ... );
1621-
1622-
This prevents memory operations before the clear leaking to after it. See
1623-
the subsection on "Locking Functions" with reference to RELEASE operation
1624-
implications.
1625-
1626-
See Documentation/atomic_ops.txt for more information. See the "Atomic
1627-
operations" subsection for information on where to use these.
1628-
1629-
16301610
MMIO WRITE BARRIER
16311611
------------------
16321612

@@ -2283,11 +2263,11 @@ operations:
22832263
change_bit();
22842264

22852265
With these the appropriate explicit memory barrier should be used if necessary
2286-
(smp_mb__before_clear_bit() for instance).
2266+
(smp_mb__before_atomic() for instance).
22872267

22882268

22892269
The following also do _not_ imply memory barriers, and so may require explicit
2290-
memory barriers under some circumstances (smp_mb__before_atomic_dec() for
2270+
memory barriers under some circumstances (smp_mb__before_atomic() for
22912271
instance):
22922272

22932273
atomic_add();

‎arch/alpha/include/asm/atomic.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,4 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
292292
#define atomic_dec(v) atomic_sub(1,(v))
293293
#define atomic64_dec(v) atomic64_sub(1,(v))
294294

295-
#define smp_mb__before_atomic_dec() smp_mb()
296-
#define smp_mb__after_atomic_dec() smp_mb()
297-
#define smp_mb__before_atomic_inc() smp_mb()
298-
#define smp_mb__after_atomic_inc() smp_mb()
299-
300295
#endif /* _ALPHA_ATOMIC_H */

‎arch/alpha/include/asm/bitops.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ __set_bit(unsigned long nr, volatile void * addr)
5353
*m |= 1 << (nr & 31);
5454
}
5555

56-
#define smp_mb__before_clear_bit() smp_mb()
57-
#define smp_mb__after_clear_bit() smp_mb()
58-
5956
static inline void
6057
clear_bit(unsigned long nr, volatile void * addr)
6158
{

‎arch/arc/include/asm/atomic.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
190190

191191
#endif /* !CONFIG_ARC_HAS_LLSC */
192192

193-
#define smp_mb__before_atomic_dec() barrier()
194-
#define smp_mb__after_atomic_dec() barrier()
195-
#define smp_mb__before_atomic_inc() barrier()
196-
#define smp_mb__after_atomic_inc() barrier()
197-
198193
/**
199194
* __atomic_add_unless - add unless the number is a given value
200195
* @v: pointer of type atomic_t

‎arch/arc/include/asm/bitops.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <linux/types.h>
2121
#include <linux/compiler.h>
22+
#include <asm/barrier.h>
2223

2324
/*
2425
* Hardware assisted read-modify-write using ARC700 LLOCK/SCOND insns.
@@ -496,10 +497,6 @@ static inline __attribute__ ((const)) int __ffs(unsigned long word)
496497
*/
497498
#define ffz(x) __ffs(~(x))
498499

499-
/* TODO does this affect uni-processor code */
500-
#define smp_mb__before_clear_bit() barrier()
501-
#define smp_mb__after_clear_bit() barrier()
502-
503500
#include <asm-generic/bitops/hweight.h>
504501
#include <asm-generic/bitops/fls64.h>
505502
#include <asm-generic/bitops/sched.h>

‎arch/arm/include/asm/atomic.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
241241

242242
#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
243243

244-
#define smp_mb__before_atomic_dec() smp_mb()
245-
#define smp_mb__after_atomic_dec() smp_mb()
246-
#define smp_mb__before_atomic_inc() smp_mb()
247-
#define smp_mb__after_atomic_inc() smp_mb()
248-
249244
#ifndef CONFIG_GENERIC_ATOMIC64
250245
typedef struct {
251246
long long counter;

‎arch/arm/include/asm/barrier.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,8 @@ do { \
7979

8080
#define set_mb(var, value) do { var = value; smp_mb(); } while (0)
8181

82+
#define smp_mb__before_atomic() smp_mb()
83+
#define smp_mb__after_atomic() smp_mb()
84+
8285
#endif /* !__ASSEMBLY__ */
8386
#endif /* __ASM_BARRIER_H */

‎arch/arm/include/asm/bitops.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626
#include <linux/compiler.h>
2727
#include <linux/irqflags.h>
28-
29-
#define smp_mb__before_clear_bit() smp_mb()
30-
#define smp_mb__after_clear_bit() smp_mb()
28+
#include <asm/barrier.h>
3129

3230
/*
3331
* These functions are the basis of our bit ops.

‎arch/arm64/include/asm/atomic.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
152152

153153
#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
154154

155-
#define smp_mb__before_atomic_dec() smp_mb()
156-
#define smp_mb__after_atomic_dec() smp_mb()
157-
#define smp_mb__before_atomic_inc() smp_mb()
158-
#define smp_mb__after_atomic_inc() smp_mb()
159-
160155
/*
161156
* 64-bit atomic operations.
162157
*/

0 commit comments

Comments
 (0)