* [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can
@ 2009-06-12 8:34 Stanislaw Gruszka
2009-06-12 14:00 ` Oleg Nesterov
0 siblings, 1 reply; 8+ messages in thread
From: Stanislaw Gruszka @ 2009-06-12 8:34 UTC (permalink / raw)
To: Thomas Gleixner
Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
Ingo Molnar, Andrew Morton
tasklist_lock is not needed to protect find_task_by_vpid() nor
thread_group_leader() nor same_thread_group() , use rcu_read_lock() instead.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
kernel/posix-cpu-timers.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index bece7c0..1fadd2f 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -37,13 +37,13 @@ static int check_clock(const clockid_t which_clock)
if (pid == 0)
return 0;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_task_by_vpid(pid);
if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
same_thread_group(p, current) : thread_group_leader(p))) {
error = -EINVAL;
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return error;
}
@@ -398,7 +398,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
new_timer->it.cpu.incr.sched = 0;
new_timer->it.cpu.expires.sched = 0;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) {
if (pid == 0) {
p = current;
@@ -422,7 +422,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
} else {
ret = -EINVAL;
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return ret;
}
--
1.5.5.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can
2009-06-12 8:34 [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can Stanislaw Gruszka
@ 2009-06-12 14:00 ` Oleg Nesterov
2009-06-12 14:44 ` Oleg Nesterov
0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2009-06-12 14:00 UTC (permalink / raw)
To: Stanislaw Gruszka
Cc: Thomas Gleixner, linux-kernel@vger.kernel.org, Peter Zijlstra,
Ingo Molnar, Andrew Morton
On 06/12, Stanislaw Gruszka wrote:
>
> tasklist_lock is not needed to protect find_task_by_vpid() nor
> thread_group_leader()
It does protect thread_group_leader(), unless we use current.
Please see below.
> @@ -398,7 +398,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
> new_timer->it.cpu.incr.sched = 0;
> new_timer->it.cpu.expires.sched = 0;
>
> - read_lock(&tasklist_lock);
> + rcu_read_lock();
> if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) {
> if (pid == 0) {
> p = current;
> @@ -422,7 +422,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
> } else {
> ret = -EINVAL;
> }
> - read_unlock(&tasklist_lock);
> + rcu_read_unlock();
Suppose that the non-main thread execs. de_thread() does
attach_pid(tsk, PIDTYPE_PID, task_pid(leader));
leader->group_leader = tsk;
under write_lock(tasklist). This means posix_cpu_timer_create() can return
-EINVAL if it is called in between, or if we found the group leader but
thread_group_leader() is called after "tsk->group_leader = tsk".
I think the patch is fine, but you should also replace thread_group_leader()
with has_group_leader_pid().
This reminds me. !CPUCLOCK_PERTHREAD timers survive after exec, but only
if ->group_leader execs. Not good.
Oleg.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can
@ 2009-06-15 8:36 Stanislaw Gruszka
0 siblings, 0 replies; 8+ messages in thread
From: Stanislaw Gruszka @ 2009-06-15 8:36 UTC (permalink / raw)
To: Thomas Gleixner
Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
Ingo Molnar
tasklist_lock is not needed to protect find_task_by_vpid() nor
same_thread_group() and if we replace thread_group_leader() by
has_group_leader_pid() we can just use RCU lock to protect some process
timers/clocks checks.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
kernel/posix-cpu-timers.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index bece7c0..029b442 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -37,13 +37,13 @@ static int check_clock(const clockid_t which_clock)
if (pid == 0)
return 0;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_task_by_vpid(pid);
if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
- same_thread_group(p, current) : thread_group_leader(p))) {
+ same_thread_group(p, current) : has_group_leader_pid(p))) {
error = -EINVAL;
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return error;
}
@@ -398,7 +398,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
new_timer->it.cpu.incr.sched = 0;
new_timer->it.cpu.expires.sched = 0;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) {
if (pid == 0) {
p = current;
@@ -412,7 +412,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
p = current->group_leader;
} else {
p = find_task_by_vpid(pid);
- if (p && !thread_group_leader(p))
+ if (p && !has_group_leader_pid(p))
p = NULL;
}
}
@@ -422,7 +422,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
} else {
ret = -EINVAL;
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return ret;
}
--
1.5.5.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can
@ 2009-06-12 6:49 Stanislaw Gruszka
2009-06-12 7:11 ` Peter Zijlstra
2009-06-12 7:48 ` Richard Kennedy
0 siblings, 2 replies; 8+ messages in thread
From: Stanislaw Gruszka @ 2009-06-12 6:49 UTC (permalink / raw)
To: Thomas Gleixner
Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
Ingo Molnar, Andrew Morton
tasklist_lock is not needed to protect find_task_by_vpid() nor
thread_group_leader() nor same_thread_group() , use rcu_read_lock() instead.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
kernel/posix-cpu-timers.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index bece7c0..1d9cdf3 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -37,13 +37,13 @@ static int check_clock(const clockid_t which_clock)
if (pid == 0)
return 0;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
p = find_task_by_vpid(pid);
if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
same_thread_group(p, current) : thread_group_leader(p))) {
error = -EINVAL;
}
- read_unlock(&tasklist_lock);
+ rcu_read_lock();
return error;
}
@@ -398,7 +398,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
new_timer->it.cpu.incr.sched = 0;
new_timer->it.cpu.expires.sched = 0;
- read_lock(&tasklist_lock);
+ rcu_read_lock();
if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) {
if (pid == 0) {
p = current;
@@ -422,7 +422,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
} else {
ret = -EINVAL;
}
- read_unlock(&tasklist_lock);
+ rcu_read_unlock();
return ret;
}
--
1.6.0.6
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can
2009-06-12 6:49 Stanislaw Gruszka
@ 2009-06-12 7:11 ` Peter Zijlstra
2009-06-12 7:48 ` Richard Kennedy
1 sibling, 0 replies; 8+ messages in thread
From: Peter Zijlstra @ 2009-06-12 7:11 UTC (permalink / raw)
To: Stanislaw Gruszka
Cc: Thomas Gleixner, linux-kernel@vger.kernel.org, Oleg Nesterov,
Ingo Molnar, Andrew Morton
On Fri, 2009-06-12 at 08:49 +0200, Stanislaw Gruszka wrote:
> tasklist_lock is not needed to protect find_task_by_vpid() nor
> thread_group_leader() nor same_thread_group() , use rcu_read_lock() instead.
Aside from not being strictly needed, one can sometimes require a
tasklist_lock reader to ensure nothing changes, however since the code
is racy in that regard anyway, this looks good.
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> kernel/posix-cpu-timers.c | 8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
> index bece7c0..1d9cdf3 100644
> --- a/kernel/posix-cpu-timers.c
> +++ b/kernel/posix-cpu-timers.c
> @@ -37,13 +37,13 @@ static int check_clock(const clockid_t which_clock)
> if (pid == 0)
> return 0;
>
> - read_lock(&tasklist_lock);
> + rcu_read_lock();
> p = find_task_by_vpid(pid);
> if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
> same_thread_group(p, current) : thread_group_leader(p))) {
> error = -EINVAL;
> }
> - read_unlock(&tasklist_lock);
> + rcu_read_lock();
>
> return error;
> }
> @@ -398,7 +398,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
> new_timer->it.cpu.incr.sched = 0;
> new_timer->it.cpu.expires.sched = 0;
>
> - read_lock(&tasklist_lock);
> + rcu_read_lock();
> if (CPUCLOCK_PERTHREAD(new_timer->it_clock)) {
> if (pid == 0) {
> p = current;
> @@ -422,7 +422,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
> } else {
> ret = -EINVAL;
> }
> - read_unlock(&tasklist_lock);
> + rcu_read_unlock();
>
> return ret;
> }
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can
2009-06-12 6:49 Stanislaw Gruszka
2009-06-12 7:11 ` Peter Zijlstra
@ 2009-06-12 7:48 ` Richard Kennedy
2009-06-12 8:02 ` Stanislaw Gruszka
1 sibling, 1 reply; 8+ messages in thread
From: Richard Kennedy @ 2009-06-12 7:48 UTC (permalink / raw)
To: Stanislaw Gruszka
Cc: Thomas Gleixner, linux-kernel@vger.kernel.org, Oleg Nesterov,
Peter Zijlstra, Ingo Molnar, Andrew Morton
Stanislaw Gruszka wrote:
> tasklist_lock is not needed to protect find_task_by_vpid() nor
> thread_group_leader() nor same_thread_group() , use rcu_read_lock() instead.
>
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> kernel/posix-cpu-timers.c | 8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
> index bece7c0..1d9cdf3 100644
> --- a/kernel/posix-cpu-timers.c
> +++ b/kernel/posix-cpu-timers.c
> @@ -37,13 +37,13 @@ static int check_clock(const clockid_t which_clock)
> if (pid == 0)
> return 0;
>
> - read_lock(&tasklist_lock);
> + rcu_read_lock();
> p = find_task_by_vpid(pid);
> if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
> same_thread_group(p, current) : thread_group_leader(p))) {
> error = -EINVAL;
> }
> - read_unlock(&tasklist_lock);
> + rcu_read_lock();
>
Did you really intend to replace an unlock with a lock?
regards
Richard
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-06-15 8:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-12 8:34 [PATCH 2/2] posix-cpu-timers: remove tasklist_lock where we can Stanislaw Gruszka
2009-06-12 14:00 ` Oleg Nesterov
2009-06-12 14:44 ` Oleg Nesterov
-- strict thread matches above, loose matches on Subject: below --
2009-06-15 8:36 Stanislaw Gruszka
2009-06-12 6:49 Stanislaw Gruszka
2009-06-12 7:11 ` Peter Zijlstra
2009-06-12 7:48 ` Richard Kennedy
2009-06-12 8:02 ` Stanislaw Gruszka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox