aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-06-22 17:01:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-06-22 17:01:01 -0400
commitfc934d40178ad4e551a17e2733241d9f29fddd70 (patch)
tree43e3f3c9019915cc41befec4dad5d1328a4cae63
parent052b398a43a7de8c68c13e7fa05d6b3d16ce6801 (diff)
parent085c789783f5f95c253740d3d0a1659ec5ff32a8 (diff)
Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull RCU updates from Ingo Molnar: - Continued initialization/Kconfig updates: hide most Kconfig options from unsuspecting users. There's now a single high level configuration option: * * RCU Subsystem * Make expert-level adjustments to RCU configuration (RCU_EXPERT) [N/y/?] (NEW) Which if answered in the negative, leaves us with a single interactive configuration option: Offload RCU callback processing from boot-selected CPUs (RCU_NOCB_CPU) [N/y/?] (NEW) All the rest of the RCU options are configured automatically. Later on we'll remove this single leftover configuration option as well. - Remove all uses of RCU-protected array indexes: replace the rcu_[access|dereference]_index_check() APIs with READ_ONCE() and rcu_lockdep_assert() - RCU CPU-hotplug cleanups - Updates to Tiny RCU: a race fix and further code shrinkage. - RCU torture-testing updates: fixes, speedups, cleanups and documentation updates. - Miscellaneous fixes - Documentation updates * 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (60 commits) rcutorture: Allow repetition factors in Kconfig-fragment lists rcutorture: Display "make oldconfig" errors rcutorture: Update TREE_RCU-kconfig.txt rcutorture: Make rcutorture scripts force RCU_EXPERT rcutorture: Update configuration fragments for rcutree.rcu_fanout_exact rcutorture: TASKS_RCU set directly, so don't explicitly set it rcutorture: Test SRCU cleanup code path rcutorture: Replace barriers with smp_store_release() and smp_load_acquire() locktorture: Change longdelay_us to longdelay_ms rcutorture: Allow negative values of nreaders to oversubscribe rcutorture: Exchange TREE03 and TREE08 NR_CPUS, speed up CPU hotplug rcutorture: Exchange TREE03 and TREE04 geometries locktorture: fix deadlock in 'rw_lock_irq' type rcu: Correctly handle non-empty Tiny RCU callback list with none ready rcutorture: Test both RCU-sched and RCU-bh for Tiny RCU rcu: Further shrink Tiny RCU by making empty functions static inlines rcu: Conditionally compile RCU's eqs warnings rcu: Remove prompt for RCU implementation rcu: Make RCU able to tolerate undefined CONFIG_RCU_KTHREAD_PRIO rcu: Make RCU able to tolerate undefined CONFIG_RCU_FANOUT_LEAF ...
-rw-r--r--Documentation/RCU/arrayRCU.txt20
-rw-r--r--Documentation/RCU/lockdep.txt10
-rw-r--r--Documentation/RCU/rcu_dereference.txt38
-rw-r--r--Documentation/RCU/whatisRCU.txt6
-rw-r--r--Documentation/kernel-parameters.txt33
-rw-r--r--Documentation/memory-barriers.txt62
-rw-r--r--arch/powerpc/include/asm/barrier.h1
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c15
-rw-r--r--include/linux/compiler.h16
-rw-r--r--include/linux/rculist.h10
-rw-r--r--include/linux/rcupdate.h70
-rw-r--r--include/linux/rcutiny.h16
-rw-r--r--include/linux/rcutree.h7
-rw-r--r--include/linux/spinlock.h2
-rw-r--r--init/Kconfig72
-rw-r--r--kernel/cpu.c4
-rw-r--r--kernel/events/ring_buffer.c2
-rw-r--r--kernel/locking/locktorture.c14
-rw-r--r--kernel/rcu/rcutorture.c103
-rw-r--r--kernel/rcu/srcu.c10
-rw-r--r--kernel/rcu/tiny.c38
-rw-r--r--kernel/rcu/tiny_plugin.h12
-rw-r--r--kernel/rcu/tree.c365
-rw-r--r--kernel/rcu/tree.h35
-rw-r--r--kernel/rcu/tree_plugin.h216
-rw-r--r--kernel/rcu/tree_trace.c6
-rw-r--r--kernel/rcu/update.c30
-rw-r--r--kernel/torture.c26
-rw-r--r--lib/Kconfig.debug66
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/configinit.sh2
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm-recheck.sh4
-rwxr-xr-xtools/testing/selftests/rcutorture/bin/kvm.sh25
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/CFcommon2
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/SRCU-N1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/SRCU-P1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot2
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TASKS015
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TASKS021
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TASKS032
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TINY022
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE011
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE022
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE02-T1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE038
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE048
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE054
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE064
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE074
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE086
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE08-T1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE08-T.boot1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot1
-rw-r--r--tools/testing/selftests/rcutorture/configs/rcu/TREE091
-rw-r--r--tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt36
57 files changed, 809 insertions, 624 deletions
diff --git a/Documentation/RCU/arrayRCU.txt b/Documentation/RCU/arrayRCU.txt
index 453ebe6953ee..f05a9afb2c39 100644
--- a/Documentation/RCU/arrayRCU.txt
+++ b/Documentation/RCU/arrayRCU.txt
@@ -10,7 +10,19 @@ also be used to protect arrays. Three situations are as follows:
10 10
113. Resizeable Arrays 113. Resizeable Arrays
12 12
13Each of these situations are discussed below. 13Each of these three situations involves an RCU-protected pointer to an
14array that is separately indexed. It might be tempting to consider use
15of RCU to instead protect the index into an array, however, this use
16case is -not- supported. The problem with RCU-protected indexes into
17arrays is that compilers can play way too many optimization games with
18integers, which means that the rules governing handling of these indexes
19are far more trouble than they are worth. If RCU-protected indexes into
20arrays prove to be particularly valuable (which they have not thus far),
21explicit cooperation from the compiler will be required to permit them
22to be safely used.
23
24That aside, each of the three RCU-protected pointer situations are
25described in the following sections.
14 26
15 27
16Situation 1: Hash Tables 28Situation 1: Hash Tables
@@ -36,9 +48,9 @@ Quick Quiz: Why is it so important that updates be rare when
36Situation 3: Resizeable Arrays 48Situation 3: Resizeable Arrays
37 49
38Use of RCU for resizeable arrays is demonstrated by the grow_ary() 50Use of RCU for resizeable arrays is demonstrated by the grow_ary()
39function used by the System V IPC code. The array is used to map from 51function formerly used by the System V IPC code. The array is used
40semaphore, message-queue, and shared-memory IDs to the data structure 52to map from semaphore, message-queue, and shared-memory IDs to the data
41that represents the corresponding IPC construct. The grow_ary() 53structure that represents the corresponding IPC construct. The grow_ary()
42function does not acquire any locks; instead its caller must hold the 54function does not acquire any locks; instead its caller must hold the
43ids->sem semaphore. 55ids->sem semaphore.
44 56
diff --git a/Documentation/RCU/lockdep.txt b/Documentation/RCU/lockdep.txt
index cd83d2348fef..da51d3068850 100644
--- a/Documentation/RCU/lockdep.txt
+++ b/Documentation/RCU/lockdep.txt
@@ -47,11 +47,6 @@ checking of rcu_dereference() primitives:
47 Use explicit check expression "c" along with 47 Use explicit check expression "c" along with
48 srcu_read_lock_held()(). This is useful in code that 48 srcu_read_lock_held()(). This is useful in code that
49 is invoked by both SRCU readers and updaters. 49 is invoked by both SRCU readers and updaters.
50 rcu_dereference_index_check(p, c):
51 Use explicit check expression "c", but the caller
52 must supply one of the rcu_read_lock_held() functions.
53 This is useful in code that uses RCU-protected arrays
54 that is invoked by both RCU readers and updaters.
55 rcu_dereference_raw(p): 50 rcu_dereference_raw(p):
56 Don't check. (Use sparingly, if at all.) 51 Don't check. (Use sparingly, if at all.)
57 rcu_dereference_protected(p, c): 52 rcu_dereference_protected(p, c):
@@ -64,11 +59,6 @@ checking of rcu_dereference() primitives:
64 but retain the compiler constraints that prevent duplicating 59 but retain the compiler constraints that prevent duplicating
65 or coalescsing. This is useful when when testing the 60 or coalescsing. This is useful when when testing the
66 value of the pointer itself, for example, against NULL. 61 value of the pointer itself, for example, against NULL.
67 rcu_access_index(idx):
68 Return the value of the index and omit all barriers, but
69 retain the compiler constraints that prevent duplicating
70 or coalescsing. This is useful when when testing the
71 value of the index itself, for example, against -1.
72 62
73The rcu_dereference_check() check expression can be any boolean 63The rcu_dereference_check() check expression can be any boolean
74expression, but would normally include a lockdep expression. However, 64expression, but would normally include a lockdep expression. However,
diff --git a/Documentation/RCU/rcu_dereference.txt b/Documentation/RCU/rcu_dereference.txt
index ceb05da5a5ac..1e6c0da994f5 100644
--- a/Documentation/RCU/rcu_dereference.txt
+++ b/Documentation/RCU/rcu_dereference.txt
@@ -25,17 +25,6 @@ o You must use one of the rcu_dereference() family of primitives
25 for an example where the compiler can in fact deduce the exact 25 for an example where the compiler can in fact deduce the exact
26 value of the pointer, and thus cause misordering. 26 value of the pointer, and thus cause misordering.
27 27
28o Do not use single-element RCU-protected arrays. The compiler
29 is within its right to assume that the value of an index into
30 such an array must necessarily evaluate to zero. The compiler
31 could then substitute the constant zero for the computation, so
32 that the array index no longer depended on the value returned
33 by rcu_dereference(). If the array index no longer depends
34 on rcu_dereference(), then both the compiler and the CPU
35 are within their rights to order the array access before the
36 rcu_dereference(), which can cause the array access to return
37 garbage.
38
39o Avoid cancellation when using the "+" and "-" infix arithmetic 28o Avoid cancellation when using the "+" and "-" infix arithmetic
40 operators. For example, for a given variable "x", avoid 29 operators. For example, for a given variable "x", avoid
41 "(x-x)". There are similar arithmetic pitfalls from other 30 "(x-x)". There are similar arithmetic pitfalls from other
@@ -76,14 +65,15 @@ o Do not use the results from the boolean "&&" and "||" when
76 dereferencing. For example, the following (rather improbable) 65 dereferencing. For example, the following (rather improbable)
77 code is buggy: 66 code is buggy:
78 67
79 int a[2]; 68 int *p;
80 int index; 69 int *q;
81 int force_zero_index = 1;
82 70
83 ... 71 ...
84 72
85 r1 = rcu_dereference(i1) 73 p = rcu_dereference(gp)
86 r2 = a[r1 && force_zero_index]; /* BUGGY!!! */ 74 q = &global_q;
75 q += p != &oom_p1 && p != &oom_p2;
76 r1 = *q; /* BUGGY!!! */
87 77
88 The reason this is buggy is that "&&" and "||" are often compiled 78 The reason this is buggy is that "&&" and "||" are often compiled
89 using branches. While weak-memory machines such as ARM or PowerPC 79 using branches. While weak-memory machines such as ARM or PowerPC
@@ -94,14 +84,15 @@ o Do not use the results from relational operators ("==", "!=",
94 ">", ">=", "<", or "<=") when dereferencing. For example, 84 ">", ">=", "<", or "<=") when dereferencing. For example,
95 the following (quite strange) code is buggy: 85 the following (quite strange) code is buggy:
96 86
97 int a[2]; 87 int *p;
98 int index; 88 int *q;
99 int flip_index = 0;
100 89
101 ... 90 ...
102 91
103 r1 = rcu_dereference(i1) 92 p = rcu_dereference(gp)
104 r2 = a[r1 != flip_index]; /* BUGGY!!! */ 93 q = &global_q;
94 q += p > &oom_p;
95 r1 = *q; /* BUGGY!!! */
105 96
106 As before, the reason this is buggy is that relational operators 97 As before, the reason this is buggy is that relational operators
107 are often compiled using branches. And as before, although 98 are often compiled using branches. And as before, although
@@ -193,6 +184,11 @@ o Be very careful about comparing pointers obtained from
193 pointer. Note that the volatile cast in rcu_dereference() 184 pointer. Note that the volatile cast in rcu_dereference()
194 will normally prevent the compiler from knowing too much. 185 will normally prevent the compiler from knowing too much.
195 186
187 However, please note that if the compiler knows that the
188 pointer takes on only one of two values, a not-equal
189 comparison will provide exactly the information that the
190 compiler needs to deduce the value of the pointer.
191
196o Disable any value-speculation optimizations that your compiler 192o Disable any value-speculation optimizations that your compiler
197 might provide, especially if you are making use of feedback-based 193 might provide, especially if you are making use of feedback-based
198 optimizations that take data collected from prior runs. Such 194 optimizations that take data collected from prior runs. Such
diff --git a/Documentation/RCU/whatisRCU.txt b/Documentation/RCU/whatisRCU.txt
index 88dfce182f66..5746b0c77f3e 100644
--- a/Documentation/RCU/whatisRCU.txt
+++ b/Documentation/RCU/whatisRCU.txt
@@ -256,7 +256,9 @@ rcu_dereference()
256 If you are going to be fetching multiple fields from the 256 If you are going to be fetching multiple fields from the
257 RCU-protected structure, using the local variable is of 257 RCU-protected structure, using the local variable is of
258 course preferred. Repeated rcu_dereference() calls look 258 course preferred. Repeated rcu_dereference() calls look
259 ugly and incur unnecessary overhead on Alpha CPUs. 259 ugly, do not guarantee that the same pointer will be returned
260 if an update happened while in the critical section, and incur
261 unnecessary overhead on Alpha CPUs.
260 262
261 Note that the value returned by rcu_dereference() is valid 263 Note that the value returned by rcu_dereference() is valid
262 only within the enclosing RCU read-side critical section. 264 only within the enclosing RCU read-side critical section.
@@ -879,9 +881,7 @@ SRCU: Initialization/cleanup
879 881
880All: lockdep-checked RCU-protected pointer access 882All: lockdep-checked RCU-protected pointer access
881 883
882 rcu_access_index
883 rcu_access_pointer 884 rcu_access_pointer
884 rcu_dereference_index_check
885 rcu_dereference_raw 885 rcu_dereference_raw
886 rcu_lockdep_assert 886 rcu_lockdep_assert
887 rcu_sleep_check 887 rcu_sleep_check
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 6726139bd289..60c9d6d0fd96 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2998,11 +2998,34 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
2998 Set maximum number of finished RCU callbacks to 2998 Set maximum number of finished RCU callbacks to
2999 process in one batch. 2999 process in one batch.
3000 3000
3001 rcutree.dump_tree= [KNL]
3002 Dump the structure of the rcu_node combining tree
3003 out at early boot. This is used for diagnostic
3004 purposes, to verify correct tree setup.
3005
3006 rcutree.gp_cleanup_delay= [KNL]
3007 Set the number of jiffies to delay each step of
3008 RCU grace-period cleanup. This only has effect
3009 when CONFIG_RCU_TORTURE_TEST_SLOW_CLEANUP is set.
3010
3001 rcutree.gp_init_delay= [KNL] 3011 rcutree.gp_init_delay= [KNL]
3002 Set the number of jiffies to delay each step of 3012 Set the number of jiffies to delay each step of
3003 RCU grace-period initialization. This only has 3013 RCU grace-period initialization. This only has
3004 effect when CONFIG_RCU_TORTURE_TEST_SLOW_INIT is 3014 effect when CONFIG_RCU_TORTURE_TEST_SLOW_INIT
3005 set. 3015 is set.
3016
3017 rcutree.gp_preinit_delay= [KNL]
3018 Set the number of jiffies to delay each step of
3019 RCU grace-period pre-initialization, that is,
3020 the propagation of recent CPU-hotplug changes up
3021 the rcu_node combining tree. This only has effect
3022 when CONFIG_RCU_TORTURE_TEST_SLOW_PREINIT is set.
3023
3024 rcutree.rcu_fanout_exact= [KNL]
3025 Disable autobalancing of the rcu_node combining
3026 tree. This is used by rcutorture, and might
3027 possibly be useful for architectures having high
3028 cache-to-cache transfer latencies.
3006 3029
3007 rcutree.rcu_fanout_leaf= [KNL] 3030 rcutree.rcu_fanout_leaf= [KNL]
3008 Increase the number of CPUs assigned to each 3031 Increase the number of CPUs assigned to each
@@ -3107,7 +3130,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
3107 test, hence the "fake". 3130 test, hence the "fake".
3108 3131
3109 rcutorture.nreaders= [KNL] 3132 rcutorture.nreaders= [KNL]
3110 Set number of RCU readers. 3133 Set number of RCU readers. The value -1 selects
3134 N-1, where N is the number of CPUs. A value
3135 "n" less than -1 selects N-n-2, where N is again
3136 the number of CPUs. For example, -2 selects N
3137 (the number of CPUs), -3 selects N+1, and so on.
3111 3138
3112 rcutorture.object_debug= [KNL] 3139 rcutorture.object_debug= [KNL]
3113 Enable debug-object double-call_rcu() testing. 3140 Enable debug-object double-call_rcu() testing.
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index f95746189b5d..360841da3744 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -617,16 +617,16 @@ case what's actually required is:
617However, stores are not speculated. This means that ordering -is- provided 617However, stores are not speculated. This means that ordering -is- provided
618for load-store control dependencies, as in the following example: 618for load-store control dependencies, as in the following example:
619 619
620 q = ACCESS_ONCE(a); 620 q = READ_ONCE_CTRL(a);
621 if (q) { 621 if (q) {
622 ACCESS_ONCE(b) = p; 622 ACCESS_ONCE(b) = p;
623 } 623 }
624 624
625Control dependencies pair normally with other types of barriers. 625Control dependencies pair normally with other types of barriers. That
626That said, please note that ACCESS_ONCE() is not optional! Without the 626said, please note that READ_ONCE_CTRL() is not optional! Without the
627ACCESS_ONCE(), might combine the load from 'a' with other loads from 627READ_ONCE_CTRL(), the compiler might combine the load from 'a' with
628'a', and the store to 'b' with other stores to 'b', with possible highly 628other loads from 'a', and the store to 'b' with other stores to 'b',
629counterintuitive effects on ordering. 629with possible highly counterintuitive effects on ordering.
630 630
631Worse yet, if the compiler is able to prove (say) that the value of 631Worse yet, if the compiler is able to prove (say) that the value of
632variable 'a' is always non-zero, it would be well within its rights 632variable 'a' is always non-zero, it would be well within its rights
@@ -636,12 +636,15 @@ as follows:
636 q = a; 636 q = a;
637 b = p; /* BUG: Compiler and CPU can both reorder!!! */ 637 b = p; /* BUG: Compiler and CPU can both reorder!!! */
638 638
639So don't leave out the ACCESS_ONCE(). 639Finally, the READ_ONCE_CTRL() includes an smp_read_barrier_depends()
640that DEC Alpha needs in order to respect control depedencies.
641
642So don't leave out the READ_ONCE_CTRL().
640 643
641It is tempting to try to enforce ordering on identical stores on both 644It is tempting to try to enforce ordering on identical stores on both
642branches of the "if" statement as follows: 645branches of the "if" statement as follows:
643 646
644 q = ACCESS_ONCE(a); 647 q = READ_ONCE_CTRL(a);
645 if (q) { 648 if (q) {
646 barrier(); 649 barrier();
647 ACCESS_ONCE(b) = p; 650 ACCESS_ONCE(b) = p;
@@ -655,7 +658,7 @@ branches of the "if" statement as follows:
655Unfortunately, current compilers will transform this as follows at high 658Unfortunately, current compilers will transform this as follows at high
656optimization levels: 659optimization levels:
657 660
658 q = ACCESS_ONCE(a); 661 q = READ_ONCE_CTRL(a);
659 barrier(); 662 barrier();
660 ACCESS_ONCE(b) = p; /* BUG: No ordering vs. load from a!!! */ 663 ACCESS_ONCE(b) = p; /* BUG: No ordering vs. load from a!!! */
661 if (q) { 664 if (q) {
@@ -685,7 +688,7 @@ memory barriers, for example, smp_store_release():
685In contrast, without explicit memory barriers, two-legged-if control 688In contrast, without explicit memory barriers, two-legged-if control
686ordering is guaranteed only when the stores differ, for example: 689ordering is guaranteed only when the stores differ, for example:
687 690
688 q = ACCESS_ONCE(a); 691 q = READ_ONCE_CTRL(a);
689 if (q) { 692 if (q) {
690 ACCESS_ONCE(b) = p; 693 ACCESS_ONCE(b) = p;
691 do_something(); 694 do_something();
@@ -694,14 +697,14 @@ ordering is guaranteed only when the stores differ, for example:
694 do_something_else(); 697 do_something_else();
695 } 698 }
696 699
697The initial ACCESS_ONCE() is still required to prevent the compiler from 700The initial READ_ONCE_CTRL() is still required to prevent the compiler
698proving the value of 'a'. 701from proving the value of 'a'.
699 702
700In addition, you need to be careful what you do with the local variable 'q', 703In addition, you need to be careful what you do with the local variable 'q',
701otherwise the compiler might be able to guess the value and again remove 704otherwise the compiler might be able to guess the value and again remove
702the needed conditional. For example: 705the needed conditional. For example:
703 706
704 q = ACCESS_ONCE(a); 707 q = READ_ONCE_CTRL(a);
705 if (q % MAX) { 708 if (q % MAX) {
706 ACCESS_ONCE(b) = p; 709 ACCESS_ONCE(b) = p;
707 do_something(); 710 do_something();
@@ -714,7 +717,7 @@ If MAX is defined to be 1, then the compiler knows that (q % MAX) is
714equal to zero, in which case the compiler is within its rights to 717equal to zero, in which case the compiler is within its rights to
715transform the above code into the following: 718transform the above code into the following:
716 719
717 q = ACCESS_ONCE(a); 720 q = READ_ONCE_CTRL(a);
718 ACCESS_ONCE(b) = p; 721 ACCESS_ONCE(b) = p;
719 do_something_else(); 722 do_something_else();
720 723
@@ -725,7 +728,7 @@ is gone, and the barrier won't bring it back. Therefore, if you are
725relying on this ordering, you should make sure that MAX is greater than 728relying on this ordering, you should make sure that MAX is greater than
726one, perhaps as follows: 729one, perhaps as follows:
727 730
728 q = ACCESS_ONCE(a); 731 q = READ_ONCE_CTRL(a);
729 BUILD_BUG_ON(MAX <= 1); /* Order load from a with store to b. */ 732 BUILD_BUG_ON(MAX <= 1); /* Order load from a with store to b. */
730 if (q % MAX) { 733 if (q % MAX) {
731 ACCESS_ONCE(b) = p; 734 ACCESS_ONCE(b) = p;
@@ -742,14 +745,15 @@ of the 'if' statement.
742You must also be careful not to rely too much on boolean short-circuit 745You must also be careful not to rely too much on boolean short-circuit
743evaluation. Consider this example: 746evaluation. Consider this example:
744 747
745 q = ACCESS_ONCE(a); 748 q = READ_ONCE_CTRL(a);
746 if (a || 1 > 0) 749 if (a || 1 > 0)
747 ACCESS_ONCE(b) = 1; 750 ACCESS_ONCE(b) = 1;
748 751
749Because the second condition is always true, the compiler can transform 752Because the first condition cannot fault and the second condition is
750this example as following, defeating control dependency: 753always true, the compiler can transform this example as following,
754defeating control dependency:
751 755
752 q = ACCESS_ONCE(a); 756 q = READ_ONCE_CTRL(a);
753 ACCESS_ONCE(b) = 1; 757 ACCESS_ONCE(b) = 1;
754 758
755This example underscores the need to ensure that the compiler cannot 759This example underscores the need to ensure that the compiler cannot
@@ -762,8 +766,8 @@ demonstrated by two related examples, with the initial values of
762x and y both being zero: 766x and y both being zero:
763 767
764 CPU 0 CPU 1 768 CPU 0 CPU 1
765 ===================== ===================== 769 ======================= =======================
766 r1 = ACCESS_ONCE(x); r2 = ACCESS_ONCE(y); 770 r1 = READ_ONCE_CTRL(x); r2 = READ_ONCE_CTRL(y);
767 if (r1 > 0) if (r2 > 0) 771 if (r1 > 0) if (r2 > 0)
768 ACCESS_ONCE(y) = 1; ACCESS_ONCE(x) = 1; 772 ACCESS_ONCE(y) = 1; ACCESS_ONCE(x) = 1;
769 773
@@ -783,7 +787,8 @@ But because control dependencies do -not- provide transitivity, the above
783assertion can fail after the combined three-CPU example completes. If you 787assertion can fail after the combined three-CPU example completes. If you
784need the three-CPU example to provide ordering, you will need smp_mb() 788need the three-CPU example to provide ordering, you will need smp_mb()
785between the loads and stores in the CPU 0 and CPU 1 code fragments, 789between the loads and stores in the CPU 0 and CPU 1 code fragments,
786that is, just before or just after the "if" statements. 790that is, just before or just after the "if" statements. Furthermore,
791the original two-CPU example is very fragile and should be avoided.
787 792
788These two examples are the LB and WWC litmus tests from this paper: 793These two examples are the LB and WWC litmus tests from this paper:
789http://www.cl.cam.ac.uk/users/pes20/ppc-supplemental/test6.pdf and this 794http://www.cl.cam.ac.uk/users/pes20/ppc-supplemental/test6.pdf and this
@@ -791,6 +796,12 @@ site: https://www.cl.cam.ac.uk/~pes20/ppcmem/index.html.
791 796
792In summary: 797In summary:
793 798
799 (*) Control dependencies must be headed by READ_ONCE_CTRL().
800 Or, as a much less preferable alternative, interpose
801 be headed by READ_ONCE() or an ACCESS_ONCE() read and must
802 have smp_read_barrier_depends() between this read and the
803 control-dependent write.
804
794 (*) Control dependencies can order prior loads against later stores. 805 (*) Control dependencies can order prior loads against later stores.
795 However, they do -not- guarantee any other sort of ordering: 806 However, they do -not- guarantee any other sort of ordering:
796 Not prior loads against later loads, nor prior stores against 807 Not prior loads against later loads, nor prior stores against
@@ -1784,10 +1795,9 @@ for each construct. These operations all imply certain barriers:
1784 1795
1785 Memory operations issued before the ACQUIRE may be completed after 1796 Memory operations issued before the ACQUIRE may be completed after
1786 the ACQUIRE operation has completed. An smp_mb__before_spinlock(), 1797 the ACQUIRE operation has completed. An smp_mb__before_spinlock(),
1787 combined with a following ACQUIRE, orders prior loads against 1798 combined with a following ACQUIRE, orders prior stores against
1788 subsequent loads and stores and also orders prior stores against 1799 subsequent loads and stores. Note that this is weaker than smp_mb()!
1789 subsequent stores. Note that this is weaker than smp_mb()! The 1800 The smp_mb__before_spinlock() primitive is free on many architectures.
1790 smp_mb__before_spinlock() primitive is free on many architectures.
1791 1801
1792 (2) RELEASE operation implication: 1802 (2) RELEASE operation implication:
1793 1803
diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
index a3bf5be111ff..1124f59b8df4 100644
--- a/arch/powerpc/include/asm/barrier.h
+++ b/arch/powerpc/include/asm/barrier.h
@@ -89,5 +89,6 @@ do { \
89 89
90#define smp_mb__before_atomic() smp_mb() 90#define smp_mb__before_atomic() smp_mb()
91#define smp_mb__after_atomic() smp_mb() 91#define smp_mb__after_atomic() smp_mb()
92#define smp_mb__before_spinlock() smp_mb()
92 93
93#endif /* _ASM_POWERPC_BARRIER_H */ 94#endif /* _ASM_POWERPC_BARRIER_H */
diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 20190bdac9d5..95cf78d44ab4 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -53,9 +53,12 @@
53static DEFINE_MUTEX(mce_chrdev_read_mutex); 53static DEFINE_MUTEX(mce_chrdev_read_mutex);
54 54
55#define rcu_dereference_check_mce(p) \ 55#define rcu_dereference_check_mce(p) \
56 rcu_dereference_index_check((p), \ 56({ \
57 rcu_read_lock_sched_held() || \ 57 rcu_lockdep_assert(rcu_read_lock_sched_held() || \
58 lockdep_is_held(&mce_chrdev_read_mutex)) 58 lockdep_is_held(&mce_chrdev_read_mutex), \
59 "suspicious rcu_dereference_check_mce() usage"); \
60 smp_load_acquire(&(p)); \
61})
59 62
60#define CREATE_TRACE_POINTS 63#define CREATE_TRACE_POINTS
61#include <trace/events/mce.h> 64#include <trace/events/mce.h>
@@ -1887,7 +1890,7 @@ out:
1887static unsigned int mce_chrdev_poll(struct file *file, poll_table *wait) 1890static unsigned int mce_chrdev_poll(struct file *file, poll_table *wait)
1888{ 1891{
1889 poll_wait(file, &mce_chrdev_wait, wait); 1892 poll_wait(file, &mce_chrdev_wait, wait);
1890 if (rcu_access_index(mcelog.next)) 1893 if (READ_ONCE(mcelog.next))
1891 return POLLIN | POLLRDNORM; 1894 return POLLIN | POLLRDNORM;
1892 if (!mce_apei_read_done && apei_check_mce()) 1895 if (!mce_apei_read_done && apei_check_mce())
1893 return POLLIN | POLLRDNORM; 1896 return POLLIN | POLLRDNORM;
@@ -1932,8 +1935,8 @@ void register_mce_write_callback(ssize_t (*fn)(struct file *filp,
1932} 1935}
1933EXPORT_SYMBOL_GPL(register_mce_write_callback); 1936EXPORT_SYMBOL_GPL(register_mce_write_callback);
1934 1937
1935ssize_t mce_chrdev_write(struct file *filp, const char __user *ubuf, 1938static ssize_t mce_chrdev_write(struct file *filp, const char __user *ubuf,
1936 size_t usize, loff_t *off) 1939 size_t usize, loff_t *off)
1937{ 1940{
1938 if (mce_write) 1941 if (mce_write)
1939 return mce_write(filp, ubuf, usize, off); 1942 return mce_write(filp, ubuf, usize, off);
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 867722591be2..5d66777914db 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -252,6 +252,22 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
252#define WRITE_ONCE(x, val) \ 252#define WRITE_ONCE(x, val) \
253 ({ typeof(x) __val = (val); __write_once_size(&(x), &__val, sizeof(__val)); __val; }) 253 ({ typeof(x) __val = (val); __write_once_size(&(x), &__val, sizeof(__val)); __val; })
254 254
255/**
256 * READ_ONCE_CTRL - Read a value heading a control dependency
257 * @x: The value to be read, heading the control dependency
258 *
259 * Control dependencies are tricky. See Documentation/memory-barriers.txt
260 * for important information on how to use them. Note that in many cases,
261 * use of smp_load_acquire() will be much simpler. Control dependencies
262 * should be avoided except on the hottest of hotpaths.
263 */
264#define READ_ONCE_CTRL(x) \
265({ \
266 typeof(x) __val = READ_ONCE(x); \
267 smp_read_barrier_depends(); /* Enforce control dependency. */ \
268 __val; \
269})
270
255#endif /* __KERNEL__ */ 271#endif /* __KERNEL__ */
256 272
257#endif /* __ASSEMBLY__ */ 273#endif /* __ASSEMBLY__ */
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index a18b16f1dc0e..17c6b1f84a77 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -29,8 +29,8 @@
29 */ 29 */
30static inline void INIT_LIST_HEAD_RCU(struct list_head *list) 30static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
31{ 31{
32 ACCESS_ONCE(list->next) = list; 32 WRITE_ONCE(list->next, list);
33 ACCESS_ONCE(list->prev) = list; 33 WRITE_ONCE(list->prev, list);
34} 34}
35 35
36/* 36/*
@@ -288,7 +288,7 @@ static inline void list_splice_init_rcu(struct list_head *list,
288#define list_first_or_null_rcu(ptr, type, member) \ 288#define list_first_or_null_rcu(ptr, type, member) \
289({ \ 289({ \
290 struct list_head *__ptr = (ptr); \ 290 struct list_head *__ptr = (ptr); \
291 struct list_head *__next = ACCESS_ONCE(__ptr->next); \ 291 struct list_head *__next = READ_ONCE(__ptr->next); \
292 likely(__ptr != __next) ? list_entry_rcu(__next, type, member) : NULL; \ 292 likely(__ptr != __next) ? list_entry_rcu(__next, type, member) : NULL; \
293}) 293})
294 294
@@ -549,8 +549,8 @@ static inline void hlist_add_behind_rcu(struct hlist_node *n,
549 */ 549 */
550#define hlist_for_each_entry_from_rcu(pos, member) \ 550#define hlist_for_each_entry_from_rcu(pos, member) \
551 for (; pos; \ 551 for (; pos; \
552 pos = hlist_entry_safe(rcu_dereference((pos)->member.next),\ 552 pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \
553 typeof(*(pos)), member)) 553 &(pos)->member)), typeof(*(pos)), member))
554 554
555#endif /* __KERNEL__ */ 555#endif /* __KERNEL__ */
556#endif 556#endif
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 573a5afd5ed8..03a899aabd17 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -292,10 +292,6 @@ void rcu_sched_qs(void);
292void rcu_bh_qs(void); 292void rcu_bh_qs(void);
293void rcu_check_callbacks(int user); 293void rcu_check_callbacks(int user);
294struct notifier_block; 294struct notifier_block;
295void rcu_idle_enter(void);
296void rcu_idle_exit(void);
297void rcu_irq_enter(void);
298void rcu_irq_exit(void);
299int rcu_cpu_notify(struct notifier_block *self, 295int rcu_cpu_notify(struct notifier_block *self,
300 unsigned long action, void *hcpu); 296 unsigned long action, void *hcpu);
301 297
@@ -364,8 +360,8 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
364#define rcu_note_voluntary_context_switch(t) \ 360#define rcu_note_voluntary_context_switch(t) \
365 do { \ 361 do { \
366 rcu_all_qs(); \ 362 rcu_all_qs(); \
367 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \ 363 if (READ_ONCE((t)->rcu_tasks_holdout)) \
368 ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \ 364 WRITE_ONCE((t)->rcu_tasks_holdout, false); \
369 } while (0) 365 } while (0)
370#else /* #ifdef CONFIG_TASKS_RCU */ 366#else /* #ifdef CONFIG_TASKS_RCU */
371#define TASKS_RCU(x) do { } while (0) 367#define TASKS_RCU(x) do { } while (0)
@@ -609,7 +605,7 @@ static inline void rcu_preempt_sleep_check(void)
609 605
610#define __rcu_access_pointer(p, space) \ 606#define __rcu_access_pointer(p, space) \
611({ \ 607({ \
612 typeof(*p) *_________p1 = (typeof(*p) *__force)ACCESS_ONCE(p); \ 608 typeof(*p) *_________p1 = (typeof(*p) *__force)READ_ONCE(p); \
613 rcu_dereference_sparse(p, space); \ 609 rcu_dereference_sparse(p, space); \
614 ((typeof(*p) __force __kernel *)(_________p1)); \ 610 ((typeof(*p) __force __kernel *)(_________p1)); \
615}) 611})
@@ -628,21 +624,6 @@ static inline void rcu_preempt_sleep_check(void)
628 ((typeof(*p) __force __kernel *)(p)); \ 624 ((typeof(*p) __force __kernel *)(p)); \
629}) 625})
630 626
631#define __rcu_access_index(p, space) \
632({ \
633 typeof(p) _________p1 = ACCESS_ONCE(p); \
634 rcu_dereference_sparse(p, space); \
635 (_________p1); \
636})
637#define __rcu_dereference_index_check(p, c) \
638({ \
639 /* Dependency order vs. p above. */ \
640 typeof(p) _________p1 = lockless_dereference(p); \
641 rcu_lockdep_assert(c, \
642 "suspicious rcu_dereference_index_check() usage"); \
643 (_________p1); \
644})
645
646/** 627/**
647 * RCU_INITIALIZER() - statically initialize an RCU-protected global variable 628 * RCU_INITIALIZER() - statically initialize an RCU-protected global variable
648 * @v: The value to statically initialize with. 629 * @v: The value to statically initialize with.
@@ -659,7 +640,7 @@ static inline void rcu_preempt_sleep_check(void)
659 */ 640 */
660#define lockless_dereference(p) \ 641#define lockless_dereference(p) \
661({ \ 642({ \
662 typeof(p) _________p1 = ACCESS_ONCE(p); \ 643 typeof(p) _________p1 = READ_ONCE(p); \
663 smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ 644 smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
664 (_________p1); \ 645 (_________p1); \
665}) 646})
@@ -702,7 +683,7 @@ static inline void rcu_preempt_sleep_check(void)
702 * @p: The pointer to read 683 * @p: The pointer to read
703 * 684 *
704 * Return the value of the specified RCU-protected pointer, but omit the 685 * Return the value of the specified RCU-protected pointer, but omit the
705 * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful 686 * smp_read_barrier_depends() and keep the READ_ONCE(). This is useful
706 * when the value of this pointer is accessed, but the pointer is not 687 * when the value of this pointer is accessed, but the pointer is not
707 * dereferenced, for example, when testing an RCU-protected pointer against 688 * dereferenced, for example, when testing an RCU-protected pointer against
708 * NULL. Although rcu_access_pointer() may also be used in cases where 689 * NULL. Although rcu_access_pointer() may also be used in cases where
@@ -787,47 +768,12 @@ static inline void rcu_preempt_sleep_check(void)
787#define rcu_dereference_raw_notrace(p) __rcu_dereference_check((p), 1, __rcu) 768#define rcu_dereference_raw_notrace(p) __rcu_dereference_check((p), 1, __rcu)
788 769
789/** 770/**
790 * rcu_access_index() - fetch RCU index with no dereferencing
791 * @p: The index to read
792 *
793 * Return the value of the specified RCU-protected index, but omit the
794 * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful
795 * when the value of this index is accessed, but the index is not
796 * dereferenced, for example, when testing an RCU-protected index against
797 * -1. Although rcu_access_index() may also be used in cases where
798 * update-side locks prevent the value of the index from changing, you
799 * should instead use rcu_dereference_index_protected() for this use case.
800 */
801#define rcu_access_index(p) __rcu_access_index((p), __rcu)
802
803/**
804 * rcu_dereference_index_check() - rcu_dereference for indices with debug checking
805 * @p: The pointer to read, prior to dereferencing
806 * @c: The conditions under which the dereference will take place
807 *
808 * Similar to rcu_dereference_check(), but omits the sparse checking.
809 * This allows rcu_dereference_index_check() to be used on integers,
810 * which can then be used as array indices. Attempting to use
811 * rcu_dereference_check() on an integer will give compiler warnings
812 * because the sparse address-space mechanism relies on dereferencing
813 * the RCU-protected pointer. Dereferencing integers is not something
814 * that even gcc will put up with.
815 *
816 * Note that this function does not implicitly check for RCU read-side
817 * critical sections. If this function gains lots of uses, it might
818 * make sense to provide versions for each flavor of RCU, but it does
819 * not make sense as of early 2010.
820 */
821#define rcu_dereference_index_check(p, c) \
822 __rcu_dereference_index_check((p), (c))
823
824/**
825 * rcu_dereference_protected() - fetch RCU pointer when updates prevented 771 * rcu_dereference_protected() - fetch RCU pointer when updates prevented
826 * @p: The pointer to read, prior to dereferencing 772 * @p: The pointer to read, prior to dereferencing
827 * @c: The conditions under which the dereference will take place 773 * @c: The conditions under which the dereference will take place
828 * 774 *
829 * Return the value of the specified RCU-protected pointer, but omit 775 * Return the value of the specified RCU-protected pointer, but omit
830 * both the smp_read_barrier_depends() and the ACCESS_ONCE(). This 776 * both the smp_read_barrier_depends() and the READ_ONCE(). This
831 * is useful in cases where update-side locks prevent the value of the 777 * is useful in cases where update-side locks prevent the value of the
832 * pointer from changing. Please note that this primitive does -not- 778 * pointer from changing. Please note that this primitive does -not-
833 * prevent the compiler from repeating this reference or combining it 779 * prevent the compiler from repeating this reference or combining it
@@ -1153,13 +1099,13 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
1153#define kfree_rcu(ptr, rcu_head) \ 1099#define kfree_rcu(ptr, rcu_head) \
1154 __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) 1100 __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
1155 1101
1156#if defined(CONFIG_TINY_RCU) || defined(CONFIG_RCU_NOCB_CPU_ALL) 1102#ifdef CONFIG_TINY_RCU
1157static inline int rcu_needs_cpu(unsigned long *delta_jiffies) 1103static inline int rcu_needs_cpu(unsigned long *delta_jiffies)
1158{ 1104{
1159 *delta_jiffies = ULONG_MAX; 1105 *delta_jiffies = ULONG_MAX;
1160 return 0; 1106 return 0;
1161} 1107}
1162#endif /* #if defined(CONFIG_TINY_RCU) || defined(CONFIG_RCU_NOCB_CPU_ALL) */ 1108#endif /* #ifdef CONFIG_TINY_RCU */
1163 1109
1164#if defined(CONFIG_RCU_NOCB_CPU_ALL) 1110#if defined(CONFIG_RCU_NOCB_CPU_ALL)
1165static inline bool rcu_is_nocb_cpu(int cpu) { return true; } 1111static inline bool rcu_is_nocb_cpu(int cpu) { return true; }
diff --git a/include/linux/rcutiny.h b/include/linux/rcutiny.h
index 937edaeb150d..3df6c1ec4e25 100644
--- a/include/linux/rcutiny.h
+++ b/include/linux/rcutiny.h
@@ -159,6 +159,22 @@ static inline void rcu_cpu_stall_reset(void)
159{ 159{
160} 160}
161 161
162static inline void rcu_idle_enter(void)
163{
164}
165
166static inline void rcu_idle_exit(void)
167{
168}
169
170static inline void rcu_irq_enter(void)
171{
172}
173
174static inline void rcu_irq_exit(void)
175{
176}
177
162static inline void exit_rcu(void) 178static inline void exit_rcu(void)
163{ 179{
164} 180}
diff --git a/include/linux/rcutree.h b/include/linux/rcutree.h
index d2e583a6aaca..3fa4a43ab415 100644
--- a/include/linux/rcutree.h
+++ b/include/linux/rcutree.h
@@ -31,9 +31,7 @@
31#define __LINUX_RCUTREE_H 31#define __LINUX_RCUTREE_H
32 32
33void rcu_note_context_switch(void); 33void rcu_note_context_switch(void);
34#ifndef CONFIG_RCU_NOCB_CPU_ALL
35int rcu_needs_cpu(unsigned long *delta_jiffies); 34int rcu_needs_cpu(unsigned long *delta_jiffies);
36#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
37void rcu_cpu_stall_reset(void); 35void rcu_cpu_stall_reset(void);
38 36
39/* 37/*
@@ -93,6 +91,11 @@ void rcu_force_quiescent_state(void);
93void rcu_bh_force_quiescent_state(void); 91void rcu_bh_force_quiescent_state(void);
94void rcu_sched_force_quiescent_state(void); 92void rcu_sched_force_quiescent_state(void);
95 93
94void rcu_idle_enter(void);
95void rcu_idle_exit(void);
96void rcu_irq_enter(void);
97void rcu_irq_exit(void);
98
96void exit_rcu(void); 99void exit_rcu(void);
97 100
98void rcu_scheduler_starting(void); 101void rcu_scheduler_starting(void);
diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index 3e18379dfa6f..0063b24b4f36 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -120,7 +120,7 @@ do { \
120/* 120/*
121 * Despite its name it doesn't necessarily has to be a full barrier. 121 * Despite its name it doesn't necessarily has to be a full barrier.
122 * It should only guarantee that a STORE before the critical section 122 * It should only guarantee that a STORE before the critical section
123 * can not be reordered with a LOAD inside this section. 123 * can not be reordered with LOADs and STOREs inside this section.
124 * spin_lock() is the one-way barrier, this LOAD can not escape out 124 * spin_lock() is the one-way barrier, this LOAD can not escape out
125 * of the region. So the default implementation simply ensures that 125 * of the region. So the default implementation simply ensures that
126 * a STORE can not move into the critical section, smp_wmb() should 126 * a STORE can not move into the critical section, smp_wmb() should
diff --git a/init/Kconfig b/init/Kconfig
index dc24dec60232..4c08197044f1 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -465,13 +465,9 @@ endmenu # "CPU/Task time and stats accounting"
465 465
466menu "RCU Subsystem" 466menu "RCU Subsystem"
467 467
468choice
469 prompt "RCU Implementation"
470 default TREE_RCU
471
472config TREE_RCU 468config TREE_RCU
473 bool "Tree-based hierarchical RCU" 469 bool
474 depends on !PREEMPT && SMP 470 default y if !PREEMPT && SMP
475 help 471 help
476 This option selects the RCU implementation that is 472 This option selects the RCU implementation that is
477 designed for very large SMP system with hundreds or 473 designed for very large SMP system with hundreds or
@@ -479,8 +475,8 @@ config TREE_RCU
479 smaller systems. 475 smaller systems.
480 476
481config PREEMPT_RCU 477config PREEMPT_RCU
482 bool "Preemptible tree-based hierarchical RCU" 478 bool
483 depends on PREEMPT 479 default y if PREEMPT
484 help 480 help
485 This option selects the RCU implementation that is 481 This option selects the RCU implementation that is
486 designed for very large SMP systems with hundreds or 482 designed for very large SMP systems with hundreds or
@@ -491,15 +487,28 @@ config PREEMPT_RCU
491 Select this option if you are unsure. 487 Select this option if you are unsure.
492 488
493config TINY_RCU 489config TINY_RCU
494 bool "UP-only small-memory-footprint RCU" 490 bool
495 depends on !PREEMPT && !SMP 491 default y if !PREEMPT && !SMP
496 help 492 help
497 This option selects the RCU implementation that is 493 This option selects the RCU implementation that is
498 designed for UP systems from which real-time response 494 designed for UP systems from which real-time response
499 is not required. This option greatly reduces the 495 is not required. This option greatly reduces the
500 memory footprint of RCU. 496 memory footprint of RCU.
501 497
502endchoice 498config RCU_EXPERT
499 bool "Make expert-level adjustments to RCU configuration"
500 default n
501 help
502 This option needs to be enabled if you wish to make
503 expert-level adjustments to RCU configuration. By default,
504 no such adjustments can be made, which has the often-beneficial
505 side-effect of preventing "make oldconfig" from asking you all
506 sorts of detailed questions about how you would like numerous
507 obscure RCU options to be set up.
508
509 Say Y if you need to make expert-level adjustments to RCU.
510
511 Say N if you are unsure.
503 512
504config SRCU 513config SRCU
505 bool 514 bool
@@ -509,7 +518,7 @@ config SRCU
509 sections. 518 sections.
510 519
511config TASKS_RCU 520config TASKS_RCU
512 bool "Task_based RCU implementation using voluntary context switch" 521 bool
513 default n 522 default n
514 select SRCU 523 select SRCU
515 help 524 help
@@ -517,8 +526,6 @@ config TASKS_RCU
517 only voluntary context switch (not preemption!), idle, and 526 only voluntary context switch (not preemption!), idle, and
518 user-mode execution as quiescent states. 527 user-mode execution as quiescent states.
519 528
520 If unsure, say N.
521
522config RCU_STALL_COMMON 529config RCU_STALL_COMMON
523 def_bool ( TREE_RCU || PREEMPT_RCU || RCU_TRACE ) 530 def_bool ( TREE_RCU || PREEMPT_RCU || RCU_TRACE )
524 help 531 help
@@ -531,9 +538,7 @@ config CONTEXT_TRACKING
531 bool 538 bool
532 539
533config RCU_USER_QS 540config RCU_USER_QS
534 bool "Consider userspace as in RCU extended quiescent state" 541 bool
535 depends on HAVE_CONTEXT_TRACKING && SMP
536 select CONTEXT_TRACKING
537 help 542 help
538 This option sets hooks on kernel / userspace boundaries and 543 This option sets hooks on kernel / userspace boundaries and
539 puts RCU in extended quiescent state when the CPU runs in 544 puts RCU in extended quiescent state when the CPU runs in
@@ -541,12 +546,6 @@ config RCU_USER_QS
541 excluded from the global RCU state machine and thus doesn't 546 excluded from the global RCU state machine and thus doesn't
542 try to keep the timer tick on for RCU. 547 try to keep the timer tick on for RCU.
543 548
544 Unless you want to hack and help the development of the full
545 dynticks mode, you shouldn't enable this option. It also
546 adds unnecessary overhead.
547
548 If unsure say N
549
550config CONTEXT_TRACKING_FORCE 549config CONTEXT_TRACKING_FORCE
551 bool "Force context tracking" 550 bool "Force context tracking"
552 depends on CONTEXT_TRACKING 551 depends on CONTEXT_TRACKING
@@ -578,7 +577,7 @@ config RCU_FANOUT
578 int "Tree-based hierarchical RCU fanout value" 577 int "Tree-based hierarchical RCU fanout value"
579 range 2 64 if 64BIT 578 range 2 64 if 64BIT
580 range 2 32 if !64BIT 579 range 2 32 if !64BIT
581 depends on TREE_RCU || PREEMPT_RCU 580 depends on (TREE_RCU || PREEMPT_RCU) && RCU_EXPERT
582 default 64 if 64BIT 581 default 64 if 64BIT
583 default 32 if !64BIT 582 default 32 if !64BIT
584 help 583 help
@@ -596,9 +595,9 @@ config RCU_FANOUT
596 595
597config RCU_FANOUT_LEAF 596config RCU_FANOUT_LEAF
598 int "Tree-based hierarchical RCU leaf-level fanout value" 597 int "Tree-based hierarchical RCU leaf-level fanout value"
599 range 2 RCU_FANOUT if 64BIT 598 range 2 64 if 64BIT
600 range 2 RCU_FANOUT if !64BIT 599 range 2 32 if !64BIT
601 depends on TREE_RCU || PREEMPT_RCU 600 depends on (TREE_RCU || PREEMPT_RCU) && RCU_EXPERT
602 default 16 601 default 16
603 help 602 help
604 This option controls the leaf-level fanout of hierarchical 603 This option controls the leaf-level fanout of hierarchical
@@ -621,23 +620,9 @@ config RCU_FANOUT_LEAF
621 620
622 Take the default if unsure. 621 Take the default if unsure.
623 622
624config RCU_FANOUT_EXACT
625 bool "Disable tree-based hierarchical RCU auto-balancing"
626 depends on TREE_RCU || PREEMPT_RCU
627 default n
628 help
629 This option forces use of the exact RCU_FANOUT value specified,
630 regardless of imbalances in the hierarchy. This is useful for
631 testing RCU itself, and might one day be useful on systems with
632 strong NUMA behavior.
633
634 Without RCU_FANOUT_EXACT, the code will balance the hierarchy.
635
636 Say N if unsure.
637
638config RCU_FAST_NO_HZ 623config RCU_FAST_NO_HZ
639 bool "Accelerate last non-dyntick-idle CPU's grace periods" 624 bool "Accelerate last non-dyntick-idle CPU's grace periods"
640 depends on NO_HZ_COMMON && SMP 625 depends on NO_HZ_COMMON && SMP && RCU_EXPERT
641 default n 626 default n
642 help 627 help
643 This option permits CPUs to enter dynticks-idle state even if 628 This option permits CPUs to enter dynticks-idle state even if
@@ -663,7 +648,7 @@ config TREE_RCU_TRACE
663 648
664config RCU_BOOST 649config RCU_BOOST
665 bool "Enable RCU priority boosting" 650 bool "Enable RCU priority boosting"
666 depends on RT_MUTEXES && PREEMPT_RCU 651 depends on RT_MUTEXES && PREEMPT_RCU && RCU_EXPERT
667 default n 652 default n
668 help 653 help
669 This option boosts the priority of preempted RCU readers that 654 This option boosts the priority of preempted RCU readers that
@@ -680,6 +665,7 @@ config RCU_KTHREAD_PRIO
680 range 0 99 if !RCU_BOOST 665 range 0 99 if !RCU_BOOST
681 default 1 if RCU_BOOST 666 default 1 if RCU_BOOST
682 default 0 if !RCU_BOOST 667 default 0 if !RCU_BOOST
668 depends on RCU_EXPERT
683 help 669 help
684 This option specifies the SCHED_FIFO priority value that will be 670 This option specifies the SCHED_FIFO priority value that will be
685 assigned to the rcuc/n and rcub/n threads and is also the value 671 assigned to the rcuc/n and rcub/n threads and is also the value
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 94bbe4695232..9c9c9fab16cc 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -398,7 +398,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
398 err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu)); 398 err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu));
399 if (err) { 399 if (err) {
400 /* CPU didn't die: tell everyone. Can't complain. */ 400 /* CPU didn't die: tell everyone. Can't complain. */
401 smpboot_unpark_threads(cpu);
402 cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu); 401 cpu_notify_nofail(CPU_DOWN_FAILED | mod, hcpu);
403 goto out_release; 402 goto out_release;
404 } 403 }
@@ -463,6 +462,7 @@ static int smpboot_thread_call(struct notifier_block *nfb,
463 462
464 switch (action & ~CPU_TASKS_FROZEN) { 463 switch (action & ~CPU_TASKS_FROZEN) {
465 464
465 case CPU_DOWN_FAILED:
466 case CPU_ONLINE: 466 case CPU_ONLINE:
467 smpboot_unpark_threads(cpu); 467 smpboot_unpark_threads(cpu);
468 break; 468 break;
@@ -479,7 +479,7 @@ static struct notifier_block smpboot_thread_notifier = {
479 .priority = CPU_PRI_SMPBOOT, 479 .priority = CPU_PRI_SMPBOOT,
480}; 480};
481 481
482void __cpuinit smpboot_thread_init(void) 482void smpboot_thread_init(void)
483{ 483{
484 register_cpu_notifier(&smpboot_thread_notifier); 484 register_cpu_notifier(&smpboot_thread_notifier);
485} 485}
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 725c416085e3..96472824a752 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -141,7 +141,7 @@ int perf_output_begin(struct perf_output_handle *handle,
141 perf_output_get_handle(handle); 141 perf_output_get_handle(handle);
142 142
143 do { 143 do {
144 tail = ACCESS_ONCE(rb->user_page->data_tail); 144 tail = READ_ONCE_CTRL(rb->user_page->data_tail);
145 offset = head = local_read(&rb->head); 145 offset = head = local_read(&rb->head);
146 if (!rb->overwrite && 146 if (!rb->overwrite &&
147 unlikely(CIRC_SPACE(head, tail, perf_data_size(rb)) < size)) 147 unlikely(CIRC_SPACE(head, tail, perf_data_size(rb)) < size))
diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index ec8cce259779..32244186f1f2 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -122,12 +122,12 @@ static int torture_lock_busted_write_lock(void)
122 122
123static void torture_lock_busted_write_delay(struct torture_random_state *trsp) 123static void torture_lock_busted_write_delay(struct torture_random_state *trsp)
124{ 124{
125 const unsigned long longdelay_us = 100; 125 const unsigned long longdelay_ms = 100;
126 126
127 /* We want a long delay occasionally to force massive contention. */ 127 /* We want a long delay occasionally to force massive contention. */
128 if (!(torture_random(trsp) % 128 if (!(torture_random(trsp) %
129 (cxt.nrealwriters_stress * 2000 * longdelay_us))) 129 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
130 mdelay(longdelay_us); 130 mdelay(longdelay_ms);
131#ifdef CONFIG_PREEMPT 131#ifdef CONFIG_PREEMPT
132 if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000))) 132 if (!(torture_random(trsp) % (cxt.nrealwriters_stress * 20000)))
133 preempt_schedule(); /* Allow test to be preempted. */ 133 preempt_schedule(); /* Allow test to be preempted. */
@@ -160,14 +160,14 @@ static int torture_spin_lock_write_lock(void) __acquires(torture_spinlock)
160static void torture_spin_lock_write_delay(struct torture_random_state *trsp) 160static void torture_spin_lock_write_delay(struct torture_random_state *trsp)
161{ 161{
162 const unsigned long shortdelay_us = 2; 162 const unsigned long shortdelay_us = 2;
163 const unsigned long longdelay_us = 100; 163 const unsigned long longdelay_ms = 100;
164 164
165 /* We want a short delay mostly to emulate likely code, and 165 /* We want a short delay mostly to emulate likely code, and
166 * we want a long delay occasionally to force massive contention. 166 * we want a long delay occasionally to force massive contention.
167 */ 167 */
168 if (!(torture_random(trsp) % 168 if (!(torture_random(trsp) %
169 (cxt.nrealwriters_stress * 2000 * longdelay_us))) 169 (cxt.nrealwriters_stress * 2000 * longdelay_ms)))
170 mdelay(longdelay_us); 170 mdelay(longdelay_ms);
171 if (!(torture_random(trsp) % 171 if (!(torture_random(trsp) %
172 (cxt.nrealwriters_stress * 2 * shortdelay_us))) 172 (cxt.nrealwriters_stress * 2 * shortdelay_us)))
173 udelay(shortdelay_us); 173 udelay(shortdelay_us);
@@ -309,7 +309,7 @@ static int torture_rwlock_read_lock_irq(void) __acquires(torture_rwlock)
309static void torture_rwlock_read_unlock_irq(void) 309static void torture_rwlock_read_unlock_irq(void)
310__releases(torture_rwlock) 310__releases(torture_rwlock)
311{ 311{
312 write_unlock_irqrestore(&torture_rwlock, cxt.cur_ops->flags); 312 read_unlock_irqrestore(&torture_rwlock, cxt.cur_ops->flags);
313} 313}
314 314
315static struct lock_torture_ops rw_lock_irq_ops = { 315static struct lock_torture_ops rw_lock_irq_ops = {
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 8dbe27611ec3..59e32684c23b 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -241,6 +241,7 @@ rcu_torture_free(struct rcu_torture *p)
241struct rcu_torture_ops { 241struct rcu_torture_ops {
242 int ttype; 242 int ttype;
243 void (*init)(void); 243 void (*init)(void);
244 void (*cleanup)(void);
244 int (*readlock)(void); 245 int (*readlock)(void);
245 void (*read_delay)(struct torture_random_state *rrsp); 246 void (*read_delay)(struct torture_random_state *rrsp);
246 void (*readunlock)(int idx); 247 void (*readunlock)(int idx);
@@ -477,10 +478,12 @@ static struct rcu_torture_ops rcu_busted_ops = {
477 */ 478 */
478 479
479DEFINE_STATIC_SRCU(srcu_ctl); 480DEFINE_STATIC_SRCU(srcu_ctl);
481static struct srcu_struct srcu_ctld;
482static struct srcu_struct *srcu_ctlp = &srcu_ctl;
480 483
481static int srcu_torture_read_lock(void) __acquires(&srcu_ctl) 484static int srcu_torture_read_lock(void) __acquires(srcu_ctlp)
482{ 485{
483 return srcu_read_lock(&srcu_ctl); 486 return srcu_read_lock(srcu_ctlp);
484} 487}
485 488
486static void srcu_read_delay(struct torture_random_state *rrsp) 489static void srcu_read_delay(struct torture_random_state *rrsp)
@@ -499,49 +502,49 @@ static void srcu_read_delay(struct torture_random_state *rrsp)
499 rcu_read_delay(rrsp); 502 rcu_read_delay(rrsp);
500} 503}
501 504
502static void srcu_torture_read_unlock(int idx) __releases(&srcu_ctl) 505static void srcu_torture_read_unlock(int idx) __releases(srcu_ctlp)
503{ 506{
504 srcu_read_unlock(&srcu_ctl, idx); 507 srcu_read_unlock(srcu_ctlp, idx);
505} 508}
506 509
507static unsigned long srcu_torture_completed(void) 510static unsigned long srcu_torture_completed(void)
508{ 511{
509 return srcu_batches_completed(&srcu_ctl); 512 return srcu_batches_completed(srcu_ctlp);
510} 513}
511 514
512static void srcu_torture_deferred_free(struct rcu_torture *rp) 515static void srcu_torture_deferred_free(struct rcu_torture *rp)
513{ 516{
514 call_srcu(&srcu_ctl, &rp->rtort_rcu, rcu_torture_cb); 517 call_srcu(srcu_ctlp, &rp->rtort_rcu, rcu_torture_cb);
515} 518}
516 519
517static void srcu_torture_synchronize(void) 520static void srcu_torture_synchronize(void)
518{ 521{
519 synchronize_srcu(&srcu_ctl); 522 synchronize_srcu(srcu_ctlp);
520} 523}
521 524
522static void srcu_torture_call(struct rcu_head *head, 525static void srcu_torture_call(struct rcu_head *head,
523 void (*func)(struct rcu_head *head)) 526 void (*func)(struct rcu_head *head))
524{ 527{
525 call_srcu(&srcu_ctl, head, func); 528 call_srcu(srcu_ctlp, head, func);
526} 529}
527 530
528static void srcu_torture_barrier(void) 531static void srcu_torture_barrier(void)
529{ 532{
530 srcu_barrier(&srcu_ctl); 533 srcu_barrier(srcu_ctlp);
531} 534}
532 535
533static void srcu_torture_stats(void) 536static void srcu_torture_stats(void)
534{ 537{
535 int cpu; 538 int cpu;
536 int idx = srcu_ctl.completed & 0x1; 539 int idx = srcu_ctlp->completed & 0x1;
537 540
538 pr_alert("%s%s per-CPU(idx=%d):", 541 pr_alert("%s%s per-CPU(idx=%d):",
539 torture_type, TORTURE_FLAG, idx); 542 torture_type, TORTURE_FLAG, idx);
540 for_each_possible_cpu(cpu) { 543 for_each_possible_cpu(cpu) {
541 long c0, c1; 544 long c0, c1;
542 545
543 c0 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx]; 546 c0 = (long)per_cpu_ptr(srcu_ctlp->per_cpu_ref, cpu)->c[!idx];
544 c1 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]; 547 c1 = (long)per_cpu_ptr(srcu_ctlp->per_cpu_ref, cpu)->c[idx];
545 pr_cont(" %d(%ld,%ld)", cpu, c0, c1); 548 pr_cont(" %d(%ld,%ld)", cpu, c0, c1);
546 } 549 }
547 pr_cont("\n"); 550 pr_cont("\n");
@@ -549,7 +552,7 @@ static void srcu_torture_stats(void)
549 552
550static void srcu_torture_synchronize_expedited(void) 553static void srcu_torture_synchronize_expedited(void)
551{ 554{
552 synchronize_srcu_expedited(&srcu_ctl); 555 synchronize_srcu_expedited(srcu_ctlp);
553} 556}
554 557
555static struct rcu_torture_ops srcu_ops = { 558static struct rcu_torture_ops srcu_ops = {
@@ -569,6 +572,38 @@ static struct rcu_torture_ops srcu_ops = {
569 .name = "srcu" 572 .name = "srcu"
570}; 573};
571 574
575static void srcu_torture_init(void)
576{
577 rcu_sync_torture_init();
578 WARN_ON(init_srcu_struct(&srcu_ctld));
579 srcu_ctlp = &srcu_ctld;
580}
581
582static void srcu_torture_cleanup(void)
583{
584 cleanup_srcu_struct(&srcu_ctld);
585 srcu_ctlp = &srcu_ctl; /* In case of a later rcutorture run. */
586}
587
588/* As above, but dynamically allocated. */
589static struct rcu_torture_ops srcud_ops = {
590 .ttype = SRCU_FLAVOR,
591 .init = srcu_torture_init,
592 .cleanup = srcu_torture_cleanup,
593 .readlock = srcu_torture_read_lock,
594 .read_delay = srcu_read_delay,
595 .readunlock = srcu_torture_read_unlock,
596 .started = NULL,
597 .completed = srcu_torture_completed,
598 .deferred_free = srcu_torture_deferred_free,
599 .sync = srcu_torture_synchronize,
600 .exp_sync = srcu_torture_synchronize_expedited,
601 .call = srcu_torture_call,
602 .cb_barrier = srcu_torture_barrier,
603 .stats = srcu_torture_stats,
604 .name = "srcud"
605};
606
572/* 607/*
573 * Definitions for sched torture testing. 608 * Definitions for sched torture testing.
574 */ 609 */
@@ -672,8 +707,8 @@ static void rcu_torture_boost_cb(struct rcu_head *head)
672 struct rcu_boost_inflight *rbip = 707 struct rcu_boost_inflight *rbip =
673 container_of(head, struct rcu_boost_inflight, rcu); 708 container_of(head, struct rcu_boost_inflight, rcu);
674 709
675 smp_mb(); /* Ensure RCU-core accesses precede clearing ->inflight */ 710 /* Ensure RCU-core accesses precede clearing ->inflight */
676 rbip->inflight = 0; 711 smp_store_release(&rbip->inflight, 0);
677} 712}
678 713
679static int rcu_torture_boost(void *arg) 714static int rcu_torture_boost(void *arg)
@@ -710,9 +745,9 @@ static int rcu_torture_boost(void *arg)
710 call_rcu_time = jiffies; 745 call_rcu_time = jiffies;
711 while (ULONG_CMP_LT(jiffies, endtime)) { 746 while (ULONG_CMP_LT(jiffies, endtime)) {
712 /* If we don't have a callback in flight, post one. */ 747 /* If we don't have a callback in flight, post one. */
713 if (!rbi.inflight) { 748 if (!smp_load_acquire(&rbi.inflight)) {
714 smp_mb(); /* RCU core before ->inflight = 1. */ 749 /* RCU core before ->inflight = 1. */
715 rbi.inflight = 1; 750 smp_store_release(&rbi.inflight, 1);
716 call_rcu(&rbi.rcu, rcu_torture_boost_cb); 751 call_rcu(&rbi.rcu, rcu_torture_boost_cb);
717 if (jiffies - call_rcu_time > 752 if (jiffies - call_rcu_time >
718 test_boost_duration * HZ - HZ / 2) { 753 test_boost_duration * HZ - HZ / 2) {
@@ -751,11 +786,10 @@ checkwait: stutter_wait("rcu_torture_boost");
751 } while (!torture_must_stop()); 786 } while (!torture_must_stop());
752 787
753 /* Clean up and exit. */ 788 /* Clean up and exit. */
754 while (!kthread_should_stop() || rbi.inflight) { 789 while (!kthread_should_stop() || smp_load_acquire(&rbi.inflight)) {
755 torture_shutdown_absorb("rcu_torture_boost"); 790 torture_shutdown_absorb("rcu_torture_boost");
756 schedule_timeout_uninterruptible(1); 791 schedule_timeout_uninterruptible(1);
757 } 792 }
758 smp_mb(); /* order accesses to ->inflight before stack-frame death. */
759 destroy_rcu_head_on_stack(&rbi.rcu); 793 destroy_rcu_head_on_stack(&rbi.rcu);
760 torture_kthread_stopping("rcu_torture_boost"); 794 torture_kthread_stopping("rcu_torture_boost");
761 return 0; 795 return 0;
@@ -1054,7 +1088,7 @@ static void rcu_torture_timer(unsigned long unused)
1054 p = rcu_dereference_check(rcu_torture_current, 1088 p = rcu_dereference_check(rcu_torture_current,
1055 rcu_read_lock_bh_held() || 1089 rcu_read_lock_bh_held() ||
1056 rcu_read_lock_sched_held() || 1090 rcu_read_lock_sched_held() ||
1057 srcu_read_lock_held(&srcu_ctl)); 1091 srcu_read_lock_held(srcu_ctlp));
1058 if (p == NULL) { 1092 if (p == NULL) {
1059 /* Leave because rcu_torture_writer is not yet underway */ 1093 /* Leave because rcu_torture_writer is not yet underway */
1060 cur_ops->readunlock(idx); 1094 cur_ops->readunlock(idx);
@@ -1128,7 +1162,7 @@ rcu_torture_reader(void *arg)
1128 p = rcu_dereference_check(rcu_torture_current, 1162 p = rcu_dereference_check(rcu_torture_current,
1129 rcu_read_lock_bh_held() || 1163 rcu_read_lock_bh_held() ||
1130 rcu_read_lock_sched_held() || 1164 rcu_read_lock_sched_held() ||
1131 srcu_read_lock_held(&srcu_ctl)); 1165 srcu_read_lock_held(srcu_ctlp));
1132 if (p == NULL) { 1166 if (p == NULL) {
1133 /* Wait for rcu_torture_writer to get underway */ 1167 /* Wait for rcu_torture_writer to get underway */
1134 cur_ops->readunlock(idx); 1168 cur_ops->readunlock(idx);
@@ -1413,12 +1447,15 @@ static int rcu_torture_barrier_cbs(void *arg)
1413 do { 1447 do {
1414 wait_event(barrier_cbs_wq[myid], 1448 wait_event(barrier_cbs_wq[myid],
1415 (newphase = 1449 (newphase =
1416 ACCESS_ONCE(barrier_phase)) != lastphase || 1450 smp_load_acquire(&barrier_phase)) != lastphase ||
1417 torture_must_stop()); 1451 torture_must_stop());
1418 lastphase = newphase; 1452 lastphase = newphase;
1419 smp_mb(); /* ensure barrier_phase load before ->call(). */
1420 if (torture_must_stop()) 1453 if (torture_must_stop())
1421 break; 1454 break;
1455 /*
1456 * The above smp_load_acquire() ensures barrier_phase load
1457 * is ordered before the folloiwng ->call().
1458 */
1422 cur_ops->call(&rcu, rcu_torture_barrier_cbf); 1459 cur_ops->call(&rcu, rcu_torture_barrier_cbf);
1423 if (atomic_dec_and_test(&barrier_cbs_count)) 1460 if (atomic_dec_and_test(&barrier_cbs_count))
1424 wake_up(&barrier_wq); 1461 wake_up(&barrier_wq);
@@ -1439,8 +1476,8 @@ static int rcu_torture_barrier(void *arg)
1439 do { 1476 do {
1440 atomic_set(&barrier_cbs_invoked, 0); 1477 atomic_set(&barrier_cbs_invoked, 0);
1441 atomic_set(&barrier_cbs_count, n_barrier_cbs); 1478 atomic_set(&barrier_cbs_count, n_barrier_cbs);
1442 smp_mb(); /* Ensure barrier_phase after prior assignments. */ 1479 /* Ensure barrier_phase ordered after prior assignments. */
1443 barrier_phase = !barrier_phase; 1480 smp_store_release(&barrier_phase, !barrier_phase);
1444 for (i = 0; i < n_barrier_cbs; i++) 1481 for (i = 0; i < n_barrier_cbs; i++)
1445 wake_up(&barrier_cbs_wq[i]); 1482 wake_up(&barrier_cbs_wq[i]);
1446 wait_event(barrier_wq, 1483 wait_event(barrier_wq,
@@ -1588,10 +1625,14 @@ rcu_torture_cleanup(void)
1588 rcutorture_booster_cleanup(i); 1625 rcutorture_booster_cleanup(i);
1589 } 1626 }
1590 1627
1591 /* Wait for all RCU callbacks to fire. */ 1628 /*
1592 1629 * Wait for all RCU callbacks to fire, then do flavor-specific
1630 * cleanup operations.
1631 */
1593 if (cur_ops->cb_barrier != NULL) 1632 if (cur_ops->cb_barrier != NULL)
1594 cur_ops->cb_barrier(); 1633 cur_ops->cb_barrier();
1634 if (cur_ops->cleanup != NULL)
1635 cur_ops->cleanup();
1595 1636
1596 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */ 1637 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
1597 1638
@@ -1668,8 +1709,8 @@ rcu_torture_init(void)
1668 int cpu; 1709 int cpu;
1669 int firsterr = 0; 1710 int firsterr = 0;
1670 static struct rcu_torture_ops *torture_ops[] = { 1711 static struct rcu_torture_ops *torture_ops[] = {
1671 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &sched_ops, 1712 &rcu_ops, &rcu_bh_ops, &rcu_busted_ops, &srcu_ops, &srcud_ops,
1672 RCUTORTURE_TASKS_OPS 1713 &sched_ops, RCUTORTURE_TASKS_OPS
1673 }; 1714 };
1674 1715
1675 if (!torture_init_begin(torture_type, verbose, &torture_runnable)) 1716 if (!torture_init_begin(torture_type, verbose, &torture_runnable))
@@ -1701,7 +1742,7 @@ rcu_torture_init(void)
1701 if (nreaders >= 0) { 1742 if (nreaders >= 0) {
1702 nrealreaders = nreaders; 1743 nrealreaders = nreaders;
1703 } else { 1744 } else {
1704 nrealreaders = num_online_cpus() - 1; 1745 nrealreaders = num_online_cpus() - 2 - nreaders;
1705 if (nrealreaders <= 0) 1746 if (nrealreaders <= 0)
1706 nrealreaders = 1; 1747 nrealreaders = 1;
1707 } 1748 }
diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
index cad76e76b4e7..fb33d35ee0b7 100644
--- a/kernel/rcu/srcu.c
+++ b/kernel/rcu/srcu.c
@@ -151,7 +151,7 @@ static unsigned long srcu_readers_seq_idx(struct srcu_struct *sp, int idx)
151 unsigned long t; 151 unsigned long t;
152 152
153 for_each_possible_cpu(cpu) { 153 for_each_possible_cpu(cpu) {
154 t = ACCESS_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->seq[idx]); 154 t = READ_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->seq[idx]);
155 sum += t; 155 sum += t;
156 } 156 }
157 return sum; 157 return sum;
@@ -168,7 +168,7 @@ static unsigned long srcu_readers_active_idx(struct srcu_struct *sp, int idx)
168 unsigned long t; 168 unsigned long t;
169 169
170 for_each_possible_cpu(cpu) { 170 for_each_possible_cpu(cpu) {
171 t = ACCESS_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->c[idx]); 171 t = READ_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->c[idx]);
172 sum += t; 172 sum += t;
173 } 173 }
174 return sum; 174 return sum;
@@ -265,8 +265,8 @@ static int srcu_readers_active(struct srcu_struct *sp)
265 unsigned long sum = 0; 265 unsigned long sum = 0;
266 266
267 for_each_possible_cpu(cpu) { 267 for_each_possible_cpu(cpu) {
268 sum += ACCESS_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->c[0]); 268 sum += READ_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->c[0]);
269 sum += ACCESS_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->c[1]); 269 sum += READ_ONCE(per_cpu_ptr(sp->per_cpu_ref, cpu)->c[1]);
270 } 270 }
271 return sum; 271 return sum;
272} 272}
@@ -296,7 +296,7 @@ int __srcu_read_lock(struct srcu_struct *sp)
296{ 296{
297 int idx; 297 int idx;
298 298
299 idx = ACCESS_ONCE(sp->completed) & 0x1; 299 idx = READ_ONCE(sp->completed) & 0x1;
300 preempt_disable(); 300 preempt_disable();
301 __this_cpu_inc(sp->per_cpu_ref->c[idx]); 301 __this_cpu_inc(sp->per_cpu_ref->c[idx]);
302 smp_mb(); /* B */ /* Avoid leaking the critical section. */ 302 smp_mb(); /* B */ /* Avoid leaking the critical section. */
diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
index 069742d61c68..591af0cb7b9f 100644
--- a/kernel/rcu/tiny.c
+++ b/kernel/rcu/tiny.c
@@ -49,39 +49,6 @@ static void __call_rcu(struct rcu_head *head,
49 49
50#include "tiny_plugin.h" 50#include "tiny_plugin.h"
51 51
52/*
53 * Enter idle, which is an extended quiescent state if we have fully
54 * entered that mode.
55 */
56void rcu_idle_enter(void)
57{
58}
59EXPORT_SYMBOL_GPL(rcu_idle_enter);
60
61/*
62 * Exit an interrupt handler towards idle.
63 */
64void rcu_irq_exit(void)
65{
66}
67EXPORT_SYMBOL_GPL(rcu_irq_exit);
68
69/*
70 * Exit idle, so that we are no longer in an extended quiescent state.
71 */
72void rcu_idle_exit(void)
73{
74}
75EXPORT_SYMBOL_GPL(rcu_idle_exit);
76
77/*
78 * Enter an interrupt handler, moving away from idle.
79 */
80void rcu_irq_enter(void)
81{
82}
83EXPORT_SYMBOL_GPL(rcu_irq_enter);
84
85#if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_RCU_TRACE) 52#if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_RCU_TRACE)
86 53
87/* 54/*
@@ -170,6 +137,11 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
170 137
171 /* Move the ready-to-invoke callbacks to a local list. */ 138 /* Move the ready-to-invoke callbacks to a local list. */
172 local_irq_save(flags); 139 local_irq_save(flags);
140 if (rcp->donetail == &rcp->rcucblist) {
141 /* No callbacks ready, so just leave. */
142 local_irq_restore(flags);
143 return;
144 }
173 RCU_TRACE(trace_rcu_batch_start(rcp->name, 0, rcp->qlen, -1)); 145 RCU_TRACE(trace_rcu_batch_start(rcp->name, 0, rcp->qlen, -1));
174 list = rcp->rcucblist; 146 list = rcp->rcucblist;
175 rcp->rcucblist = *rcp->donetail; 147 rcp->rcucblist = *rcp->donetail;
diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
index f94e209a10d6..e492a5253e0f 100644
--- a/kernel/rcu/tiny_plugin.h
+++ b/kernel/rcu/tiny_plugin.h
@@ -144,16 +144,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
144 return; 144 return;
145 rcp->ticks_this_gp++; 145 rcp->ticks_this_gp++;
146 j = jiffies; 146 j = jiffies;
147 js = ACCESS_ONCE(rcp->jiffies_stall); 147 js = READ_ONCE(rcp->jiffies_stall);
148 if (rcp->rcucblist && ULONG_CMP_GE(j, js)) { 148 if (rcp->rcucblist && ULONG_CMP_GE(j, js)) {
149 pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n", 149 pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n",
150 rcp->name, rcp->ticks_this_gp, DYNTICK_TASK_EXIT_IDLE, 150 rcp->name, rcp->ticks_this_gp, DYNTICK_TASK_EXIT_IDLE,
151 jiffies - rcp->gp_start, rcp->qlen); 151 jiffies - rcp->gp_start, rcp->qlen);
152 dump_stack(); 152 dump_stack();
153 ACCESS_ONCE(rcp->jiffies_stall) = jiffies + 153 WRITE_ONCE(rcp->jiffies_stall,
154 3 * rcu_jiffies_till_stall_check() + 3; 154 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
155 } else if (ULONG_CMP_GE(j, js)) { 155 } else if (ULONG_CMP_GE(j, js)) {
156 ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check(); 156 WRITE_ONCE(rcp->jiffies_stall,
157 jiffies + rcu_jiffies_till_stall_check());
157 } 158 }
158} 159}
159 160
@@ -161,7 +162,8 @@ static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
161{ 162{
162 rcp->ticks_this_gp = 0; 163 rcp->ticks_this_gp = 0;
163 rcp->gp_start = jiffies; 164 rcp->gp_start = jiffies;
164 ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check(); 165 WRITE_ONCE(rcp->jiffies_stall,
166 jiffies + rcu_jiffies_till_stall_check());
165} 167}
166 168
167static void check_cpu_stalls(void) 169static void check_cpu_stalls(void)
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 8cf7304b2867..add042926a66 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -91,7 +91,7 @@ static const char *tp_##sname##_varname __used __tracepoint_string = sname##_var
91 91
92#define RCU_STATE_INITIALIZER(sname, sabbr, cr) \ 92#define RCU_STATE_INITIALIZER(sname, sabbr, cr) \
93DEFINE_RCU_TPS(sname) \ 93DEFINE_RCU_TPS(sname) \
94DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, sname##_data); \ 94static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, sname##_data); \
95struct rcu_state sname##_state = { \ 95struct rcu_state sname##_state = { \
96 .level = { &sname##_state.node[0] }, \ 96 .level = { &sname##_state.node[0] }, \
97 .rda = &sname##_data, \ 97 .rda = &sname##_data, \
@@ -110,11 +110,18 @@ struct rcu_state sname##_state = { \
110RCU_STATE_INITIALIZER(rcu_sched, 's', call_rcu_sched); 110RCU_STATE_INITIALIZER(rcu_sched, 's', call_rcu_sched);
111RCU_STATE_INITIALIZER(rcu_bh, 'b', call_rcu_bh); 111RCU_STATE_INITIALIZER(rcu_bh, 'b', call_rcu_bh);
112 112
113static struct rcu_state *rcu_state_p; 113static struct rcu_state *const rcu_state_p;
114static struct rcu_data __percpu *const rcu_data_p;
114LIST_HEAD(rcu_struct_flavors); 115LIST_HEAD(rcu_struct_flavors);
115 116
116/* Increase (but not decrease) the CONFIG_RCU_FANOUT_LEAF at boot time. */ 117/* Dump rcu_node combining tree at boot to verify correct setup. */
117static int rcu_fanout_leaf = CONFIG_RCU_FANOUT_LEAF; 118static bool dump_tree;
119module_param(dump_tree, bool, 0444);
120/* Control rcu_node-tree auto-balancing at boot time. */
121static bool rcu_fanout_exact;
122module_param(rcu_fanout_exact, bool, 0444);
123/* Increase (but not decrease) the RCU_FANOUT_LEAF at boot time. */
124static int rcu_fanout_leaf = RCU_FANOUT_LEAF;
118module_param(rcu_fanout_leaf, int, 0444); 125module_param(rcu_fanout_leaf, int, 0444);
119int rcu_num_lvls __read_mostly = RCU_NUM_LVLS; 126int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
120static int num_rcu_lvl[] = { /* Number of rcu_nodes at specified level. */ 127static int num_rcu_lvl[] = { /* Number of rcu_nodes at specified level. */
@@ -159,17 +166,46 @@ static void invoke_rcu_core(void);
159static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp); 166static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp);
160 167
161/* rcuc/rcub kthread realtime priority */ 168/* rcuc/rcub kthread realtime priority */
169#ifdef CONFIG_RCU_KTHREAD_PRIO
162static int kthread_prio = CONFIG_RCU_KTHREAD_PRIO; 170static int kthread_prio = CONFIG_RCU_KTHREAD_PRIO;
171#else /* #ifdef CONFIG_RCU_KTHREAD_PRIO */
172static int kthread_prio = IS_ENABLED(CONFIG_RCU_BOOST) ? 1 : 0;
173#endif /* #else #ifdef CONFIG_RCU_KTHREAD_PRIO */
163module_param(kthread_prio, int, 0644); 174module_param(kthread_prio, int, 0644);
164 175
165/* Delay in jiffies for grace-period initialization delays, debug only. */ 176/* Delay in jiffies for grace-period initialization delays, debug only. */
177
178#ifdef CONFIG_RCU_TORTURE_TEST_SLOW_PREINIT
179static int gp_preinit_delay = CONFIG_RCU_TORTURE_TEST_SLOW_PREINIT_DELAY;
180module_param(gp_preinit_delay, int, 0644);
181#else /* #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_PREINIT */
182static const int gp_preinit_delay;
183#endif /* #else #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_PREINIT */
184
166#ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT 185#ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT
167static int gp_init_delay = CONFIG_RCU_TORTURE_TEST_SLOW_INIT_DELAY; 186static int gp_init_delay = CONFIG_RCU_TORTURE_TEST_SLOW_INIT_DELAY;
168module_param(gp_init_delay, int, 0644); 187module_param(gp_init_delay, int, 0644);
169#else /* #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */ 188#else /* #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */
170static const int gp_init_delay; 189static const int gp_init_delay;
171#endif /* #else #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */ 190#endif /* #else #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_INIT */
172#define PER_RCU_NODE_PERIOD 10 /* Number of grace periods between delays. */ 191
192#ifdef CONFIG_RCU_TORTURE_TEST_SLOW_CLEANUP
193static int gp_cleanup_delay = CONFIG_RCU_TORTURE_TEST_SLOW_CLEANUP_DELAY;
194module_param(gp_cleanup_delay, int, 0644);
195#else /* #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_CLEANUP */
196static const int gp_cleanup_delay;
197#endif /* #else #ifdef CONFIG_RCU_TORTURE_TEST_SLOW_CLEANUP */
198
199/*
200 * Number of grace periods between delays, normalized by the duration of
201 * the delay. The longer the the delay, the more the grace periods between
202 * each delay. The reason for this normalization is that it means that,
203 * for non-zero delays, the overall slowdown of grace periods is constant
204 * regardless of the duration of the delay. This arrangement balances
205 * the need for long delays to increase some race probabilities with the
206 * need for fast grace periods to increase other race probabilities.
207 */
208#define PER_RCU_NODE_PERIOD 3 /* Number of grace periods between delays. */
173 209
174/* 210/*
175 * Track the rcutorture test sequence number and the update version 211 * Track the rcutorture test sequence number and the update version
@@ -191,17 +227,17 @@ unsigned long rcutorture_vernum;
191 */ 227 */
192unsigned long rcu_rnp_online_cpus(struct rcu_node *rnp) 228unsigned long rcu_rnp_online_cpus(struct rcu_node *rnp)
193{ 229{
194 return ACCESS_ONCE(rnp->qsmaskinitnext); 230 return READ_ONCE(rnp->qsmaskinitnext);
195} 231}
196 232
197/* 233/*
198 * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s 234 * Return true if an RCU grace period is in progress. The READ_ONCE()s
199 * permit this function to be invoked without holding the root rcu_node 235 * permit this function to be invoked without holding the root rcu_node
200 * structure's ->lock, but of course results can be subject to change. 236 * structure's ->lock, but of course results can be subject to change.
201 */ 237 */
202static int rcu_gp_in_progress(struct rcu_state *rsp) 238static int rcu_gp_in_progress(struct rcu_state *rsp)
203{ 239{
204 return ACCESS_ONCE(rsp->completed) != ACCESS_ONCE(rsp->gpnum); 240 return READ_ONCE(rsp->completed) != READ_ONCE(rsp->gpnum);
205} 241}
206 242
207/* 243/*
@@ -278,8 +314,8 @@ static void rcu_momentary_dyntick_idle(void)
278 if (!(resched_mask & rsp->flavor_mask)) 314 if (!(resched_mask & rsp->flavor_mask))
279 continue; 315 continue;
280 smp_mb(); /* rcu_sched_qs_mask before cond_resched_completed. */ 316 smp_mb(); /* rcu_sched_qs_mask before cond_resched_completed. */
281 if (ACCESS_ONCE(rdp->mynode->completed) != 317 if (READ_ONCE(rdp->mynode->completed) !=
282 ACCESS_ONCE(rdp->cond_resched_completed)) 318 READ_ONCE(rdp->cond_resched_completed))
283 continue; 319 continue;
284 320
285 /* 321 /*
@@ -491,9 +527,9 @@ void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
491 break; 527 break;
492 } 528 }
493 if (rsp != NULL) { 529 if (rsp != NULL) {
494 *flags = ACCESS_ONCE(rsp->gp_flags); 530 *flags = READ_ONCE(rsp->gp_flags);
495 *gpnum = ACCESS_ONCE(rsp->gpnum); 531 *gpnum = READ_ONCE(rsp->gpnum);
496 *completed = ACCESS_ONCE(rsp->completed); 532 *completed = READ_ONCE(rsp->completed);
497 return; 533 return;
498 } 534 }
499 *flags = 0; 535 *flags = 0;
@@ -539,10 +575,10 @@ static struct rcu_node *rcu_get_root(struct rcu_state *rsp)
539static int rcu_future_needs_gp(struct rcu_state *rsp) 575static int rcu_future_needs_gp(struct rcu_state *rsp)
540{ 576{
541 struct rcu_node *rnp = rcu_get_root(rsp); 577 struct rcu_node *rnp = rcu_get_root(rsp);
542 int idx = (ACCESS_ONCE(rnp->completed) + 1) & 0x1; 578 int idx = (READ_ONCE(rnp->completed) + 1) & 0x1;
543 int *fp = &rnp->need_future_gp[idx]; 579 int *fp = &rnp->need_future_gp[idx];
544 580
545 return ACCESS_ONCE(*fp); 581 return READ_ONCE(*fp);
546} 582}
547 583
548/* 584/*
@@ -565,7 +601,7 @@ cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp)
565 return 1; /* Yes, this CPU has newly registered callbacks. */ 601 return 1; /* Yes, this CPU has newly registered callbacks. */
566 for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++) 602 for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++)
567 if (rdp->nxttail[i - 1] != rdp->nxttail[i] && 603 if (rdp->nxttail[i - 1] != rdp->nxttail[i] &&
568 ULONG_CMP_LT(ACCESS_ONCE(rsp->completed), 604 ULONG_CMP_LT(READ_ONCE(rsp->completed),
569 rdp->nxtcompleted[i])) 605 rdp->nxtcompleted[i]))
570 return 1; /* Yes, CBs for future grace period. */ 606 return 1; /* Yes, CBs for future grace period. */
571 return 0; /* No grace period needed. */ 607 return 0; /* No grace period needed. */
@@ -585,7 +621,8 @@ static void rcu_eqs_enter_common(long long oldval, bool user)
585 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks); 621 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
586 622
587 trace_rcu_dyntick(TPS("Start"), oldval, rdtp->dynticks_nesting); 623 trace_rcu_dyntick(TPS("Start"), oldval, rdtp->dynticks_nesting);
588 if (!user && !is_idle_task(current)) { 624 if (IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
625 !user && !is_idle_task(current)) {
589 struct task_struct *idle __maybe_unused = 626 struct task_struct *idle __maybe_unused =
590 idle_task(smp_processor_id()); 627 idle_task(smp_processor_id());
591 628
@@ -604,7 +641,8 @@ static void rcu_eqs_enter_common(long long oldval, bool user)
604 smp_mb__before_atomic(); /* See above. */ 641 smp_mb__before_atomic(); /* See above. */
605 atomic_inc(&rdtp->dynticks); 642 atomic_inc(&rdtp->dynticks);
606 smp_mb__after_atomic(); /* Force ordering with next sojourn. */ 643 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
607 WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1); 644 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
645 atomic_read(&rdtp->dynticks) & 0x1);
608 rcu_dynticks_task_enter(); 646 rcu_dynticks_task_enter();
609 647
610 /* 648 /*
@@ -630,7 +668,8 @@ static void rcu_eqs_enter(bool user)
630 668
631 rdtp = this_cpu_ptr(&rcu_dynticks); 669 rdtp = this_cpu_ptr(&rcu_dynticks);
632 oldval = rdtp->dynticks_nesting; 670 oldval = rdtp->dynticks_nesting;
633 WARN_ON_ONCE((oldval & DYNTICK_TASK_NEST_MASK) == 0); 671 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
672 (oldval & DYNTICK_TASK_NEST_MASK) == 0);
634 if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE) { 673 if ((oldval & DYNTICK_TASK_NEST_MASK) == DYNTICK_TASK_NEST_VALUE) {
635 rdtp->dynticks_nesting = 0; 674 rdtp->dynticks_nesting = 0;
636 rcu_eqs_enter_common(oldval, user); 675 rcu_eqs_enter_common(oldval, user);
@@ -703,7 +742,8 @@ void rcu_irq_exit(void)
703 rdtp = this_cpu_ptr(&rcu_dynticks); 742 rdtp = this_cpu_ptr(&rcu_dynticks);
704 oldval = rdtp->dynticks_nesting; 743 oldval = rdtp->dynticks_nesting;
705 rdtp->dynticks_nesting--; 744 rdtp->dynticks_nesting--;
706 WARN_ON_ONCE(rdtp->dynticks_nesting < 0); 745 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
746 rdtp->dynticks_nesting < 0);
707 if (rdtp->dynticks_nesting) 747 if (rdtp->dynticks_nesting)
708 trace_rcu_dyntick(TPS("--="), oldval, rdtp->dynticks_nesting); 748 trace_rcu_dyntick(TPS("--="), oldval, rdtp->dynticks_nesting);
709 else 749 else
@@ -728,10 +768,12 @@ static void rcu_eqs_exit_common(long long oldval, int user)
728 atomic_inc(&rdtp->dynticks); 768 atomic_inc(&rdtp->dynticks);
729 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */ 769 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
730 smp_mb__after_atomic(); /* See above. */ 770 smp_mb__after_atomic(); /* See above. */
731 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1)); 771 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
772 !(atomic_read(&rdtp->dynticks) & 0x1));
732 rcu_cleanup_after_idle(); 773 rcu_cleanup_after_idle();
733 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting); 774 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
734 if (!user && !is_idle_task(current)) { 775 if (IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
776 !user && !is_idle_task(current)) {
735 struct task_struct *idle __maybe_unused = 777 struct task_struct *idle __maybe_unused =
736 idle_task(smp_processor_id()); 778 idle_task(smp_processor_id());
737 779
@@ -755,7 +797,7 @@ static void rcu_eqs_exit(bool user)
755 797
756 rdtp = this_cpu_ptr(&rcu_dynticks); 798 rdtp = this_cpu_ptr(&rcu_dynticks);
757 oldval = rdtp->dynticks_nesting; 799 oldval = rdtp->dynticks_nesting;
758 WARN_ON_ONCE(oldval < 0); 800 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && oldval < 0);
759 if (oldval & DYNTICK_TASK_NEST_MASK) { 801 if (oldval & DYNTICK_TASK_NEST_MASK) {
760 rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE; 802 rdtp->dynticks_nesting += DYNTICK_TASK_NEST_VALUE;
761 } else { 803 } else {
@@ -828,7 +870,8 @@ void rcu_irq_enter(void)
828 rdtp = this_cpu_ptr(&rcu_dynticks); 870 rdtp = this_cpu_ptr(&rcu_dynticks);
829 oldval = rdtp->dynticks_nesting; 871 oldval = rdtp->dynticks_nesting;
830 rdtp->dynticks_nesting++; 872 rdtp->dynticks_nesting++;
831 WARN_ON_ONCE(rdtp->dynticks_nesting == 0); 873 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
874 rdtp->dynticks_nesting == 0);
832 if (oldval) 875 if (oldval)
833 trace_rcu_dyntick(TPS("++="), oldval, rdtp->dynticks_nesting); 876 trace_rcu_dyntick(TPS("++="), oldval, rdtp->dynticks_nesting);
834 else 877 else
@@ -1011,9 +1054,9 @@ static int dyntick_save_progress_counter(struct rcu_data *rdp,
1011 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti")); 1054 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
1012 return 1; 1055 return 1;
1013 } else { 1056 } else {
1014 if (ULONG_CMP_LT(ACCESS_ONCE(rdp->gpnum) + ULONG_MAX / 4, 1057 if (ULONG_CMP_LT(READ_ONCE(rdp->gpnum) + ULONG_MAX / 4,
1015 rdp->mynode->gpnum)) 1058 rdp->mynode->gpnum))
1016 ACCESS_ONCE(rdp->gpwrap) = true; 1059 WRITE_ONCE(rdp->gpwrap, true);
1017 return 0; 1060 return 0;
1018 } 1061 }
1019} 1062}
@@ -1093,12 +1136,12 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
1093 if (ULONG_CMP_GE(jiffies, 1136 if (ULONG_CMP_GE(jiffies,
1094 rdp->rsp->gp_start + jiffies_till_sched_qs) || 1137 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
1095 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) { 1138 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
1096 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) { 1139 if (!(READ_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
1097 ACCESS_ONCE(rdp->cond_resched_completed) = 1140 WRITE_ONCE(rdp->cond_resched_completed,
1098 ACCESS_ONCE(rdp->mynode->completed); 1141 READ_ONCE(rdp->mynode->completed));
1099 smp_mb(); /* ->cond_resched_completed before *rcrmp. */ 1142 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
1100 ACCESS_ONCE(*rcrmp) = 1143 WRITE_ONCE(*rcrmp,
1101 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask; 1144 READ_ONCE(*rcrmp) + rdp->rsp->flavor_mask);
1102 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */ 1145 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
1103 rdp->rsp->jiffies_resched += 5; /* Enable beating. */ 1146 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
1104 } else if (ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) { 1147 } else if (ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
@@ -1119,9 +1162,9 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
1119 rsp->gp_start = j; 1162 rsp->gp_start = j;
1120 smp_wmb(); /* Record start time before stall time. */ 1163 smp_wmb(); /* Record start time before stall time. */
1121 j1 = rcu_jiffies_till_stall_check(); 1164 j1 = rcu_jiffies_till_stall_check();
1122 ACCESS_ONCE(rsp->jiffies_stall) = j + j1; 1165 WRITE_ONCE(rsp->jiffies_stall, j + j1);
1123 rsp->jiffies_resched = j + j1 / 2; 1166 rsp->jiffies_resched = j + j1 / 2;
1124 rsp->n_force_qs_gpstart = ACCESS_ONCE(rsp->n_force_qs); 1167 rsp->n_force_qs_gpstart = READ_ONCE(rsp->n_force_qs);
1125} 1168}
1126 1169
1127/* 1170/*
@@ -1133,10 +1176,11 @@ static void rcu_check_gp_kthread_starvation(struct rcu_state *rsp)
1133 unsigned long j; 1176 unsigned long j;
1134 1177
1135 j = jiffies; 1178 j = jiffies;
1136 gpa = ACCESS_ONCE(rsp->gp_activity); 1179 gpa = READ_ONCE(rsp->gp_activity);
1137 if (j - gpa > 2 * HZ) 1180 if (j - gpa > 2 * HZ)
1138 pr_err("%s kthread starved for %ld jiffies!\n", 1181 pr_err("%s kthread starved for %ld jiffies! g%lu c%lu f%#x\n",
1139 rsp->name, j - gpa); 1182 rsp->name, j - gpa,
1183 rsp->gpnum, rsp->completed, rsp->gp_flags);
1140} 1184}
1141 1185
1142/* 1186/*
@@ -1173,12 +1217,13 @@ static void print_other_cpu_stall(struct rcu_state *rsp, unsigned long gpnum)
1173 /* Only let one CPU complain about others per time interval. */ 1217 /* Only let one CPU complain about others per time interval. */
1174 1218
1175 raw_spin_lock_irqsave(&rnp->lock, flags); 1219 raw_spin_lock_irqsave(&rnp->lock, flags);
1176 delta = jiffies - ACCESS_ONCE(rsp->jiffies_stall); 1220 delta = jiffies - READ_ONCE(rsp->jiffies_stall);
1177 if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) { 1221 if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) {
1178 raw_spin_unlock_irqrestore(&rnp->lock, flags); 1222 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1179 return; 1223 return;
1180 } 1224 }
1181 ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3; 1225 WRITE_ONCE(rsp->jiffies_stall,
1226 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
1182 raw_spin_unlock_irqrestore(&rnp->lock, flags); 1227 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1183 1228
1184 /* 1229 /*
@@ -1212,12 +1257,12 @@ static void print_other_cpu_stall(struct rcu_state *rsp, unsigned long gpnum)
1212 if (ndetected) { 1257 if (ndetected) {
1213 rcu_dump_cpu_stacks(rsp); 1258 rcu_dump_cpu_stacks(rsp);
1214 } else { 1259 } else {
1215 if (ACCESS_ONCE(rsp->gpnum) != gpnum || 1260 if (READ_ONCE(rsp->gpnum) != gpnum ||
1216 ACCESS_ONCE(rsp->completed) == gpnum) { 1261 READ_ONCE(rsp->completed) == gpnum) {
1217 pr_err("INFO: Stall ended before state dump start\n"); 1262 pr_err("INFO: Stall ended before state dump start\n");
1218 } else { 1263 } else {
1219 j = jiffies; 1264 j = jiffies;
1220 gpa = ACCESS_ONCE(rsp->gp_activity); 1265 gpa = READ_ONCE(rsp->gp_activity);
1221 pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n", 1266 pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n",
1222 rsp->name, j - gpa, j, gpa, 1267 rsp->name, j - gpa, j, gpa,
1223 jiffies_till_next_fqs, 1268 jiffies_till_next_fqs,
@@ -1262,9 +1307,9 @@ static void print_cpu_stall(struct rcu_state *rsp)
1262 rcu_dump_cpu_stacks(rsp); 1307 rcu_dump_cpu_stacks(rsp);
1263 1308
1264 raw_spin_lock_irqsave(&rnp->lock, flags); 1309 raw_spin_lock_irqsave(&rnp->lock, flags);
1265 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall))) 1310 if (ULONG_CMP_GE(jiffies, READ_ONCE(rsp->jiffies_stall)))
1266 ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 1311 WRITE_ONCE(rsp->jiffies_stall,
1267 3 * rcu_jiffies_till_stall_check() + 3; 1312 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
1268 raw_spin_unlock_irqrestore(&rnp->lock, flags); 1313 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1269 1314
1270 /* 1315 /*
@@ -1307,20 +1352,20 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
1307 * Given this check, comparisons of jiffies, rsp->jiffies_stall, 1352 * Given this check, comparisons of jiffies, rsp->jiffies_stall,
1308 * and rsp->gp_start suffice to forestall false positives. 1353 * and rsp->gp_start suffice to forestall false positives.
1309 */ 1354 */
1310 gpnum = ACCESS_ONCE(rsp->gpnum); 1355 gpnum = READ_ONCE(rsp->gpnum);
1311 smp_rmb(); /* Pick up ->gpnum first... */ 1356 smp_rmb(); /* Pick up ->gpnum first... */
1312 js = ACCESS_ONCE(rsp->jiffies_stall); 1357 js = READ_ONCE(rsp->jiffies_stall);
1313 smp_rmb(); /* ...then ->jiffies_stall before the rest... */ 1358 smp_rmb(); /* ...then ->jiffies_stall before the rest... */
1314 gps = ACCESS_ONCE(rsp->gp_start); 1359 gps = READ_ONCE(rsp->gp_start);
1315 smp_rmb(); /* ...and finally ->gp_start before ->completed. */ 1360 smp_rmb(); /* ...and finally ->gp_start before ->completed. */
1316 completed = ACCESS_ONCE(rsp->completed); 1361 completed = READ_ONCE(rsp->completed);
1317 if (ULONG_CMP_GE(completed, gpnum) || 1362 if (ULONG_CMP_GE(completed, gpnum) ||
1318 ULONG_CMP_LT(j, js) || 1363 ULONG_CMP_LT(j, js) ||
1319 ULONG_CMP_GE(gps, js)) 1364 ULONG_CMP_GE(gps, js))
1320 return; /* No stall or GP completed since entering function. */ 1365 return; /* No stall or GP completed since entering function. */
1321 rnp = rdp->mynode; 1366 rnp = rdp->mynode;
1322 if (rcu_gp_in_progress(rsp) && 1367 if (rcu_gp_in_progress(rsp) &&
1323 (ACCESS_ONCE(rnp->qsmask) & rdp->grpmask)) { 1368 (READ_ONCE(rnp->qsmask) & rdp->grpmask)) {
1324 1369
1325 /* We haven't checked in, so go dump stack. */ 1370 /* We haven't checked in, so go dump stack. */
1326 print_cpu_stall(rsp); 1371 print_cpu_stall(rsp);
@@ -1347,7 +1392,7 @@ void rcu_cpu_stall_reset(void)
1347 struct rcu_state *rsp; 1392 struct rcu_state *rsp;
1348 1393
1349 for_each_rcu_flavor(rsp) 1394 for_each_rcu_flavor(rsp)
1350 ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2; 1395 WRITE_ONCE(rsp->jiffies_stall, jiffies + ULONG_MAX / 2);
1351} 1396}
1352 1397
1353/* 1398/*
@@ -1457,7 +1502,7 @@ rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp,
1457 * doing some extra useless work. 1502 * doing some extra useless work.
1458 */ 1503 */
1459 if (rnp->gpnum != rnp->completed || 1504 if (rnp->gpnum != rnp->completed ||
1460 ACCESS_ONCE(rnp_root->gpnum) != ACCESS_ONCE(rnp_root->completed)) { 1505 READ_ONCE(rnp_root->gpnum) != READ_ONCE(rnp_root->completed)) {
1461 rnp->need_future_gp[c & 0x1]++; 1506 rnp->need_future_gp[c & 0x1]++;
1462 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleaf")); 1507 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleaf"));
1463 goto out; 1508 goto out;
@@ -1542,7 +1587,7 @@ static int rcu_future_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
1542static void rcu_gp_kthread_wake(struct rcu_state *rsp) 1587static void rcu_gp_kthread_wake(struct rcu_state *rsp)
1543{ 1588{
1544 if (current == rsp->gp_kthread || 1589 if (current == rsp->gp_kthread ||
1545 !ACCESS_ONCE(rsp->gp_flags) || 1590 !READ_ONCE(rsp->gp_flags) ||
1546 !rsp->gp_kthread) 1591 !rsp->gp_kthread)
1547 return; 1592 return;
1548 wake_up(&rsp->gp_wq); 1593 wake_up(&rsp->gp_wq);
@@ -1677,7 +1722,7 @@ static bool __note_gp_changes(struct rcu_state *rsp, struct rcu_node *rnp,
1677 1722
1678 /* Handle the ends of any preceding grace periods first. */ 1723 /* Handle the ends of any preceding grace periods first. */
1679 if (rdp->completed == rnp->completed && 1724 if (rdp->completed == rnp->completed &&
1680 !unlikely(ACCESS_ONCE(rdp->gpwrap))) { 1725 !unlikely(READ_ONCE(rdp->gpwrap))) {
1681 1726
1682 /* No grace period end, so just accelerate recent callbacks. */ 1727 /* No grace period end, so just accelerate recent callbacks. */
1683 ret = rcu_accelerate_cbs(rsp, rnp, rdp); 1728 ret = rcu_accelerate_cbs(rsp, rnp, rdp);
@@ -1692,7 +1737,7 @@ static bool __note_gp_changes(struct rcu_state *rsp, struct rcu_node *rnp,
1692 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuend")); 1737 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuend"));
1693 } 1738 }
1694 1739
1695 if (rdp->gpnum != rnp->gpnum || unlikely(ACCESS_ONCE(rdp->gpwrap))) { 1740 if (rdp->gpnum != rnp->gpnum || unlikely(READ_ONCE(rdp->gpwrap))) {
1696 /* 1741 /*
1697 * If the current grace period is waiting for this CPU, 1742 * If the current grace period is waiting for this CPU,
1698 * set up to detect a quiescent state, otherwise don't 1743 * set up to detect a quiescent state, otherwise don't
@@ -1704,7 +1749,7 @@ static bool __note_gp_changes(struct rcu_state *rsp, struct rcu_node *rnp,
1704 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr); 1749 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr);
1705 rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask); 1750 rdp->qs_pending = !!(rnp->qsmask & rdp->grpmask);
1706 zero_cpu_stall_ticks(rdp); 1751 zero_cpu_stall_ticks(rdp);
1707 ACCESS_ONCE(rdp->gpwrap) = false; 1752 WRITE_ONCE(rdp->gpwrap, false);
1708 } 1753 }
1709 return ret; 1754 return ret;
1710} 1755}
@@ -1717,9 +1762,9 @@ static void note_gp_changes(struct rcu_state *rsp, struct rcu_data *rdp)
1717 1762
1718 local_irq_save(flags); 1763 local_irq_save(flags);
1719 rnp = rdp->mynode; 1764 rnp = rdp->mynode;
1720 if ((rdp->gpnum == ACCESS_ONCE(rnp->gpnum) && 1765 if ((rdp->gpnum == READ_ONCE(rnp->gpnum) &&
1721 rdp->completed == ACCESS_ONCE(rnp->completed) && 1766 rdp->completed == READ_ONCE(rnp->completed) &&
1722 !unlikely(ACCESS_ONCE(rdp->gpwrap))) || /* w/out lock. */ 1767 !unlikely(READ_ONCE(rdp->gpwrap))) || /* w/out lock. */
1723 !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */ 1768 !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */
1724 local_irq_restore(flags); 1769 local_irq_restore(flags);
1725 return; 1770 return;
@@ -1731,6 +1776,13 @@ static void note_gp_changes(struct rcu_state *rsp, struct rcu_data *rdp)
1731 rcu_gp_kthread_wake(rsp); 1776 rcu_gp_kthread_wake(rsp);
1732} 1777}
1733 1778
1779static void rcu_gp_slow(struct rcu_state *rsp, int delay)
1780{
1781 if (delay > 0 &&
1782 !(rsp->gpnum % (rcu_num_nodes * PER_RCU_NODE_PERIOD * delay)))
1783 schedule_timeout_uninterruptible(delay);
1784}
1785
1734/* 1786/*
1735 * Initialize a new grace period. Return 0 if no grace period required. 1787 * Initialize a new grace period. Return 0 if no grace period required.
1736 */ 1788 */
@@ -1740,15 +1792,15 @@ static int rcu_gp_init(struct rcu_state *rsp)
1740 struct rcu_data *rdp; 1792 struct rcu_data *rdp;
1741 struct rcu_node *rnp = rcu_get_root(rsp); 1793 struct rcu_node *rnp = rcu_get_root(rsp);
1742 1794
1743 ACCESS_ONCE(rsp->gp_activity) = jiffies; 1795 WRITE_ONCE(rsp->gp_activity, jiffies);
1744 raw_spin_lock_irq(&rnp->lock); 1796 raw_spin_lock_irq(&rnp->lock);
1745 smp_mb__after_unlock_lock(); 1797 smp_mb__after_unlock_lock();
1746 if (!ACCESS_ONCE(rsp->gp_flags)) { 1798 if (!READ_ONCE(rsp->gp_flags)) {
1747 /* Spurious wakeup, tell caller to go back to sleep. */ 1799 /* Spurious wakeup, tell caller to go back to sleep. */
1748 raw_spin_unlock_irq(&rnp->lock); 1800 raw_spin_unlock_irq(&rnp->lock);
1749 return 0; 1801 return 0;
1750 } 1802 }
1751 ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */ 1803 WRITE_ONCE(rsp->gp_flags, 0); /* Clear all flags: New grace period. */
1752 1804
1753 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) { 1805 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
1754 /* 1806 /*
@@ -1773,6 +1825,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
1773 * will handle subsequent offline CPUs. 1825 * will handle subsequent offline CPUs.
1774 */ 1826 */
1775 rcu_for_each_leaf_node(rsp, rnp) { 1827 rcu_for_each_leaf_node(rsp, rnp) {
1828 rcu_gp_slow(rsp, gp_preinit_delay);
1776 raw_spin_lock_irq(&rnp->lock); 1829 raw_spin_lock_irq(&rnp->lock);
1777 smp_mb__after_unlock_lock(); 1830 smp_mb__after_unlock_lock();
1778 if (rnp->qsmaskinit == rnp->qsmaskinitnext && 1831 if (rnp->qsmaskinit == rnp->qsmaskinitnext &&
@@ -1829,14 +1882,15 @@ static int rcu_gp_init(struct rcu_state *rsp)
1829 * process finishes, because this kthread handles both. 1882 * process finishes, because this kthread handles both.
1830 */ 1883 */
1831 rcu_for_each_node_breadth_first(rsp, rnp) { 1884 rcu_for_each_node_breadth_first(rsp, rnp) {
1885 rcu_gp_slow(rsp, gp_init_delay);
1832 raw_spin_lock_irq(&rnp->lock); 1886 raw_spin_lock_irq(&rnp->lock);
1833 smp_mb__after_unlock_lock(); 1887 smp_mb__after_unlock_lock();
1834 rdp = this_cpu_ptr(rsp->rda); 1888 rdp = this_cpu_ptr(rsp->rda);
1835 rcu_preempt_check_blocked_tasks(rnp); 1889 rcu_preempt_check_blocked_tasks(rnp);
1836 rnp->qsmask = rnp->qsmaskinit; 1890 rnp->qsmask = rnp->qsmaskinit;
1837 ACCESS_ONCE(rnp->gpnum) = rsp->gpnum; 1891 WRITE_ONCE(rnp->gpnum, rsp->gpnum);
1838 if (WARN_ON_ONCE(rnp->completed != rsp->completed)) 1892 if (WARN_ON_ONCE(rnp->completed != rsp->completed))
1839 ACCESS_ONCE(rnp->completed) = rsp->completed; 1893 WRITE_ONCE(rnp->completed, rsp->completed);
1840 if (rnp == rdp->mynode) 1894 if (rnp == rdp->mynode)
1841 (void)__note_gp_changes(rsp, rnp, rdp); 1895 (void)__note_gp_changes(rsp, rnp, rdp);
1842 rcu_preempt_boost_start_gp(rnp); 1896 rcu_preempt_boost_start_gp(rnp);
@@ -1845,10 +1899,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
1845 rnp->grphi, rnp->qsmask); 1899 rnp->grphi, rnp->qsmask);
1846 raw_spin_unlock_irq(&rnp->lock); 1900 raw_spin_unlock_irq(&rnp->lock);
1847 cond_resched_rcu_qs(); 1901 cond_resched_rcu_qs();
1848 ACCESS_ONCE(rsp->gp_activity) = jiffies; 1902 WRITE_ONCE(rsp->gp_activity, jiffies);
1849 if (gp_init_delay > 0 &&
1850 !(rsp->gpnum % (rcu_num_nodes * PER_RCU_NODE_PERIOD)))
1851 schedule_timeout_uninterruptible(gp_init_delay);
1852 } 1903 }
1853 1904
1854 return 1; 1905 return 1;
@@ -1864,7 +1915,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
1864 unsigned long maxj; 1915 unsigned long maxj;
1865 struct rcu_node *rnp = rcu_get_root(rsp); 1916 struct rcu_node *rnp = rcu_get_root(rsp);
1866 1917
1867 ACCESS_ONCE(rsp->gp_activity) = jiffies; 1918 WRITE_ONCE(rsp->gp_activity, jiffies);
1868 rsp->n_force_qs++; 1919 rsp->n_force_qs++;
1869 if (fqs_state == RCU_SAVE_DYNTICK) { 1920 if (fqs_state == RCU_SAVE_DYNTICK) {
1870 /* Collect dyntick-idle snapshots. */ 1921 /* Collect dyntick-idle snapshots. */
@@ -1882,11 +1933,11 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
1882 force_qs_rnp(rsp, rcu_implicit_dynticks_qs, &isidle, &maxj); 1933 force_qs_rnp(rsp, rcu_implicit_dynticks_qs, &isidle, &maxj);
1883 } 1934 }
1884 /* Clear flag to prevent immediate re-entry. */ 1935 /* Clear flag to prevent immediate re-entry. */
1885 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) { 1936 if (READ_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
1886 raw_spin_lock_irq(&rnp->lock); 1937 raw_spin_lock_irq(&rnp->lock);
1887 smp_mb__after_unlock_lock(); 1938 smp_mb__after_unlock_lock();
1888 ACCESS_ONCE(rsp->gp_flags) = 1939 WRITE_ONCE(rsp->gp_flags,
1889 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS; 1940 READ_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS);
1890 raw_spin_unlock_irq(&rnp->lock); 1941 raw_spin_unlock_irq(&rnp->lock);
1891 } 1942 }
1892 return fqs_state; 1943 return fqs_state;
@@ -1903,7 +1954,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
1903 struct rcu_data *rdp; 1954 struct rcu_data *rdp;
1904 struct rcu_node *rnp = rcu_get_root(rsp); 1955 struct rcu_node *rnp = rcu_get_root(rsp);
1905 1956
1906 ACCESS_ONCE(rsp->gp_activity) = jiffies; 1957 WRITE_ONCE(rsp->gp_activity, jiffies);
1907 raw_spin_lock_irq(&rnp->lock); 1958 raw_spin_lock_irq(&rnp->lock);
1908 smp_mb__after_unlock_lock(); 1959 smp_mb__after_unlock_lock();
1909 gp_duration = jiffies - rsp->gp_start; 1960 gp_duration = jiffies - rsp->gp_start;
@@ -1934,7 +1985,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
1934 smp_mb__after_unlock_lock(); 1985 smp_mb__after_unlock_lock();
1935 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp)); 1986 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp));
1936 WARN_ON_ONCE(rnp->qsmask); 1987 WARN_ON_ONCE(rnp->qsmask);
1937 ACCESS_ONCE(rnp->completed) = rsp->gpnum; 1988 WRITE_ONCE(rnp->completed, rsp->gpnum);
1938 rdp = this_cpu_ptr(rsp->rda); 1989 rdp = this_cpu_ptr(rsp->rda);
1939 if (rnp == rdp->mynode) 1990 if (rnp == rdp->mynode)
1940 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp; 1991 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
@@ -1942,7 +1993,8 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
1942 nocb += rcu_future_gp_cleanup(rsp, rnp); 1993 nocb += rcu_future_gp_cleanup(rsp, rnp);
1943 raw_spin_unlock_irq(&rnp->lock); 1994 raw_spin_unlock_irq(&rnp->lock);
1944 cond_resched_rcu_qs(); 1995 cond_resched_rcu_qs();
1945 ACCESS_ONCE(rsp->gp_activity) = jiffies; 1996 WRITE_ONCE(rsp->gp_activity, jiffies);
1997 rcu_gp_slow(rsp, gp_cleanup_delay);
1946 } 1998 }
1947 rnp = rcu_get_root(rsp); 1999 rnp = rcu_get_root(rsp);
1948 raw_spin_lock_irq(&rnp->lock); 2000 raw_spin_lock_irq(&rnp->lock);
@@ -1950,16 +2002,16 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
1950 rcu_nocb_gp_set(rnp, nocb); 2002 rcu_nocb_gp_set(rnp, nocb);
1951 2003
1952 /* Declare grace period done. */ 2004 /* Declare grace period done. */
1953 ACCESS_ONCE(rsp->completed) = rsp->gpnum; 2005 WRITE_ONCE(rsp->completed, rsp->gpnum);
1954 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end")); 2006 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
1955 rsp->fqs_state = RCU_GP_IDLE; 2007 rsp->fqs_state = RCU_GP_IDLE;
1956 rdp = this_cpu_ptr(rsp->rda); 2008 rdp = this_cpu_ptr(rsp->rda);
1957 /* Advance CBs to reduce false positives below. */ 2009 /* Advance CBs to reduce false positives below. */
1958 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp; 2010 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
1959 if (needgp || cpu_needs_another_gp(rsp, rdp)) { 2011 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
1960 ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT; 2012 WRITE_ONCE(rsp->gp_flags, RCU_GP_FLAG_INIT);
1961 trace_rcu_grace_period(rsp->name, 2013 trace_rcu_grace_period(rsp->name,
1962 ACCESS_ONCE(rsp->gpnum), 2014 READ_ONCE(rsp->gpnum),
1963 TPS("newreq")); 2015 TPS("newreq"));
1964 } 2016 }
1965 raw_spin_unlock_irq(&rnp->lock); 2017 raw_spin_unlock_irq(&rnp->lock);
@@ -1983,20 +2035,20 @@ static int __noreturn rcu_gp_kthread(void *arg)
1983 /* Handle grace-period start. */ 2035 /* Handle grace-period start. */
1984 for (;;) { 2036 for (;;) {
1985 trace_rcu_grace_period(rsp->name, 2037 trace_rcu_grace_period(rsp->name,
1986 ACCESS_ONCE(rsp->gpnum), 2038 READ_ONCE(rsp->gpnum),
1987 TPS("reqwait")); 2039 TPS("reqwait"));
1988 rsp->gp_state = RCU_GP_WAIT_GPS; 2040 rsp->gp_state = RCU_GP_WAIT_GPS;
1989 wait_event_interruptible(rsp->gp_wq, 2041 wait_event_interruptible(rsp->gp_wq,
1990 ACCESS_ONCE(rsp->gp_flags) & 2042 READ_ONCE(rsp->gp_flags) &
1991 RCU_GP_FLAG_INIT); 2043 RCU_GP_FLAG_INIT);
1992 /* Locking provides needed memory barrier. */ 2044 /* Locking provides needed memory barrier. */
1993 if (rcu_gp_init(rsp)) 2045 if (rcu_gp_init(rsp))
1994 break; 2046 break;
1995 cond_resched_rcu_qs(); 2047 cond_resched_rcu_qs();
1996 ACCESS_ONCE(rsp->gp_activity) = jiffies; 2048 WRITE_ONCE(rsp->gp_activity, jiffies);
1997 WARN_ON(signal_pending(current)); 2049 WARN_ON(signal_pending(current));
1998 trace_rcu_grace_period(rsp->name, 2050 trace_rcu_grace_period(rsp->name,
1999 ACCESS_ONCE(rsp->gpnum), 2051 READ_ONCE(rsp->gpnum),
2000 TPS("reqwaitsig")); 2052 TPS("reqwaitsig"));
2001 } 2053 }
2002 2054
@@ -2012,39 +2064,39 @@ static int __noreturn rcu_gp_kthread(void *arg)
2012 if (!ret) 2064 if (!ret)
2013 rsp->jiffies_force_qs = jiffies + j; 2065 rsp->jiffies_force_qs = jiffies + j;
2014 trace_rcu_grace_period(rsp->name, 2066 trace_rcu_grace_period(rsp->name,
2015 ACCESS_ONCE(rsp->gpnum), 2067 READ_ONCE(rsp->gpnum),
2016 TPS("fqswait")); 2068 TPS("fqswait"));
2017 rsp->gp_state = RCU_GP_WAIT_FQS; 2069 rsp->gp_state = RCU_GP_WAIT_FQS;
2018 ret = wait_event_interruptible_timeout(rsp->gp_wq, 2070 ret = wait_event_interruptible_timeout(rsp->gp_wq,
2019 ((gf = ACCESS_ONCE(rsp->gp_flags)) & 2071 ((gf = READ_ONCE(rsp->gp_flags)) &
2020 RCU_GP_FLAG_FQS) || 2072 RCU_GP_FLAG_FQS) ||
2021 (!ACCESS_ONCE(rnp->qsmask) && 2073 (!READ_ONCE(rnp->qsmask) &&
2022 !rcu_preempt_blocked_readers_cgp(rnp)), 2074 !rcu_preempt_blocked_readers_cgp(rnp)),
2023 j); 2075 j);
2024 /* Locking provides needed memory barriers. */ 2076 /* Locking provides needed memory barriers. */
2025 /* If grace period done, leave loop. */ 2077 /* If grace period done, leave loop. */
2026 if (!ACCESS_ONCE(rnp->qsmask) && 2078 if (!READ_ONCE(rnp->qsmask) &&
2027 !rcu_preempt_blocked_readers_cgp(rnp)) 2079 !rcu_preempt_blocked_readers_cgp(rnp))
2028 break; 2080 break;
2029 /* If time for quiescent-state forcing, do it. */ 2081 /* If time for quiescent-state forcing, do it. */
2030 if (ULONG_CMP_GE(jiffies, rsp->jiffies_force_qs) || 2082 if (ULONG_CMP_GE(jiffies, rsp->jiffies_force_qs) ||
2031 (gf & RCU_GP_FLAG_FQS)) { 2083 (gf & RCU_GP_FLAG_FQS)) {
2032 trace_rcu_grace_period(rsp->name, 2084 trace_rcu_grace_period(rsp->name,
2033 ACCESS_ONCE(rsp->gpnum), 2085 READ_ONCE(rsp->gpnum),
2034 TPS("fqsstart")); 2086 TPS("fqsstart"));
2035 fqs_state = rcu_gp_fqs(rsp, fqs_state); 2087 fqs_state = rcu_gp_fqs(rsp, fqs_state);
2036 trace_rcu_grace_period(rsp->name, 2088 trace_rcu_grace_period(rsp->name,
2037 ACCESS_ONCE(rsp->gpnum), 2089 READ_ONCE(rsp->gpnum),
2038 TPS("fqsend")); 2090 TPS("fqsend"));
2039 cond_resched_rcu_qs(); 2091 cond_resched_rcu_qs();
2040 ACCESS_ONCE(rsp->gp_activity) = jiffies; 2092 WRITE_ONCE(rsp->gp_activity, jiffies);
2041 } else { 2093 } else {
2042 /* Deal with stray signal. */ 2094 /* Deal with stray signal. */
2043 cond_resched_rcu_qs(); 2095 cond_resched_rcu_qs();
2044 ACCESS_ONCE(rsp->gp_activity) = jiffies; 2096 WRITE_ONCE(rsp->gp_activity, jiffies);
2045 WARN_ON(signal_pending(current)); 2097 WARN_ON(signal_pending(current));
2046 trace_rcu_grace_period(rsp->name, 2098 trace_rcu_grace_period(rsp->name,
2047 ACCESS_ONCE(rsp->gpnum), 2099 READ_ONCE(rsp->gpnum),
2048 TPS("fqswaitsig")); 2100 TPS("fqswaitsig"));
2049 } 2101 }
2050 j = jiffies_till_next_fqs; 2102 j = jiffies_till_next_fqs;
@@ -2086,8 +2138,8 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
2086 */ 2138 */
2087 return false; 2139 return false;
2088 } 2140 }
2089 ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT; 2141 WRITE_ONCE(rsp->gp_flags, RCU_GP_FLAG_INIT);
2090 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum), 2142 trace_rcu_grace_period(rsp->name, READ_ONCE(rsp->gpnum),
2091 TPS("newreq")); 2143 TPS("newreq"));
2092 2144
2093 /* 2145 /*
@@ -2137,6 +2189,7 @@ static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags)
2137 __releases(rcu_get_root(rsp)->lock) 2189 __releases(rcu_get_root(rsp)->lock)
2138{ 2190{
2139 WARN_ON_ONCE(!rcu_gp_in_progress(rsp)); 2191 WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
2192 WRITE_ONCE(rsp->gp_flags, READ_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS);
2140 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags); 2193 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
2141 rcu_gp_kthread_wake(rsp); 2194 rcu_gp_kthread_wake(rsp);
2142} 2195}
@@ -2334,8 +2387,6 @@ rcu_check_quiescent_state(struct rcu_state *rsp, struct rcu_data *rdp)
2334 rcu_report_qs_rdp(rdp->cpu, rsp, rdp); 2387 rcu_report_qs_rdp(rdp->cpu, rsp, rdp);
2335} 2388}
2336 2389
2337#ifdef CONFIG_HOTPLUG_CPU
2338
2339/* 2390/*
2340 * Send the specified CPU's RCU callbacks to the orphanage. The 2391 * Send the specified CPU's RCU callbacks to the orphanage. The
2341 * specified CPU must be offline, and the caller must hold the 2392 * specified CPU must be offline, and the caller must hold the
@@ -2346,7 +2397,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
2346 struct rcu_node *rnp, struct rcu_data *rdp) 2397 struct rcu_node *rnp, struct rcu_data *rdp)
2347{ 2398{
2348 /* No-CBs CPUs do not have orphanable callbacks. */ 2399 /* No-CBs CPUs do not have orphanable callbacks. */
2349 if (rcu_is_nocb_cpu(rdp->cpu)) 2400 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) || rcu_is_nocb_cpu(rdp->cpu))
2350 return; 2401 return;
2351 2402
2352 /* 2403 /*
@@ -2359,7 +2410,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
2359 rsp->qlen += rdp->qlen; 2410 rsp->qlen += rdp->qlen;
2360 rdp->n_cbs_orphaned += rdp->qlen; 2411 rdp->n_cbs_orphaned += rdp->qlen;
2361 rdp->qlen_lazy = 0; 2412 rdp->qlen_lazy = 0;
2362 ACCESS_ONCE(rdp->qlen) = 0; 2413 WRITE_ONCE(rdp->qlen, 0);
2363 } 2414 }
2364 2415
2365 /* 2416 /*
@@ -2405,7 +2456,8 @@ static void rcu_adopt_orphan_cbs(struct rcu_state *rsp, unsigned long flags)
2405 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda); 2456 struct rcu_data *rdp = raw_cpu_ptr(rsp->rda);
2406 2457
2407 /* No-CBs CPUs are handled specially. */ 2458 /* No-CBs CPUs are handled specially. */
2408 if (rcu_nocb_adopt_orphan_cbs(rsp, rdp, flags)) 2459 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) ||
2460 rcu_nocb_adopt_orphan_cbs(rsp, rdp, flags))
2409 return; 2461 return;
2410 2462
2411 /* Do the accounting first. */ 2463 /* Do the accounting first. */
@@ -2452,6 +2504,9 @@ static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
2452 RCU_TRACE(struct rcu_data *rdp = this_cpu_ptr(rsp->rda)); 2504 RCU_TRACE(struct rcu_data *rdp = this_cpu_ptr(rsp->rda));
2453 RCU_TRACE(struct rcu_node *rnp = rdp->mynode); 2505 RCU_TRACE(struct rcu_node *rnp = rdp->mynode);
2454 2506
2507 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
2508 return;
2509
2455 RCU_TRACE(mask = rdp->grpmask); 2510 RCU_TRACE(mask = rdp->grpmask);
2456 trace_rcu_grace_period(rsp->name, 2511 trace_rcu_grace_period(rsp->name,
2457 rnp->gpnum + 1 - !!(rnp->qsmask & mask), 2512 rnp->gpnum + 1 - !!(rnp->qsmask & mask),
@@ -2480,7 +2535,8 @@ static void rcu_cleanup_dead_rnp(struct rcu_node *rnp_leaf)
2480 long mask; 2535 long mask;
2481 struct rcu_node *rnp = rnp_leaf; 2536 struct rcu_node *rnp = rnp_leaf;
2482 2537
2483 if (rnp->qsmaskinit || rcu_preempt_has_tasks(rnp)) 2538 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) ||
2539 rnp->qsmaskinit || rcu_preempt_has_tasks(rnp))
2484 return; 2540 return;
2485 for (;;) { 2541 for (;;) {
2486 mask = rnp->grpmask; 2542 mask = rnp->grpmask;
@@ -2511,6 +2567,9 @@ static void rcu_cleanup_dying_idle_cpu(int cpu, struct rcu_state *rsp)
2511 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu); 2567 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
2512 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */ 2568 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
2513 2569
2570 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
2571 return;
2572
2514 /* Remove outgoing CPU from mask in the leaf rcu_node structure. */ 2573 /* Remove outgoing CPU from mask in the leaf rcu_node structure. */
2515 mask = rdp->grpmask; 2574 mask = rdp->grpmask;
2516 raw_spin_lock_irqsave(&rnp->lock, flags); 2575 raw_spin_lock_irqsave(&rnp->lock, flags);
@@ -2532,6 +2591,9 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
2532 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu); 2591 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
2533 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */ 2592 struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */
2534 2593
2594 if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
2595 return;
2596
2535 /* Adjust any no-longer-needed kthreads. */ 2597 /* Adjust any no-longer-needed kthreads. */
2536 rcu_boost_kthread_setaffinity(rnp, -1); 2598 rcu_boost_kthread_setaffinity(rnp, -1);
2537 2599
@@ -2546,26 +2608,6 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
2546 cpu, rdp->qlen, rdp->nxtlist); 2608 cpu, rdp->qlen, rdp->nxtlist);
2547} 2609}
2548 2610
2549#else /* #ifdef CONFIG_HOTPLUG_CPU */
2550
2551static void rcu_cleanup_dying_cpu(struct rcu_state *rsp)
2552{
2553}
2554
2555static void __maybe_unused rcu_cleanup_dead_rnp(struct rcu_node *rnp_leaf)
2556{
2557}
2558
2559static void rcu_cleanup_dying_idle_cpu(int cpu, struct rcu_state *rsp)
2560{
2561}
2562
2563static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
2564{
2565}
2566
2567#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
2568
2569/* 2611/*
2570 * Invoke any RCU callbacks that have made it to the end of their grace 2612 * Invoke any RCU callbacks that have made it to the end of their grace
2571 * period. Thottle as specified by rdp->blimit. 2613 * period. Thottle as specified by rdp->blimit.
@@ -2580,7 +2622,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
2580 /* If no callbacks are ready, just return. */ 2622 /* If no callbacks are ready, just return. */
2581 if (!cpu_has_callbacks_ready_to_invoke(rdp)) { 2623 if (!cpu_has_callbacks_ready_to_invoke(rdp)) {
2582 trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, 0); 2624 trace_rcu_batch_start(rsp->name, rdp->qlen_lazy, rdp->qlen, 0);
2583 trace_rcu_batch_end(rsp->name, 0, !!ACCESS_ONCE(rdp->nxtlist), 2625 trace_rcu_batch_end(rsp->name, 0, !!READ_ONCE(rdp->nxtlist),
2584 need_resched(), is_idle_task(current), 2626 need_resched(), is_idle_task(current),
2585 rcu_is_callbacks_kthread()); 2627 rcu_is_callbacks_kthread());
2586 return; 2628 return;
@@ -2636,7 +2678,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
2636 } 2678 }
2637 smp_mb(); /* List handling before counting for rcu_barrier(). */ 2679 smp_mb(); /* List handling before counting for rcu_barrier(). */
2638 rdp->qlen_lazy -= count_lazy; 2680 rdp->qlen_lazy -= count_lazy;
2639 ACCESS_ONCE(rdp->qlen) = rdp->qlen - count; 2681 WRITE_ONCE(rdp->qlen, rdp->qlen - count);
2640 rdp->n_cbs_invoked += count; 2682 rdp->n_cbs_invoked += count;
2641 2683
2642 /* Reinstate batch limit if we have worked down the excess. */ 2684 /* Reinstate batch limit if we have worked down the excess. */
@@ -2730,10 +2772,6 @@ static void force_qs_rnp(struct rcu_state *rsp,
2730 mask = 0; 2772 mask = 0;
2731 raw_spin_lock_irqsave(&rnp->lock, flags); 2773 raw_spin_lock_irqsave(&rnp->lock, flags);
2732 smp_mb__after_unlock_lock(); 2774 smp_mb__after_unlock_lock();
2733 if (!rcu_gp_in_progress(rsp)) {
2734 raw_spin_unlock_irqrestore(&rnp->lock, flags);
2735 return;
2736 }
2737 if (rnp->qsmask == 0) { 2775 if (rnp->qsmask == 0) {
2738 if (rcu_state_p == &rcu_sched_state || 2776 if (rcu_state_p == &rcu_sched_state ||
2739 rsp != rcu_state_p || 2777 rsp != rcu_state_p ||
@@ -2763,8 +2801,6 @@ static void force_qs_rnp(struct rcu_state *rsp,
2763 bit = 1; 2801 bit = 1;
2764 for (; cpu <= rnp->grphi; cpu++, bit <<= 1) { 2802 for (; cpu <= rnp->grphi; cpu++, bit <<= 1) {
2765 if ((rnp->qsmask & bit) != 0) { 2803 if ((rnp->qsmask & bit) != 0) {
2766 if ((rnp->qsmaskinit & bit) == 0)
2767 *isidle = false; /* Pending hotplug. */
2768 if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj)) 2804 if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj))
2769 mask |= bit; 2805 mask |= bit;
2770 } 2806 }
@@ -2793,7 +2829,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
2793 /* Funnel through hierarchy to reduce memory contention. */ 2829 /* Funnel through hierarchy to reduce memory contention. */
2794 rnp = __this_cpu_read(rsp->rda->mynode); 2830 rnp = __this_cpu_read(rsp->rda->mynode);
2795 for (; rnp != NULL; rnp = rnp->parent) { 2831 for (; rnp != NULL; rnp = rnp->parent) {
2796 ret = (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) || 2832 ret = (READ_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) ||
2797 !raw_spin_trylock(&rnp->fqslock); 2833 !raw_spin_trylock(&rnp->fqslock);
2798 if (rnp_old != NULL) 2834 if (rnp_old != NULL)
2799 raw_spin_unlock(&rnp_old->fqslock); 2835 raw_spin_unlock(&rnp_old->fqslock);
@@ -2809,13 +2845,12 @@ static void force_quiescent_state(struct rcu_state *rsp)
2809 raw_spin_lock_irqsave(&rnp_old->lock, flags); 2845 raw_spin_lock_irqsave(&rnp_old->lock, flags);
2810 smp_mb__after_unlock_lock(); 2846 smp_mb__after_unlock_lock();
2811 raw_spin_unlock(&rnp_old->fqslock); 2847 raw_spin_unlock(&rnp_old->fqslock);
2812 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) { 2848 if (READ_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
2813 rsp->n_force_qs_lh++; 2849 rsp->n_force_qs_lh++;
2814 raw_spin_unlock_irqrestore(&rnp_old->lock, flags); 2850 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
2815 return; /* Someone beat us to it. */ 2851 return; /* Someone beat us to it. */
2816 } 2852 }
2817 ACCESS_ONCE(rsp->gp_flags) = 2853 WRITE_ONCE(rsp->gp_flags, READ_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS);
2818 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
2819 raw_spin_unlock_irqrestore(&rnp_old->lock, flags); 2854 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
2820 rcu_gp_kthread_wake(rsp); 2855 rcu_gp_kthread_wake(rsp);
2821} 2856}
@@ -2881,7 +2916,7 @@ static void rcu_process_callbacks(struct softirq_action *unused)
2881 */ 2916 */
2882static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) 2917static void invoke_rcu_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
2883{ 2918{
2884 if (unlikely(!ACCESS_ONCE(rcu_scheduler_fully_active))) 2919 if (unlikely(!READ_ONCE(rcu_scheduler_fully_active)))
2885 return; 2920 return;
2886 if (likely(!rsp->boost)) { 2921 if (likely(!rsp->boost)) {
2887 rcu_do_batch(rsp, rdp); 2922 rcu_do_batch(rsp, rdp);
@@ -2972,7 +3007,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
2972 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */ 3007 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
2973 if (debug_rcu_head_queue(head)) { 3008 if (debug_rcu_head_queue(head)) {
2974 /* Probable double call_rcu(), so leak the callback. */ 3009 /* Probable double call_rcu(), so leak the callback. */
2975 ACCESS_ONCE(head->func) = rcu_leak_callback; 3010 WRITE_ONCE(head->func, rcu_leak_callback);
2976 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n"); 3011 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
2977 return; 3012 return;
2978 } 3013 }
@@ -3011,7 +3046,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
3011 if (!likely(rdp->nxtlist)) 3046 if (!likely(rdp->nxtlist))
3012 init_default_callback_list(rdp); 3047 init_default_callback_list(rdp);
3013 } 3048 }
3014 ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1; 3049 WRITE_ONCE(rdp->qlen, rdp->qlen + 1);
3015 if (lazy) 3050 if (lazy)
3016 rdp->qlen_lazy++; 3051 rdp->qlen_lazy++;
3017 else 3052 else
@@ -3287,7 +3322,7 @@ void synchronize_sched_expedited(void)
3287 if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start), 3322 if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
3288 (ulong)atomic_long_read(&rsp->expedited_done) + 3323 (ulong)atomic_long_read(&rsp->expedited_done) +
3289 ULONG_MAX / 8)) { 3324 ULONG_MAX / 8)) {
3290 synchronize_sched(); 3325 wait_rcu_gp(call_rcu_sched);
3291 atomic_long_inc(&rsp->expedited_wrap); 3326 atomic_long_inc(&rsp->expedited_wrap);
3292 return; 3327 return;
3293 } 3328 }
@@ -3450,14 +3485,14 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
3450 } 3485 }
3451 3486
3452 /* Has another RCU grace period completed? */ 3487 /* Has another RCU grace period completed? */
3453 if (ACCESS_ONCE(rnp->completed) != rdp->completed) { /* outside lock */ 3488 if (READ_ONCE(rnp->completed) != rdp->completed) { /* outside lock */
3454 rdp->n_rp_gp_completed++; 3489 rdp->n_rp_gp_completed++;
3455 return 1; 3490 return 1;
3456 } 3491 }
3457 3492
3458 /* Has a new RCU grace period started? */ 3493 /* Has a new RCU grace period started? */
3459 if (ACCESS_ONCE(rnp->gpnum) != rdp->gpnum || 3494 if (READ_ONCE(rnp->gpnum) != rdp->gpnum ||
3460 unlikely(ACCESS_ONCE(rdp->gpwrap))) { /* outside lock */ 3495 unlikely(READ_ONCE(rdp->gpwrap))) { /* outside lock */
3461 rdp->n_rp_gp_started++; 3496 rdp->n_rp_gp_started++;
3462 return 1; 3497 return 1;
3463 } 3498 }
@@ -3493,7 +3528,7 @@ static int rcu_pending(void)
3493 * non-NULL, store an indication of whether all callbacks are lazy. 3528 * non-NULL, store an indication of whether all callbacks are lazy.
3494 * (If there are no callbacks, all of them are deemed to be lazy.) 3529 * (If there are no callbacks, all of them are deemed to be lazy.)
3495 */ 3530 */
3496static int __maybe_unused rcu_cpu_has_callbacks(bool *all_lazy) 3531static bool __maybe_unused rcu_cpu_has_callbacks(bool *all_lazy)
3497{ 3532{
3498 bool al = true; 3533 bool al = true;
3499 bool hc = false; 3534 bool hc = false;
@@ -3564,7 +3599,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
3564{ 3599{
3565 int cpu; 3600 int cpu;
3566 struct rcu_data *rdp; 3601 struct rcu_data *rdp;
3567 unsigned long snap = ACCESS_ONCE(rsp->n_barrier_done); 3602 unsigned long snap = READ_ONCE(rsp->n_barrier_done);
3568 unsigned long snap_done; 3603 unsigned long snap_done;
3569 3604
3570 _rcu_barrier_trace(rsp, "Begin", -1, snap); 3605 _rcu_barrier_trace(rsp, "Begin", -1, snap);
@@ -3606,10 +3641,10 @@ static void _rcu_barrier(struct rcu_state *rsp)
3606 3641
3607 /* 3642 /*
3608 * Increment ->n_barrier_done to avoid duplicate work. Use 3643 * Increment ->n_barrier_done to avoid duplicate work. Use
3609 * ACCESS_ONCE() to prevent the compiler from speculating 3644 * WRITE_ONCE() to prevent the compiler from speculating
3610 * the increment to precede the early-exit check. 3645 * the increment to precede the early-exit check.
3611 */ 3646 */
3612 ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1; 3647 WRITE_ONCE(rsp->n_barrier_done, rsp->n_barrier_done + 1);
3613 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1); 3648 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
3614 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done); 3649 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
3615 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */ 3650 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
@@ -3645,7 +3680,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
3645 __call_rcu(&rdp->barrier_head, 3680 __call_rcu(&rdp->barrier_head,
3646 rcu_barrier_callback, rsp, cpu, 0); 3681 rcu_barrier_callback, rsp, cpu, 0);
3647 } 3682 }
3648 } else if (ACCESS_ONCE(rdp->qlen)) { 3683 } else if (READ_ONCE(rdp->qlen)) {
3649 _rcu_barrier_trace(rsp, "OnlineQ", cpu, 3684 _rcu_barrier_trace(rsp, "OnlineQ", cpu,
3650 rsp->n_barrier_done); 3685 rsp->n_barrier_done);
3651 smp_call_function_single(cpu, rcu_barrier_func, rsp, 1); 3686 smp_call_function_single(cpu, rcu_barrier_func, rsp, 1);
@@ -3665,7 +3700,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
3665 3700
3666 /* Increment ->n_barrier_done to prevent duplicate work. */ 3701 /* Increment ->n_barrier_done to prevent duplicate work. */
3667 smp_mb(); /* Keep increment after above mechanism. */ 3702 smp_mb(); /* Keep increment after above mechanism. */
3668 ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1; 3703 WRITE_ONCE(rsp->n_barrier_done, rsp->n_barrier_done + 1);
3669 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0); 3704 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
3670 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done); 3705 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
3671 smp_mb(); /* Keep increment before caller's subsequent code. */ 3706 smp_mb(); /* Keep increment before caller's subsequent code. */
@@ -3780,7 +3815,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
3780 rdp->gpnum = rnp->completed; /* Make CPU later note any new GP. */ 3815 rdp->gpnum = rnp->completed; /* Make CPU later note any new GP. */
3781 rdp->completed = rnp->completed; 3816 rdp->completed = rnp->completed;
3782 rdp->passed_quiesce = false; 3817 rdp->passed_quiesce = false;
3783 rdp->rcu_qs_ctr_snap = __this_cpu_read(rcu_qs_ctr); 3818 rdp->rcu_qs_ctr_snap = per_cpu(rcu_qs_ctr, cpu);
3784 rdp->qs_pending = false; 3819 rdp->qs_pending = false;
3785 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuonl")); 3820 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("cpuonl"));
3786 raw_spin_unlock_irqrestore(&rnp->lock, flags); 3821 raw_spin_unlock_irqrestore(&rnp->lock, flags);
@@ -3924,16 +3959,16 @@ void rcu_scheduler_starting(void)
3924 3959
3925/* 3960/*
3926 * Compute the per-level fanout, either using the exact fanout specified 3961 * Compute the per-level fanout, either using the exact fanout specified
3927 * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT. 3962 * or balancing the tree, depending on the rcu_fanout_exact boot parameter.
3928 */ 3963 */
3929static void __init rcu_init_levelspread(struct rcu_state *rsp) 3964static void __init rcu_init_levelspread(struct rcu_state *rsp)
3930{ 3965{
3931 int i; 3966 int i;
3932 3967
3933 if (IS_ENABLED(CONFIG_RCU_FANOUT_EXACT)) { 3968 if (rcu_fanout_exact) {
3934 rsp->levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf; 3969 rsp->levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf;
3935 for (i = rcu_num_lvls - 2; i >= 0; i--) 3970 for (i = rcu_num_lvls - 2; i >= 0; i--)
3936 rsp->levelspread[i] = CONFIG_RCU_FANOUT; 3971 rsp->levelspread[i] = RCU_FANOUT;
3937 } else { 3972 } else {
3938 int ccur; 3973 int ccur;
3939 int cprv; 3974 int cprv;
@@ -3971,9 +4006,9 @@ static void __init rcu_init_one(struct rcu_state *rsp,
3971 4006
3972 BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf)); /* Fix buf[] init! */ 4007 BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf)); /* Fix buf[] init! */
3973 4008
3974 /* Silence gcc 4.8 warning about array index out of range. */ 4009 /* Silence gcc 4.8 false positive about array index out of range. */
3975 if (rcu_num_lvls > RCU_NUM_LVLS) 4010 if (rcu_num_lvls <= 0 || rcu_num_lvls > RCU_NUM_LVLS)
3976 panic("rcu_init_one: rcu_num_lvls overflow"); 4011 panic("rcu_init_one: rcu_num_lvls out of range");
3977 4012
3978 /* Initialize the level-tracking arrays. */ 4013 /* Initialize the level-tracking arrays. */
3979 4014
@@ -4059,7 +4094,7 @@ static void __init rcu_init_geometry(void)
4059 jiffies_till_next_fqs = d; 4094 jiffies_till_next_fqs = d;
4060 4095
4061 /* If the compile-time values are accurate, just leave. */ 4096 /* If the compile-time values are accurate, just leave. */
4062 if (rcu_fanout_leaf == CONFIG_RCU_FANOUT_LEAF && 4097 if (rcu_fanout_leaf == RCU_FANOUT_LEAF &&
4063 nr_cpu_ids == NR_CPUS) 4098 nr_cpu_ids == NR_CPUS)
4064 return; 4099 return;
4065 pr_info("RCU: Adjusting geometry for rcu_fanout_leaf=%d, nr_cpu_ids=%d\n", 4100 pr_info("RCU: Adjusting geometry for rcu_fanout_leaf=%d, nr_cpu_ids=%d\n",
@@ -4073,7 +4108,7 @@ static void __init rcu_init_geometry(void)
4073 rcu_capacity[0] = 1; 4108 rcu_capacity[0] = 1;
4074 rcu_capacity[1] = rcu_fanout_leaf; 4109 rcu_capacity[1] = rcu_fanout_leaf;
4075 for (i = 2; i <= MAX_RCU_LVLS; i++) 4110 for (i = 2; i <= MAX_RCU_LVLS; i++)
4076 rcu_capacity[i] = rcu_capacity[i - 1] * CONFIG_RCU_FANOUT; 4111 rcu_capacity[i] = rcu_capacity[i - 1] * RCU_FANOUT;
4077 4112
4078 /* 4113 /*
4079 * The boot-time rcu_fanout_leaf parameter is only permitted 4114 * The boot-time rcu_fanout_leaf parameter is only permitted
@@ -4083,7 +4118,7 @@ static void __init rcu_init_geometry(void)
4083 * the configured number of CPUs. Complain and fall back to the 4118 * the configured number of CPUs. Complain and fall back to the
4084 * compile-time values if these limits are exceeded. 4119 * compile-time values if these limits are exceeded.
4085 */ 4120 */
4086 if (rcu_fanout_leaf < CONFIG_RCU_FANOUT_LEAF || 4121 if (rcu_fanout_leaf < RCU_FANOUT_LEAF ||
4087 rcu_fanout_leaf > sizeof(unsigned long) * 8 || 4122 rcu_fanout_leaf > sizeof(unsigned long) * 8 ||
4088 n > rcu_capacity[MAX_RCU_LVLS]) { 4123 n > rcu_capacity[MAX_RCU_LVLS]) {
4089 WARN_ON(1); 4124 WARN_ON(1);
@@ -4109,6 +4144,28 @@ static void __init rcu_init_geometry(void)
4109 rcu_num_nodes -= n; 4144 rcu_num_nodes -= n;
4110} 4145}
4111 4146
4147/*
4148 * Dump out the structure of the rcu_node combining tree associated
4149 * with the rcu_state structure referenced by rsp.
4150 */
4151static void __init rcu_dump_rcu_node_tree(struct rcu_state *rsp)
4152{
4153 int level = 0;
4154 struct rcu_node *rnp;
4155
4156 pr_info("rcu_node tree layout dump\n");
4157 pr_info(" ");
4158 rcu_for_each_node_breadth_first(rsp, rnp) {
4159 if (rnp->level != level) {
4160 pr_cont("\n");
4161 pr_info(" ");
4162 level = rnp->level;
4163 }
4164 pr_cont("%d:%d ^%d ", rnp->grplo, rnp->grphi, rnp->grpnum);
4165 }
4166 pr_cont("\n");
4167}
4168
4112void __init rcu_init(void) 4169void __init rcu_init(void)
4113{ 4170{
4114 int cpu; 4171 int cpu;
@@ -4119,6 +4176,8 @@ void __init rcu_init(void)
4119 rcu_init_geometry(); 4176 rcu_init_geometry();
4120 rcu_init_one(&rcu_bh_state, &rcu_bh_data); 4177 rcu_init_one(&rcu_bh_state, &rcu_bh_data);
4121 rcu_init_one(&rcu_sched_state, &rcu_sched_data); 4178 rcu_init_one(&rcu_sched_state, &rcu_sched_data);
4179 if (dump_tree)
4180 rcu_dump_rcu_node_tree(&rcu_sched_state);
4122 __rcu_init_preempt(); 4181 __rcu_init_preempt();
4123 open_softirq(RCU_SOFTIRQ, rcu_process_callbacks); 4182 open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
4124 4183
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index a69d3dab2ec4..4adb7ca0bf47 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -35,11 +35,33 @@
35 * In practice, this did work well going from three levels to four. 35 * In practice, this did work well going from three levels to four.
36 * Of course, your mileage may vary. 36 * Of course, your mileage may vary.
37 */ 37 */
38
38#define MAX_RCU_LVLS 4 39#define MAX_RCU_LVLS 4
39#define RCU_FANOUT_1 (CONFIG_RCU_FANOUT_LEAF) 40
40#define RCU_FANOUT_2 (RCU_FANOUT_1 * CONFIG_RCU_FANOUT) 41#ifdef CONFIG_RCU_FANOUT
41#define RCU_FANOUT_3 (RCU_FANOUT_2 * CONFIG_RCU_FANOUT) 42#define RCU_FANOUT CONFIG_RCU_FANOUT
42#define RCU_FANOUT_4 (RCU_FANOUT_3 * CONFIG_RCU_FANOUT) 43#else /* #ifdef CONFIG_RCU_FANOUT */
44# ifdef CONFIG_64BIT
45# define RCU_FANOUT 64
46# else
47# define RCU_FANOUT 32
48# endif
49#endif /* #else #ifdef CONFIG_RCU_FANOUT */
50
51#ifdef CONFIG_RCU_FANOUT_LEAF
52#define RCU_FANOUT_LEAF CONFIG_RCU_FANOUT_LEAF
53#else /* #ifdef CONFIG_RCU_FANOUT_LEAF */
54# ifdef CONFIG_64BIT
55# define RCU_FANOUT_LEAF 64
56# else
57# define RCU_FANOUT_LEAF 32
58# endif
59#endif /* #else #ifdef CONFIG_RCU_FANOUT_LEAF */
60
61#define RCU_FANOUT_1 (RCU_FANOUT_LEAF)
62#define RCU_FANOUT_2 (RCU_FANOUT_1 * RCU_FANOUT)
63#define RCU_FANOUT_3 (RCU_FANOUT_2 * RCU_FANOUT)
64#define RCU_FANOUT_4 (RCU_FANOUT_3 * RCU_FANOUT)
43 65
44#if NR_CPUS <= RCU_FANOUT_1 66#if NR_CPUS <= RCU_FANOUT_1
45# define RCU_NUM_LVLS 1 67# define RCU_NUM_LVLS 1
@@ -170,7 +192,6 @@ struct rcu_node {
170 /* if there is no such task. If there */ 192 /* if there is no such task. If there */
171 /* is no current expedited grace period, */ 193 /* is no current expedited grace period, */
172 /* then there can cannot be any such task. */ 194 /* then there can cannot be any such task. */
173#ifdef CONFIG_RCU_BOOST
174 struct list_head *boost_tasks; 195 struct list_head *boost_tasks;
175 /* Pointer to first task that needs to be */ 196 /* Pointer to first task that needs to be */
176 /* priority boosted, or NULL if no priority */ 197 /* priority boosted, or NULL if no priority */
@@ -208,7 +229,6 @@ struct rcu_node {
208 unsigned long n_balk_nos; 229 unsigned long n_balk_nos;
209 /* Refused to boost: not sure why, though. */ 230 /* Refused to boost: not sure why, though. */
210 /* This can happen due to race conditions. */ 231 /* This can happen due to race conditions. */
211#endif /* #ifdef CONFIG_RCU_BOOST */
212#ifdef CONFIG_RCU_NOCB_CPU 232#ifdef CONFIG_RCU_NOCB_CPU
213 wait_queue_head_t nocb_gp_wq[2]; 233 wait_queue_head_t nocb_gp_wq[2];
214 /* Place for rcu_nocb_kthread() to wait GP. */ 234 /* Place for rcu_nocb_kthread() to wait GP. */
@@ -519,14 +539,11 @@ extern struct list_head rcu_struct_flavors;
519 * RCU implementation internal declarations: 539 * RCU implementation internal declarations:
520 */ 540 */
521extern struct rcu_state rcu_sched_state; 541extern struct rcu_state rcu_sched_state;
522DECLARE_PER_CPU(struct rcu_data, rcu_sched_data);
523 542
524extern struct rcu_state rcu_bh_state; 543extern struct rcu_state rcu_bh_state;
525DECLARE_PER_CPU(struct rcu_data, rcu_bh_data);
526 544
527#ifdef CONFIG_PREEMPT_RCU 545#ifdef CONFIG_PREEMPT_RCU
528extern struct rcu_state rcu_preempt_state; 546extern struct rcu_state rcu_preempt_state;
529DECLARE_PER_CPU(struct rcu_data, rcu_preempt_data);
530#endif /* #ifdef CONFIG_PREEMPT_RCU */ 547#endif /* #ifdef CONFIG_PREEMPT_RCU */
531 548
532#ifdef CONFIG_RCU_BOOST 549#ifdef CONFIG_RCU_BOOST
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 8c0ec0f5a027..32664347091a 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -43,7 +43,17 @@ DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
43DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops); 43DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
44DEFINE_PER_CPU(char, rcu_cpu_has_work); 44DEFINE_PER_CPU(char, rcu_cpu_has_work);
45 45
46#endif /* #ifdef CONFIG_RCU_BOOST */ 46#else /* #ifdef CONFIG_RCU_BOOST */
47
48/*
49 * Some architectures do not define rt_mutexes, but if !CONFIG_RCU_BOOST,
50 * all uses are in dead code. Provide a definition to keep the compiler
51 * happy, but add WARN_ON_ONCE() to complain if used in the wrong place.
52 * This probably needs to be excluded from -rt builds.
53 */
54#define rt_mutex_owner(a) ({ WARN_ON_ONCE(1); NULL; })
55
56#endif /* #else #ifdef CONFIG_RCU_BOOST */
47 57
48#ifdef CONFIG_RCU_NOCB_CPU 58#ifdef CONFIG_RCU_NOCB_CPU
49static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */ 59static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */
@@ -60,11 +70,11 @@ static void __init rcu_bootup_announce_oddness(void)
60{ 70{
61 if (IS_ENABLED(CONFIG_RCU_TRACE)) 71 if (IS_ENABLED(CONFIG_RCU_TRACE))
62 pr_info("\tRCU debugfs-based tracing is enabled.\n"); 72 pr_info("\tRCU debugfs-based tracing is enabled.\n");
63 if ((IS_ENABLED(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || 73 if ((IS_ENABLED(CONFIG_64BIT) && RCU_FANOUT != 64) ||
64 (!IS_ENABLED(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32)) 74 (!IS_ENABLED(CONFIG_64BIT) && RCU_FANOUT != 32))
65 pr_info("\tCONFIG_RCU_FANOUT set to non-default value of %d\n", 75 pr_info("\tCONFIG_RCU_FANOUT set to non-default value of %d\n",
66 CONFIG_RCU_FANOUT); 76 RCU_FANOUT);
67 if (IS_ENABLED(CONFIG_RCU_FANOUT_EXACT)) 77 if (rcu_fanout_exact)
68 pr_info("\tHierarchical RCU autobalancing is disabled.\n"); 78 pr_info("\tHierarchical RCU autobalancing is disabled.\n");
69 if (IS_ENABLED(CONFIG_RCU_FAST_NO_HZ)) 79 if (IS_ENABLED(CONFIG_RCU_FAST_NO_HZ))
70 pr_info("\tRCU dyntick-idle grace-period acceleration is enabled.\n"); 80 pr_info("\tRCU dyntick-idle grace-period acceleration is enabled.\n");
@@ -76,10 +86,10 @@ static void __init rcu_bootup_announce_oddness(void)
76 pr_info("\tAdditional per-CPU info printed with stalls.\n"); 86 pr_info("\tAdditional per-CPU info printed with stalls.\n");
77 if (NUM_RCU_LVL_4 != 0) 87 if (NUM_RCU_LVL_4 != 0)
78 pr_info("\tFour-level hierarchy is enabled.\n"); 88 pr_info("\tFour-level hierarchy is enabled.\n");
79 if (CONFIG_RCU_FANOUT_LEAF != 16) 89 if (RCU_FANOUT_LEAF != 16)
80 pr_info("\tBuild-time adjustment of leaf fanout to %d.\n", 90 pr_info("\tBuild-time adjustment of leaf fanout to %d.\n",
81 CONFIG_RCU_FANOUT_LEAF); 91 RCU_FANOUT_LEAF);
82 if (rcu_fanout_leaf != CONFIG_RCU_FANOUT_LEAF) 92 if (rcu_fanout_leaf != RCU_FANOUT_LEAF)
83 pr_info("\tBoot-time adjustment of leaf fanout to %d.\n", rcu_fanout_leaf); 93 pr_info("\tBoot-time adjustment of leaf fanout to %d.\n", rcu_fanout_leaf);
84 if (nr_cpu_ids != NR_CPUS) 94 if (nr_cpu_ids != NR_CPUS)
85 pr_info("\tRCU restricting CPUs from NR_CPUS=%d to nr_cpu_ids=%d.\n", NR_CPUS, nr_cpu_ids); 95 pr_info("\tRCU restricting CPUs from NR_CPUS=%d to nr_cpu_ids=%d.\n", NR_CPUS, nr_cpu_ids);
@@ -90,7 +100,8 @@ static void __init rcu_bootup_announce_oddness(void)
90#ifdef CONFIG_PREEMPT_RCU 100#ifdef CONFIG_PREEMPT_RCU
91 101
92RCU_STATE_INITIALIZER(rcu_preempt, 'p', call_rcu); 102RCU_STATE_INITIALIZER(rcu_preempt, 'p', call_rcu);
93static struct rcu_state *rcu_state_p = &rcu_preempt_state; 103static struct rcu_state *const rcu_state_p = &rcu_preempt_state;
104static struct rcu_data __percpu *const rcu_data_p = &rcu_preempt_data;
94 105
95static int rcu_preempted_readers_exp(struct rcu_node *rnp); 106static int rcu_preempted_readers_exp(struct rcu_node *rnp);
96static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp, 107static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
@@ -116,11 +127,11 @@ static void __init rcu_bootup_announce(void)
116 */ 127 */
117static void rcu_preempt_qs(void) 128static void rcu_preempt_qs(void)
118{ 129{
119 if (!__this_cpu_read(rcu_preempt_data.passed_quiesce)) { 130 if (!__this_cpu_read(rcu_data_p->passed_quiesce)) {
120 trace_rcu_grace_period(TPS("rcu_preempt"), 131 trace_rcu_grace_period(TPS("rcu_preempt"),
121 __this_cpu_read(rcu_preempt_data.gpnum), 132 __this_cpu_read(rcu_data_p->gpnum),
122 TPS("cpuqs")); 133 TPS("cpuqs"));
123 __this_cpu_write(rcu_preempt_data.passed_quiesce, 1); 134 __this_cpu_write(rcu_data_p->passed_quiesce, 1);
124 barrier(); /* Coordinate with rcu_preempt_check_callbacks(). */ 135 barrier(); /* Coordinate with rcu_preempt_check_callbacks(). */
125 current->rcu_read_unlock_special.b.need_qs = false; 136 current->rcu_read_unlock_special.b.need_qs = false;
126 } 137 }
@@ -150,7 +161,7 @@ static void rcu_preempt_note_context_switch(void)
150 !t->rcu_read_unlock_special.b.blocked) { 161 !t->rcu_read_unlock_special.b.blocked) {
151 162
152 /* Possibly blocking in an RCU read-side critical section. */ 163 /* Possibly blocking in an RCU read-side critical section. */
153 rdp = this_cpu_ptr(rcu_preempt_state.rda); 164 rdp = this_cpu_ptr(rcu_state_p->rda);
154 rnp = rdp->mynode; 165 rnp = rdp->mynode;
155 raw_spin_lock_irqsave(&rnp->lock, flags); 166 raw_spin_lock_irqsave(&rnp->lock, flags);
156 smp_mb__after_unlock_lock(); 167 smp_mb__after_unlock_lock();
@@ -180,10 +191,9 @@ static void rcu_preempt_note_context_switch(void)
180 if ((rnp->qsmask & rdp->grpmask) && rnp->gp_tasks != NULL) { 191 if ((rnp->qsmask & rdp->grpmask) && rnp->gp_tasks != NULL) {
181 list_add(&t->rcu_node_entry, rnp->gp_tasks->prev); 192 list_add(&t->rcu_node_entry, rnp->gp_tasks->prev);
182 rnp->gp_tasks = &t->rcu_node_entry; 193 rnp->gp_tasks = &t->rcu_node_entry;
183#ifdef CONFIG_RCU_BOOST 194 if (IS_ENABLED(CONFIG_RCU_BOOST) &&
184 if (rnp->boost_tasks != NULL) 195 rnp->boost_tasks != NULL)
185 rnp->boost_tasks = rnp->gp_tasks; 196 rnp->boost_tasks = rnp->gp_tasks;
186#endif /* #ifdef CONFIG_RCU_BOOST */
187 } else { 197 } else {
188 list_add(&t->rcu_node_entry, &rnp->blkd_tasks); 198 list_add(&t->rcu_node_entry, &rnp->blkd_tasks);
189 if (rnp->qsmask & rdp->grpmask) 199 if (rnp->qsmask & rdp->grpmask)
@@ -263,9 +273,7 @@ void rcu_read_unlock_special(struct task_struct *t)
263 bool empty_exp_now; 273 bool empty_exp_now;
264 unsigned long flags; 274 unsigned long flags;
265 struct list_head *np; 275 struct list_head *np;
266#ifdef CONFIG_RCU_BOOST
267 bool drop_boost_mutex = false; 276 bool drop_boost_mutex = false;
268#endif /* #ifdef CONFIG_RCU_BOOST */
269 struct rcu_node *rnp; 277 struct rcu_node *rnp;
270 union rcu_special special; 278 union rcu_special special;
271 279
@@ -307,9 +315,11 @@ void rcu_read_unlock_special(struct task_struct *t)
307 t->rcu_read_unlock_special.b.blocked = false; 315 t->rcu_read_unlock_special.b.blocked = false;
308 316
309 /* 317 /*
310 * Remove this task from the list it blocked on. The 318 * Remove this task from the list it blocked on. The task
311 * task can migrate while we acquire the lock, but at 319 * now remains queued on the rcu_node corresponding to
312 * most one time. So at most two passes through loop. 320 * the CPU it first blocked on, so the first attempt to
321 * acquire the task's rcu_node's ->lock will succeed.
322 * Keep the loop and add a WARN_ON() out of sheer paranoia.
313 */ 323 */
314 for (;;) { 324 for (;;) {
315 rnp = t->rcu_blocked_node; 325 rnp = t->rcu_blocked_node;
@@ -317,6 +327,7 @@ void rcu_read_unlock_special(struct task_struct *t)
317 smp_mb__after_unlock_lock(); 327 smp_mb__after_unlock_lock();
318 if (rnp == t->rcu_blocked_node) 328 if (rnp == t->rcu_blocked_node)
319 break; 329 break;
330 WARN_ON_ONCE(1);
320 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */ 331 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
321 } 332 }
322 empty_norm = !rcu_preempt_blocked_readers_cgp(rnp); 333 empty_norm = !rcu_preempt_blocked_readers_cgp(rnp);
@@ -331,12 +342,12 @@ void rcu_read_unlock_special(struct task_struct *t)
331 rnp->gp_tasks = np; 342 rnp->gp_tasks = np;
332 if (&t->rcu_node_entry == rnp->exp_tasks) 343 if (&t->rcu_node_entry == rnp->exp_tasks)
333 rnp->exp_tasks = np; 344 rnp->exp_tasks = np;
334#ifdef CONFIG_RCU_BOOST 345 if (IS_ENABLED(CONFIG_RCU_BOOST)) {
335 if (&t->rcu_node_entry == rnp->boost_tasks) 346 if (&t->rcu_node_entry == rnp->boost_tasks)
336 rnp->boost_tasks = np; 347 rnp->boost_tasks = np;
337 /* Snapshot ->boost_mtx ownership with rcu_node lock held. */ 348 /* Snapshot ->boost_mtx ownership w/rnp->lock held. */
338 drop_boost_mutex = rt_mutex_owner(&rnp->boost_mtx) == t; 349 drop_boost_mutex = rt_mutex_owner(&rnp->boost_mtx) == t;
339#endif /* #ifdef CONFIG_RCU_BOOST */ 350 }
340 351
341 /* 352 /*
342 * If this was the last task on the current list, and if 353 * If this was the last task on the current list, and if
@@ -353,24 +364,21 @@ void rcu_read_unlock_special(struct task_struct *t)
353 rnp->grplo, 364 rnp->grplo,
354 rnp->grphi, 365 rnp->grphi,
355 !!rnp->gp_tasks); 366 !!rnp->gp_tasks);
356 rcu_report_unblock_qs_rnp(&rcu_preempt_state, 367 rcu_report_unblock_qs_rnp(rcu_state_p, rnp, flags);
357 rnp, flags);
358 } else { 368 } else {
359 raw_spin_unlock_irqrestore(&rnp->lock, flags); 369 raw_spin_unlock_irqrestore(&rnp->lock, flags);
360 } 370 }
361 371
362#ifdef CONFIG_RCU_BOOST
363 /* Unboost if we were boosted. */ 372 /* Unboost if we were boosted. */
364 if (drop_boost_mutex) 373 if (IS_ENABLED(CONFIG_RCU_BOOST) && drop_boost_mutex)
365 rt_mutex_unlock(&rnp->boost_mtx); 374 rt_mutex_unlock(&rnp->boost_mtx);
366#endif /* #ifdef CONFIG_RCU_BOOST */
367 375
368 /* 376 /*
369 * If this was the last task on the expedited lists, 377 * If this was the last task on the expedited lists,
370 * then we need to report up the rcu_node hierarchy. 378 * then we need to report up the rcu_node hierarchy.
371 */ 379 */
372 if (!empty_exp && empty_exp_now) 380 if (!empty_exp && empty_exp_now)
373 rcu_report_exp_rnp(&rcu_preempt_state, rnp, true); 381 rcu_report_exp_rnp(rcu_state_p, rnp, true);
374 } else { 382 } else {
375 local_irq_restore(flags); 383 local_irq_restore(flags);
376 } 384 }
@@ -390,7 +398,7 @@ static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
390 raw_spin_unlock_irqrestore(&rnp->lock, flags); 398 raw_spin_unlock_irqrestore(&rnp->lock, flags);
391 return; 399 return;
392 } 400 }
393 t = list_entry(rnp->gp_tasks, 401 t = list_entry(rnp->gp_tasks->prev,
394 struct task_struct, rcu_node_entry); 402 struct task_struct, rcu_node_entry);
395 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) 403 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry)
396 sched_show_task(t); 404 sched_show_task(t);
@@ -447,7 +455,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp)
447 if (!rcu_preempt_blocked_readers_cgp(rnp)) 455 if (!rcu_preempt_blocked_readers_cgp(rnp))
448 return 0; 456 return 0;
449 rcu_print_task_stall_begin(rnp); 457 rcu_print_task_stall_begin(rnp);
450 t = list_entry(rnp->gp_tasks, 458 t = list_entry(rnp->gp_tasks->prev,
451 struct task_struct, rcu_node_entry); 459 struct task_struct, rcu_node_entry);
452 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) { 460 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
453 pr_cont(" P%d", t->pid); 461 pr_cont(" P%d", t->pid);
@@ -491,8 +499,8 @@ static void rcu_preempt_check_callbacks(void)
491 return; 499 return;
492 } 500 }
493 if (t->rcu_read_lock_nesting > 0 && 501 if (t->rcu_read_lock_nesting > 0 &&
494 __this_cpu_read(rcu_preempt_data.qs_pending) && 502 __this_cpu_read(rcu_data_p->qs_pending) &&
495 !__this_cpu_read(rcu_preempt_data.passed_quiesce)) 503 !__this_cpu_read(rcu_data_p->passed_quiesce))
496 t->rcu_read_unlock_special.b.need_qs = true; 504 t->rcu_read_unlock_special.b.need_qs = true;
497} 505}
498 506
@@ -500,7 +508,7 @@ static void rcu_preempt_check_callbacks(void)
500 508
501static void rcu_preempt_do_callbacks(void) 509static void rcu_preempt_do_callbacks(void)
502{ 510{
503 rcu_do_batch(&rcu_preempt_state, this_cpu_ptr(&rcu_preempt_data)); 511 rcu_do_batch(rcu_state_p, this_cpu_ptr(rcu_data_p));
504} 512}
505 513
506#endif /* #ifdef CONFIG_RCU_BOOST */ 514#endif /* #ifdef CONFIG_RCU_BOOST */
@@ -510,7 +518,7 @@ static void rcu_preempt_do_callbacks(void)
510 */ 518 */
511void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu)) 519void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
512{ 520{
513 __call_rcu(head, func, &rcu_preempt_state, -1, 0); 521 __call_rcu(head, func, rcu_state_p, -1, 0);
514} 522}
515EXPORT_SYMBOL_GPL(call_rcu); 523EXPORT_SYMBOL_GPL(call_rcu);
516 524
@@ -570,7 +578,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
570static int sync_rcu_preempt_exp_done(struct rcu_node *rnp) 578static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
571{ 579{
572 return !rcu_preempted_readers_exp(rnp) && 580 return !rcu_preempted_readers_exp(rnp) &&
573 ACCESS_ONCE(rnp->expmask) == 0; 581 READ_ONCE(rnp->expmask) == 0;
574} 582}
575 583
576/* 584/*
@@ -711,12 +719,12 @@ sync_rcu_preempt_exp_init2(struct rcu_state *rsp, struct rcu_node *rnp)
711void synchronize_rcu_expedited(void) 719void synchronize_rcu_expedited(void)
712{ 720{
713 struct rcu_node *rnp; 721 struct rcu_node *rnp;
714 struct rcu_state *rsp = &rcu_preempt_state; 722 struct rcu_state *rsp = rcu_state_p;
715 unsigned long snap; 723 unsigned long snap;
716 int trycount = 0; 724 int trycount = 0;
717 725
718 smp_mb(); /* Caller's modifications seen first by other CPUs. */ 726 smp_mb(); /* Caller's modifications seen first by other CPUs. */
719 snap = ACCESS_ONCE(sync_rcu_preempt_exp_count) + 1; 727 snap = READ_ONCE(sync_rcu_preempt_exp_count) + 1;
720 smp_mb(); /* Above access cannot bleed into critical section. */ 728 smp_mb(); /* Above access cannot bleed into critical section. */
721 729
722 /* 730 /*
@@ -740,7 +748,7 @@ void synchronize_rcu_expedited(void)
740 */ 748 */
741 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) { 749 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
742 if (ULONG_CMP_LT(snap, 750 if (ULONG_CMP_LT(snap,
743 ACCESS_ONCE(sync_rcu_preempt_exp_count))) { 751 READ_ONCE(sync_rcu_preempt_exp_count))) {
744 put_online_cpus(); 752 put_online_cpus();
745 goto mb_ret; /* Others did our work for us. */ 753 goto mb_ret; /* Others did our work for us. */
746 } 754 }
@@ -752,7 +760,7 @@ void synchronize_rcu_expedited(void)
752 return; 760 return;
753 } 761 }
754 } 762 }
755 if (ULONG_CMP_LT(snap, ACCESS_ONCE(sync_rcu_preempt_exp_count))) { 763 if (ULONG_CMP_LT(snap, READ_ONCE(sync_rcu_preempt_exp_count))) {
756 put_online_cpus(); 764 put_online_cpus();
757 goto unlock_mb_ret; /* Others did our work for us. */ 765 goto unlock_mb_ret; /* Others did our work for us. */
758 } 766 }
@@ -780,8 +788,7 @@ void synchronize_rcu_expedited(void)
780 788
781 /* Clean up and exit. */ 789 /* Clean up and exit. */
782 smp_mb(); /* ensure expedited GP seen before counter increment. */ 790 smp_mb(); /* ensure expedited GP seen before counter increment. */
783 ACCESS_ONCE(sync_rcu_preempt_exp_count) = 791 WRITE_ONCE(sync_rcu_preempt_exp_count, sync_rcu_preempt_exp_count + 1);
784 sync_rcu_preempt_exp_count + 1;
785unlock_mb_ret: 792unlock_mb_ret:
786 mutex_unlock(&sync_rcu_preempt_exp_mutex); 793 mutex_unlock(&sync_rcu_preempt_exp_mutex);
787mb_ret: 794mb_ret:
@@ -799,7 +806,7 @@ EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
799 */ 806 */
800void rcu_barrier(void) 807void rcu_barrier(void)
801{ 808{
802 _rcu_barrier(&rcu_preempt_state); 809 _rcu_barrier(rcu_state_p);
803} 810}
804EXPORT_SYMBOL_GPL(rcu_barrier); 811EXPORT_SYMBOL_GPL(rcu_barrier);
805 812
@@ -808,7 +815,7 @@ EXPORT_SYMBOL_GPL(rcu_barrier);
808 */ 815 */
809static void __init __rcu_init_preempt(void) 816static void __init __rcu_init_preempt(void)
810{ 817{
811 rcu_init_one(&rcu_preempt_state, &rcu_preempt_data); 818 rcu_init_one(rcu_state_p, rcu_data_p);
812} 819}
813 820
814/* 821/*
@@ -831,7 +838,8 @@ void exit_rcu(void)
831 838
832#else /* #ifdef CONFIG_PREEMPT_RCU */ 839#else /* #ifdef CONFIG_PREEMPT_RCU */
833 840
834static struct rcu_state *rcu_state_p = &rcu_sched_state; 841static struct rcu_state *const rcu_state_p = &rcu_sched_state;
842static struct rcu_data __percpu *const rcu_data_p = &rcu_sched_data;
835 843
836/* 844/*
837 * Tell them what RCU they are running. 845 * Tell them what RCU they are running.
@@ -994,8 +1002,8 @@ static int rcu_boost(struct rcu_node *rnp)
994 struct task_struct *t; 1002 struct task_struct *t;
995 struct list_head *tb; 1003 struct list_head *tb;
996 1004
997 if (ACCESS_ONCE(rnp->exp_tasks) == NULL && 1005 if (READ_ONCE(rnp->exp_tasks) == NULL &&
998 ACCESS_ONCE(rnp->boost_tasks) == NULL) 1006 READ_ONCE(rnp->boost_tasks) == NULL)
999 return 0; /* Nothing left to boost. */ 1007 return 0; /* Nothing left to boost. */
1000 1008
1001 raw_spin_lock_irqsave(&rnp->lock, flags); 1009 raw_spin_lock_irqsave(&rnp->lock, flags);
@@ -1048,8 +1056,8 @@ static int rcu_boost(struct rcu_node *rnp)
1048 rt_mutex_lock(&rnp->boost_mtx); 1056 rt_mutex_lock(&rnp->boost_mtx);
1049 rt_mutex_unlock(&rnp->boost_mtx); /* Then keep lockdep happy. */ 1057 rt_mutex_unlock(&rnp->boost_mtx); /* Then keep lockdep happy. */
1050 1058
1051 return ACCESS_ONCE(rnp->exp_tasks) != NULL || 1059 return READ_ONCE(rnp->exp_tasks) != NULL ||
1052 ACCESS_ONCE(rnp->boost_tasks) != NULL; 1060 READ_ONCE(rnp->boost_tasks) != NULL;
1053} 1061}
1054 1062
1055/* 1063/*
@@ -1173,7 +1181,7 @@ static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
1173 struct sched_param sp; 1181 struct sched_param sp;
1174 struct task_struct *t; 1182 struct task_struct *t;
1175 1183
1176 if (&rcu_preempt_state != rsp) 1184 if (rcu_state_p != rsp)
1177 return 0; 1185 return 0;
1178 1186
1179 if (!rcu_scheduler_fully_active || rcu_rnp_online_cpus(rnp) == 0) 1187 if (!rcu_scheduler_fully_active || rcu_rnp_online_cpus(rnp) == 0)
@@ -1367,13 +1375,12 @@ static void rcu_prepare_kthreads(int cpu)
1367 * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs 1375 * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs
1368 * any flavor of RCU. 1376 * any flavor of RCU.
1369 */ 1377 */
1370#ifndef CONFIG_RCU_NOCB_CPU_ALL
1371int rcu_needs_cpu(unsigned long *delta_jiffies) 1378int rcu_needs_cpu(unsigned long *delta_jiffies)
1372{ 1379{
1373 *delta_jiffies = ULONG_MAX; 1380 *delta_jiffies = ULONG_MAX;
1374 return rcu_cpu_has_callbacks(NULL); 1381 return IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL)
1382 ? 0 : rcu_cpu_has_callbacks(NULL);
1375} 1383}
1376#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1377 1384
1378/* 1385/*
1379 * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up 1386 * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
@@ -1462,7 +1469,7 @@ static bool __maybe_unused rcu_try_advance_all_cbs(void)
1462 * callbacks not yet ready to invoke. 1469 * callbacks not yet ready to invoke.
1463 */ 1470 */
1464 if ((rdp->completed != rnp->completed || 1471 if ((rdp->completed != rnp->completed ||
1465 unlikely(ACCESS_ONCE(rdp->gpwrap))) && 1472 unlikely(READ_ONCE(rdp->gpwrap))) &&
1466 rdp->nxttail[RCU_DONE_TAIL] != rdp->nxttail[RCU_NEXT_TAIL]) 1473 rdp->nxttail[RCU_DONE_TAIL] != rdp->nxttail[RCU_NEXT_TAIL])
1467 note_gp_changes(rsp, rdp); 1474 note_gp_changes(rsp, rdp);
1468 1475
@@ -1480,11 +1487,15 @@ static bool __maybe_unused rcu_try_advance_all_cbs(void)
1480 * 1487 *
1481 * The caller must have disabled interrupts. 1488 * The caller must have disabled interrupts.
1482 */ 1489 */
1483#ifndef CONFIG_RCU_NOCB_CPU_ALL
1484int rcu_needs_cpu(unsigned long *dj) 1490int rcu_needs_cpu(unsigned long *dj)
1485{ 1491{
1486 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks); 1492 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
1487 1493
1494 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL)) {
1495 *dj = ULONG_MAX;
1496 return 0;
1497 }
1498
1488 /* Snapshot to detect later posting of non-lazy callback. */ 1499 /* Snapshot to detect later posting of non-lazy callback. */
1489 rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted; 1500 rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted;
1490 1501
@@ -1511,7 +1522,6 @@ int rcu_needs_cpu(unsigned long *dj)
1511 } 1522 }
1512 return 0; 1523 return 0;
1513} 1524}
1514#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1515 1525
1516/* 1526/*
1517 * Prepare a CPU for idle from an RCU perspective. The first major task 1527 * Prepare a CPU for idle from an RCU perspective. The first major task
@@ -1525,7 +1535,6 @@ int rcu_needs_cpu(unsigned long *dj)
1525 */ 1535 */
1526static void rcu_prepare_for_idle(void) 1536static void rcu_prepare_for_idle(void)
1527{ 1537{
1528#ifndef CONFIG_RCU_NOCB_CPU_ALL
1529 bool needwake; 1538 bool needwake;
1530 struct rcu_data *rdp; 1539 struct rcu_data *rdp;
1531 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks); 1540 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
@@ -1533,8 +1542,11 @@ static void rcu_prepare_for_idle(void)
1533 struct rcu_state *rsp; 1542 struct rcu_state *rsp;
1534 int tne; 1543 int tne;
1535 1544
1545 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL))
1546 return;
1547
1536 /* Handle nohz enablement switches conservatively. */ 1548 /* Handle nohz enablement switches conservatively. */
1537 tne = ACCESS_ONCE(tick_nohz_active); 1549 tne = READ_ONCE(tick_nohz_active);
1538 if (tne != rdtp->tick_nohz_enabled_snap) { 1550 if (tne != rdtp->tick_nohz_enabled_snap) {
1539 if (rcu_cpu_has_callbacks(NULL)) 1551 if (rcu_cpu_has_callbacks(NULL))
1540 invoke_rcu_core(); /* force nohz to see update. */ 1552 invoke_rcu_core(); /* force nohz to see update. */
@@ -1580,7 +1592,6 @@ static void rcu_prepare_for_idle(void)
1580 if (needwake) 1592 if (needwake)
1581 rcu_gp_kthread_wake(rsp); 1593 rcu_gp_kthread_wake(rsp);
1582 } 1594 }
1583#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1584} 1595}
1585 1596
1586/* 1597/*
@@ -1590,12 +1601,11 @@ static void rcu_prepare_for_idle(void)
1590 */ 1601 */
1591static void rcu_cleanup_after_idle(void) 1602static void rcu_cleanup_after_idle(void)
1592{ 1603{
1593#ifndef CONFIG_RCU_NOCB_CPU_ALL 1604 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL) ||
1594 if (rcu_is_nocb_cpu(smp_processor_id())) 1605 rcu_is_nocb_cpu(smp_processor_id()))
1595 return; 1606 return;
1596 if (rcu_try_advance_all_cbs()) 1607 if (rcu_try_advance_all_cbs())
1597 invoke_rcu_core(); 1608 invoke_rcu_core();
1598#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
1599} 1609}
1600 1610
1601/* 1611/*
@@ -1760,7 +1770,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
1760 atomic_read(&rdtp->dynticks) & 0xfff, 1770 atomic_read(&rdtp->dynticks) & 0xfff,
1761 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting, 1771 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
1762 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu), 1772 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
1763 ACCESS_ONCE(rsp->n_force_qs) - rsp->n_force_qs_gpstart, 1773 READ_ONCE(rsp->n_force_qs) - rsp->n_force_qs_gpstart,
1764 fast_no_hz); 1774 fast_no_hz);
1765} 1775}
1766 1776
@@ -1898,11 +1908,11 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
1898{ 1908{
1899 struct rcu_data *rdp_leader = rdp->nocb_leader; 1909 struct rcu_data *rdp_leader = rdp->nocb_leader;
1900 1910
1901 if (!ACCESS_ONCE(rdp_leader->nocb_kthread)) 1911 if (!READ_ONCE(rdp_leader->nocb_kthread))
1902 return; 1912 return;
1903 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) { 1913 if (READ_ONCE(rdp_leader->nocb_leader_sleep) || force) {
1904 /* Prior smp_mb__after_atomic() orders against prior enqueue. */ 1914 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
1905 ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false; 1915 WRITE_ONCE(rdp_leader->nocb_leader_sleep, false);
1906 wake_up(&rdp_leader->nocb_wq); 1916 wake_up(&rdp_leader->nocb_wq);
1907 } 1917 }
1908} 1918}
@@ -1934,14 +1944,14 @@ static bool rcu_nocb_cpu_needs_barrier(struct rcu_state *rsp, int cpu)
1934 ret = atomic_long_read(&rdp->nocb_q_count); 1944 ret = atomic_long_read(&rdp->nocb_q_count);
1935 1945
1936#ifdef CONFIG_PROVE_RCU 1946#ifdef CONFIG_PROVE_RCU
1937 rhp = ACCESS_ONCE(rdp->nocb_head); 1947 rhp = READ_ONCE(rdp->nocb_head);
1938 if (!rhp) 1948 if (!rhp)
1939 rhp = ACCESS_ONCE(rdp->nocb_gp_head); 1949 rhp = READ_ONCE(rdp->nocb_gp_head);
1940 if (!rhp) 1950 if (!rhp)
1941 rhp = ACCESS_ONCE(rdp->nocb_follower_head); 1951 rhp = READ_ONCE(rdp->nocb_follower_head);
1942 1952
1943 /* Having no rcuo kthread but CBs after scheduler starts is bad! */ 1953 /* Having no rcuo kthread but CBs after scheduler starts is bad! */
1944 if (!ACCESS_ONCE(rdp->nocb_kthread) && rhp && 1954 if (!READ_ONCE(rdp->nocb_kthread) && rhp &&
1945 rcu_scheduler_fully_active) { 1955 rcu_scheduler_fully_active) {
1946 /* RCU callback enqueued before CPU first came online??? */ 1956 /* RCU callback enqueued before CPU first came online??? */
1947 pr_err("RCU: Never-onlined no-CBs CPU %d has CB %p\n", 1957 pr_err("RCU: Never-onlined no-CBs CPU %d has CB %p\n",
@@ -1975,12 +1985,12 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
1975 atomic_long_add(rhcount, &rdp->nocb_q_count); 1985 atomic_long_add(rhcount, &rdp->nocb_q_count);
1976 /* rcu_barrier() relies on ->nocb_q_count add before xchg. */ 1986 /* rcu_barrier() relies on ->nocb_q_count add before xchg. */
1977 old_rhpp = xchg(&rdp->nocb_tail, rhtp); 1987 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
1978 ACCESS_ONCE(*old_rhpp) = rhp; 1988 WRITE_ONCE(*old_rhpp, rhp);
1979 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy); 1989 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
1980 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */ 1990 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
1981 1991
1982 /* If we are not being polled and there is a kthread, awaken it ... */ 1992 /* If we are not being polled and there is a kthread, awaken it ... */
1983 t = ACCESS_ONCE(rdp->nocb_kthread); 1993 t = READ_ONCE(rdp->nocb_kthread);
1984 if (rcu_nocb_poll || !t) { 1994 if (rcu_nocb_poll || !t) {
1985 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, 1995 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
1986 TPS("WakeNotPoll")); 1996 TPS("WakeNotPoll"));
@@ -2118,7 +2128,7 @@ static void rcu_nocb_wait_gp(struct rcu_data *rdp)
2118 for (;;) { 2128 for (;;) {
2119 wait_event_interruptible( 2129 wait_event_interruptible(
2120 rnp->nocb_gp_wq[c & 0x1], 2130 rnp->nocb_gp_wq[c & 0x1],
2121 (d = ULONG_CMP_GE(ACCESS_ONCE(rnp->completed), c))); 2131 (d = ULONG_CMP_GE(READ_ONCE(rnp->completed), c)));
2122 if (likely(d)) 2132 if (likely(d))
2123 break; 2133 break;
2124 WARN_ON(signal_pending(current)); 2134 WARN_ON(signal_pending(current));
@@ -2145,7 +2155,7 @@ wait_again:
2145 if (!rcu_nocb_poll) { 2155 if (!rcu_nocb_poll) {
2146 trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, "Sleep"); 2156 trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, "Sleep");
2147 wait_event_interruptible(my_rdp->nocb_wq, 2157 wait_event_interruptible(my_rdp->nocb_wq,
2148 !ACCESS_ONCE(my_rdp->nocb_leader_sleep)); 2158 !READ_ONCE(my_rdp->nocb_leader_sleep));
2149 /* Memory barrier handled by smp_mb() calls below and repoll. */ 2159 /* Memory barrier handled by smp_mb() calls below and repoll. */
2150 } else if (firsttime) { 2160 } else if (firsttime) {
2151 firsttime = false; /* Don't drown trace log with "Poll"! */ 2161 firsttime = false; /* Don't drown trace log with "Poll"! */
@@ -2159,12 +2169,12 @@ wait_again:
2159 */ 2169 */
2160 gotcbs = false; 2170 gotcbs = false;
2161 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower) { 2171 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower) {
2162 rdp->nocb_gp_head = ACCESS_ONCE(rdp->nocb_head); 2172 rdp->nocb_gp_head = READ_ONCE(rdp->nocb_head);
2163 if (!rdp->nocb_gp_head) 2173 if (!rdp->nocb_gp_head)
2164 continue; /* No CBs here, try next follower. */ 2174 continue; /* No CBs here, try next follower. */
2165 2175
2166 /* Move callbacks to wait-for-GP list, which is empty. */ 2176 /* Move callbacks to wait-for-GP list, which is empty. */
2167 ACCESS_ONCE(rdp->nocb_head) = NULL; 2177 WRITE_ONCE(rdp->nocb_head, NULL);
2168 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head); 2178 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
2169 gotcbs = true; 2179 gotcbs = true;
2170 } 2180 }
@@ -2184,7 +2194,7 @@ wait_again:
2184 my_rdp->nocb_leader_sleep = true; 2194 my_rdp->nocb_leader_sleep = true;
2185 smp_mb(); /* Ensure _sleep true before scan. */ 2195 smp_mb(); /* Ensure _sleep true before scan. */
2186 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower) 2196 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower)
2187 if (ACCESS_ONCE(rdp->nocb_head)) { 2197 if (READ_ONCE(rdp->nocb_head)) {
2188 /* Found CB, so short-circuit next wait. */ 2198 /* Found CB, so short-circuit next wait. */
2189 my_rdp->nocb_leader_sleep = false; 2199 my_rdp->nocb_leader_sleep = false;
2190 break; 2200 break;
@@ -2205,7 +2215,7 @@ wait_again:
2205 2215
2206 /* Each pass through the following loop wakes a follower, if needed. */ 2216 /* Each pass through the following loop wakes a follower, if needed. */
2207 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower) { 2217 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower) {
2208 if (ACCESS_ONCE(rdp->nocb_head)) 2218 if (READ_ONCE(rdp->nocb_head))
2209 my_rdp->nocb_leader_sleep = false;/* No need to sleep.*/ 2219 my_rdp->nocb_leader_sleep = false;/* No need to sleep.*/
2210 if (!rdp->nocb_gp_head) 2220 if (!rdp->nocb_gp_head)
2211 continue; /* No CBs, so no need to wake follower. */ 2221 continue; /* No CBs, so no need to wake follower. */
@@ -2241,7 +2251,7 @@ static void nocb_follower_wait(struct rcu_data *rdp)
2241 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, 2251 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2242 "FollowerSleep"); 2252 "FollowerSleep");
2243 wait_event_interruptible(rdp->nocb_wq, 2253 wait_event_interruptible(rdp->nocb_wq,
2244 ACCESS_ONCE(rdp->nocb_follower_head)); 2254 READ_ONCE(rdp->nocb_follower_head));
2245 } else if (firsttime) { 2255 } else if (firsttime) {
2246 /* Don't drown trace log with "Poll"! */ 2256 /* Don't drown trace log with "Poll"! */
2247 firsttime = false; 2257 firsttime = false;
@@ -2282,10 +2292,10 @@ static int rcu_nocb_kthread(void *arg)
2282 nocb_follower_wait(rdp); 2292 nocb_follower_wait(rdp);
2283 2293
2284 /* Pull the ready-to-invoke callbacks onto local list. */ 2294 /* Pull the ready-to-invoke callbacks onto local list. */
2285 list = ACCESS_ONCE(rdp->nocb_follower_head); 2295 list = READ_ONCE(rdp->nocb_follower_head);
2286 BUG_ON(!list); 2296 BUG_ON(!list);
2287 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty"); 2297 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
2288 ACCESS_ONCE(rdp->nocb_follower_head) = NULL; 2298 WRITE_ONCE(rdp->nocb_follower_head, NULL);
2289 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head); 2299 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
2290 2300
2291 /* Each pass through the following loop invokes a callback. */ 2301 /* Each pass through the following loop invokes a callback. */
@@ -2324,7 +2334,7 @@ static int rcu_nocb_kthread(void *arg)
2324/* Is a deferred wakeup of rcu_nocb_kthread() required? */ 2334/* Is a deferred wakeup of rcu_nocb_kthread() required? */
2325static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp) 2335static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
2326{ 2336{
2327 return ACCESS_ONCE(rdp->nocb_defer_wakeup); 2337 return READ_ONCE(rdp->nocb_defer_wakeup);
2328} 2338}
2329 2339
2330/* Do a deferred wakeup of rcu_nocb_kthread(). */ 2340/* Do a deferred wakeup of rcu_nocb_kthread(). */
@@ -2334,8 +2344,8 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
2334 2344
2335 if (!rcu_nocb_need_deferred_wakeup(rdp)) 2345 if (!rcu_nocb_need_deferred_wakeup(rdp))
2336 return; 2346 return;
2337 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup); 2347 ndw = READ_ONCE(rdp->nocb_defer_wakeup);
2338 ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT; 2348 WRITE_ONCE(rdp->nocb_defer_wakeup, RCU_NOGP_WAKE_NOT);
2339 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE); 2349 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
2340 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake")); 2350 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
2341} 2351}
@@ -2448,7 +2458,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
2448 t = kthread_run(rcu_nocb_kthread, rdp_spawn, 2458 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
2449 "rcuo%c/%d", rsp->abbr, cpu); 2459 "rcuo%c/%d", rsp->abbr, cpu);
2450 BUG_ON(IS_ERR(t)); 2460 BUG_ON(IS_ERR(t));
2451 ACCESS_ONCE(rdp_spawn->nocb_kthread) = t; 2461 WRITE_ONCE(rdp_spawn->nocb_kthread, t);
2452} 2462}
2453 2463
2454/* 2464/*
@@ -2663,7 +2673,7 @@ static void rcu_sysidle_enter(int irq)
2663 2673
2664 /* Record start of fully idle period. */ 2674 /* Record start of fully idle period. */
2665 j = jiffies; 2675 j = jiffies;
2666 ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j; 2676 WRITE_ONCE(rdtp->dynticks_idle_jiffies, j);
2667 smp_mb__before_atomic(); 2677 smp_mb__before_atomic();
2668 atomic_inc(&rdtp->dynticks_idle); 2678 atomic_inc(&rdtp->dynticks_idle);
2669 smp_mb__after_atomic(); 2679 smp_mb__after_atomic();
@@ -2681,7 +2691,7 @@ static void rcu_sysidle_enter(int irq)
2681 */ 2691 */
2682void rcu_sysidle_force_exit(void) 2692void rcu_sysidle_force_exit(void)
2683{ 2693{
2684 int oldstate = ACCESS_ONCE(full_sysidle_state); 2694 int oldstate = READ_ONCE(full_sysidle_state);
2685 int newoldstate; 2695 int newoldstate;
2686 2696
2687 /* 2697 /*
@@ -2794,7 +2804,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
2794 smp_mb(); /* Read counters before timestamps. */ 2804 smp_mb(); /* Read counters before timestamps. */
2795 2805
2796 /* Pick up timestamps. */ 2806 /* Pick up timestamps. */
2797 j = ACCESS_ONCE(rdtp->dynticks_idle_jiffies); 2807 j = READ_ONCE(rdtp->dynticks_idle_jiffies);
2798 /* If this CPU entered idle more recently, update maxj timestamp. */ 2808 /* If this CPU entered idle more recently, update maxj timestamp. */
2799 if (ULONG_CMP_LT(*maxj, j)) 2809 if (ULONG_CMP_LT(*maxj, j))
2800 *maxj = j; 2810 *maxj = j;
@@ -2831,11 +2841,11 @@ static unsigned long rcu_sysidle_delay(void)
2831static void rcu_sysidle(unsigned long j) 2841static void rcu_sysidle(unsigned long j)
2832{ 2842{
2833 /* Check the current state. */ 2843 /* Check the current state. */
2834 switch (ACCESS_ONCE(full_sysidle_state)) { 2844 switch (READ_ONCE(full_sysidle_state)) {
2835 case RCU_SYSIDLE_NOT: 2845 case RCU_SYSIDLE_NOT:
2836 2846
2837 /* First time all are idle, so note a short idle period. */ 2847 /* First time all are idle, so note a short idle period. */
2838 ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT; 2848 WRITE_ONCE(full_sysidle_state, RCU_SYSIDLE_SHORT);
2839 break; 2849 break;
2840 2850
2841 case RCU_SYSIDLE_SHORT: 2851 case RCU_SYSIDLE_SHORT:
@@ -2873,7 +2883,7 @@ static void rcu_sysidle_cancel(void)
2873{ 2883{
2874 smp_mb(); 2884 smp_mb();
2875 if (full_sysidle_state > RCU_SYSIDLE_SHORT) 2885 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
2876 ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT; 2886 WRITE_ONCE(full_sysidle_state, RCU_SYSIDLE_NOT);
2877} 2887}
2878 2888
2879/* 2889/*
@@ -2925,7 +2935,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
2925 smp_mb(); /* grace period precedes setting inuse. */ 2935 smp_mb(); /* grace period precedes setting inuse. */
2926 2936
2927 rshp = container_of(rhp, struct rcu_sysidle_head, rh); 2937 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
2928 ACCESS_ONCE(rshp->inuse) = 0; 2938 WRITE_ONCE(rshp->inuse, 0);
2929} 2939}
2930 2940
2931/* 2941/*
@@ -2936,7 +2946,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
2936bool rcu_sys_is_idle(void) 2946bool rcu_sys_is_idle(void)
2937{ 2947{
2938 static struct rcu_sysidle_head rsh; 2948 static struct rcu_sysidle_head rsh;
2939 int rss = ACCESS_ONCE(full_sysidle_state); 2949 int rss = READ_ONCE(full_sysidle_state);
2940 2950
2941 if (WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu)) 2951 if (WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu))
2942 return false; 2952 return false;
@@ -2964,7 +2974,7 @@ bool rcu_sys_is_idle(void)
2964 } 2974 }
2965 rcu_sysidle_report(rcu_state_p, isidle, maxj, false); 2975 rcu_sysidle_report(rcu_state_p, isidle, maxj, false);
2966 oldrss = rss; 2976 oldrss = rss;
2967 rss = ACCESS_ONCE(full_sysidle_state); 2977 rss = READ_ONCE(full_sysidle_state);
2968 } 2978 }
2969 } 2979 }
2970 2980
@@ -3048,10 +3058,10 @@ static bool rcu_nohz_full_cpu(struct rcu_state *rsp)
3048#ifdef CONFIG_NO_HZ_FULL 3058#ifdef CONFIG_NO_HZ_FULL
3049 if (tick_nohz_full_cpu(smp_processor_id()) && 3059 if (tick_nohz_full_cpu(smp_processor_id()) &&
3050 (!rcu_gp_in_progress(rsp) || 3060 (!rcu_gp_in_progress(rsp) ||
3051 ULONG_CMP_LT(jiffies, ACCESS_ONCE(rsp->gp_start) + HZ))) 3061 ULONG_CMP_LT(jiffies, READ_ONCE(rsp->gp_start) + HZ)))
3052 return 1; 3062 return true;
3053#endif /* #ifdef CONFIG_NO_HZ_FULL */ 3063#endif /* #ifdef CONFIG_NO_HZ_FULL */
3054 return 0; 3064 return false;
3055} 3065}
3056 3066
3057/* 3067/*
@@ -3077,7 +3087,7 @@ static void rcu_bind_gp_kthread(void)
3077static void rcu_dynticks_task_enter(void) 3087static void rcu_dynticks_task_enter(void)
3078{ 3088{
3079#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) 3089#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
3080 ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id(); 3090 WRITE_ONCE(current->rcu_tasks_idle_cpu, smp_processor_id());
3081#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ 3091#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
3082} 3092}
3083 3093
@@ -3085,6 +3095,6 @@ static void rcu_dynticks_task_enter(void)
3085static void rcu_dynticks_task_exit(void) 3095static void rcu_dynticks_task_exit(void)
3086{ 3096{
3087#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) 3097#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
3088 ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1; 3098 WRITE_ONCE(current->rcu_tasks_idle_cpu, -1);
3089#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */ 3099#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
3090} 3100}
diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
index f92361efd0f5..3ea7ffc7d5c4 100644
--- a/kernel/rcu/tree_trace.c
+++ b/kernel/rcu/tree_trace.c
@@ -277,7 +277,7 @@ static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
277 seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n", 277 seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n",
278 rsp->n_force_qs, rsp->n_force_qs_ngp, 278 rsp->n_force_qs, rsp->n_force_qs_ngp,
279 rsp->n_force_qs - rsp->n_force_qs_ngp, 279 rsp->n_force_qs - rsp->n_force_qs_ngp,
280 ACCESS_ONCE(rsp->n_force_qs_lh), rsp->qlen_lazy, rsp->qlen); 280 READ_ONCE(rsp->n_force_qs_lh), rsp->qlen_lazy, rsp->qlen);
281 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) { 281 for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) {
282 if (rnp->level != level) { 282 if (rnp->level != level) {
283 seq_puts(m, "\n"); 283 seq_puts(m, "\n");
@@ -323,8 +323,8 @@ static void show_one_rcugp(struct seq_file *m, struct rcu_state *rsp)
323 struct rcu_node *rnp = &rsp->node[0]; 323 struct rcu_node *rnp = &rsp->node[0];
324 324
325 raw_spin_lock_irqsave(&rnp->lock, flags); 325 raw_spin_lock_irqsave(&rnp->lock, flags);
326 completed = ACCESS_ONCE(rsp->completed); 326 completed = READ_ONCE(rsp->completed);
327 gpnum = ACCESS_ONCE(rsp->gpnum); 327 gpnum = READ_ONCE(rsp->gpnum);
328 if (completed == gpnum) 328 if (completed == gpnum)
329 gpage = 0; 329 gpage = 0;
330 else 330 else
diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
index 1f133350da01..afaecb7a799a 100644
--- a/kernel/rcu/update.c
+++ b/kernel/rcu/update.c
@@ -150,14 +150,14 @@ void __rcu_read_unlock(void)
150 barrier(); /* critical section before exit code. */ 150 barrier(); /* critical section before exit code. */
151 t->rcu_read_lock_nesting = INT_MIN; 151 t->rcu_read_lock_nesting = INT_MIN;
152 barrier(); /* assign before ->rcu_read_unlock_special load */ 152 barrier(); /* assign before ->rcu_read_unlock_special load */
153 if (unlikely(ACCESS_ONCE(t->rcu_read_unlock_special.s))) 153 if (unlikely(READ_ONCE(t->rcu_read_unlock_special.s)))
154 rcu_read_unlock_special(t); 154 rcu_read_unlock_special(t);
155 barrier(); /* ->rcu_read_unlock_special load before assign */ 155 barrier(); /* ->rcu_read_unlock_special load before assign */
156 t->rcu_read_lock_nesting = 0; 156 t->rcu_read_lock_nesting = 0;
157 } 157 }
158#ifdef CONFIG_PROVE_LOCKING 158#ifdef CONFIG_PROVE_LOCKING
159 { 159 {
160 int rrln = ACCESS_ONCE(t->rcu_read_lock_nesting); 160 int rrln = READ_ONCE(t->rcu_read_lock_nesting);
161 161
162 WARN_ON_ONCE(rrln < 0 && rrln > INT_MIN / 2); 162 WARN_ON_ONCE(rrln < 0 && rrln > INT_MIN / 2);
163 } 163 }
@@ -389,17 +389,17 @@ module_param(rcu_cpu_stall_timeout, int, 0644);
389 389
390int rcu_jiffies_till_stall_check(void) 390int rcu_jiffies_till_stall_check(void)
391{ 391{
392 int till_stall_check = ACCESS_ONCE(rcu_cpu_stall_timeout); 392 int till_stall_check = READ_ONCE(rcu_cpu_stall_timeout);
393 393
394 /* 394 /*
395 * Limit check must be consistent with the Kconfig limits 395 * Limit check must be consistent with the Kconfig limits
396 * for CONFIG_RCU_CPU_STALL_TIMEOUT. 396 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
397 */ 397 */
398 if (till_stall_check < 3) { 398 if (till_stall_check < 3) {
399 ACCESS_ONCE(rcu_cpu_stall_timeout) = 3; 399 WRITE_ONCE(rcu_cpu_stall_timeout, 3);
400 till_stall_check = 3; 400 till_stall_check = 3;
401 } else if (till_stall_check > 300) { 401 } else if (till_stall_check > 300) {
402 ACCESS_ONCE(rcu_cpu_stall_timeout) = 300; 402 WRITE_ONCE(rcu_cpu_stall_timeout, 300);
403 till_stall_check = 300; 403 till_stall_check = 300;
404 } 404 }
405 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA; 405 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
@@ -550,12 +550,12 @@ static void check_holdout_task(struct task_struct *t,
550{ 550{
551 int cpu; 551 int cpu;
552 552
553 if (!ACCESS_ONCE(t->rcu_tasks_holdout) || 553 if (!READ_ONCE(t->rcu_tasks_holdout) ||
554 t->rcu_tasks_nvcsw != ACCESS_ONCE(t->nvcsw) || 554 t->rcu_tasks_nvcsw != READ_ONCE(t->nvcsw) ||
555 !ACCESS_ONCE(t->on_rq) || 555 !READ_ONCE(t->on_rq) ||
556 (IS_ENABLED(CONFIG_NO_HZ_FULL) && 556 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
557 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) { 557 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
558 ACCESS_ONCE(t->rcu_tasks_holdout) = false; 558 WRITE_ONCE(t->rcu_tasks_holdout, false);
559 list_del_init(&t->rcu_tasks_holdout_list); 559 list_del_init(&t->rcu_tasks_holdout_list);
560 put_task_struct(t); 560 put_task_struct(t);
561 return; 561 return;
@@ -639,11 +639,11 @@ static int __noreturn rcu_tasks_kthread(void *arg)
639 */ 639 */
640 rcu_read_lock(); 640 rcu_read_lock();
641 for_each_process_thread(g, t) { 641 for_each_process_thread(g, t) {
642 if (t != current && ACCESS_ONCE(t->on_rq) && 642 if (t != current && READ_ONCE(t->on_rq) &&
643 !is_idle_task(t)) { 643 !is_idle_task(t)) {
644 get_task_struct(t); 644 get_task_struct(t);
645 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw); 645 t->rcu_tasks_nvcsw = READ_ONCE(t->nvcsw);
646 ACCESS_ONCE(t->rcu_tasks_holdout) = true; 646 WRITE_ONCE(t->rcu_tasks_holdout, true);
647 list_add(&t->rcu_tasks_holdout_list, 647 list_add(&t->rcu_tasks_holdout_list,
648 &rcu_tasks_holdouts); 648 &rcu_tasks_holdouts);
649 } 649 }
@@ -672,7 +672,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
672 struct task_struct *t1; 672 struct task_struct *t1;
673 673
674 schedule_timeout_interruptible(HZ); 674 schedule_timeout_interruptible(HZ);
675 rtst = ACCESS_ONCE(rcu_task_stall_timeout); 675 rtst = READ_ONCE(rcu_task_stall_timeout);
676 needreport = rtst > 0 && 676 needreport = rtst > 0 &&
677 time_after(jiffies, lastreport + rtst); 677 time_after(jiffies, lastreport + rtst);
678 if (needreport) 678 if (needreport)
@@ -728,7 +728,7 @@ static void rcu_spawn_tasks_kthread(void)
728 static struct task_struct *rcu_tasks_kthread_ptr; 728 static struct task_struct *rcu_tasks_kthread_ptr;
729 struct task_struct *t; 729 struct task_struct *t;
730 730
731 if (ACCESS_ONCE(rcu_tasks_kthread_ptr)) { 731 if (READ_ONCE(rcu_tasks_kthread_ptr)) {
732 smp_mb(); /* Ensure caller sees full kthread. */ 732 smp_mb(); /* Ensure caller sees full kthread. */
733 return; 733 return;
734 } 734 }
@@ -740,7 +740,7 @@ static void rcu_spawn_tasks_kthread(void)
740 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread"); 740 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
741 BUG_ON(IS_ERR(t)); 741 BUG_ON(IS_ERR(t));
742 smp_mb(); /* Ensure others see full kthread. */ 742 smp_mb(); /* Ensure others see full kthread. */
743 ACCESS_ONCE(rcu_tasks_kthread_ptr) = t; 743 WRITE_ONCE(rcu_tasks_kthread_ptr, t);
744 mutex_unlock(&rcu_tasks_kthread_mutex); 744 mutex_unlock(&rcu_tasks_kthread_mutex);
745} 745}
746 746
diff --git a/kernel/torture.c b/kernel/torture.c
index dd70993c266c..3e4840633d3e 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -409,7 +409,7 @@ static void (*torture_shutdown_hook)(void);
409 */ 409 */
410void torture_shutdown_absorb(const char *title) 410void torture_shutdown_absorb(const char *title)
411{ 411{
412 while (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { 412 while (READ_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
413 pr_notice("torture thread %s parking due to system shutdown\n", 413 pr_notice("torture thread %s parking due to system shutdown\n",
414 title); 414 title);
415 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT); 415 schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
@@ -480,9 +480,9 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
480 unsigned long unused2, void *unused3) 480 unsigned long unused2, void *unused3)
481{ 481{
482 mutex_lock(&fullstop_mutex); 482 mutex_lock(&fullstop_mutex);
483 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) { 483 if (READ_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
484 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected"); 484 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
485 ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN; 485 WRITE_ONCE(fullstop, FULLSTOP_SHUTDOWN);
486 } else { 486 } else {
487 pr_warn("Concurrent rmmod and shutdown illegal!\n"); 487 pr_warn("Concurrent rmmod and shutdown illegal!\n");
488 } 488 }
@@ -523,13 +523,13 @@ static int stutter;
523 */ 523 */
524void stutter_wait(const char *title) 524void stutter_wait(const char *title)
525{ 525{
526 while (ACCESS_ONCE(stutter_pause_test) || 526 while (READ_ONCE(stutter_pause_test) ||
527 (torture_runnable && !ACCESS_ONCE(*torture_runnable))) { 527 (torture_runnable && !READ_ONCE(*torture_runnable))) {
528 if (stutter_pause_test) 528 if (stutter_pause_test)
529 if (ACCESS_ONCE(stutter_pause_test) == 1) 529 if (READ_ONCE(stutter_pause_test) == 1)
530 schedule_timeout_interruptible(1); 530 schedule_timeout_interruptible(1);
531 else 531 else
532 while (ACCESS_ONCE(stutter_pause_test)) 532 while (READ_ONCE(stutter_pause_test))
533 cond_resched(); 533 cond_resched();
534 else 534 else
535 schedule_timeout_interruptible(round_jiffies_relative(HZ)); 535 schedule_timeout_interruptible(round_jiffies_relative(HZ));
@@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
549 if (!torture_must_stop()) { 549 if (!torture_must_stop()) {
550 if (stutter > 1) { 550 if (stutter > 1) {
551 schedule_timeout_interruptible(stutter - 1); 551 schedule_timeout_interruptible(stutter - 1);
552 ACCESS_ONCE(stutter_pause_test) = 2; 552 WRITE_ONCE(stutter_pause_test, 2);
553 } 553 }
554 schedule_timeout_interruptible(1); 554 schedule_timeout_interruptible(1);
555 ACCESS_ONCE(stutter_pause_test) = 1; 555 WRITE_ONCE(stutter_pause_test, 1);
556 } 556 }
557 if (!torture_must_stop()) 557 if (!torture_must_stop())
558 schedule_timeout_interruptible(stutter); 558 schedule_timeout_interruptible(stutter);
559 ACCESS_ONCE(stutter_pause_test) = 0; 559 WRITE_ONCE(stutter_pause_test, 0);
560 torture_shutdown_absorb("torture_stutter"); 560 torture_shutdown_absorb("torture_stutter");
561 } while (!torture_must_stop()); 561 } while (!torture_must_stop());
562 torture_kthread_stopping("torture_stutter"); 562 torture_kthread_stopping("torture_stutter");
@@ -642,13 +642,13 @@ EXPORT_SYMBOL_GPL(torture_init_end);
642bool torture_cleanup_begin(void) 642bool torture_cleanup_begin(void)
643{ 643{
644 mutex_lock(&fullstop_mutex); 644 mutex_lock(&fullstop_mutex);
645 if (ACCESS_ONCE(fullstop) == FULLSTOP_SHUTDOWN) { 645 if (READ_ONCE(fullstop) == FULLSTOP_SHUTDOWN) {
646 pr_warn("Concurrent rmmod and shutdown illegal!\n"); 646 pr_warn("Concurrent rmmod and shutdown illegal!\n");
647 mutex_unlock(&fullstop_mutex); 647 mutex_unlock(&fullstop_mutex);
648 schedule_timeout_uninterruptible(10); 648 schedule_timeout_uninterruptible(10);
649 return true; 649 return true;
650 } 650 }
651 ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD; 651 WRITE_ONCE(fullstop, FULLSTOP_RMMOD);
652 mutex_unlock(&fullstop_mutex); 652 mutex_unlock(&fullstop_mutex);
653 torture_shutdown_cleanup(); 653 torture_shutdown_cleanup();
654 torture_shuffle_cleanup(); 654 torture_shuffle_cleanup();
@@ -681,7 +681,7 @@ EXPORT_SYMBOL_GPL(torture_must_stop);
681 */ 681 */
682bool torture_must_stop_irq(void) 682bool torture_must_stop_irq(void)
683{ 683{
684 return ACCESS_ONCE(fullstop) != FULLSTOP_DONTSTOP; 684 return READ_ONCE(fullstop) != FULLSTOP_DONTSTOP;
685} 685}
686EXPORT_SYMBOL_GPL(torture_must_stop_irq); 686EXPORT_SYMBOL_GPL(torture_must_stop_irq);
687 687
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index ba2b0c87e65b..b908048f8d6a 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1233,6 +1233,7 @@ config RCU_TORTURE_TEST
1233 depends on DEBUG_KERNEL 1233 depends on DEBUG_KERNEL
1234 select TORTURE_TEST 1234 select TORTURE_TEST
1235 select SRCU 1235 select SRCU
1236 select TASKS_RCU
1236 default n 1237 default n
1237 help 1238 help
1238 This option provides a kernel module that runs torture tests 1239 This option provides a kernel module that runs torture tests
@@ -1261,12 +1262,38 @@ config RCU_TORTURE_TEST_RUNNABLE
1261 Say N here if you want the RCU torture tests to start only 1262 Say N here if you want the RCU torture tests to start only
1262 after being manually enabled via /proc. 1263 after being manually enabled via /proc.
1263 1264
1265config RCU_TORTURE_TEST_SLOW_PREINIT
1266 bool "Slow down RCU grace-period pre-initialization to expose races"
1267 depends on RCU_TORTURE_TEST
1268 help
1269 This option delays grace-period pre-initialization (the
1270 propagation of CPU-hotplug changes up the rcu_node combining
1271 tree) for a few jiffies between initializing each pair of
1272 consecutive rcu_node structures. This helps to expose races
1273 involving grace-period pre-initialization, in other words, it
1274 makes your kernel less stable. It can also greatly increase
1275 grace-period latency, especially on systems with large numbers
1276 of CPUs. This is useful when torture-testing RCU, but in
1277 almost no other circumstance.
1278
1279 Say Y here if you want your system to crash and hang more often.
1280 Say N if you want a sane system.
1281
1282config RCU_TORTURE_TEST_SLOW_PREINIT_DELAY
1283 int "How much to slow down RCU grace-period pre-initialization"
1284 range 0 5
1285 default 3
1286 depends on RCU_TORTURE_TEST_SLOW_PREINIT
1287 help
1288 This option specifies the number of jiffies to wait between
1289 each rcu_node structure pre-initialization step.
1290
1264config RCU_TORTURE_TEST_SLOW_INIT 1291config RCU_TORTURE_TEST_SLOW_INIT
1265 bool "Slow down RCU grace-period initialization to expose races" 1292 bool "Slow down RCU grace-period initialization to expose races"
1266 depends on RCU_TORTURE_TEST 1293 depends on RCU_TORTURE_TEST
1267 help 1294 help
1268 This option makes grace-period initialization block for a 1295 This option delays grace-period initialization for a few
1269 few jiffies between initializing each pair of consecutive 1296 jiffies between initializing each pair of consecutive
1270 rcu_node structures. This helps to expose races involving 1297 rcu_node structures. This helps to expose races involving
1271 grace-period initialization, in other words, it makes your 1298 grace-period initialization, in other words, it makes your
1272 kernel less stable. It can also greatly increase grace-period 1299 kernel less stable. It can also greatly increase grace-period
@@ -1286,6 +1313,30 @@ config RCU_TORTURE_TEST_SLOW_INIT_DELAY
1286 This option specifies the number of jiffies to wait between 1313 This option specifies the number of jiffies to wait between
1287 each rcu_node structure initialization. 1314 each rcu_node structure initialization.
1288 1315
1316config RCU_TORTURE_TEST_SLOW_CLEANUP
1317 bool "Slow down RCU grace-period cleanup to expose races"
1318 depends on RCU_TORTURE_TEST
1319 help
1320 This option delays grace-period cleanup for a few jiffies
1321 between cleaning up each pair of consecutive rcu_node
1322 structures. This helps to expose races involving grace-period
1323 cleanup, in other words, it makes your kernel less stable.
1324 It can also greatly increase grace-period latency, especially
1325 on systems with large numbers of CPUs. This is useful when
1326 torture-testing RCU, but in almost no other circumstance.
1327
1328 Say Y here if you want your system to crash and hang more often.
1329 Say N if you want a sane system.
1330
1331config RCU_TORTURE_TEST_SLOW_CLEANUP_DELAY
1332 int "How much to slow down RCU grace-period cleanup"
1333 range 0 5
1334 default 3
1335 depends on RCU_TORTURE_TEST_SLOW_CLEANUP
1336 help
1337 This option specifies the number of jiffies to wait between
1338 each rcu_node structure cleanup operation.
1339
1289config RCU_CPU_STALL_TIMEOUT 1340config RCU_CPU_STALL_TIMEOUT
1290 int "RCU CPU stall timeout in seconds" 1341 int "RCU CPU stall timeout in seconds"
1291 depends on RCU_STALL_COMMON 1342 depends on RCU_STALL_COMMON
@@ -1322,6 +1373,17 @@ config RCU_TRACE
1322 Say Y here if you want to enable RCU tracing 1373 Say Y here if you want to enable RCU tracing
1323 Say N if you are unsure. 1374 Say N if you are unsure.
1324 1375
1376config RCU_EQS_DEBUG
1377 bool "Use this when adding any sort of NO_HZ support to your arch"
1378 depends on DEBUG_KERNEL
1379 help
1380 This option provides consistency checks in RCU's handling of
1381 NO_HZ. These checks have proven quite helpful in detecting
1382 bugs in arch-specific NO_HZ code.
1383
1384 Say N here if you need ultimate kernel/user switch latencies
1385 Say Y if you are unsure
1386
1325endmenu # "RCU Debugging" 1387endmenu # "RCU Debugging"
1326 1388
1327config DEBUG_BLOCK_EXT_DEVT 1389config DEBUG_BLOCK_EXT_DEVT
diff --git a/tools/testing/selftests/rcutorture/bin/configinit.sh b/tools/testing/selftests/rcutorture/bin/configinit.sh
index 15f1a17ca96e..3f81a1095206 100755
--- a/tools/testing/selftests/rcutorture/bin/configinit.sh
+++ b/tools/testing/selftests/rcutorture/bin/configinit.sh
@@ -66,7 +66,7 @@ make $buildloc $TORTURE_DEFCONFIG > $builddir/Make.defconfig.out 2>&1
66mv $builddir/.config $builddir/.config.sav 66mv $builddir/.config $builddir/.config.sav
67sh $T/upd.sh < $builddir/.config.sav > $builddir/.config 67sh $T/upd.sh < $builddir/.config.sav > $builddir/.config
68cp $builddir/.config $builddir/.config.new 68cp $builddir/.config $builddir/.config.new
69yes '' | make $buildloc oldconfig > $builddir/Make.modconfig.out 2>&1 69yes '' | make $buildloc oldconfig > $builddir/Make.oldconfig.out 2> $builddir/Make.oldconfig.err
70 70
71# verify new config matches specification. 71# verify new config matches specification.
72configcheck.sh $builddir/.config $c 72configcheck.sh $builddir/.config $c
diff --git a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
index 4f5b20f367a9..d86bdd6b6cc2 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
@@ -43,6 +43,10 @@ do
43 if test -f "$i/console.log" 43 if test -f "$i/console.log"
44 then 44 then
45 configcheck.sh $i/.config $i/ConfigFragment 45 configcheck.sh $i/.config $i/ConfigFragment
46 if test -r $i/Make.oldconfig.err
47 then
48 cat $i/Make.oldconfig.err
49 fi
46 parse-build.sh $i/Make.out $configfile 50 parse-build.sh $i/Make.out $configfile
47 parse-torture.sh $i/console.log $configfile 51 parse-torture.sh $i/console.log $configfile
48 parse-console.sh $i/console.log $configfile 52 parse-console.sh $i/console.log $configfile
diff --git a/tools/testing/selftests/rcutorture/bin/kvm.sh b/tools/testing/selftests/rcutorture/bin/kvm.sh
index dd2812ceb0ba..fbe2dbff1e21 100755
--- a/tools/testing/selftests/rcutorture/bin/kvm.sh
+++ b/tools/testing/selftests/rcutorture/bin/kvm.sh
@@ -55,7 +55,7 @@ usage () {
55 echo " --bootargs kernel-boot-arguments" 55 echo " --bootargs kernel-boot-arguments"
56 echo " --bootimage relative-path-to-kernel-boot-image" 56 echo " --bootimage relative-path-to-kernel-boot-image"
57 echo " --buildonly" 57 echo " --buildonly"
58 echo " --configs \"config-file list\"" 58 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
59 echo " --cpus N" 59 echo " --cpus N"
60 echo " --datestamp string" 60 echo " --datestamp string"
61 echo " --defconfig string" 61 echo " --defconfig string"
@@ -178,13 +178,26 @@ fi
178touch $T/cfgcpu 178touch $T/cfgcpu
179for CF in $configs 179for CF in $configs
180do 180do
181 if test -f "$CONFIGFRAG/$CF" 181 case $CF in
182 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
183 config_reps=`echo $CF | sed -e 's/\*.*$//'`
184 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
185 ;;
186 *)
187 config_reps=1
188 CF1=$CF
189 ;;
190 esac
191 if test -f "$CONFIGFRAG/$CF1"
182 then 192 then
183 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF` 193 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
184 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF" "$cpu_count"` 194 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
185 echo $CF $cpu_count >> $T/cfgcpu 195 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
196 do
197 echo $CF1 $cpu_count >> $T/cfgcpu
198 done
186 else 199 else
187 echo "The --configs file $CF does not exist, terminating." 200 echo "The --configs file $CF1 does not exist, terminating."
188 exit 1 201 exit 1
189 fi 202 fi
190done 203done
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/CFcommon b/tools/testing/selftests/rcutorture/configs/rcu/CFcommon
index 49701218dc62..f824b4c9d9d9 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/CFcommon
+++ b/tools/testing/selftests/rcutorture/configs/rcu/CFcommon
@@ -1,3 +1,5 @@
1CONFIG_RCU_TORTURE_TEST=y 1CONFIG_RCU_TORTURE_TEST=y
2CONFIG_PRINTK_TIME=y 2CONFIG_PRINTK_TIME=y
3CONFIG_RCU_TORTURE_TEST_SLOW_CLEANUP=y
3CONFIG_RCU_TORTURE_TEST_SLOW_INIT=y 4CONFIG_RCU_TORTURE_TEST_SLOW_INIT=y
5CONFIG_RCU_TORTURE_TEST_SLOW_PREINIT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N
index 9fbb41b9b314..1a087c3c8bb8 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-N
@@ -5,3 +5,4 @@ CONFIG_HOTPLUG_CPU=y
5CONFIG_PREEMPT_NONE=y 5CONFIG_PREEMPT_NONE=y
6CONFIG_PREEMPT_VOLUNTARY=n 6CONFIG_PREEMPT_VOLUNTARY=n
7CONFIG_PREEMPT=n 7CONFIG_PREEMPT=n
8CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P
index 4b6f272dba27..4837430a71c0 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P
@@ -5,3 +5,4 @@ CONFIG_HOTPLUG_CPU=y
5CONFIG_PREEMPT_NONE=n 5CONFIG_PREEMPT_NONE=n
6CONFIG_PREEMPT_VOLUNTARY=n 6CONFIG_PREEMPT_VOLUNTARY=n
7CONFIG_PREEMPT=y 7CONFIG_PREEMPT=y
8#CHECK#CONFIG_RCU_EXPERT=n
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot
index 238bfe3bd0cc..84a7d51b7481 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/SRCU-P.boot
@@ -1 +1 @@
rcutorture.torture_type=srcu rcutorture.torture_type=srcud
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TASKS01 b/tools/testing/selftests/rcutorture/configs/rcu/TASKS01
index 97f0a0b27ef7..2cc0e60eba6e 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TASKS01
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TASKS01
@@ -5,5 +5,6 @@ CONFIG_PREEMPT_NONE=n
5CONFIG_PREEMPT_VOLUNTARY=n 5CONFIG_PREEMPT_VOLUNTARY=n
6CONFIG_PREEMPT=y 6CONFIG_PREEMPT=y
7CONFIG_DEBUG_LOCK_ALLOC=y 7CONFIG_DEBUG_LOCK_ALLOC=y
8CONFIG_PROVE_RCU=y 8CONFIG_PROVE_LOCKING=n
9CONFIG_TASKS_RCU=y 9#CHECK#CONFIG_PROVE_RCU=n
10CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TASKS02 b/tools/testing/selftests/rcutorture/configs/rcu/TASKS02
index 696d2ea74d13..ad2be91e5ee7 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TASKS02
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TASKS02
@@ -2,4 +2,3 @@ CONFIG_SMP=n
2CONFIG_PREEMPT_NONE=y 2CONFIG_PREEMPT_NONE=y
3CONFIG_PREEMPT_VOLUNTARY=n 3CONFIG_PREEMPT_VOLUNTARY=n
4CONFIG_PREEMPT=n 4CONFIG_PREEMPT=n
5CONFIG_TASKS_RCU=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TASKS03 b/tools/testing/selftests/rcutorture/configs/rcu/TASKS03
index 9c60da5b5d1d..c70c51d5ded1 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TASKS03
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TASKS03
@@ -6,8 +6,8 @@ CONFIG_HIBERNATION=n
6CONFIG_PREEMPT_NONE=n 6CONFIG_PREEMPT_NONE=n
7CONFIG_PREEMPT_VOLUNTARY=n 7CONFIG_PREEMPT_VOLUNTARY=n
8CONFIG_PREEMPT=y 8CONFIG_PREEMPT=y
9CONFIG_TASKS_RCU=y
10CONFIG_HZ_PERIODIC=n 9CONFIG_HZ_PERIODIC=n
11CONFIG_NO_HZ_IDLE=n 10CONFIG_NO_HZ_IDLE=n
12CONFIG_NO_HZ_FULL=y 11CONFIG_NO_HZ_FULL=y
13CONFIG_NO_HZ_FULL_ALL=y 12CONFIG_NO_HZ_FULL_ALL=y
13#CHECK#CONFIG_RCU_EXPERT=n
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TINY02 b/tools/testing/selftests/rcutorture/configs/rcu/TINY02
index 36e41df3d27a..f1892e0371c9 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TINY02
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TINY02
@@ -8,7 +8,7 @@ CONFIG_NO_HZ_IDLE=n
8CONFIG_NO_HZ_FULL=n 8CONFIG_NO_HZ_FULL=n
9CONFIG_RCU_TRACE=y 9CONFIG_RCU_TRACE=y
10CONFIG_PROVE_LOCKING=y 10CONFIG_PROVE_LOCKING=y
11CONFIG_PROVE_RCU=y 11#CHECK#CONFIG_PROVE_RCU=y
12CONFIG_DEBUG_LOCK_ALLOC=y 12CONFIG_DEBUG_LOCK_ALLOC=y
13CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 13CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
14CONFIG_PREEMPT_COUNT=y 14CONFIG_PREEMPT_COUNT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot b/tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot
index 0f0802730014..6c1a292a65fb 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TINY02.boot
@@ -1,2 +1,3 @@
1rcupdate.rcu_self_test=1 1rcupdate.rcu_self_test=1
2rcupdate.rcu_self_test_bh=1 2rcupdate.rcu_self_test_bh=1
3rcutorture.torture_type=rcu_bh
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE01 b/tools/testing/selftests/rcutorture/configs/rcu/TREE01
index f8a10a7500c6..8e9137f66831 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE01
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE01
@@ -16,3 +16,4 @@ CONFIG_DEBUG_LOCK_ALLOC=n
16CONFIG_RCU_CPU_STALL_INFO=n 16CONFIG_RCU_CPU_STALL_INFO=n
17CONFIG_RCU_BOOST=n 17CONFIG_RCU_BOOST=n
18CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 18CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
19CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE02 b/tools/testing/selftests/rcutorture/configs/rcu/TREE02
index 629122fb8b4a..aeea6a204d14 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE02
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE02
@@ -14,10 +14,10 @@ CONFIG_SUSPEND=n
14CONFIG_HIBERNATION=n 14CONFIG_HIBERNATION=n
15CONFIG_RCU_FANOUT=3 15CONFIG_RCU_FANOUT=3
16CONFIG_RCU_FANOUT_LEAF=3 16CONFIG_RCU_FANOUT_LEAF=3
17CONFIG_RCU_FANOUT_EXACT=n
18CONFIG_RCU_NOCB_CPU=n 17CONFIG_RCU_NOCB_CPU=n
19CONFIG_DEBUG_LOCK_ALLOC=y 18CONFIG_DEBUG_LOCK_ALLOC=y
20CONFIG_PROVE_LOCKING=n 19CONFIG_PROVE_LOCKING=n
21CONFIG_RCU_CPU_STALL_INFO=n 20CONFIG_RCU_CPU_STALL_INFO=n
22CONFIG_RCU_BOOST=n 21CONFIG_RCU_BOOST=n
23CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
23CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE02-T b/tools/testing/selftests/rcutorture/configs/rcu/TREE02-T
index a25de47888a4..2ac9e68ea3d1 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE02-T
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE02-T
@@ -14,7 +14,6 @@ CONFIG_SUSPEND=n
14CONFIG_HIBERNATION=n 14CONFIG_HIBERNATION=n
15CONFIG_RCU_FANOUT=3 15CONFIG_RCU_FANOUT=3
16CONFIG_RCU_FANOUT_LEAF=3 16CONFIG_RCU_FANOUT_LEAF=3
17CONFIG_RCU_FANOUT_EXACT=n
18CONFIG_RCU_NOCB_CPU=n 17CONFIG_RCU_NOCB_CPU=n
19CONFIG_DEBUG_LOCK_ALLOC=y 18CONFIG_DEBUG_LOCK_ALLOC=y
20CONFIG_PROVE_LOCKING=n 19CONFIG_PROVE_LOCKING=n
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE03 b/tools/testing/selftests/rcutorture/configs/rcu/TREE03
index 53f24e0a0ab6..72aa7d87ea99 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE03
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE03
@@ -1,5 +1,5 @@
1CONFIG_SMP=y 1CONFIG_SMP=y
2CONFIG_NR_CPUS=8 2CONFIG_NR_CPUS=16
3CONFIG_PREEMPT_NONE=n 3CONFIG_PREEMPT_NONE=n
4CONFIG_PREEMPT_VOLUNTARY=n 4CONFIG_PREEMPT_VOLUNTARY=n
5CONFIG_PREEMPT=y 5CONFIG_PREEMPT=y
@@ -9,12 +9,12 @@ CONFIG_NO_HZ_IDLE=n
9CONFIG_NO_HZ_FULL=n 9CONFIG_NO_HZ_FULL=n
10CONFIG_RCU_TRACE=y 10CONFIG_RCU_TRACE=y
11CONFIG_HOTPLUG_CPU=y 11CONFIG_HOTPLUG_CPU=y
12CONFIG_RCU_FANOUT=4 12CONFIG_RCU_FANOUT=2
13CONFIG_RCU_FANOUT_LEAF=4 13CONFIG_RCU_FANOUT_LEAF=2
14CONFIG_RCU_FANOUT_EXACT=n
15CONFIG_RCU_NOCB_CPU=n 14CONFIG_RCU_NOCB_CPU=n
16CONFIG_DEBUG_LOCK_ALLOC=n 15CONFIG_DEBUG_LOCK_ALLOC=n
17CONFIG_RCU_CPU_STALL_INFO=n 16CONFIG_RCU_CPU_STALL_INFO=n
18CONFIG_RCU_BOOST=y 17CONFIG_RCU_BOOST=y
19CONFIG_RCU_KTHREAD_PRIO=2 18CONFIG_RCU_KTHREAD_PRIO=2
20CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 19CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
20CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot b/tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot
new file mode 100644
index 000000000000..120c0c88d100
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE03.boot
@@ -0,0 +1 @@
rcutorture.onoff_interval=1 rcutorture.onoff_holdoff=30
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE04 b/tools/testing/selftests/rcutorture/configs/rcu/TREE04
index 0f84db35b36d..3f5112751cda 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE04
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE04
@@ -13,10 +13,10 @@ CONFIG_RCU_TRACE=y
13CONFIG_HOTPLUG_CPU=n 13CONFIG_HOTPLUG_CPU=n
14CONFIG_SUSPEND=n 14CONFIG_SUSPEND=n
15CONFIG_HIBERNATION=n 15CONFIG_HIBERNATION=n
16CONFIG_RCU_FANOUT=2 16CONFIG_RCU_FANOUT=4
17CONFIG_RCU_FANOUT_LEAF=2 17CONFIG_RCU_FANOUT_LEAF=4
18CONFIG_RCU_FANOUT_EXACT=n
19CONFIG_RCU_NOCB_CPU=n 18CONFIG_RCU_NOCB_CPU=n
20CONFIG_DEBUG_LOCK_ALLOC=n 19CONFIG_DEBUG_LOCK_ALLOC=n
21CONFIG_RCU_CPU_STALL_INFO=y 20CONFIG_RCU_CPU_STALL_INFO=n
22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 21CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
22CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE05 b/tools/testing/selftests/rcutorture/configs/rcu/TREE05
index 212e3bfd2b2a..c04dfea6fd21 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE05
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE05
@@ -12,11 +12,11 @@ CONFIG_RCU_TRACE=n
12CONFIG_HOTPLUG_CPU=y 12CONFIG_HOTPLUG_CPU=y
13CONFIG_RCU_FANOUT=6 13CONFIG_RCU_FANOUT=6
14CONFIG_RCU_FANOUT_LEAF=6 14CONFIG_RCU_FANOUT_LEAF=6
15CONFIG_RCU_FANOUT_EXACT=n
16CONFIG_RCU_NOCB_CPU=y 15CONFIG_RCU_NOCB_CPU=y
17CONFIG_RCU_NOCB_CPU_NONE=y 16CONFIG_RCU_NOCB_CPU_NONE=y
18CONFIG_DEBUG_LOCK_ALLOC=y 17CONFIG_DEBUG_LOCK_ALLOC=y
19CONFIG_PROVE_LOCKING=y 18CONFIG_PROVE_LOCKING=y
20CONFIG_PROVE_RCU=y 19#CHECK#CONFIG_PROVE_RCU=y
21CONFIG_RCU_CPU_STALL_INFO=n 20CONFIG_RCU_CPU_STALL_INFO=n
22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 21CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
22CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE06 b/tools/testing/selftests/rcutorture/configs/rcu/TREE06
index 7eee63b44218..f51d2c73a68e 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE06
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE06
@@ -14,10 +14,10 @@ CONFIG_SUSPEND=n
14CONFIG_HIBERNATION=n 14CONFIG_HIBERNATION=n
15CONFIG_RCU_FANOUT=6 15CONFIG_RCU_FANOUT=6
16CONFIG_RCU_FANOUT_LEAF=6 16CONFIG_RCU_FANOUT_LEAF=6
17CONFIG_RCU_FANOUT_EXACT=y
18CONFIG_RCU_NOCB_CPU=n 17CONFIG_RCU_NOCB_CPU=n
19CONFIG_DEBUG_LOCK_ALLOC=y 18CONFIG_DEBUG_LOCK_ALLOC=y
20CONFIG_PROVE_LOCKING=y 19CONFIG_PROVE_LOCKING=y
21CONFIG_PROVE_RCU=y 20#CHECK#CONFIG_PROVE_RCU=y
22CONFIG_RCU_CPU_STALL_INFO=n 21CONFIG_RCU_CPU_STALL_INFO=n
23CONFIG_DEBUG_OBJECTS_RCU_HEAD=y 22CONFIG_DEBUG_OBJECTS_RCU_HEAD=y
23CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot b/tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot
index da9a03a398db..dd90f28ed700 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE06.boot
@@ -1,3 +1,4 @@
1rcupdate.rcu_self_test=1 1rcupdate.rcu_self_test=1
2rcupdate.rcu_self_test_bh=1 2rcupdate.rcu_self_test_bh=1
3rcupdate.rcu_self_test_sched=1 3rcupdate.rcu_self_test_sched=1
4rcutree.rcu_fanout_exact=1
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE07 b/tools/testing/selftests/rcutorture/configs/rcu/TREE07
index 92a97fa97dec..f422af4ff5a3 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE07
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE07
@@ -15,8 +15,8 @@ CONFIG_RCU_TRACE=y
15CONFIG_HOTPLUG_CPU=y 15CONFIG_HOTPLUG_CPU=y
16CONFIG_RCU_FANOUT=2 16CONFIG_RCU_FANOUT=2
17CONFIG_RCU_FANOUT_LEAF=2 17CONFIG_RCU_FANOUT_LEAF=2
18CONFIG_RCU_FANOUT_EXACT=n
19CONFIG_RCU_NOCB_CPU=n 18CONFIG_RCU_NOCB_CPU=n
20CONFIG_DEBUG_LOCK_ALLOC=n 19CONFIG_DEBUG_LOCK_ALLOC=n
21CONFIG_RCU_CPU_STALL_INFO=y 20CONFIG_RCU_CPU_STALL_INFO=n
22CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 21CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
22CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE08 b/tools/testing/selftests/rcutorture/configs/rcu/TREE08
index 5812027d6f9f..a24d2ca30646 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE08
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE08
@@ -1,5 +1,5 @@
1CONFIG_SMP=y 1CONFIG_SMP=y
2CONFIG_NR_CPUS=16 2CONFIG_NR_CPUS=8
3CONFIG_PREEMPT_NONE=n 3CONFIG_PREEMPT_NONE=n
4CONFIG_PREEMPT_VOLUNTARY=n 4CONFIG_PREEMPT_VOLUNTARY=n
5CONFIG_PREEMPT=y 5CONFIG_PREEMPT=y
@@ -13,13 +13,13 @@ CONFIG_HOTPLUG_CPU=n
13CONFIG_SUSPEND=n 13CONFIG_SUSPEND=n
14CONFIG_HIBERNATION=n 14CONFIG_HIBERNATION=n
15CONFIG_RCU_FANOUT=3 15CONFIG_RCU_FANOUT=3
16CONFIG_RCU_FANOUT_EXACT=y
17CONFIG_RCU_FANOUT_LEAF=2 16CONFIG_RCU_FANOUT_LEAF=2
18CONFIG_RCU_NOCB_CPU=y 17CONFIG_RCU_NOCB_CPU=y
19CONFIG_RCU_NOCB_CPU_ALL=y 18CONFIG_RCU_NOCB_CPU_ALL=y
20CONFIG_DEBUG_LOCK_ALLOC=n 19CONFIG_DEBUG_LOCK_ALLOC=n
21CONFIG_PROVE_LOCKING=y 20CONFIG_PROVE_LOCKING=y
22CONFIG_PROVE_RCU=y 21#CHECK#CONFIG_PROVE_RCU=y
23CONFIG_RCU_CPU_STALL_INFO=n 22CONFIG_RCU_CPU_STALL_INFO=n
24CONFIG_RCU_BOOST=n 23CONFIG_RCU_BOOST=n
25CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 24CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
25CONFIG_RCU_EXPERT=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T b/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T
index 3eaeccacb083..b2b8cea69dc9 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T
@@ -13,7 +13,6 @@ CONFIG_HOTPLUG_CPU=n
13CONFIG_SUSPEND=n 13CONFIG_SUSPEND=n
14CONFIG_HIBERNATION=n 14CONFIG_HIBERNATION=n
15CONFIG_RCU_FANOUT=3 15CONFIG_RCU_FANOUT=3
16CONFIG_RCU_FANOUT_EXACT=y
17CONFIG_RCU_FANOUT_LEAF=2 16CONFIG_RCU_FANOUT_LEAF=2
18CONFIG_RCU_NOCB_CPU=y 17CONFIG_RCU_NOCB_CPU=y
19CONFIG_RCU_NOCB_CPU_ALL=y 18CONFIG_RCU_NOCB_CPU_ALL=y
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T.boot b/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T.boot
new file mode 100644
index 000000000000..883149b5f2d1
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE08-T.boot
@@ -0,0 +1 @@
rcutree.rcu_fanout_exact=1
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot b/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot
index 2561daf605ad..fb066dc82769 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE08.boot
@@ -1,3 +1,4 @@
1rcutorture.torture_type=sched 1rcutorture.torture_type=sched
2rcupdate.rcu_self_test=1 2rcupdate.rcu_self_test=1
3rcupdate.rcu_self_test_sched=1 3rcupdate.rcu_self_test_sched=1
4rcutree.rcu_fanout_exact=1
diff --git a/tools/testing/selftests/rcutorture/configs/rcu/TREE09 b/tools/testing/selftests/rcutorture/configs/rcu/TREE09
index 6076b36f6c0b..aa4ed08d999d 100644
--- a/tools/testing/selftests/rcutorture/configs/rcu/TREE09
+++ b/tools/testing/selftests/rcutorture/configs/rcu/TREE09
@@ -16,3 +16,4 @@ CONFIG_DEBUG_LOCK_ALLOC=n
16CONFIG_RCU_CPU_STALL_INFO=n 16CONFIG_RCU_CPU_STALL_INFO=n
17CONFIG_RCU_BOOST=n 17CONFIG_RCU_BOOST=n
18CONFIG_DEBUG_OBJECTS_RCU_HEAD=n 18CONFIG_DEBUG_OBJECTS_RCU_HEAD=n
19#CHECK#CONFIG_RCU_EXPERT=n
diff --git a/tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt b/tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt
index ec03c883db00..b24c0004fc49 100644
--- a/tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt
+++ b/tools/testing/selftests/rcutorture/doc/TREE_RCU-kconfig.txt
@@ -12,13 +12,12 @@ CONFIG_NO_HZ_IDLE -- Do those not otherwise specified. (Groups of two.)
12CONFIG_NO_HZ_FULL -- Do two, one with CONFIG_NO_HZ_FULL_SYSIDLE. 12CONFIG_NO_HZ_FULL -- Do two, one with CONFIG_NO_HZ_FULL_SYSIDLE.
13CONFIG_NO_HZ_FULL_SYSIDLE -- Do one. 13CONFIG_NO_HZ_FULL_SYSIDLE -- Do one.
14CONFIG_PREEMPT -- Do half. (First three and #8.) 14CONFIG_PREEMPT -- Do half. (First three and #8.)
15CONFIG_PROVE_LOCKING -- Do all but two, covering CONFIG_PROVE_RCU and not. 15CONFIG_PROVE_LOCKING -- Do several, covering CONFIG_DEBUG_LOCK_ALLOC=y and not.
16CONFIG_PROVE_RCU -- Do all but one under CONFIG_PROVE_LOCKING. 16CONFIG_PROVE_RCU -- Hardwired to CONFIG_PROVE_LOCKING.
17CONFIG_RCU_BOOST -- one of PREEMPT_RCU. 17CONFIG_RCU_BOOST -- one of PREEMPT_RCU.
18CONFIG_RCU_KTHREAD_PRIO -- set to 2 for _BOOST testing. 18CONFIG_RCU_KTHREAD_PRIO -- set to 2 for _BOOST testing.
19CONFIG_RCU_CPU_STALL_INFO -- Do one. 19CONFIG_RCU_CPU_STALL_INFO -- Now default, avoid at least twice.
20CONFIG_RCU_FANOUT -- Cover hierarchy as currently, but overlap with others. 20CONFIG_RCU_FANOUT -- Cover hierarchy, but overlap with others.
21CONFIG_RCU_FANOUT_EXACT -- Do one.
22CONFIG_RCU_FANOUT_LEAF -- Do one non-default. 21CONFIG_RCU_FANOUT_LEAF -- Do one non-default.
23CONFIG_RCU_FAST_NO_HZ -- Do one, but not with CONFIG_RCU_NOCB_CPU_ALL. 22CONFIG_RCU_FAST_NO_HZ -- Do one, but not with CONFIG_RCU_NOCB_CPU_ALL.
24CONFIG_RCU_NOCB_CPU -- Do three, see below. 23CONFIG_RCU_NOCB_CPU -- Do three, see below.
@@ -27,28 +26,19 @@ CONFIG_RCU_NOCB_CPU_NONE -- Do one.
27CONFIG_RCU_NOCB_CPU_ZERO -- Do one. 26CONFIG_RCU_NOCB_CPU_ZERO -- Do one.
28CONFIG_RCU_TRACE -- Do half. 27CONFIG_RCU_TRACE -- Do half.
29CONFIG_SMP -- Need one !SMP for PREEMPT_RCU. 28CONFIG_SMP -- Need one !SMP for PREEMPT_RCU.
29!RCU_EXPERT -- Do a few, but these have to be vanilla configurations.
30RCU-bh: Do one with PREEMPT and one with !PREEMPT. 30RCU-bh: Do one with PREEMPT and one with !PREEMPT.
31RCU-sched: Do one with PREEMPT but not BOOST. 31RCU-sched: Do one with PREEMPT but not BOOST.
32 32
33 33
34Hierarchy: 34Boot parameters:
35 35
36TREE01. CONFIG_NR_CPUS=8, CONFIG_RCU_FANOUT=8, CONFIG_RCU_FANOUT_EXACT=n. 36nohz_full - do at least one.
37TREE02. CONFIG_NR_CPUS=8, CONFIG_RCU_FANOUT=3, CONFIG_RCU_FANOUT_EXACT=n, 37maxcpu -- do at least one.
38 CONFIG_RCU_FANOUT_LEAF=3. 38rcupdate.rcu_self_test_bh -- Do at least one each, offloaded and not.
39TREE03. CONFIG_NR_CPUS=8, CONFIG_RCU_FANOUT=4, CONFIG_RCU_FANOUT_EXACT=n, 39rcupdate.rcu_self_test_sched -- Do at least one each, offloaded and not.
40 CONFIG_RCU_FANOUT_LEAF=4. 40rcupdate.rcu_self_test -- Do at least one each, offloaded and not.
41TREE04. CONFIG_NR_CPUS=8, CONFIG_RCU_FANOUT=2, CONFIG_RCU_FANOUT_EXACT=n, 41rcutree.rcu_fanout_exact -- Do at least one.
42 CONFIG_RCU_FANOUT_LEAF=2.
43TREE05. CONFIG_NR_CPUS=8, CONFIG_RCU_FANOUT=6, CONFIG_RCU_FANOUT_EXACT=n
44 CONFIG_RCU_FANOUT_LEAF=6.
45TREE06. CONFIG_NR_CPUS=8, CONFIG_RCU_FANOUT=6, CONFIG_RCU_FANOUT_EXACT=y
46 CONFIG_RCU_FANOUT_LEAF=6.
47TREE07. CONFIG_NR_CPUS=16, CONFIG_RCU_FANOUT=2, CONFIG_RCU_FANOUT_EXACT=n,
48 CONFIG_RCU_FANOUT_LEAF=2.
49TREE08. CONFIG_NR_CPUS=16, CONFIG_RCU_FANOUT=3, CONFIG_RCU_FANOUT_EXACT=y,
50 CONFIG_RCU_FANOUT_LEAF=2.
51TREE09. CONFIG_NR_CPUS=1.
52 42
53 43
54Kconfig Parameters Ignored: 44Kconfig Parameters Ignored: