Skip to content

Commit 46f1ec2

Browse files
committed
Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull RCU updates from Ingo Molnar: "The changes in this cycle are: - RCU flavor consolidation cleanups and optmizations - Documentation updates - Miscellaneous fixes - SRCU updates - RCU-sync flavor consolidation - Torture-test updates - Linux-kernel memory-consistency-model updates, most notably the addition of plain C-language accesses" * 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (61 commits) tools/memory-model: Improve data-race detection tools/memory-model: Change definition of rcu-fence tools/memory-model: Expand definition of barrier tools/memory-model: Do not use "herd" to refer to "herd7" tools/memory-model: Fix comment in MP+poonceonces.litmus Documentation: atomic_t.txt: Explain ordering provided by smp_mb__{before,after}_atomic() rcu: Don't return a value from rcu_assign_pointer() rcu: Force inlining of rcu_read_lock() rcu: Fix irritating whitespace error in rcu_assign_pointer() rcu: Upgrade sync_exp_work_done() to smp_mb() rcutorture: Upper case solves the case of the vanishing NULL pointer torture: Suppress propagating trace_printk() warning rcutorture: Dump trace buffer for callback pipe drain failures torture: Add --trust-make to suppress "make clean" torture: Make --cpus override idleness calculations torture: Run kernel build in source directory torture: Add function graph-tracing cheat sheet torture: Capture qemu output rcutorture: Tweak kvm options rcutorture: Add trivial RCU implementation ...
2 parents 223cea6 + 83086d6 commit 46f1ec2

Some content is hidden

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

61 files changed

+845
-466
lines changed

Documentation/RCU/rcuref.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ please read on.
1212
Reference counting on elements of lists which are protected by traditional
1313
reader/writer spinlocks or semaphores are straightforward:
1414

15+
CODE LISTING A:
1516
1. 2.
1617
add() search_and_reference()
1718
{ {
@@ -28,7 +29,8 @@ add() search_and_reference()
2829
release_referenced() delete()
2930
{ {
3031
... write_lock(&list_lock);
31-
atomic_dec(&el->rc, relfunc) ...
32+
if(atomic_dec_and_test(&el->rc)) ...
33+
kfree(el);
3234
... remove_element
3335
} write_unlock(&list_lock);
3436
...
@@ -44,6 +46,7 @@ search_and_reference() could potentially hold reference to an element which
4446
has already been deleted from the list/array. Use atomic_inc_not_zero()
4547
in this scenario as follows:
4648

49+
CODE LISTING B:
4750
1. 2.
4851
add() search_and_reference()
4952
{ {
@@ -79,6 +82,7 @@ search_and_reference() code path. In such cases, the
7982
atomic_dec_and_test() may be moved from delete() to el_free()
8083
as follows:
8184

85+
CODE LISTING C:
8286
1. 2.
8387
add() search_and_reference()
8488
{ {
@@ -114,6 +118,17 @@ element can therefore safely be freed. This in turn guarantees that if
114118
any reader finds the element, that reader may safely acquire a reference
115119
without checking the value of the reference counter.
116120

121+
A clear advantage of the RCU-based pattern in listing C over the one
122+
in listing B is that any call to search_and_reference() that locates
123+
a given object will succeed in obtaining a reference to that object,
124+
even given a concurrent invocation of delete() for that same object.
125+
Similarly, a clear advantage of both listings B and C over listing A is
126+
that a call to delete() is not delayed even if there are an arbitrarily
127+
large number of calls to search_and_reference() searching for the same
128+
object that delete() was invoked on. Instead, all that is delayed is
129+
the eventual invocation of kfree(), which is usually not a problem on
130+
modern computer systems, even the small ones.
131+
117132
In cases where delete() can sleep, synchronize_rcu() can be called from
118133
delete(), so that el_free() can be subsumed into delete as follows:
119134

@@ -130,3 +145,7 @@ delete()
130145
kfree(el);
131146
...
132147
}
148+
149+
As additional examples in the kernel, the pattern in listing C is used by
150+
reference counting of struct pid, while the pattern in listing B is used by
151+
struct posix_acl.

Documentation/RCU/stallwarn.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ rcupdate.rcu_task_stall_timeout
153153
This boot/sysfs parameter controls the RCU-tasks stall warning
154154
interval. A value of zero or less suppresses RCU-tasks stall
155155
warnings. A positive value sets the stall-warning interval
156-
in jiffies. An RCU-tasks stall warning starts with the line:
156+
in seconds. An RCU-tasks stall warning starts with the line:
157157

158158
INFO: rcu_tasks detected stalls on tasks:
159159

Documentation/RCU/whatisRCU.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,17 @@ synchronize_rcu()
212212

213213
rcu_assign_pointer()
214214

215-
typeof(p) rcu_assign_pointer(p, typeof(p) v);
215+
void rcu_assign_pointer(p, typeof(p) v);
216216

217217
Yes, rcu_assign_pointer() -is- implemented as a macro, though it
218218
would be cool to be able to declare a function in this manner.
219219
(Compiler experts will no doubt disagree.)
220220

221221
The updater uses this function to assign a new value to an
222222
RCU-protected pointer, in order to safely communicate the change
223-
in value from the updater to the reader. This function returns
224-
the new value, and also executes any memory-barrier instructions
225-
required for a given CPU architecture.
223+
in value from the updater to the reader. This macro does not
224+
evaluate to an rvalue, but it does execute any memory-barrier
225+
instructions required for a given CPU architecture.
226226

227227
Perhaps just as important, it serves to document (1) which
228228
pointers are protected by RCU and (2) the point at which a

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,6 +3752,12 @@
37523752
the propagation of recent CPU-hotplug changes up
37533753
the rcu_node combining tree.
37543754

3755+
rcutree.use_softirq= [KNL]
3756+
If set to zero, move all RCU_SOFTIRQ processing to
3757+
per-CPU rcuc kthreads. Defaults to a non-zero
3758+
value, meaning that RCU_SOFTIRQ is used by default.
3759+
Specify rcutree.use_softirq=0 to use rcuc kthreads.
3760+
37553761
rcutree.rcu_fanout_exact= [KNL]
37563762
Disable autobalancing of the rcu_node combining
37573763
tree. This is used by rcutorture, and might

Documentation/atomic_t.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,14 @@ The barriers:
187187

188188
smp_mb__{before,after}_atomic()
189189

190-
only apply to the RMW ops and can be used to augment/upgrade the ordering
191-
inherent to the used atomic op. These barriers provide a full smp_mb().
190+
only apply to the RMW atomic ops and can be used to augment/upgrade the
191+
ordering inherent to the op. These barriers act almost like a full smp_mb():
192+
smp_mb__before_atomic() orders all earlier accesses against the RMW op
193+
itself and all accesses following it, and smp_mb__after_atomic() orders all
194+
later accesses against the RMW op and all accesses preceding it. However,
195+
accesses between the smp_mb__{before,after}_atomic() and the RMW op are not
196+
ordered, so it is advisable to place the barrier right next to the RMW atomic
197+
op whenever possible.
192198

193199
These helper barriers exist because architectures have varying implicit
194200
ordering on their SMP atomic primitives. For example our TSO architectures
@@ -212,7 +218,9 @@ Further, while something like:
212218
atomic_dec(&X);
213219

214220
is a 'typical' RELEASE pattern, the barrier is strictly stronger than
215-
a RELEASE. Similarly for something like:
221+
a RELEASE because it orders preceding instructions against both the read
222+
and write parts of the atomic_dec(), and against all following instructions
223+
as well. Similarly, something like:
216224

217225
atomic_inc(&X);
218226
smp_mb__after_atomic();
@@ -244,7 +252,8 @@ strictly stronger than ACQUIRE. As illustrated:
244252

245253
This should not happen; but a hypothetical atomic_inc_acquire() --
246254
(void)atomic_fetch_inc_acquire() for instance -- would allow the outcome,
247-
since then:
255+
because it would not order the W part of the RMW against the following
256+
WRITE_ONCE. Thus:
248257

249258
P1 P2
250259

Documentation/core-api/circular-buffers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Circular Buffers
33
================
44

55
:Author: David Howells <[email protected]>
6-
:Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
6+
:Author: Paul E. McKenney <[email protected]>
77

88

99
Linux provides a number of features that can be used to implement circular

Documentation/memory-barriers.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
============================
44

55
By: David Howells <[email protected]>
6-
Paul E. McKenney <paulmck@linux.vnet.ibm.com>
6+
Paul E. McKenney <[email protected]>
77
Will Deacon <[email protected]>
88
Peter Zijlstra <[email protected]>
99

Documentation/translations/ko_KR/memory-barriers.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Documentation/memory-barriers.txt
2424
=========================
2525

2626
저자: David Howells <[email protected]>
27-
Paul E. McKenney <paulmck@linux.vnet.ibm.com>
27+
Paul E. McKenney <[email protected]>
2828
Will Deacon <[email protected]>
2929
Peter Zijlstra <[email protected]>
3030

include/linux/lockdep.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,18 @@ do { \
632632
"IRQs not disabled as expected\n"); \
633633
} while (0)
634634

635+
#define lockdep_assert_in_irq() do { \
636+
WARN_ONCE(debug_locks && !current->lockdep_recursion && \
637+
!current->hardirq_context, \
638+
"Not in hardirq as expected\n"); \
639+
} while (0)
640+
635641
#else
636642
# define might_lock(lock) do { } while (0)
637643
# define might_lock_read(lock) do { } while (0)
638644
# define lockdep_assert_irqs_enabled() do { } while (0)
639645
# define lockdep_assert_irqs_disabled() do { } while (0)
646+
# define lockdep_assert_in_irq() do { } while (0)
640647
#endif
641648

642649
#ifdef CONFIG_LOCKDEP

include/linux/module.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/rbtree_latch.h>
2222
#include <linux/error-injection.h>
2323
#include <linux/tracepoint-defs.h>
24+
#include <linux/srcu.h>
2425

2526
#include <linux/percpu.h>
2627
#include <asm/module.h>
@@ -450,6 +451,10 @@ struct module {
450451
unsigned int num_tracepoints;
451452
tracepoint_ptr_t *tracepoints_ptrs;
452453
#endif
454+
#ifdef CONFIG_TREE_SRCU
455+
unsigned int num_srcu_structs;
456+
struct srcu_struct **srcu_struct_ptrs;
457+
#endif
453458
#ifdef CONFIG_BPF_EVENTS
454459
unsigned int num_bpf_raw_events;
455460
struct bpf_raw_event_map *bpf_raw_events;

include/linux/percpu-rwsem.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ struct percpu_rw_semaphore {
1717
int readers_block;
1818
};
1919

20-
#define DEFINE_STATIC_PERCPU_RWSEM(name) \
20+
#define __DEFINE_PERCPU_RWSEM(name, is_static) \
2121
static DEFINE_PER_CPU(unsigned int, __percpu_rwsem_rc_##name); \
22-
static struct percpu_rw_semaphore name = { \
23-
.rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC), \
22+
is_static struct percpu_rw_semaphore name = { \
23+
.rss = __RCU_SYNC_INITIALIZER(name.rss), \
2424
.read_count = &__percpu_rwsem_rc_##name, \
2525
.rw_sem = __RWSEM_INITIALIZER(name.rw_sem), \
2626
.writer = __RCUWAIT_INITIALIZER(name.writer), \
2727
}
28+
#define DEFINE_PERCPU_RWSEM(name) \
29+
__DEFINE_PERCPU_RWSEM(name, /* not static */)
30+
#define DEFINE_STATIC_PERCPU_RWSEM(name) \
31+
__DEFINE_PERCPU_RWSEM(name, static)
2832

2933
extern int __percpu_down_read(struct percpu_rw_semaphore *, int);
3034
extern void __percpu_up_read(struct percpu_rw_semaphore *);

include/linux/rcu_sync.h

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,44 @@
1313
#include <linux/wait.h>
1414
#include <linux/rcupdate.h>
1515

16-
enum rcu_sync_type { RCU_SYNC, RCU_SCHED_SYNC, RCU_BH_SYNC };
17-
1816
/* Structure to mediate between updaters and fastpath-using readers. */
1917
struct rcu_sync {
2018
int gp_state;
2119
int gp_count;
2220
wait_queue_head_t gp_wait;
2321

24-
int cb_state;
2522
struct rcu_head cb_head;
26-
27-
enum rcu_sync_type gp_type;
2823
};
2924

30-
extern void rcu_sync_lockdep_assert(struct rcu_sync *);
31-
3225
/**
3326
* rcu_sync_is_idle() - Are readers permitted to use their fastpaths?
3427
* @rsp: Pointer to rcu_sync structure to use for synchronization
3528
*
36-
* Returns true if readers are permitted to use their fastpaths.
37-
* Must be invoked within an RCU read-side critical section whose
38-
* flavor matches that of the rcu_sync struture.
29+
* Returns true if readers are permitted to use their fastpaths. Must be
30+
* invoked within some flavor of RCU read-side critical section.
3931
*/
4032
static inline bool rcu_sync_is_idle(struct rcu_sync *rsp)
4133
{
42-
#ifdef CONFIG_PROVE_RCU
43-
rcu_sync_lockdep_assert(rsp);
44-
#endif
45-
return !rsp->gp_state; /* GP_IDLE */
34+
RCU_LOCKDEP_WARN(!rcu_read_lock_held() &&
35+
!rcu_read_lock_bh_held() &&
36+
!rcu_read_lock_sched_held(),
37+
"suspicious rcu_sync_is_idle() usage");
38+
return !READ_ONCE(rsp->gp_state); /* GP_IDLE */
4639
}
4740

48-
extern void rcu_sync_init(struct rcu_sync *, enum rcu_sync_type);
41+
extern void rcu_sync_init(struct rcu_sync *);
4942
extern void rcu_sync_enter_start(struct rcu_sync *);
5043
extern void rcu_sync_enter(struct rcu_sync *);
5144
extern void rcu_sync_exit(struct rcu_sync *);
5245
extern void rcu_sync_dtor(struct rcu_sync *);
5346

54-
#define __RCU_SYNC_INITIALIZER(name, type) { \
47+
#define __RCU_SYNC_INITIALIZER(name) { \
5548
.gp_state = 0, \
5649
.gp_count = 0, \
5750
.gp_wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.gp_wait), \
58-
.cb_state = 0, \
59-
.gp_type = type, \
6051
}
6152

62-
#define __DEFINE_RCU_SYNC(name, type) \
63-
struct rcu_sync_struct name = __RCU_SYNC_INITIALIZER(name, type)
64-
65-
#define DEFINE_RCU_SYNC(name) \
66-
__DEFINE_RCU_SYNC(name, RCU_SYNC)
67-
68-
#define DEFINE_RCU_SCHED_SYNC(name) \
69-
__DEFINE_RCU_SYNC(name, RCU_SCHED_SYNC)
70-
71-
#define DEFINE_RCU_BH_SYNC(name) \
72-
__DEFINE_RCU_SYNC(name, RCU_BH_SYNC)
53+
#define DEFINE_RCU_SYNC(name) \
54+
struct rcu_sync name = __RCU_SYNC_INITIALIZER(name)
7355

7456
#endif /* _LINUX_RCU_SYNC_H_ */

include/linux/rcupdate.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,15 @@ static inline void rcu_preempt_sleep_check(void) { }
365365
* other macros that it invokes.
366366
*/
367367
#define rcu_assign_pointer(p, v) \
368-
({ \
368+
do { \
369369
uintptr_t _r_a_p__v = (uintptr_t)(v); \
370-
rcu_check_sparse(p, __rcu); \
370+
rcu_check_sparse(p, __rcu); \
371371
\
372372
if (__builtin_constant_p(v) && (_r_a_p__v) == (uintptr_t)NULL) \
373373
WRITE_ONCE((p), (typeof(p))(_r_a_p__v)); \
374374
else \
375375
smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
376-
_r_a_p__v; \
377-
})
376+
} while (0)
378377

379378
/**
380379
* rcu_swap_protected() - swap an RCU and a regular pointer
@@ -586,7 +585,7 @@ static inline void rcu_preempt_sleep_check(void) { }
586585
* read-side critical sections may be preempted and they may also block, but
587586
* only when acquiring spinlocks that are subject to priority inheritance.
588587
*/
589-
static inline void rcu_read_lock(void)
588+
static __always_inline void rcu_read_lock(void)
590589
{
591590
__rcu_read_lock();
592591
__acquire(RCU);
@@ -803,7 +802,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
803802
/**
804803
* kfree_rcu() - kfree an object after a grace period.
805804
* @ptr: pointer to kfree
806-
* @rcu_head: the name of the struct rcu_head within the type of @ptr.
805+
* @rhf: the name of the struct rcu_head within the type of @ptr.
807806
*
808807
* Many rcu callbacks functions just call kfree() on the base structure.
809808
* These functions are trivial, but their size adds up, and furthermore
@@ -826,9 +825,13 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
826825
* The BUILD_BUG_ON check must not involve any function calls, hence the
827826
* checks are done in macros here.
828827
*/
829-
#define kfree_rcu(ptr, rcu_head) \
830-
__kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
831-
828+
#define kfree_rcu(ptr, rhf) \
829+
do { \
830+
typeof (ptr) ___p = (ptr); \
831+
\
832+
if (___p) \
833+
__kfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \
834+
} while (0)
832835

833836
/*
834837
* Place this after a lock-acquisition primitive to guarantee that

include/linux/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ union rcu_special {
565565
u8 blocked;
566566
u8 need_qs;
567567
u8 exp_hint; /* Hint for performance. */
568-
u8 pad; /* No garbage from compiler! */
568+
u8 deferred_qs;
569569
} b; /* Bits. */
570570
u32 s; /* Set of bits. */
571571
};

include/linux/srcutree.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,17 @@ struct srcu_struct {
120120
*
121121
* See include/linux/percpu-defs.h for the rules on per-CPU variables.
122122
*/
123-
#define __DEFINE_SRCU(name, is_static) \
124-
static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data);\
125-
is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name##_srcu_data)
123+
#ifdef MODULE
124+
# define __DEFINE_SRCU(name, is_static) \
125+
is_static struct srcu_struct name; \
126+
struct srcu_struct * const __srcu_struct_##name \
127+
__section("___srcu_struct_ptrs") = &name
128+
#else
129+
# define __DEFINE_SRCU(name, is_static) \
130+
static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data); \
131+
is_static struct srcu_struct name = \
132+
__SRCU_STRUCT_INIT(name, name##_srcu_data)
133+
#endif
126134
#define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
127135
#define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
128136

include/linux/torture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int torture_shutdown_init(int ssecs, void (*cleanup)(void));
6666

6767
/* Task stuttering, which forces load/no-load transitions. */
6868
bool stutter_wait(const char *title);
69-
int torture_stutter_init(int s);
69+
int torture_stutter_init(int s, int sgap);
7070

7171
/* Initialization and cleanup. */
7272
bool torture_init_begin(char *ttype, int v);

0 commit comments

Comments
 (0)