public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Wang <wangyun@linux.vnet.ibm.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Ingo Molnar <mingo@elte.hu>, Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [RFC BUG] There is a potential bug in "yield_to"
Date: Thu, 05 Jul 2012 13:31:43 +0800	[thread overview]
Message-ID: <4FF526BF.7030000@linux.vnet.ibm.com> (raw)

Hi, All

I found there may be a potential bug in "yield_to":

        local_irq_save(flags);
        rq = this_rq();

again:	

//task's rq may already changed in "sched_move_task"

        p_rq = task_rq(p);
        double_rq_lock(rq, p_rq);
        while (task_rq(p) != p_rq) {
                double_rq_unlock(rq, p_rq);
                goto again;
        }

I think it may happen in this scene:

	cpu 0				cpu 1(task a)

					yield_to {
					disable_irq
	sched_move_task {		rq = this_rq();
	task_rq_lock(task a)		double_rq_lock

	hold lock of rq 1			
	set_task_rq			//task rq changed
	release lock of rq 1

					hold lock of rq 1
					but task b no longer
					there

					set rq 1's current to
					skip which is not task a

which means we hold a rq's lock but it's current is not the one should
do yield.

Only "sched_move_task" will cause this issue as it will move the task
which is still running.

The bug will make the task who want to do yield failed to set skip buddy
to himself, but to a innocent task instead, not very harmful and almost
impossible to occur in normal, but should we fix it with another check
"rq == this_rq()"?

Regards,
Michael Wang


             reply	other threads:[~2012-07-05  5:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05  5:31 Michael Wang [this message]
2012-07-05  8:35 ` [RFC BUG] There is a potential bug in "yield_to" Peter Zijlstra
2012-07-05 23:50   ` Michael Wang

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=4FF526BF.7030000@linux.vnet.ibm.com \
    --to=wangyun@linux.vnet.ibm.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox