[Race condition] Race condition at cpuidle_enter_s2idle & __cfi_slowpath_diag
From: Kuyo Chang
Date: Thu Aug 11 2022 - 03:54:43 EST
Hi Sami,
During doing s2idle(Suspend-To-Idle) flow, I found a task will put into
runqueue by __cfi_slowpath_diag.
The code trace about fail case as below:
call_cpuidle_s2idle
->if (current_clr_polling_and_test()) //check resched flag
return -EBUSY;
->cpuidle_enter_s2idle
->enter_s2idle_proper
->target_state->enter_s2idle(dev, drv, index);
Meanwhile the log shows the __cfi_slowpath_diag function will wake up a
task to CPU, below is the backtrace
__cfi_slowpath_diag
find_check_fn
rcu_irq_enter
rcu_nmi_enter
rcu_cleanup_after_idle
invoke_rcu_core
raise_softirq(RCU_SOFTIRQ)
raise_softirq_irqoff
if (!in_interrupt() && should_wake_ksoftirqd())
wakeup_softirqd();
//wake up flow
wake_up_process
try_to_wake_up
ttwu_queue
ttwu_do_activate
ttwu_do_wakeup
check_preempt_curr
resched_curr
set_tsk_need_resched(curr);
So It will violate the initial check at call_cpuidle_s2idle(Now it
exists a task at rq and need reched, so it should not enter
cpuidle_enter_s2idle )
if (current_clr_polling_and_test())
return -EBUSY;
I look the racing may be related to the following patch
57cd6d1 cfi: Fix __cfi_slowpath_diag RCU usage with cpuidle
https://android.googlesource.com/kernel/common/+/57cd6d1
Do you have any suggestion for this issue?
Thank you.