public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: 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: Sat, 8 Oct 2016 19:06:38 +0200	[thread overview]
Message-ID: <20161008170638.GK3568@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <1475922278-3306-1-git-send-email-wanpeng.li@hotmail.com>

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.

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

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!

  reply	other threads:[~2016-10-08 17:06 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 [this message]
2016-10-08 23:39   ` Wanpeng Li

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=20161008170638.GK3568@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=efault@gmx.de \
    --cc=kernellwp@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.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