linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][RFC] Always unlock 'tasklist_lock' in kernel/exit.c::do_wait()
@ 2010-12-20 22:30 Jesper Juhl
  2010-12-21  5:54 ` Andrew Morton
  2010-12-21 10:30 ` Oleg Nesterov
  0 siblings, 2 replies; 3+ messages in thread
From: Jesper Juhl @ 2010-12-20 22:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Oleg Nesterov, Roland McGrath, Ingo Molnar,
	Paul E. McKenney

Hi,

The Coverity checker spotted this. I think it has a point, but I'm not 
intimate with this code so there could be somethingI'm missing.

It seems that kernel/exit.c::do_wait() does not always release 
'tasklist_lock'. There are multiple ways the code could be changed to make 
sure it's always released, I just picked the most straight forward one.

Does this look right to everyone else or is it just me?
I've only compile tested the patch so far.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 exit.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index 676149a..456b13d 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1647,12 +1647,16 @@ repeat:
 	tsk = current;
 	do {
 		retval = do_wait_thread(wo, tsk);
-		if (retval)
+		if (retval) {
+			read_unlock(&tasklist_lock);
 			goto end;
+		}
 
 		retval = ptrace_do_wait(wo, tsk);
-		if (retval)
+		if (retval) {
+			read_unlock(&tasklist_lock);
 			goto end;
+		}
 
 		if (wo->wo_flags & __WNOTHREAD)
 			break;



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][RFC] Always unlock 'tasklist_lock' in kernel/exit.c::do_wait()
  2010-12-20 22:30 [PATCH][RFC] Always unlock 'tasklist_lock' in kernel/exit.c::do_wait() Jesper Juhl
@ 2010-12-21  5:54 ` Andrew Morton
  2010-12-21 10:30 ` Oleg Nesterov
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2010-12-21  5:54 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: linux-kernel, Oleg Nesterov, Roland McGrath, Ingo Molnar,
	Paul E. McKenney

On Mon, 20 Dec 2010 23:30:38 +0100 (CET) Jesper Juhl <jj@chaosbits.net> wrote:

> The Coverity checker spotted this. I think it has a point, but I'm not 
> intimate with this code so there could be somethingI'm missing.
> 
> It seems that kernel/exit.c::do_wait() does not always release 
> 'tasklist_lock'.

do_wait_thread() and ptrace_do_wait() will have released tasklist_lock
if they returned non-zero.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][RFC] Always unlock 'tasklist_lock' in kernel/exit.c::do_wait()
  2010-12-20 22:30 [PATCH][RFC] Always unlock 'tasklist_lock' in kernel/exit.c::do_wait() Jesper Juhl
  2010-12-21  5:54 ` Andrew Morton
@ 2010-12-21 10:30 ` Oleg Nesterov
  1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2010-12-21 10:30 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: linux-kernel, Andrew Morton, Roland McGrath, Ingo Molnar,
	Paul E. McKenney

On 12/20, Jesper Juhl wrote:
>
> Hi,
>
> The Coverity checker spotted this. I think it has a point, but I'm not
> intimate with this code so there could be somethingI'm missing.
>
> It seems that kernel/exit.c::do_wait() does not always release
> 'tasklist_lock'. There are multiple ways the code could be changed to make
> sure it's always released, I just picked the most straight forward one.
>
> Does this look right to everyone else or is it just me?
> I've only compile tested the patch so far.
>
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  exit.c |    8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/exit.c b/kernel/exit.c
> index 676149a..456b13d 100644
> --- a/kernel/exit.c
> +++ b/kernel/exit.c
> @@ -1647,12 +1647,16 @@ repeat:
>  	tsk = current;
>  	do {
>  		retval = do_wait_thread(wo, tsk);
> -		if (retval)
> +		if (retval) {
> +			read_unlock(&tasklist_lock);

No, this is not right.

If wait_consider_task() returns nonzero (pid or errcode), tasklist_lock
should be already released.

That is why, for example, wait_task_stopped() does BUG_ON(!retval) after
it drops tasklist.

Oleg.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-12-21 10:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20 22:30 [PATCH][RFC] Always unlock 'tasklist_lock' in kernel/exit.c::do_wait() Jesper Juhl
2010-12-21  5:54 ` Andrew Morton
2010-12-21 10:30 ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).