From: Peter Zijlstra <peterz@infradead.org>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: raistlin@linux.it, juri.lelli@gmail.com,
Ingo Molnar <mingo@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] sched: Fix __sched_setscheduler() nice test
Date: Thu, 16 Jan 2014 19:33:05 +0100 [thread overview]
Message-ID: <20140116183305.GB9481@laptop.programming.kicks-ass.net> (raw)
In-Reply-To: <20140116165425.GA9481@laptop.programming.kicks-ass.net>
So I tried to make can_nice() do what I thought it did; but I'm not sure
the result is worth the effort.
Also, binder seems to use can_nice() -- but I really couldn't be arsed
to look at it.
---
Index: linux-2.6/kernel/sched/auto_group.c
===================================================================
--- linux-2.6.orig/kernel/sched/auto_group.c
+++ linux-2.6/kernel/sched/auto_group.c
@@ -210,7 +210,7 @@ int proc_sched_autogroup_set_nice(struct
if (err)
return err;
- if (nice < 0 && !can_nice(current, nice))
+ if (!can_nice(current, nice))
return -EPERM;
/* this is a heavy operation taking global locks.. */
Index: linux-2.6/kernel/sched/core.c
===================================================================
--- linux-2.6.orig/kernel/sched/core.c
+++ linux-2.6/kernel/sched/core.c
@@ -3017,17 +3017,22 @@ void set_user_nice(struct task_struct *p
EXPORT_SYMBOL(set_user_nice);
/*
- * can_nice - check if a task can reduce its nice value
+ * can_nice - check if a task can change its nice value
* @p: task
* @nice: nice value
*/
-int can_nice(const struct task_struct *p, const int nice)
+bool can_nice(const struct task_struct *p, const int nice)
{
/* convert nice value [19,-20] to rlimit style value [1,40] */
int nice_rlim = 20 - nice;
- return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
- capable(CAP_SYS_NICE));
+ if (nice >= TASK_NICE(p))
+ return true;
+
+ if (nice_rlim <= task_rlimit(p, RLIMIT_NICE) || capable(CAP_SYS_NICE))
+ return true;
+
+ return false;
}
#ifdef __ARCH_WANT_SYS_NICE
@@ -3059,7 +3064,7 @@ SYSCALL_DEFINE1(nice, int, increment)
if (nice > 19)
nice = 19;
- if (increment < 0 && !can_nice(current, nice))
+ if (!can_nice(current, nice))
return -EPERM;
retval = security_task_setnice(current, nice);
@@ -3296,8 +3301,7 @@ static int __sched_setscheduler(struct t
*/
if (user && !capable(CAP_SYS_NICE)) {
if (fair_policy(policy)) {
- if (attr->sched_nice < TASK_NICE(p) &&
- !can_nice(p, attr->sched_nice))
+ if (!can_nice(p, attr->sched_nice))
return -EPERM;
}
@@ -3320,8 +3324,18 @@ static int __sched_setscheduler(struct t
* SCHED_NORMAL if the RLIMIT_NICE would normally permit it.
*/
if (p->policy == SCHED_IDLE && policy != SCHED_IDLE) {
- if (!can_nice(p, TASK_NICE(p)))
- return -EPERM;
+ int static_prio = p->static_prio;
+ int err = 0;
+
+ p->static_prio = NICE_TO_PRIO(20);
+
+ if (!can_nice(p, PRIO_TO_NICE(static_prio)))
+ err = -EPERM;
+
+ p->static_prio = static_prio;
+
+ if (err)
+ return err;
}
/* can't change other user's priorities */
Index: linux-2.6/kernel/sys.c
===================================================================
--- linux-2.6.orig/kernel/sys.c
+++ linux-2.6/kernel/sys.c
@@ -144,7 +144,7 @@ static int set_one_prio(struct task_stru
error = -EPERM;
goto out;
}
- if (niceval < task_nice(p) && !can_nice(p, niceval)) {
+ if (!can_nice(p, niceval)) {
error = -EACCES;
goto out;
}
next prev parent reply other threads:[~2014-01-16 18:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-15 8:27 [BUG] [ tip/sched/core ] System unresponsive after booting Daniel Lezcano
2014-01-15 9:22 ` Ingo Molnar
2014-01-15 10:39 ` Peter Zijlstra
2014-01-15 11:00 ` Peter Zijlstra
2014-01-15 14:05 ` Peter Zijlstra
2014-01-15 9:25 ` Michael wang
2014-01-15 11:30 ` Peter Zijlstra
2014-01-15 13:28 ` Daniel Lezcano
2014-01-16 13:40 ` [tip:sched/core] sched: Preserve the nice level over sched_setscheduler() and sched_setparam() calls tip-bot for Peter Zijlstra
2014-01-15 13:27 ` [BUG] [ tip/sched/core ] System unresponsive after booting Daniel Lezcano
2014-01-15 12:04 ` Peter Zijlstra
2014-01-15 12:24 ` Ingo Molnar
2014-01-15 13:45 ` Daniel Lezcano
2014-01-15 13:09 ` Daniel Lezcano
2014-01-16 13:48 ` Daniel Lezcano
2014-01-16 14:17 ` Peter Zijlstra
2014-01-16 14:20 ` Daniel Lezcano
2014-01-16 14:25 ` Peter Zijlstra
2014-01-16 14:30 ` Daniel Lezcano
2014-01-16 15:42 ` Peter Zijlstra
2014-01-16 15:50 ` Daniel Lezcano
2014-01-16 16:54 ` [PATCH] sched: Fix __sched_setscheduler() nice test Peter Zijlstra
2014-01-16 18:33 ` Peter Zijlstra [this message]
2014-01-16 18:39 ` [tip:sched/core] " tip-bot for Peter Zijlstra
2014-01-16 15:28 ` [BUG] [ tip/sched/core ] System unresponsive after booting Daniel Lezcano
2014-01-16 15:48 ` Peter Zijlstra
2014-01-16 15:51 ` Daniel Lezcano
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=20140116183305.GB9481@laptop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=daniel.lezcano@linaro.org \
--cc=juri.lelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=raistlin@linux.it \
/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