rcu: Add Kconfig option for strict RCU grace periods
authorPaul E. McKenney <paulmck@kernel.org>
Wed, 5 Aug 2020 22:51:20 +0000 (15:51 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Tue, 25 Aug 2020 01:40:23 +0000 (18:40 -0700)
People running automated tests have asked for a way to make RCU minimize
grace-period duration in order to increase the probability of KASAN
detecting a pointer being improperly leaked from an RCU read-side critical
section, for example, like this:

rcu_read_lock();
p = rcu_dereference(gp);
do_something_with(p); // OK
rcu_read_unlock();
do_something_else_with(p); // BUG!!!

The rcupdate.rcu_expedited boot parameter is a start in this direction,
given that it makes calls to synchronize_rcu() instead invoke the faster
(and more wasteful) synchronize_rcu_expedited().  However, this does
nothing to shorten RCU grace periods that are instead initiated by
call_rcu(), and RCU pointer-leak bugs can involve call_rcu() just as
surely as they can synchronize_rcu().

This commit therefore adds a RCU_STRICT_GRACE_PERIOD Kconfig option
that will be used to shorten normal (non-expedited) RCU grace periods.
This commit also dumps out a message when this option is in effect.
Later commits will actually shorten grace periods.

Reported-by Jann Horn <jannh@google.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/Kconfig.debug
kernel/rcu/tree_plugin.h

index 3cf6132a4bb9f5d251771045a5a379d0acecf935..cab5a4bebe9c5eacd8ad162be5eb11a79f64a85f 100644 (file)
@@ -114,4 +114,19 @@ config RCU_EQS_DEBUG
          Say N here if you need ultimate kernel/user switch latencies
          Say Y if you are unsure
 
+config RCU_STRICT_GRACE_PERIOD
+       bool "Provide debug RCU implementation with short grace periods"
+       depends on DEBUG_KERNEL && RCU_EXPERT
+       default n
+       select PREEMPT_COUNT if PREEMPT=n
+       help
+         Select this option to build an RCU variant that is strict about
+         grace periods, making them as short as it can.  This limits
+         scalability, destroys real-time response, degrades battery
+         lifetime and kills performance.  Don't try this on large
+         machines, as in systems with more than about 10 or 20 CPUs.
+         But in conjunction with tools like KASAN, it can be helpful
+         when looking for certain types of RCU usage bugs, for example,
+         too-short RCU read-side critical sections.
+
 endmenu # "RCU Debugging"
index 982fc5be5269871c6650f82a685016f66273f522..44cf77db7cae8ea54f7e740feb33533ad55db661 100644 (file)
@@ -36,6 +36,8 @@ static void __init rcu_bootup_announce_oddness(void)
                pr_info("\tRCU dyntick-idle grace-period acceleration is enabled.\n");
        if (IS_ENABLED(CONFIG_PROVE_RCU))
                pr_info("\tRCU lockdep checking is enabled.\n");
+       if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD))
+               pr_info("\tRCU strict (and thus non-scalable) grace periods enabled.\n");
        if (RCU_NUM_LVLS >= 4)
                pr_info("\tFour(or more)-level hierarchy is enabled.\n");
        if (RCU_FANOUT_LEAF != 16)