mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hillf Danton <dhillf@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] sched: correct testing need_resched in mutex_spin_on_owner()
Date: Tue, 7 Jun 2011 22:14:53 +0800	[thread overview]
Message-ID: <BANLkTimZzpUZe3vFe4aQdQBZBOS1a4=9rQ@mail.gmail.com> (raw)
In-Reply-To: <1307455140.2322.262.camel@twins>

On Tue, Jun 7, 2011 at 9:59 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, 2011-06-07 at 15:47 +0200, Peter Zijlstra wrote:
>> On Tue, 2011-06-07 at 21:41 +0800, Hillf Danton wrote:
>> > It is suppose to check the owner task that is not absolutly running on the
>> > local CPU,
>>
>> Oh, why do you think so?
>>
>> > and if NEED_RESCHED is happenly set on the current task of local
>> > CPU, we get incorrect result.
>>
>> Only if your above assumption holds, which it doesn't. It explicitly
>> checks to see if _this_ cpu needs a resched while spinning, if so it
>> bails the spinning and calls schedule in the lock slow path.
>>
>> If the owner cpu reschedules, owner will leave the rq and
>> owner_running() will return false, also breaking the loop.
>>
>> >
>> > Signed-off-by: Hillf Danton <dhillf@gmail.com>
>> > ---
>> >  kernel/sched.c |    2 +-
>> >  1 files changed, 1 insertions(+), 1 deletions(-)
>> >
>> > diff --git a/kernel/sched.c b/kernel/sched.c
>> > index fd18f39..3ea64fe 100644
>> > --- a/kernel/sched.c
>> > +++ b/kernel/sched.c
>> > @@ -4326,7 +4326,7 @@ int mutex_spin_on_owner(struct mutex *lock,
>> > struct task_struct *owner)
>> >             return 0;
>> >
>> >     while (owner_running(lock, owner)) {
>> > -           if (need_resched())
>> > +           if (test_tsk_need_resched(owner))
>> >                     return 0;
>> >
>
> Furthermore, that can crash the machine, as there's no guarantee owner
> is a sane pointer at this point.
>

Well, why is owner_running looped safely?

thanks
           Hillf

  reply	other threads:[~2011-06-07 14:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-07 13:41 Hillf Danton
2011-06-07 13:47 ` Peter Zijlstra
2011-06-07 13:50   ` Peter Zijlstra
2011-06-07 13:59   ` Peter Zijlstra
2011-06-07 14:14     ` Hillf Danton [this message]
2011-06-07 14:10   ` Hillf Danton
2011-06-07 14:24     ` Peter Zijlstra
2011-06-07 14:36       ` Hillf Danton
2011-06-07 14:40         ` Peter Zijlstra
2011-06-07 14:47           ` Hillf Danton
2011-06-07 15:08             ` Steven Rostedt
2011-06-07 18:22               ` Hillf Danton
2011-06-07 18:34                 ` Steven Rostedt
2011-06-07 15:20             ` Peter Zijlstra
2011-06-07 15:43               ` Steven Rostedt

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='BANLkTimZzpUZe3vFe4aQdQBZBOS1a4=9rQ@mail.gmail.com' \
    --to=dhillf@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /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

all inboxes | Powered by JetHome®