Эх сурвалжийг харах

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>
Oleg Nesterov 10 жил өмнө
parent
commit
3a518b76af

+ 6 - 0
include/linux/rcu_sync.h

@@ -40,6 +40,8 @@ struct rcu_sync {
 	enum rcu_sync_type	gp_type;
 	enum rcu_sync_type	gp_type;
 };
 };
 
 
+extern bool __rcu_sync_is_idle(struct rcu_sync *);
+
 /**
 /**
  * rcu_sync_is_idle() - Are readers permitted to use their fastpaths?
  * rcu_sync_is_idle() - Are readers permitted to use their fastpaths?
  * @rsp: Pointer to rcu_sync structure to use for synchronization
  * @rsp: Pointer to rcu_sync structure to use for synchronization
@@ -50,7 +52,11 @@ struct rcu_sync {
  */
  */
 static inline bool rcu_sync_is_idle(struct rcu_sync *rsp)
 static inline bool rcu_sync_is_idle(struct rcu_sync *rsp)
 {
 {
+#ifdef CONFIG_PROVE_RCU
+	return __rcu_sync_is_idle(rsp);
+#else
 	return !rsp->gp_state; /* GP_IDLE */
 	return !rsp->gp_state; /* GP_IDLE */
+#endif
 }
 }
 
 
 extern void rcu_sync_init(struct rcu_sync *, enum rcu_sync_type);
 extern void rcu_sync_init(struct rcu_sync *, enum rcu_sync_type);

+ 20 - 0
kernel/rcu/sync.c

@@ -23,21 +23,33 @@
 #include <linux/rcu_sync.h>
 #include <linux/rcu_sync.h>
 #include <linux/sched.h>
 #include <linux/sched.h>
 
 
+#ifdef CONFIG_PROVE_RCU
+#define __INIT_HELD(func)	.held = func,
+#else
+#define __INIT_HELD(func)
+#endif
+
 static const struct {
 static const struct {
 	void (*sync)(void);
 	void (*sync)(void);
 	void (*call)(struct rcu_head *, void (*)(struct rcu_head *));
 	void (*call)(struct rcu_head *, void (*)(struct rcu_head *));
+#ifdef CONFIG_PROVE_RCU
+	int  (*held)(void);
+#endif
 } gp_ops[] = {
 } gp_ops[] = {
 	[RCU_SYNC] = {
 	[RCU_SYNC] = {
 		.sync = synchronize_rcu,
 		.sync = synchronize_rcu,
 		.call = call_rcu,
 		.call = call_rcu,
+		__INIT_HELD(rcu_read_lock_held)
 	},
 	},
 	[RCU_SCHED_SYNC] = {
 	[RCU_SCHED_SYNC] = {
 		.sync = synchronize_sched,
 		.sync = synchronize_sched,
 		.call = call_rcu_sched,
 		.call = call_rcu_sched,
+		__INIT_HELD(rcu_read_lock_sched_held)
 	},
 	},
 	[RCU_BH_SYNC] = {
 	[RCU_BH_SYNC] = {
 		.sync = synchronize_rcu_bh,
 		.sync = synchronize_rcu_bh,
 		.call = call_rcu_bh,
 		.call = call_rcu_bh,
+		__INIT_HELD(rcu_read_lock_bh_held)
 	},
 	},
 };
 };
 
 
@@ -46,6 +58,14 @@ enum { CB_IDLE = 0, CB_PENDING, CB_REPLAY };
 
 
 #define	rss_lock	gp_wait.lock
 #define	rss_lock	gp_wait.lock
 
 
+#ifdef CONFIG_PROVE_RCU
+bool __rcu_sync_is_idle(struct rcu_sync *rsp)
+{
+	WARN_ON(!gp_ops[rsp->gp_type].held());
+	return rsp->gp_state == GP_IDLE;
+}
+#endif
+
 /**
 /**
  * rcu_sync_init() - Initialize an rcu_sync structure
  * rcu_sync_init() - Initialize an rcu_sync structure
  * @rsp: Pointer to rcu_sync structure to be initialized
  * @rsp: Pointer to rcu_sync structure to be initialized