linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wanpeng Li <kernellwp@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Wanpeng Li <wanpeng.li@hotmail.com>,
	Ingo Molnar <mingo@kernel.org>, Mike Galbraith <efault@gmx.de>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] sched/fair: Fix dereference NULL sched domain during select_idle_sibling
Date: Sun, 9 Oct 2016 07:39:49 +0800	[thread overview]
Message-ID: <CANRm+CzAwEhO4McNYrzBvqs1wWenthxSMDVWxkCm4JEFghEupQ@mail.gmail.com> (raw)
In-Reply-To: <20161008170638.GK3568@worktop.programming.kicks-ass.net>

2016-10-09 1:06 GMT+08:00 Peter Zijlstra <peterz@infradead.org>:
> On Sat, Oct 08, 2016 at 06:24:38PM +0800, Wanpeng Li wrote:
>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 543b2f2..03a6620 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -5472,19 +5472,29 @@ static inline int select_idle_smt(struct task_struct *p, struct sched_domain *sd
>>   */
>>  static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int target)
>>  {
>> -     struct sched_domain *this_sd = rcu_dereference(*this_cpu_ptr(&sd_llc));
>
> So select_idle_cpu() <- select_idle_sibling() is called from two places,
> both which already hold rcu_read_lock() afaict.

Agreed.

>
> This would've insta-triggered a rcu-lockdep splat otherwise I think.

CONFIG_LOCKDEP_SUPPORT=y
CONFIG_LOCKDEP=y
CONFIG_DEBUG_LOCKDEP=y
CONFIG_DEBUG_LOCK_ALLOC=y

So it is interesting why not a rcu-lockdep splat. :)

>
> That is, selsect_task_rq_fair() has rcu_read_lock() taken when calling
> this, and task_numa_compare() does too.
>
>> +     struct sched_domain *this_sd;
>>       u64 avg_idle = this_rq()->avg_idle;
>> -     u64 avg_cost = this_sd->avg_scan_cost;
>> +     u64 avg_cost;
>>       u64 time, cost;
>>       s64 delta;
>>       int cpu, wrap;
>>
>> +     rcu_read_lock();
>> +     this_sd = rcu_dereference(*this_cpu_ptr(&sd_llc));
>> +     if (!this_sd) {
>> +             cpu = -1;
>> +             goto unlock;
>> +     }
>
> Yes, this is the part that was missing. We need to test this_sd after
> the lookup.
>
> Thanks for looking at this!

NP, I will send out v2 soon. :)

Regards,
Wanpeng Li

      reply	other threads:[~2016-10-08 23:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-08 10:24 [PATCH] sched/fair: Fix dereference NULL sched domain during select_idle_sibling Wanpeng Li
2016-10-08 17:06 ` Peter Zijlstra
2016-10-08 23:39   ` Wanpeng Li [this message]

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=CANRm+CzAwEhO4McNYrzBvqs1wWenthxSMDVWxkCm4JEFghEupQ@mail.gmail.com \
    --to=kernellwp@gmail.com \
    --cc=efault@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=wanpeng.li@hotmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).