All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Huang Ying <ying.huang@intel.com>,
	Lai Jiangshan <laijs@cn.fujitsu.com>,
	Lai Jiangshan <eag0628@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: Possible lock-less list race in scheduler_ipi()
Date: Fri, 6 Mar 2015 22:07:03 +0000 (UTC)	[thread overview]
Message-ID: <933936114.242980.1425679623451.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20150306153925.224d4383@gandalf.local.home>

----- Original Message -----
> From: "Steven Rostedt" <rostedt@goodmis.org>
> To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
> Cc: "Linus Torvalds" <torvalds@linux-foundation.org>, "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>, "Huang Ying"
> <ying.huang@intel.com>, "Lai Jiangshan" <laijs@cn.fujitsu.com>, "Lai Jiangshan" <eag0628@gmail.com>, "Peter
> Zijlstra" <peterz@infradead.org>, "LKML" <linux-kernel@vger.kernel.org>, "Ingo Molnar" <mingo@kernel.org>
> Sent: Friday, March 6, 2015 3:39:25 PM
> Subject: Re: Possible lock-less list race in scheduler_ipi()
> 
> On Fri, 6 Mar 2015 15:38:21 -0500
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > On Fri, 6 Mar 2015 19:39:44 +0000 (UTC)
> > Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:
> > 
> > ask concurrently with the llist iteration within sched_ttwu_pending().
> > > 
> > > AFAIU, ttwu_queue_remote() is called from ttwu_queue() without holding
> > > the rq lock. So I'm wondering what prevents corruption of the wake_list
> > > in this situation.
> > 
> > I guess if it is on the wake_list, then the task's state is already
> > RUNNING. Any other task can switch a task's state to RUNNING but only
> > the task itself can switch it back to something else. If the task is on
> > the wake_list, it's state is already RUNNING, but it has not run yet.
> > That means any other wakeup will jump to the "goto out" and skip over
> > the ttwu_queue() call.
> 
> If my assumption is indeed the case, then these types of subtleties
> really need comments in the code.

My understanding is that try_to_wake_up, by calling ttwu_queue(),
is responsible for enqueuing the task into the wake_list. Inspection
of try_to_wake_up() seems to show that the state of the task is set
to TASK_WAKING by try_to_wake_up.

Then when dequeuing the task from the llist, ttwu_do_wakeup sets the
task state to TASK_RUNNING.

Both TASK_WAKING and TASK_RUNNING mean that the try_to_wake_up check
for if (!(p->state & state)), which is typically done against TASK_NORMAL,
will skip the following ttwu_queue() for that task until it is set to
TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE again.

So there should not be any double-enqueue AFAIU.

Thanks,

Mathieu





-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2015-03-06 22:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <995381344.227770.1425597484864.JavaMail.zimbra@efficios.com>
2015-03-05 23:48 ` Possible lock-less list race in scheduler_ipi() Mathieu Desnoyers
2015-03-06  1:02   ` Linus Torvalds
2015-03-06 14:35     ` Mathieu Desnoyers
2015-03-06 19:03       ` Steven Rostedt
2015-03-06 19:39         ` Mathieu Desnoyers
2015-03-06 20:38           ` Steven Rostedt
2015-03-06 20:39             ` Steven Rostedt
2015-03-06 22:07               ` Mathieu Desnoyers [this message]
2015-03-06 17:09   ` Paul E. McKenney

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=933936114.242980.1425679623451.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=eag0628@gmail.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    --cc=ying.huang@intel.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.