All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: "Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	herton@mandriva.com.br, dvgevers@xs4all.nl
Subject: Re: [local DoS] Re: Linux 2.6.24-rc4
Date: Tue, 4 Dec 2007 17:08:42 +0100	[thread overview]
Message-ID: <20071204160842.GA31501@elte.hu> (raw)
In-Reply-To: <20071204140425.05b0b458@mandriva.com.br>


* Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br> wrote:

> | The problem is on SMP: if sched_rr_get_interval() gets a task from 
> | an otherwise idle runqueue, then rq->load.weight is 0. Normally 
> | sched_slice() is only used on a busy runqueue. So the correct fixup 
> | site is not in sched_slice() but in sys_sched_rr_get_interval() - 
> | i'm working on the right fix, i hope to be able to send a pull 
> | request in a few minutes.
> 
>  Ingo, I can reproduce this w/o SMP support as well.

hm, if you run this as an RT task, right? Or can you trigger it via pure 
SCHED_OTHER tasks as well? Below is my candidate fix.

	Ingo

--------------->
Subject: sched: fix crash in sys_sched_rr_get_interval()
From: Ingo Molnar <mingo@elte.hu>

Luiz Fernando N. Capitulino reported that sched_rr_get_interval()
crashes for SCHED_OTHER tasks that are on an idle runqueue.

The fix is to return a 0 timeslice for tasks that are on an idle
runqueue. (and which are not running, obviously)

Reported-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/sched.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Index: linux/kernel/sched.c
===================================================================
--- linux.orig/kernel/sched.c
+++ linux/kernel/sched.c
@@ -4850,17 +4850,21 @@ long sys_sched_rr_get_interval(pid_t pid
 	if (retval)
 		goto out_unlock;
 
-	if (p->policy == SCHED_FIFO)
-		time_slice = 0;
-	else if (p->policy == SCHED_RR)
+	/*
+	 * Time slice is 0 for SCHED_FIFO tasks and for SCHED_OTHER
+	 * tasks that are on an otherwise idle runqueue:
+	 */
+	time_slice = 0;
+	if (p->policy == SCHED_RR) {
 		time_slice = DEF_TIMESLICE;
-	else {
+	} else {
 		struct sched_entity *se = &p->se;
 		unsigned long flags;
 		struct rq *rq;
 
 		rq = task_rq_lock(p, &flags);
-		time_slice = NS_TO_JIFFIES(sched_slice(cfs_rq_of(se), se));
+		if (rq->cfs.load.weight)
+			time_slice = NS_TO_JIFFIES(sched_slice(&rq->cfs, se));
 		task_rq_unlock(rq, &flags);
 	}
 	read_unlock(&tasklist_lock);

  reply	other threads:[~2007-12-04 16:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-04  5:08 Linux 2.6.24-rc4 Linus Torvalds
2007-12-04 10:23 ` [build failure] Re: Linux 2.6.24-rc4 on S390x Kamalesh Babulal
2007-12-04 10:31   ` Martin Schwidefsky
2007-12-04 10:32   ` Ingo Molnar
2007-12-04 13:22 ` Linux 2.6.24-rc4 Nicolas Pitre
2007-12-04 16:04   ` Jeff Garzik
2007-12-04 14:07 ` [local DoS] " Luiz Fernando N. Capitulino
2007-12-04 15:56   ` Linus Torvalds
2007-12-04 16:00     ` Ingo Molnar
2007-12-04 16:04       ` Luiz Fernando N. Capitulino
2007-12-04 16:08         ` Ingo Molnar [this message]
2007-12-04 16:18       ` [git pull] scheduler fixes Ingo Molnar
2007-12-04 16:40         ` Luiz Fernando N. Capitulino
2007-12-04 18:28         ` Greg KH
2007-12-04 18:41           ` Luiz Fernando N. Capitulino
2007-12-04 21:04             ` Ingo Molnar
2007-12-04 20:51 ` Linux 2.6.24-rc4 Maciej Rutecki
2007-12-04 21:06   ` Linus Torvalds
2007-12-04 21:19     ` Maciej Rutecki
2007-12-04 21:23   ` ATA ACPI (was Re: Linux 2.6.24-rc4) Jeff Garzik
2007-12-04 21:25     ` Jeff Garzik
2007-12-04 21:25       ` Alan Cox
2007-12-04 21:27     ` Jeff Garzik
2007-12-04 22:48       ` Maciej Rutecki
2007-12-04 23:00         ` Jeff Garzik
2007-12-05  7:46           ` Maciej Rutecki
2007-12-10  8:42             ` Tejun Heo
2007-12-05  0:23 ` Linux 2.6.24-rc4 Diego Calleja

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=20071204160842.GA31501@elte.hu \
    --to=mingo@elte.hu \
    --cc=dvgevers@xs4all.nl \
    --cc=herton@mandriva.com.br \
    --cc=lcapitulino@mandriva.com.br \
    --cc=linux-kernel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.