Skip to content
  • Alex Shi's avatar
    PM / CPU: replace raw_notifier with atomic_notifier · 313c8c16
    Alex Shi authored
    This patch replaces an rwlock and raw notifier by an atomic notifier
    protected by a spin_lock and RCU.
    
    The main reason for this change is due to a 'scheduling while atomic'
    bug with RT kernels on ARM/ARM64. On ARM/ARM64, the rwlock
    cpu_pm_notifier_lock in cpu_pm_enter/exit() causes a potential
    schedule after IRQ disable in the idle call chain:
    
    cpu_startup_entry
      cpu_idle_loop
        local_irq_disable()
        cpuidle_idle_call
          call_cpuidle
            cpuidle_enter
              cpuidle_enter_state
                ->enter :arm_enter_idle_state
                  cpu_pm_enter/exit
                    CPU_PM_CPU_IDLE_ENTER
                      read_lock(&cpu_pm_notifier_lock); <-- sleep in idle
                         __rt_spin_lock();
                            schedule();
    
    The kernel panic is here:
    [    4.609601] BUG: scheduling while atomic: swapper/1/0/0x00000002
    [    4.609608] [<ffff0000086fae70>] arm_enter_idle_state+0x18/0x70
    [    4.609614] Modules linked in:
    [    4.609615] [...
    313c8c16