mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Daniel Axtens <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: peterz@infradead.org, khlebnikov@yandex-team.ru,
	bsegall@google.com, mingo@kernel.org, efault@gmx.de,
	hpa@zytor.com, linux-kernel@vger.kernel.org,
	torvalds@linux-foundation.org, dja@axtens.net,
	tglx@linutronix.de
Subject: [tip:sched/core] sched/fair: WARN() and refuse to set buddy when !se->on_rq
Date: Tue, 20 Jun 2017 06:26:51 -0700	[thread overview]
Message-ID: <tip-c5ae366e12b2bd56fc7d7e9d484836bec9ddc110@git.kernel.org> (raw)
In-Reply-To: <20170510201139.16236-1-dja@axtens.net>

Commit-ID:  c5ae366e12b2bd56fc7d7e9d484836bec9ddc110
Gitweb:     http://git.kernel.org/tip/c5ae366e12b2bd56fc7d7e9d484836bec9ddc110
Author:     Daniel Axtens <dja@axtens.net>
AuthorDate: Thu, 11 May 2017 06:11:39 +1000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 20 Jun 2017 12:26:52 +0200

sched/fair: WARN() and refuse to set buddy when !se->on_rq

If we set a next or last buddy for a se that is not on_rq, we will
end up taking a NULL pointer dereference in wakeup_preempt_entity
via pick_next_task_fair.

Detect when we would be about to do that, throw a warning and
then refuse to actually set it.

This has been suggested at least twice:

  https://marc.info/?l=linux-kernel&m=146651668921468&w=2
  https://lkml.org/lkml/2016/6/16/663

I recently had to debug a problem with these (we hadn't backported
Konstantin's patches in this area) and this would have saved a lot
of time/pain.

Just do it.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Cc: Ben Segall <bsegall@google.com>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20170510201139.16236-1-dja@axtens.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 396bca9..cb3a3da 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6164,8 +6164,11 @@ static void set_last_buddy(struct sched_entity *se)
 	if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
 		return;
 
-	for_each_sched_entity(se)
+	for_each_sched_entity(se) {
+		if (SCHED_WARN_ON(!se->on_rq))
+			return;
 		cfs_rq_of(se)->last = se;
+	}
 }
 
 static void set_next_buddy(struct sched_entity *se)
@@ -6173,8 +6176,11 @@ static void set_next_buddy(struct sched_entity *se)
 	if (entity_is_task(se) && unlikely(task_of(se)->policy == SCHED_IDLE))
 		return;
 
-	for_each_sched_entity(se)
+	for_each_sched_entity(se) {
+		if (SCHED_WARN_ON(!se->on_rq))
+			return;
 		cfs_rq_of(se)->next = se;
+	}
 }
 
 static void set_skip_buddy(struct sched_entity *se)

      parent reply	other threads:[~2017-06-20 13:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-10 20:11 [PATCH v2] sched/fair: WARN " Daniel Axtens
2017-06-19 14:05 ` Daniel Axtens
2017-06-20  7:41   ` Konstantin Khlebnikov
2017-06-20 10:27 ` [PATCH] sched/debug: Fix SCHED_WARN_ON() to return a value on !CONFIG_SCHED_DEBUG as well Ingo Molnar
2017-06-20 13:52   ` Daniel Axtens
2017-06-20 13:26 ` tip-bot for Daniel Axtens [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=tip-c5ae366e12b2bd56fc7d7e9d484836bec9ddc110@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bsegall@google.com \
    --cc=dja@axtens.net \
    --cc=efault@gmx.de \
    --cc=hpa@zytor.com \
    --cc=khlebnikov@yandex-team.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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

Powered by JetHome