[PATCH v3 7/7] rcu: Add CONFIG_RCU_SR_NORMAL_DEBUG_GP

From: Uladzislau Rezki (Sony)
Date: Tue Nov 28 2023 - 03:01:29 EST


This option enables additional debugging for detecting a grace
period incompletion for synchronize_rcu() users. If a GP is not
fully passed for any user, the warning message is emitted.

Signed-off-by: Uladzislau Rezki (Sony) <urezki@xxxxxxxxx>
---
kernel/rcu/Kconfig.debug | 12 ++++++++++++
kernel/rcu/tree.c | 7 +++++--
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/Kconfig.debug b/kernel/rcu/Kconfig.debug
index 2984de629f74..3d44106ca1f0 100644
--- a/kernel/rcu/Kconfig.debug
+++ b/kernel/rcu/Kconfig.debug
@@ -143,4 +143,16 @@ config RCU_STRICT_GRACE_PERIOD
when looking for certain types of RCU usage bugs, for example,
too-short RCU read-side critical sections.

+config RCU_SR_NORMAL_DEBUG_GP
+ bool "Debug synchronize_rcu() callers for a grace period completion"
+ depends on DEBUG_KERNEL && RCU_EXPERT
+ default n
+ help
+ This option enables additional debugging for detecting a grace
+ period incompletion for synchronize_rcu() users. If a GP is not
+ fully passed for any user, the warning message is emitted.
+
+ Say Y here if you want to enable such debugging
+ Say N if you are unsure.
+
endmenu # "RCU Debugging"
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index c0d3e46730e8..421bce4b8dd7 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1547,7 +1547,8 @@ static void rcu_sr_normal_complete(struct llist_node *node)
(struct rcu_head *) node, struct rcu_synchronize, head);
unsigned long oldstate = (unsigned long) rs->head.func;

- WARN_ONCE(!rcu_gp_is_expedited() && !poll_state_synchronize_rcu(oldstate),
+ WARN_ONCE(IS_ENABLED(CONFIG_RCU_SR_NORMAL_DEBUG_GP) &&
+ !poll_state_synchronize_rcu(oldstate),
"A full grace period is not passed yet: %lu",
rcu_seq_diff(get_state_synchronize_rcu(), oldstate));

@@ -3822,7 +3823,9 @@ static void synchronize_rcu_normal(void)
* This code might be preempted, therefore take a GP
* snapshot before adding a request.
*/
- rs.head.func = (void *) get_state_synchronize_rcu();
+ if (IS_ENABLED(CONFIG_RCU_SR_NORMAL_DEBUG_GP))
+ rs.head.func = (void *) get_state_synchronize_rcu();
+
rcu_sr_normal_add_req(&rs);

/* Kick a GP and start waiting. */
--
2.39.2