All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuyo Chang <kuyo.chang@mediatek.com>
To: Sami Tolvanen <samitolvanen@google.com>,
	Kees Cook <keescook@chromium.org>,
	Nathan Chancellor <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	Ingo Molnar <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Ben Segall" <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	"Daniel Bristot de Oliveira" <bristot@redhat.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Joel Fernandes <joel@joelfernandes.org>, <rcu@vger.kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Daniel Lezcano" <daniel.lezcano@linaro.org>
Cc: <kuyo.chang@mediatek.com>, <linux-pm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <wsd_upstream@mediatek.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>, <rcu@vger.kernel.org>,
	<llvm@lists.linux.dev>
Subject: [Race condition] Race condition at cpuidle_enter_s2idle & __cfi_slowpath_diag
Date: Thu, 11 Aug 2022 15:54:28 +0800	[thread overview]
Message-ID: <3bcf5d974b98acccde89e8d5567d3ddcdfb44800.camel@mediatek.com> (raw)

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.



WARNING: multiple messages have this Message-ID (diff)
From: Kuyo Chang <kuyo.chang@mediatek.com>
To: Sami Tolvanen <samitolvanen@google.com>,
	Kees Cook <keescook@chromium.org>,
	Nathan Chancellor <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	Ingo Molnar <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Ben Segall" <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	"Daniel Bristot de Oliveira" <bristot@redhat.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Joel Fernandes <joel@joelfernandes.org>, <rcu@vger.kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Daniel Lezcano" <daniel.lezcano@linaro.org>
Cc: <kuyo.chang@mediatek.com>, <linux-pm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <wsd_upstream@mediatek.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>, <rcu@vger.kernel.org>,
	<llvm@lists.linux.dev>
Subject: [Race condition] Race condition at cpuidle_enter_s2idle & __cfi_slowpath_diag
Date: Thu, 11 Aug 2022 15:54:28 +0800	[thread overview]
Message-ID: <3bcf5d974b98acccde89e8d5567d3ddcdfb44800.camel@mediatek.com> (raw)

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.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2022-08-11  8:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11  7:54 Kuyo Chang [this message]
2022-08-11  7:54 ` [Race condition] Race condition at cpuidle_enter_s2idle & __cfi_slowpath_diag Kuyo Chang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3bcf5d974b98acccde89e8d5567d3ddcdfb44800.camel@mediatek.com \
    --to=kuyo.chang@mediatek.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=jiangshanlai@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=juri.lelli@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=vincent.guittot@linaro.org \
    --cc=wsd_upstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.