rcu: Make rcu_blocking_is_gp() stop early-boot might_sleep()
authorZqiang <qiang1.zhang@intel.com>
Thu, 15 Dec 2022 03:57:55 +0000 (11:57 +0800)
committerPaul E. McKenney <paulmck@kernel.org>
Wed, 4 Jan 2023 01:28:34 +0000 (17:28 -0800)
Currently, rcu_blocking_is_gp() invokes might_sleep() even during early
boot when interrupts are disabled and before the scheduler is scheduling.
This is at best an accident waiting to happen.  Therefore, this commit
moves that might_sleep() under an rcu_scheduler_active check in order
to ensure that might_sleep() is not invoked unless sleeping might actually
happen.

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tree.c

index 0147e69..15f9765 100644 (file)
@@ -3333,9 +3333,10 @@ void __init kfree_rcu_scheduler_running(void)
  */
 static int rcu_blocking_is_gp(void)
 {
-       if (rcu_scheduler_active != RCU_SCHEDULER_INACTIVE)
+       if (rcu_scheduler_active != RCU_SCHEDULER_INACTIVE) {
+               might_sleep();
                return false;
-       might_sleep();  /* Check for RCU read-side critical section. */
+       }
        return true;
 }