Skip to content

Commit 3a518b7

Browse files
oleg-nesterovpaulmck
authored andcommitted
rcu_sync: Add CONFIG_PROVE_RCU checks
This commit validates that the caller of rcu_sync_is_idle() holds the corresponding type of RCU read-side lock, but only in kernels built with CONFIG_PROVE_RCU=y. This validation is carried out via a new rcu_sync_ops->held() method that is checked within rcu_sync_is_idle(). Note that although this does add code to the fast path, it only does so in kernels built with CONFIG_PROVE_RCU=y. Suggested-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
1 parent 82e8c56 commit 3a518b7

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎include/linux/rcu_sync.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct rcu_sync {
4040
enum rcu_sync_type gp_type;
4141
};
4242

43+
extern bool __rcu_sync_is_idle(struct rcu_sync *);
44+
4345
/**
4446
* rcu_sync_is_idle() - Are readers permitted to use their fastpaths?
4547
* @rsp: Pointer to rcu_sync structure to use for synchronization
@@ -50,7 +52,11 @@ struct rcu_sync {
5052
*/
5153
static inline bool rcu_sync_is_idle(struct rcu_sync *rsp)
5254
{
55+
#ifdef CONFIG_PROVE_RCU
56+
return __rcu_sync_is_idle(rsp);
57+
#else
5358
return !rsp->gp_state; /* GP_IDLE */
59+
#endif
5460
}
5561

5662
extern void rcu_sync_init(struct rcu_sync *, enum rcu_sync_type);

‎kernel/rcu/sync.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,33 @@
2323
#include <linux/rcu_sync.h>
2424
#include <linux/sched.h>
2525

26+
#ifdef CONFIG_PROVE_RCU
27+
#define __INIT_HELD(func) .held = func,
28+
#else
29+
#define __INIT_HELD(func)
30+
#endif
31+
2632
static const struct {
2733
void (*sync)(void);
2834
void (*call)(struct rcu_head *, void (*)(struct rcu_head *));
35+
#ifdef CONFIG_PROVE_RCU
36+
int (*held)(void);
37+
#endif
2938
} gp_ops[] = {
3039
[RCU_SYNC] = {
3140
.sync = synchronize_rcu,
3241
.call = call_rcu,
42+
__INIT_HELD(rcu_read_lock_held)
3343
},
3444
[RCU_SCHED_SYNC] = {
3545
.sync = synchronize_sched,
3646
.call = call_rcu_sched,
47+
__INIT_HELD(rcu_read_lock_sched_held)
3748
},
3849
[RCU_BH_SYNC] = {
3950
.sync = synchronize_rcu_bh,
4051
.call = call_rcu_bh,
52+
__INIT_HELD(rcu_read_lock_bh_held)
4153
},
4254
};
4355

@@ -46,6 +58,14 @@ enum { CB_IDLE = 0, CB_PENDING, CB_REPLAY };
4658

4759
#define rss_lock gp_wait.lock
4860

61+
#ifdef CONFIG_PROVE_RCU
62+
bool __rcu_sync_is_idle(struct rcu_sync *rsp)
63+
{
64+
WARN_ON(!gp_ops[rsp->gp_type].held());
65+
return rsp->gp_state == GP_IDLE;
66+
}
67+
#endif
68+
4969
/**
5070
* rcu_sync_init() - Initialize an rcu_sync structure
5171
* @rsp: Pointer to rcu_sync structure to be initialized

0 commit comments

Comments
 (0)