Skip to content

Commit 11ca7a9

Browse files
author
Paul E. McKenney
committed
Merge branches 'consolidate.2019.05.28a', 'doc.2019.05.28a', 'fixes.2019.06.13a', 'srcu.2019.05.28a', 'sync.2019.05.28a' and 'torture.2019.05.28a' into HEAD
consolidate.2019.05.28a: RCU flavor consolidation cleanups and optmizations. doc.2019.05.28a: Documentation updates. fixes.2019.06.13a: Miscellaneous fixes. srcu.2019.05.28a: SRCU updates. sync.2019.05.28a: RCU-sync flavor consolidation. torture.2019.05.28a: Torture-test updates.
6 parents f0b6356 + 588759a + 9129b01 + 11b0004 + 89da3b9 + 354ea05 commit 11ca7a9

45 files changed

Lines changed: 484 additions & 262 deletions

Some content is hidden

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

‎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/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 <dhowells@redhat.com>
6-
:Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
6+
:Author: Paul E. McKenney <paulmck@linux.ibm.com>
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 <dhowells@redhat.com>
6-
Paul E. McKenney <paulmck@linux.vnet.ibm.com>
6+
Paul E. McKenney <paulmck@linux.ibm.com>
77
Will Deacon <will.deacon@arm.com>
88
Peter Zijlstra <peterz@infradead.org>
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 <dhowells@redhat.com>
27-
Paul E. McKenney <paulmck@linux.vnet.ibm.com>
27+
Paul E. McKenney <paulmck@linux.ibm.com>
2828
Will Deacon <will.deacon@arm.com>
2929
Peter Zijlstra <peterz@infradead.org>
3030

‎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
@@ -367,16 +367,15 @@ static inline void rcu_preempt_sleep_check(void) { }
367367
* other macros that it invokes.
368368
*/
369369
#define rcu_assign_pointer(p, v) \
370-
({ \
370+
do { \
371371
uintptr_t _r_a_p__v = (uintptr_t)(v); \
372-
rcu_check_sparse(p, __rcu); \
372+
rcu_check_sparse(p, __rcu); \
373373
\
374374
if (__builtin_constant_p(v) && (_r_a_p__v) == (uintptr_t)NULL) \
375375
WRITE_ONCE((p), (typeof(p))(_r_a_p__v)); \
376376
else \
377377
smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
378-
_r_a_p__v; \
379-
})
378+
} while (0)
380379

381380
/**
382381
* rcu_swap_protected() - swap an RCU and a regular pointer
@@ -588,7 +587,7 @@ static inline void rcu_preempt_sleep_check(void) { }
588587
* read-side critical sections may be preempted and they may also block, but
589588
* only when acquiring spinlocks that are subject to priority inheritance.
590589
*/
591-
static inline void rcu_read_lock(void)
590+
static __always_inline void rcu_read_lock(void)
592591
{
593592
__rcu_read_lock();
594593
__acquire(RCU);
@@ -805,7 +804,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
805804
/**
806805
* kfree_rcu() - kfree an object after a grace period.
807806
* @ptr: pointer to kfree
808-
* @rcu_head: the name of the struct rcu_head within the type of @ptr.
807+
* @rhf: the name of the struct rcu_head within the type of @ptr.
809808
*
810809
* Many rcu callbacks functions just call kfree() on the base structure.
811810
* These functions are trivial, but their size adds up, and furthermore
@@ -828,9 +827,13 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
828827
* The BUILD_BUG_ON check must not involve any function calls, hence the
829828
* checks are done in macros here.
830829
*/
831-
#define kfree_rcu(ptr, rcu_head) \
832-
__kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
833-
830+
#define kfree_rcu(ptr, rhf) \
831+
do { \
832+
typeof (ptr) ___p = (ptr); \
833+
\
834+
if (___p) \
835+
__kfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \
836+
} while (0)
834837

835838
/*
836839
* Place this after a lock-acquisition primitive to guarantee that

0 commit comments

Comments
 (0)