aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-16 16:17:56 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-16 16:17:56 -0400
commit1c19b68a279c58d6da4379bf8b6d679a300a1daf (patch)
treed3907c0aa9119477dfd961bb127468d58233ac4d
parent49817c33433a3cd6f320b13699e6746cc39b453b (diff)
parenta1cc5bcfcfca0b99f009b117785142dbdc3b87a3 (diff)
Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking changes from Ingo Molnar: "The main changes in this cycle were: - pvqspinlock statistics fixes (Davidlohr Bueso) - flip atomic_fetch_or() arguments (Peter Zijlstra) - locktorture simplification (Paul E. McKenney) - documentation updates (SeongJae Park, David Howells, Davidlohr Bueso, Paul E McKenney, Peter Zijlstra, Will Deacon) - various fixes" * 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: locking/atomics: Flip atomic_fetch_or() arguments locking/pvqspinlock: Robustify init_qspinlock_stat() locking/pvqspinlock: Avoid double resetting of stats lcoking/locktorture: Simplify the torture_runnable computation locking/Documentation: Clarify that ACQUIRE applies to loads, RELEASE applies to stores locking/Documentation: State purpose of memory-barriers.txt locking/Documentation: Add disclaimer locking/Documentation/lockdep: Fix spelling mistakes locking/lockdep: Deinline register_lock_class(), save 2328 bytes locking/locktorture: Fix NULL pointer dereference for cleanup paths locking/locktorture: Fix deboosting NULL pointer dereference locking/Documentation: Mention smp_cond_acquire() locking/Documentation: Insert white spaces consistently locking/Documentation: Fix formatting inconsistencies locking/Documentation: Add missed subsection in TOC locking/Documentation: Fix missed s/lock/acquire renames locking/Documentation: Clarify relationship of barrier() to control dependencies
-rw-r--r--Documentation/locking/lockdep-design.txt4
-rw-r--r--Documentation/memory-barriers.txt117
-rw-r--r--include/linux/atomic.h4
-rw-r--r--kernel/locking/lockdep.c2
-rw-r--r--kernel/locking/locktorture.c25
-rw-r--r--kernel/locking/qspinlock_stat.h24
-rw-r--r--kernel/time/tick-sched.c4
7 files changed, 117 insertions, 63 deletions
diff --git a/Documentation/locking/lockdep-design.txt b/Documentation/locking/lockdep-design.txt
index 5001280e9d82..9de1c158d44c 100644
--- a/Documentation/locking/lockdep-design.txt
+++ b/Documentation/locking/lockdep-design.txt
@@ -97,7 +97,7 @@ between any two lock-classes:
97 <hardirq-safe> -> <hardirq-unsafe> 97 <hardirq-safe> -> <hardirq-unsafe>
98 <softirq-safe> -> <softirq-unsafe> 98 <softirq-safe> -> <softirq-unsafe>
99 99
100The first rule comes from the fact the a hardirq-safe lock could be 100The first rule comes from the fact that a hardirq-safe lock could be
101taken by a hardirq context, interrupting a hardirq-unsafe lock - and 101taken by a hardirq context, interrupting a hardirq-unsafe lock - and
102thus could result in a lock inversion deadlock. Likewise, a softirq-safe 102thus could result in a lock inversion deadlock. Likewise, a softirq-safe
103lock could be taken by an softirq context, interrupting a softirq-unsafe 103lock could be taken by an softirq context, interrupting a softirq-unsafe
@@ -220,7 +220,7 @@ calculated, which hash is unique for every lock chain. The hash value,
220when the chain is validated for the first time, is then put into a hash 220when the chain is validated for the first time, is then put into a hash
221table, which hash-table can be checked in a lockfree manner. If the 221table, which hash-table can be checked in a lockfree manner. If the
222locking chain occurs again later on, the hash table tells us that we 222locking chain occurs again later on, the hash table tells us that we
223dont have to validate the chain again. 223don't have to validate the chain again.
224 224
225Troubleshooting: 225Troubleshooting:
226---------------- 226----------------
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index 3729cbe60e41..147ae8ec836f 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -4,8 +4,40 @@
4 4
5By: David Howells <dhowells@redhat.com> 5By: David Howells <dhowells@redhat.com>
6 Paul E. McKenney <paulmck@linux.vnet.ibm.com> 6 Paul E. McKenney <paulmck@linux.vnet.ibm.com>
7 Will Deacon <will.deacon@arm.com>
8 Peter Zijlstra <peterz@infradead.org>
7 9
8Contents: 10==========
11DISCLAIMER
12==========
13
14This document is not a specification; it is intentionally (for the sake of
15brevity) and unintentionally (due to being human) incomplete. This document is
16meant as a guide to using the various memory barriers provided by Linux, but
17in case of any doubt (and there are many) please ask.
18
19To repeat, this document is not a specification of what Linux expects from
20hardware.
21
22The purpose of this document is twofold:
23
24 (1) to specify the minimum functionality that one can rely on for any
25 particular barrier, and
26
27 (2) to provide a guide as to how to use the barriers that are available.
28
29Note that an architecture can provide more than the minimum requirement
30for any particular barrier, but if the architecure provides less than
31that, that architecture is incorrect.
32
33Note also that it is possible that a barrier may be a no-op for an
34architecture because the way that arch works renders an explicit barrier
35unnecessary in that case.
36
37
38========
39CONTENTS
40========
9 41
10 (*) Abstract memory access model. 42 (*) Abstract memory access model.
11 43
@@ -31,15 +63,15 @@ Contents:
31 63
32 (*) Implicit kernel memory barriers. 64 (*) Implicit kernel memory barriers.
33 65
34 - Locking functions. 66 - Lock acquisition functions.
35 - Interrupt disabling functions. 67 - Interrupt disabling functions.
36 - Sleep and wake-up functions. 68 - Sleep and wake-up functions.
37 - Miscellaneous functions. 69 - Miscellaneous functions.
38 70
39 (*) Inter-CPU locking barrier effects. 71 (*) Inter-CPU acquiring barrier effects.
40 72
41 - Locks vs memory accesses. 73 - Acquires vs memory accesses.
42 - Locks vs I/O accesses. 74 - Acquires vs I/O accesses.
43 75
44 (*) Where are memory barriers needed? 76 (*) Where are memory barriers needed?
45 77
@@ -61,6 +93,7 @@ Contents:
61 (*) The things CPUs get up to. 93 (*) The things CPUs get up to.
62 94
63 - And then there's the Alpha. 95 - And then there's the Alpha.
96 - Virtual Machine Guests.
64 97
65 (*) Example uses. 98 (*) Example uses.
66 99
@@ -148,7 +181,7 @@ As a further example, consider this sequence of events:
148 181
149 CPU 1 CPU 2 182 CPU 1 CPU 2
150 =============== =============== 183 =============== ===============
151 { A == 1, B == 2, C = 3, P == &A, Q == &C } 184 { A == 1, B == 2, C == 3, P == &A, Q == &C }
152 B = 4; Q = P; 185 B = 4; Q = P;
153 P = &B D = *Q; 186 P = &B D = *Q;
154 187
@@ -430,8 +463,9 @@ And a couple of implicit varieties:
430 This acts as a one-way permeable barrier. It guarantees that all memory 463 This acts as a one-way permeable barrier. It guarantees that all memory
431 operations after the ACQUIRE operation will appear to happen after the 464 operations after the ACQUIRE operation will appear to happen after the
432 ACQUIRE operation with respect to the other components of the system. 465 ACQUIRE operation with respect to the other components of the system.
433 ACQUIRE operations include LOCK operations and smp_load_acquire() 466 ACQUIRE operations include LOCK operations and both smp_load_acquire()
434 operations. 467 and smp_cond_acquire() operations. The later builds the necessary ACQUIRE
468 semantics from relying on a control dependency and smp_rmb().
435 469
436 Memory operations that occur before an ACQUIRE operation may appear to 470 Memory operations that occur before an ACQUIRE operation may appear to
437 happen after it completes. 471 happen after it completes.
@@ -464,6 +498,11 @@ And a couple of implicit varieties:
464 This means that ACQUIRE acts as a minimal "acquire" operation and 498 This means that ACQUIRE acts as a minimal "acquire" operation and
465 RELEASE acts as a minimal "release" operation. 499 RELEASE acts as a minimal "release" operation.
466 500
501A subset of the atomic operations described in atomic_ops.txt have ACQUIRE
502and RELEASE variants in addition to fully-ordered and relaxed (no barrier
503semantics) definitions. For compound atomics performing both a load and a
504store, ACQUIRE semantics apply only to the load and RELEASE semantics apply
505only to the store portion of the operation.
467 506
468Memory barriers are only required where there's a possibility of interaction 507Memory barriers are only required where there's a possibility of interaction
469between two CPUs or between a CPU and a device. If it can be guaranteed that 508between two CPUs or between a CPU and a device. If it can be guaranteed that
@@ -517,7 +556,7 @@ following sequence of events:
517 556
518 CPU 1 CPU 2 557 CPU 1 CPU 2
519 =============== =============== 558 =============== ===============
520 { A == 1, B == 2, C = 3, P == &A, Q == &C } 559 { A == 1, B == 2, C == 3, P == &A, Q == &C }
521 B = 4; 560 B = 4;
522 <write barrier> 561 <write barrier>
523 WRITE_ONCE(P, &B) 562 WRITE_ONCE(P, &B)
@@ -544,7 +583,7 @@ between the address load and the data load:
544 583
545 CPU 1 CPU 2 584 CPU 1 CPU 2
546 =============== =============== 585 =============== ===============
547 { A == 1, B == 2, C = 3, P == &A, Q == &C } 586 { A == 1, B == 2, C == 3, P == &A, Q == &C }
548 B = 4; 587 B = 4;
549 <write barrier> 588 <write barrier>
550 WRITE_ONCE(P, &B); 589 WRITE_ONCE(P, &B);
@@ -813,9 +852,10 @@ In summary:
813 the same variable, then those stores must be ordered, either by 852 the same variable, then those stores must be ordered, either by
814 preceding both of them with smp_mb() or by using smp_store_release() 853 preceding both of them with smp_mb() or by using smp_store_release()
815 to carry out the stores. Please note that it is -not- sufficient 854 to carry out the stores. Please note that it is -not- sufficient
816 to use barrier() at beginning of each leg of the "if" statement, 855 to use barrier() at beginning of each leg of the "if" statement
817 as optimizing compilers do not necessarily respect barrier() 856 because, as shown by the example above, optimizing compilers can
818 in this case. 857 destroy the control dependency while respecting the letter of the
858 barrier() law.
819 859
820 (*) Control dependencies require at least one run-time conditional 860 (*) Control dependencies require at least one run-time conditional
821 between the prior load and the subsequent store, and this 861 between the prior load and the subsequent store, and this
@@ -1731,15 +1771,15 @@ The Linux kernel has eight basic CPU memory barriers:
1731 1771
1732 1772
1733All memory barriers except the data dependency barriers imply a compiler 1773All memory barriers except the data dependency barriers imply a compiler
1734barrier. Data dependencies do not impose any additional compiler ordering. 1774barrier. Data dependencies do not impose any additional compiler ordering.
1735 1775
1736Aside: In the case of data dependencies, the compiler would be expected 1776Aside: In the case of data dependencies, the compiler would be expected
1737to issue the loads in the correct order (eg. `a[b]` would have to load 1777to issue the loads in the correct order (eg. `a[b]` would have to load
1738the value of b before loading a[b]), however there is no guarantee in 1778the value of b before loading a[b]), however there is no guarantee in
1739the C specification that the compiler may not speculate the value of b 1779the C specification that the compiler may not speculate the value of b
1740(eg. is equal to 1) and load a before b (eg. tmp = a[1]; if (b != 1) 1780(eg. is equal to 1) and load a before b (eg. tmp = a[1]; if (b != 1)
1741tmp = a[b]; ). There is also the problem of a compiler reloading b after 1781tmp = a[b]; ). There is also the problem of a compiler reloading b after
1742having loaded a[b], thus having a newer copy of b than a[b]. A consensus 1782having loaded a[b], thus having a newer copy of b than a[b]. A consensus
1743has not yet been reached about these problems, however the READ_ONCE() 1783has not yet been reached about these problems, however the READ_ONCE()
1744macro is a good place to start looking. 1784macro is a good place to start looking.
1745 1785
@@ -1794,6 +1834,7 @@ There are some more advanced barrier functions:
1794 1834
1795 1835
1796 (*) lockless_dereference(); 1836 (*) lockless_dereference();
1837
1797 This can be thought of as a pointer-fetch wrapper around the 1838 This can be thought of as a pointer-fetch wrapper around the
1798 smp_read_barrier_depends() data-dependency barrier. 1839 smp_read_barrier_depends() data-dependency barrier.
1799 1840
@@ -1858,7 +1899,7 @@ This is a variation on the mandatory write barrier that causes writes to weakly
1858ordered I/O regions to be partially ordered. Its effects may go beyond the 1899ordered I/O regions to be partially ordered. Its effects may go beyond the
1859CPU->Hardware interface and actually affect the hardware at some level. 1900CPU->Hardware interface and actually affect the hardware at some level.
1860 1901
1861See the subsection "Locks vs I/O accesses" for more information. 1902See the subsection "Acquires vs I/O accesses" for more information.
1862 1903
1863 1904
1864=============================== 1905===============================
@@ -1873,8 +1914,8 @@ provide more substantial guarantees, but these may not be relied upon outside
1873of arch specific code. 1914of arch specific code.
1874 1915
1875 1916
1876ACQUIRING FUNCTIONS 1917LOCK ACQUISITION FUNCTIONS
1877------------------- 1918--------------------------
1878 1919
1879The Linux kernel has a number of locking constructs: 1920The Linux kernel has a number of locking constructs:
1880 1921
@@ -1895,7 +1936,7 @@ for each construct. These operations all imply certain barriers:
1895 Memory operations issued before the ACQUIRE may be completed after 1936 Memory operations issued before the ACQUIRE may be completed after
1896 the ACQUIRE operation has completed. An smp_mb__before_spinlock(), 1937 the ACQUIRE operation has completed. An smp_mb__before_spinlock(),
1897 combined with a following ACQUIRE, orders prior stores against 1938 combined with a following ACQUIRE, orders prior stores against
1898 subsequent loads and stores. Note that this is weaker than smp_mb()! 1939 subsequent loads and stores. Note that this is weaker than smp_mb()!
1899 The smp_mb__before_spinlock() primitive is free on many architectures. 1940 The smp_mb__before_spinlock() primitive is free on many architectures.
1900 1941
1901 (2) RELEASE operation implication: 1942 (2) RELEASE operation implication:
@@ -2090,9 +2131,9 @@ or:
2090 event_indicated = 1; 2131 event_indicated = 1;
2091 wake_up_process(event_daemon); 2132 wake_up_process(event_daemon);
2092 2133
2093A write memory barrier is implied by wake_up() and co. if and only if they wake 2134A write memory barrier is implied by wake_up() and co. if and only if they
2094something up. The barrier occurs before the task state is cleared, and so sits 2135wake something up. The barrier occurs before the task state is cleared, and so
2095between the STORE to indicate the event and the STORE to set TASK_RUNNING: 2136sits between the STORE to indicate the event and the STORE to set TASK_RUNNING:
2096 2137
2097 CPU 1 CPU 2 2138 CPU 1 CPU 2
2098 =============================== =============================== 2139 =============================== ===============================
@@ -2206,7 +2247,7 @@ three CPUs; then should the following sequence of events occur:
2206 2247
2207Then there is no guarantee as to what order CPU 3 will see the accesses to *A 2248Then there is no guarantee as to what order CPU 3 will see the accesses to *A
2208through *H occur in, other than the constraints imposed by the separate locks 2249through *H occur in, other than the constraints imposed by the separate locks
2209on the separate CPUs. It might, for example, see: 2250on the separate CPUs. It might, for example, see:
2210 2251
2211 *E, ACQUIRE M, ACQUIRE Q, *G, *C, *F, *A, *B, RELEASE Q, *D, *H, RELEASE M 2252 *E, ACQUIRE M, ACQUIRE Q, *G, *C, *F, *A, *B, RELEASE Q, *D, *H, RELEASE M
2212 2253
@@ -2486,9 +2527,9 @@ The following operations are special locking primitives:
2486 clear_bit_unlock(); 2527 clear_bit_unlock();
2487 __clear_bit_unlock(); 2528 __clear_bit_unlock();
2488 2529
2489These implement ACQUIRE-class and RELEASE-class operations. These should be used in 2530These implement ACQUIRE-class and RELEASE-class operations. These should be
2490preference to other operations when implementing locking primitives, because 2531used in preference to other operations when implementing locking primitives,
2491their implementations can be optimised on many architectures. 2532because their implementations can be optimised on many architectures.
2492 2533
2493[!] Note that special memory barrier primitives are available for these 2534[!] Note that special memory barrier primitives are available for these
2494situations because on some CPUs the atomic instructions used imply full memory 2535situations because on some CPUs the atomic instructions used imply full memory
@@ -2568,12 +2609,12 @@ explicit barriers are used.
2568 2609
2569Normally this won't be a problem because the I/O accesses done inside such 2610Normally this won't be a problem because the I/O accesses done inside such
2570sections will include synchronous load operations on strictly ordered I/O 2611sections will include synchronous load operations on strictly ordered I/O
2571registers that form implicit I/O barriers. If this isn't sufficient then an 2612registers that form implicit I/O barriers. If this isn't sufficient then an
2572mmiowb() may need to be used explicitly. 2613mmiowb() may need to be used explicitly.
2573 2614
2574 2615
2575A similar situation may occur between an interrupt routine and two routines 2616A similar situation may occur between an interrupt routine and two routines
2576running on separate CPUs that communicate with each other. If such a case is 2617running on separate CPUs that communicate with each other. If such a case is
2577likely, then interrupt-disabling locks should be used to guarantee ordering. 2618likely, then interrupt-disabling locks should be used to guarantee ordering.
2578 2619
2579 2620
@@ -2587,8 +2628,8 @@ functions:
2587 (*) inX(), outX(): 2628 (*) inX(), outX():
2588 2629
2589 These are intended to talk to I/O space rather than memory space, but 2630 These are intended to talk to I/O space rather than memory space, but
2590 that's primarily a CPU-specific concept. The i386 and x86_64 processors do 2631 that's primarily a CPU-specific concept. The i386 and x86_64 processors
2591 indeed have special I/O space access cycles and instructions, but many 2632 do indeed have special I/O space access cycles and instructions, but many
2592 CPUs don't have such a concept. 2633 CPUs don't have such a concept.
2593 2634
2594 The PCI bus, amongst others, defines an I/O space concept which - on such 2635 The PCI bus, amongst others, defines an I/O space concept which - on such
@@ -2610,7 +2651,7 @@ functions:
2610 2651
2611 Whether these are guaranteed to be fully ordered and uncombined with 2652 Whether these are guaranteed to be fully ordered and uncombined with
2612 respect to each other on the issuing CPU depends on the characteristics 2653 respect to each other on the issuing CPU depends on the characteristics
2613 defined for the memory window through which they're accessing. On later 2654 defined for the memory window through which they're accessing. On later
2614 i386 architecture machines, for example, this is controlled by way of the 2655 i386 architecture machines, for example, this is controlled by way of the
2615 MTRR registers. 2656 MTRR registers.
2616 2657
@@ -2635,10 +2676,10 @@ functions:
2635 (*) readX_relaxed(), writeX_relaxed() 2676 (*) readX_relaxed(), writeX_relaxed()
2636 2677
2637 These are similar to readX() and writeX(), but provide weaker memory 2678 These are similar to readX() and writeX(), but provide weaker memory
2638 ordering guarantees. Specifically, they do not guarantee ordering with 2679 ordering guarantees. Specifically, they do not guarantee ordering with
2639 respect to normal memory accesses (e.g. DMA buffers) nor do they guarantee 2680 respect to normal memory accesses (e.g. DMA buffers) nor do they guarantee
2640 ordering with respect to LOCK or UNLOCK operations. If the latter is 2681 ordering with respect to LOCK or UNLOCK operations. If the latter is
2641 required, an mmiowb() barrier can be used. Note that relaxed accesses to 2682 required, an mmiowb() barrier can be used. Note that relaxed accesses to
2642 the same peripheral are guaranteed to be ordered with respect to each 2683 the same peripheral are guaranteed to be ordered with respect to each
2643 other. 2684 other.
2644 2685
@@ -3040,8 +3081,9 @@ The Alpha defines the Linux kernel's memory barrier model.
3040 3081
3041See the subsection on "Cache Coherency" above. 3082See the subsection on "Cache Coherency" above.
3042 3083
3084
3043VIRTUAL MACHINE GUESTS 3085VIRTUAL MACHINE GUESTS
3044------------------- 3086----------------------
3045 3087
3046Guests running within virtual machines might be affected by SMP effects even if 3088Guests running within virtual machines might be affected by SMP effects even if
3047the guest itself is compiled without SMP support. This is an artifact of 3089the guest itself is compiled without SMP support. This is an artifact of
@@ -3050,7 +3092,7 @@ barriers for this use-case would be possible but is often suboptimal.
3050 3092
3051To handle this case optimally, low-level virt_mb() etc macros are available. 3093To handle this case optimally, low-level virt_mb() etc macros are available.
3052These have the same effect as smp_mb() etc when SMP is enabled, but generate 3094These have the same effect as smp_mb() etc when SMP is enabled, but generate
3053identical code for SMP and non-SMP systems. For example, virtual machine guests 3095identical code for SMP and non-SMP systems. For example, virtual machine guests
3054should use virt_mb() rather than smp_mb() when synchronizing against a 3096should use virt_mb() rather than smp_mb() when synchronizing against a
3055(possibly SMP) host. 3097(possibly SMP) host.
3056 3098
@@ -3058,6 +3100,7 @@ These are equivalent to smp_mb() etc counterparts in all other respects,
3058in particular, they do not control MMIO effects: to control 3100in particular, they do not control MMIO effects: to control
3059MMIO effects, use mandatory barriers. 3101MMIO effects, use mandatory barriers.
3060 3102
3103
3061============ 3104============
3062EXAMPLE USES 3105EXAMPLE USES
3063============ 3106============
diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index 506c3531832e..e451534fe54d 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -560,11 +560,11 @@ static inline int atomic_dec_if_positive(atomic_t *v)
560 560
561/** 561/**
562 * atomic_fetch_or - perform *p |= mask and return old value of *p 562 * atomic_fetch_or - perform *p |= mask and return old value of *p
563 * @p: pointer to atomic_t
564 * @mask: mask to OR on the atomic_t 563 * @mask: mask to OR on the atomic_t
564 * @p: pointer to atomic_t
565 */ 565 */
566#ifndef atomic_fetch_or 566#ifndef atomic_fetch_or
567static inline int atomic_fetch_or(atomic_t *p, int mask) 567static inline int atomic_fetch_or(int mask, atomic_t *p)
568{ 568{
569 int old, val = atomic_read(p); 569 int old, val = atomic_read(p);
570 570
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 78c1c0ee6dc1..874d53eaf389 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -708,7 +708,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
708 * yet. Otherwise we look it up. We cache the result in the lock object 708 * yet. Otherwise we look it up. We cache the result in the lock object
709 * itself, so actual lookup of the hash should be once per lock object. 709 * itself, so actual lookup of the hash should be once per lock object.
710 */ 710 */
711static inline struct lock_class * 711static struct lock_class *
712register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force) 712register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
713{ 713{
714 struct lockdep_subclass_key *key; 714 struct lockdep_subclass_key *key;
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index 8ef1919d63b2..f8c5af52a131 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -75,12 +75,7 @@ struct lock_stress_stats {
75 long n_lock_acquired; 75 long n_lock_acquired;
76}; 76};
77 77
78#if defined(MODULE) 78int torture_runnable = IS_ENABLED(MODULE);
79#define LOCKTORTURE_RUNNABLE_INIT 1
80#else
81#define LOCKTORTURE_RUNNABLE_INIT 0
82#endif
83int torture_runnable = LOCKTORTURE_RUNNABLE_INIT;
84module_param(torture_runnable, int, 0444); 79module_param(torture_runnable, int, 0444);
85MODULE_PARM_DESC(torture_runnable, "Start locktorture at module init"); 80MODULE_PARM_DESC(torture_runnable, "Start locktorture at module init");
86 81
@@ -394,12 +389,12 @@ static void torture_rtmutex_boost(struct torture_random_state *trsp)
394 389
395 if (!rt_task(current)) { 390 if (!rt_task(current)) {
396 /* 391 /*
397 * (1) Boost priority once every ~50k operations. When the 392 * Boost priority once every ~50k operations. When the
398 * task tries to take the lock, the rtmutex it will account 393 * task tries to take the lock, the rtmutex it will account
399 * for the new priority, and do any corresponding pi-dance. 394 * for the new priority, and do any corresponding pi-dance.
400 */ 395 */
401 if (!(torture_random(trsp) % 396 if (trsp && !(torture_random(trsp) %
402 (cxt.nrealwriters_stress * factor))) { 397 (cxt.nrealwriters_stress * factor))) {
403 policy = SCHED_FIFO; 398 policy = SCHED_FIFO;
404 param.sched_priority = MAX_RT_PRIO - 1; 399 param.sched_priority = MAX_RT_PRIO - 1;
405 } else /* common case, do nothing */ 400 } else /* common case, do nothing */
@@ -748,6 +743,15 @@ static void lock_torture_cleanup(void)
748 if (torture_cleanup_begin()) 743 if (torture_cleanup_begin())
749 return; 744 return;
750 745
746 /*
747 * Indicates early cleanup, meaning that the test has not run,
748 * such as when passing bogus args when loading the module. As
749 * such, only perform the underlying torture-specific cleanups,
750 * and avoid anything related to locktorture.
751 */
752 if (!cxt.lwsa)
753 goto end;
754
751 if (writer_tasks) { 755 if (writer_tasks) {
752 for (i = 0; i < cxt.nrealwriters_stress; i++) 756 for (i = 0; i < cxt.nrealwriters_stress; i++)
753 torture_stop_kthread(lock_torture_writer, 757 torture_stop_kthread(lock_torture_writer,
@@ -776,6 +780,7 @@ static void lock_torture_cleanup(void)
776 else 780 else
777 lock_torture_print_module_parms(cxt.cur_ops, 781 lock_torture_print_module_parms(cxt.cur_ops,
778 "End of test: SUCCESS"); 782 "End of test: SUCCESS");
783end:
779 torture_cleanup_end(); 784 torture_cleanup_end();
780} 785}
781 786
@@ -870,6 +875,7 @@ static int __init lock_torture_init(void)
870 VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory"); 875 VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory");
871 firsterr = -ENOMEM; 876 firsterr = -ENOMEM;
872 kfree(cxt.lwsa); 877 kfree(cxt.lwsa);
878 cxt.lwsa = NULL;
873 goto unwind; 879 goto unwind;
874 } 880 }
875 881
@@ -878,6 +884,7 @@ static int __init lock_torture_init(void)
878 cxt.lrsa[i].n_lock_acquired = 0; 884 cxt.lrsa[i].n_lock_acquired = 0;
879 } 885 }
880 } 886 }
887
881 lock_torture_print_module_parms(cxt.cur_ops, "Start of test"); 888 lock_torture_print_module_parms(cxt.cur_ops, "Start of test");
882 889
883 /* Prepare torture context. */ 890 /* Prepare torture context. */
diff --git a/kernel/locking/qspinlock_stat.h b/kernel/locking/qspinlock_stat.h
index d734b7502001..22e025309845 100644
--- a/kernel/locking/qspinlock_stat.h
+++ b/kernel/locking/qspinlock_stat.h
@@ -191,8 +191,6 @@ static ssize_t qstat_write(struct file *file, const char __user *user_buf,
191 191
192 for (i = 0 ; i < qstat_num; i++) 192 for (i = 0 ; i < qstat_num; i++)
193 WRITE_ONCE(ptr[i], 0); 193 WRITE_ONCE(ptr[i], 0);
194 for (i = 0 ; i < qstat_num; i++)
195 WRITE_ONCE(ptr[i], 0);
196 } 194 }
197 return count; 195 return count;
198} 196}
@@ -214,10 +212,8 @@ static int __init init_qspinlock_stat(void)
214 struct dentry *d_qstat = debugfs_create_dir("qlockstat", NULL); 212 struct dentry *d_qstat = debugfs_create_dir("qlockstat", NULL);
215 int i; 213 int i;
216 214
217 if (!d_qstat) { 215 if (!d_qstat)
218 pr_warn("Could not create 'qlockstat' debugfs directory\n"); 216 goto out;
219 return 0;
220 }
221 217
222 /* 218 /*
223 * Create the debugfs files 219 * Create the debugfs files
@@ -227,12 +223,20 @@ static int __init init_qspinlock_stat(void)
227 * performance. 223 * performance.
228 */ 224 */
229 for (i = 0; i < qstat_num; i++) 225 for (i = 0; i < qstat_num; i++)
230 debugfs_create_file(qstat_names[i], 0400, d_qstat, 226 if (!debugfs_create_file(qstat_names[i], 0400, d_qstat,
231 (void *)(long)i, &fops_qstat); 227 (void *)(long)i, &fops_qstat))
228 goto fail_undo;
229
230 if (!debugfs_create_file(qstat_names[qstat_reset_cnts], 0200, d_qstat,
231 (void *)(long)qstat_reset_cnts, &fops_qstat))
232 goto fail_undo;
232 233
233 debugfs_create_file(qstat_names[qstat_reset_cnts], 0200, d_qstat,
234 (void *)(long)qstat_reset_cnts, &fops_qstat);
235 return 0; 234 return 0;
235fail_undo:
236 debugfs_remove_recursive(d_qstat);
237out:
238 pr_warn("Could not create 'qlockstat' debugfs entries\n");
239 return -ENOMEM;
236} 240}
237fs_initcall(init_qspinlock_stat); 241fs_initcall(init_qspinlock_stat);
238 242
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 58e3310c9b21..3daa49ff0719 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -262,7 +262,7 @@ static void tick_nohz_dep_set_all(atomic_t *dep,
262{ 262{
263 int prev; 263 int prev;
264 264
265 prev = atomic_fetch_or(dep, BIT(bit)); 265 prev = atomic_fetch_or(BIT(bit), dep);
266 if (!prev) 266 if (!prev)
267 tick_nohz_full_kick_all(); 267 tick_nohz_full_kick_all();
268} 268}
@@ -292,7 +292,7 @@ void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit)
292 292
293 ts = per_cpu_ptr(&tick_cpu_sched, cpu); 293 ts = per_cpu_ptr(&tick_cpu_sched, cpu);
294 294
295 prev = atomic_fetch_or(&ts->tick_dep_mask, BIT(bit)); 295 prev = atomic_fetch_or(BIT(bit), &ts->tick_dep_mask);
296 if (!prev) { 296 if (!prev) {
297 preempt_disable(); 297 preempt_disable();
298 /* Perf needs local kick that is NMI safe */ 298 /* Perf needs local kick that is NMI safe */