* [patch 0/4] sched: Replace read_lock(&tasklist_lock) with RCU - the easy part
@ 2009-12-09 10:14 Thomas Gleixner
2009-12-09 10:14 ` [patch 1/4] sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam() Thomas Gleixner
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Thomas Gleixner @ 2009-12-09 10:14 UTC (permalink / raw)
To: LKML; +Cc: Ingo Molnar, Peter Zijlstra
First batch of patches which replace read_lock(&tasklist_lock) with
RCU.
Thanks,
tglx
^ permalink raw reply [flat|nested] 8+ messages in thread
* [patch 1/4] sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam()
2009-12-09 10:14 [patch 0/4] sched: Replace read_lock(&tasklist_lock) with RCU - the easy part Thomas Gleixner
@ 2009-12-09 10:14 ` Thomas Gleixner
2009-12-14 16:31 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner
2009-12-09 10:15 ` [patch 2/4] sched: Use rcu in sched_get/set_affinity() Thomas Gleixner
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Thomas Gleixner @ 2009-12-09 10:14 UTC (permalink / raw)
To: LKML; +Cc: Ingo Molnar, Peter Zijlstra
[-- Attachment #1: sched-use-rcu-in-sched_getscheduler.patch --]
[-- Type: text/plain, Size: 1844 bytes --]
read_lock(&tasklist_lock) does not protect sys_sched_getscheduler and
sys_sched_getparam() against a concurrent update of the policy or
scheduler parameters as do_sched_setscheduler() does not take the
tasklist_lock. The accessed integers can be retrieved w/o locking and
are snapshots anyway.
Using rcu_read_lock() to protect find_task_by_vpid() and prevent the
task struct from going away is not changing the above situation.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/sched.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
Index: linux-2.6-tip/kernel/sched.c
===================================================================
--- linux-2.6-tip.orig/kernel/sched.c
+++ linux-2.6-tip/kernel/sched.c
@@ -6477,7 +6477,7 @@ SYSCALL_DEFINE1(sched_getscheduler, pid_
return -EINVAL;
retval = -ESRCH;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
if (p) {
retval = security_task_getscheduler(p);
@@ -6485,7 +6485,7 @@ SYSCALL_DEFINE1(sched_getscheduler, pid_
retval = p->policy
| (p->sched_reset_on_fork ? SCHED_RESET_ON_FORK : 0);
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return retval;
}
@@ -6503,7 +6503,7 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, p
if (!param || pid < 0)
return -EINVAL;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
retval = -ESRCH;
if (!p)
@@ -6514,7 +6514,7 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, p
goto out_unlock;
lp.sched_priority = p->rt_priority;
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
/*
* This one might sleep, we cannot do it with a spinlock held ...
@@ -6524,7 +6524,7 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, p
return retval;
out_unlock:
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return retval;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [patch 2/4] sched: Use rcu in sched_get/set_affinity()
2009-12-09 10:14 [patch 0/4] sched: Replace read_lock(&tasklist_lock) with RCU - the easy part Thomas Gleixner
2009-12-09 10:14 ` [patch 1/4] sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam() Thomas Gleixner
@ 2009-12-09 10:15 ` Thomas Gleixner
2009-12-14 16:31 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner
2009-12-09 10:15 ` [patch 3/4] sched: Rename bogus label in sched_setaffinity() Thomas Gleixner
2009-12-09 10:15 ` [patch 4/4] sched: Use rcu in sched_get_rr_param Thomas Gleixner
3 siblings, 1 reply; 8+ messages in thread
From: Thomas Gleixner @ 2009-12-09 10:15 UTC (permalink / raw)
To: LKML; +Cc: Ingo Molnar, Peter Zijlstra
[-- Attachment #1: sched-use-rcu-in-affinity-get-set.patch --]
[-- Type: text/plain, Size: 1675 bytes --]
tasklist_lock is held read locked to protect the find_task_by_vpid()
call and to prevent the task going away. sched_setaffinity acquires a
task struct ref and drops tasklist lock right away. The access to the
cpus_allowed mask is protected by rq->lock.
rcu_read_lock() provides the same protection here.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/sched.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
Index: linux-2.6-tip/kernel/sched.c
===================================================================
--- linux-2.6-tip.orig/kernel/sched.c
+++ linux-2.6-tip/kernel/sched.c
@@ -6535,22 +6535,18 @@ long sched_setaffinity(pid_t pid, const
int retval;
get_online_cpus();
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
if (!p) {
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
put_online_cpus();
return -ESRCH;
}
- /*
- * It is not safe to call set_cpus_allowed with the
- * tasklist_lock held. We will bump the task_struct's
- * usage count and then drop tasklist_lock.
- */
+ /* Prevent p going away */
get_task_struct(p);
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) {
retval = -ENOMEM;
@@ -6636,7 +6632,7 @@ long sched_getaffinity(pid_t pid, struct
int retval;
get_online_cpus();
- read_lock(&tasklist_lock);
+ rcu_read_lock();
retval = -ESRCH;
p = find_process_by_pid(pid);
@@ -6652,7 +6648,7 @@ long sched_getaffinity(pid_t pid, struct
task_rq_unlock(rq, &flags);
out_unlock:
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
put_online_cpus();
return retval;
^ permalink raw reply [flat|nested] 8+ messages in thread
* [patch 3/4] sched: Rename bogus label in sched_setaffinity()
2009-12-09 10:14 [patch 0/4] sched: Replace read_lock(&tasklist_lock) with RCU - the easy part Thomas Gleixner
2009-12-09 10:14 ` [patch 1/4] sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam() Thomas Gleixner
2009-12-09 10:15 ` [patch 2/4] sched: Use rcu in sched_get/set_affinity() Thomas Gleixner
@ 2009-12-09 10:15 ` Thomas Gleixner
2009-12-09 10:15 ` [patch 4/4] sched: Use rcu in sched_get_rr_param Thomas Gleixner
3 siblings, 0 replies; 8+ messages in thread
From: Thomas Gleixner @ 2009-12-09 10:15 UTC (permalink / raw)
To: LKML; +Cc: Ingo Molnar, Peter Zijlstra
[-- Attachment #1: sched-fix-bogus-label.patch --]
[-- Type: text/plain, Size: 952 bytes --]
out_unlock: is bogus as there is nothing to unlock. Rename it.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/sched.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: linux-2.6-tip/kernel/sched.c
===================================================================
--- linux-2.6-tip.orig/kernel/sched.c
+++ linux-2.6-tip/kernel/sched.c
@@ -6558,11 +6558,11 @@ long sched_setaffinity(pid_t pid, const
}
retval = -EPERM;
if (!check_same_owner(p) && !capable(CAP_SYS_NICE))
- goto out_unlock;
+ goto out_free;
retval = security_task_setscheduler(p, 0, NULL);
if (retval)
- goto out_unlock;
+ goto out_free;
cpuset_cpus_allowed(p, cpus_allowed);
cpumask_and(new_mask, in_mask, cpus_allowed);
@@ -6581,7 +6581,7 @@ long sched_setaffinity(pid_t pid, const
goto again;
}
}
-out_unlock:
+out_free:
free_cpumask_var(new_mask);
out_free_cpus_allowed:
free_cpumask_var(cpus_allowed);
^ permalink raw reply [flat|nested] 8+ messages in thread
* [patch 4/4] sched: Use rcu in sched_get_rr_param
2009-12-09 10:14 [patch 0/4] sched: Replace read_lock(&tasklist_lock) with RCU - the easy part Thomas Gleixner
` (2 preceding siblings ...)
2009-12-09 10:15 ` [patch 3/4] sched: Rename bogus label in sched_setaffinity() Thomas Gleixner
@ 2009-12-09 10:15 ` Thomas Gleixner
2009-12-14 16:31 ` [tip:sched/urgent] sched: Use rcu in sched_get_rr_param() tip-bot for Thomas Gleixner
3 siblings, 1 reply; 8+ messages in thread
From: Thomas Gleixner @ 2009-12-09 10:15 UTC (permalink / raw)
To: LKML; +Cc: Ingo Molnar, Peter Zijlstra
[-- Attachment #1: sched-use-rcu-in-sched-get-rr-param.patch --]
[-- Type: text/plain, Size: 1314 bytes --]
read_lock(&tasklist_lock) does not protect sys_sched_get_rr_param()
against a concurrent update of the policy or scheduler parameters as
do_sched_scheduler() does not take the tasklist_lock.
The access to task->sched_class->get_rr_interval is protected by
task_rq_lock(task).
Use rcu_read_lock() to protect find_task_by_vpid() and prevent the
task struct from going away.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/sched.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: linux-2.6-tip/kernel/sched.c
===================================================================
--- linux-2.6-tip.orig/kernel/sched.c
+++ linux-2.6-tip/kernel/sched.c
@@ -6892,7 +6892,7 @@ SYSCALL_DEFINE2(sched_rr_get_interval, p
return -EINVAL;
retval = -ESRCH;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
if (!p)
goto out_unlock;
@@ -6905,13 +6905,13 @@ SYSCALL_DEFINE2(sched_rr_get_interval, p
time_slice = p->sched_class->get_rr_interval(rq, p);
task_rq_unlock(rq, &flags);
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
jiffies_to_timespec(time_slice, &t);
retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
return retval;
out_unlock:
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return retval;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [tip:sched/urgent] sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam()
2009-12-09 10:14 ` [patch 1/4] sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam() Thomas Gleixner
@ 2009-12-14 16:31 ` tip-bot for Thomas Gleixner
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Thomas Gleixner @ 2009-12-14 16:31 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, peterz, tglx, mingo
Commit-ID: 5fe85be081edf0ac92d83f9c39e0ab5c1371eb82
Gitweb: http://git.kernel.org/tip/5fe85be081edf0ac92d83f9c39e0ab5c1371eb82
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 9 Dec 2009 10:14:58 +0000
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 14 Dec 2009 17:11:34 +0100
sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam()
read_lock(&tasklist_lock) does not protect
sys_sched_getscheduler and sys_sched_getparam() against a
concurrent update of the policy or scheduler parameters as
do_sched_setscheduler() does not take the tasklist_lock. The
accessed integers can be retrieved w/o locking and are snapshots
anyway.
Using rcu_read_lock() to protect find_task_by_vpid() and prevent
the task struct from going away is not changing the above
situation.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <20091209100706.753790977@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/sched.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/sched.c b/kernel/sched.c
index 258c73c..1782bee 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -6458,7 +6458,7 @@ SYSCALL_DEFINE1(sched_getscheduler, pid_t, pid)
return -EINVAL;
retval = -ESRCH;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
if (p) {
retval = security_task_getscheduler(p);
@@ -6466,7 +6466,7 @@ SYSCALL_DEFINE1(sched_getscheduler, pid_t, pid)
retval = p->policy
| (p->sched_reset_on_fork ? SCHED_RESET_ON_FORK : 0);
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return retval;
}
@@ -6484,7 +6484,7 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, pid, struct sched_param __user *, param)
if (!param || pid < 0)
return -EINVAL;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
retval = -ESRCH;
if (!p)
@@ -6495,7 +6495,7 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, pid, struct sched_param __user *, param)
goto out_unlock;
lp.sched_priority = p->rt_priority;
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
/*
* This one might sleep, we cannot do it with a spinlock held ...
@@ -6505,7 +6505,7 @@ SYSCALL_DEFINE2(sched_getparam, pid_t, pid, struct sched_param __user *, param)
return retval;
out_unlock:
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return retval;
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [tip:sched/urgent] sched: Use rcu in sched_get/set_affinity()
2009-12-09 10:15 ` [patch 2/4] sched: Use rcu in sched_get/set_affinity() Thomas Gleixner
@ 2009-12-14 16:31 ` tip-bot for Thomas Gleixner
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Thomas Gleixner @ 2009-12-14 16:31 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, peterz, tglx, mingo
Commit-ID: 23f5d142519621b16cf2b378cf8adf4dcf01a616
Gitweb: http://git.kernel.org/tip/23f5d142519621b16cf2b378cf8adf4dcf01a616
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 9 Dec 2009 10:15:01 +0000
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 14 Dec 2009 17:11:35 +0100
sched: Use rcu in sched_get/set_affinity()
tasklist_lock is held read locked to protect the
find_task_by_vpid() call and to prevent the task going away.
sched_setaffinity acquires a task struct ref and drops tasklist
lock right away. The access to the cpus_allowed mask is
protected by rq->lock.
rcu_read_lock() provides the same protection here.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <20091209100706.789059966@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/sched.c | 16 ++++++----------
1 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/kernel/sched.c b/kernel/sched.c
index 1782bee..7989312 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -6516,22 +6516,18 @@ long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
int retval;
get_online_cpus();
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
if (!p) {
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
put_online_cpus();
return -ESRCH;
}
- /*
- * It is not safe to call set_cpus_allowed with the
- * tasklist_lock held. We will bump the task_struct's
- * usage count and then drop tasklist_lock.
- */
+ /* Prevent p going away */
get_task_struct(p);
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) {
retval = -ENOMEM;
@@ -6617,7 +6613,7 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask)
int retval;
get_online_cpus();
- read_lock(&tasklist_lock);
+ rcu_read_lock();
retval = -ESRCH;
p = find_process_by_pid(pid);
@@ -6633,7 +6629,7 @@ long sched_getaffinity(pid_t pid, struct cpumask *mask)
task_rq_unlock(rq, &flags);
out_unlock:
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
put_online_cpus();
return retval;
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [tip:sched/urgent] sched: Use rcu in sched_get_rr_param()
2009-12-09 10:15 ` [patch 4/4] sched: Use rcu in sched_get_rr_param Thomas Gleixner
@ 2009-12-14 16:31 ` tip-bot for Thomas Gleixner
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Thomas Gleixner @ 2009-12-14 16:31 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, peterz, tglx, mingo
Commit-ID: 1a551ae715825bb2a2107a2dd68de024a1fa4e32
Gitweb: http://git.kernel.org/tip/1a551ae715825bb2a2107a2dd68de024a1fa4e32
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 9 Dec 2009 10:15:11 +0000
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 14 Dec 2009 17:11:35 +0100
sched: Use rcu in sched_get_rr_param()
read_lock(&tasklist_lock) does not protect
sys_sched_get_rr_param() against a concurrent update of the
policy or scheduler parameters as do_sched_scheduler() does not
take the tasklist_lock.
The access to task->sched_class->get_rr_interval is protected by
task_rq_lock(task).
Use rcu_read_lock() to protect find_task_by_vpid() and prevent
the task struct from going away.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <20091209100706.862897167@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
kernel/sched.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/sched.c b/kernel/sched.c
index 7989312..db5c266 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -6873,7 +6873,7 @@ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
return -EINVAL;
retval = -ESRCH;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_process_by_pid(pid);
if (!p)
goto out_unlock;
@@ -6886,13 +6886,13 @@ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
time_slice = p->sched_class->get_rr_interval(rq, p);
task_rq_unlock(rq, &flags);
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
jiffies_to_timespec(time_slice, &t);
retval = copy_to_user(interval, &t, sizeof(t)) ? -EFAULT : 0;
return retval;
out_unlock:
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return retval;
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-12-14 16:32 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-09 10:14 [patch 0/4] sched: Replace read_lock(&tasklist_lock) with RCU - the easy part Thomas Gleixner
2009-12-09 10:14 ` [patch 1/4] sched: Use rcu in sys_sched_getscheduler/sys_sched_getparam() Thomas Gleixner
2009-12-14 16:31 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner
2009-12-09 10:15 ` [patch 2/4] sched: Use rcu in sched_get/set_affinity() Thomas Gleixner
2009-12-14 16:31 ` [tip:sched/urgent] " tip-bot for Thomas Gleixner
2009-12-09 10:15 ` [patch 3/4] sched: Rename bogus label in sched_setaffinity() Thomas Gleixner
2009-12-09 10:15 ` [patch 4/4] sched: Use rcu in sched_get_rr_param Thomas Gleixner
2009-12-14 16:31 ` [tip:sched/urgent] sched: Use rcu in sched_get_rr_param() tip-bot for Thomas Gleixner
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.