linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	mingo@elte.hu
Subject: Re: [PATCH] rcu_read_lock/unlock protect find_task_by_vpid call
Date: Mon, 8 Nov 2010 05:19:58 -0800	[thread overview]
Message-ID: <20101108131958.GD2580@linux.vnet.ibm.com> (raw)
In-Reply-To: <20101108102817.GN27712@swordfish.minsk.epam.com>

On Mon, Nov 08, 2010 at 12:28:17PM +0200, Sergey Senozhatsky wrote:
> On (11/07/10 19:01), Paul E. McKenney wrote:
> > On Mon, Nov 08, 2010 at 07:04:43AM +0900, Tetsuo Handa wrote:
> > > Hello.
> > > 
> > > Paul E. McKenney wrote:
> > > > > Users missing rcu_read_lock() when calling find_task_by_vpid():
> > > > > 
> > > > >   check_clock() in kernel/posix-cpu-timers.c
> > > > 
> > > > 	This one has read_lock(&tasklist_lock).
> > > > 
> > > Excuse me. Holding tasklist_lock lock does not help.
> > > We must call rcu_read_lock() explicitly.
> > > That's why 9728e5d6 "kernel/pid.c: update comment on find_task_by_pid_ns" was made.
> > 
> > OK, good point, there are a few more kernels of unpopped corn here.
> >
> 
> Hello,
> I prepared a patch for posix-cpu-timers. 
> 
> [PATCH] posix-cpu-timers: rcu_read_lock/unlock protect find_task_by_vpid call
> Reviewed-by: Oleg Nesterov <oleg@redhat.com>
> 
> http://lkml.org/lkml/2010/11/3/257

Ah, very good, thank you!!!

							Thanx, Paul

> 	Sergey
> 
>  
> > > I think there are users who needlessly call read_lock(&tasklist_lock)
> > > when they can use rcu_read_lock() instead.
> > > But I don't know when to use read_lock(&tasklist_lock).
> > > 
> > > If read_lock(&tasklist_lock) is needed only when we want to access
> > > the "struct task_struct" after rcu_read_unlock(), maybe it is cleaner to
> > > use a helper like
> > > 
> > > struct task_struct *find_task_and_get(pid_t pid)
> > > {
> > > 	struct task_struct *task;
> > > 	read_lock(&tasklist_lock);
> > > 	rcu_read_lock();
> > > 	task = find_task_by_vpid(pid);
> > > 	rcu_read_unlock();
> > > 	if (task)
> > > 		get_task_struct(task);
> > > 	read_unlock(&tasklist_lock);
> > > 	return task;
> > > }
> > > 
> > > and hide tasklist_lock.
> > 
> > This makes a lot of sense to me!  That said, most of the current
> > open-coded variants of your find_task_and_get() seem to have the
> > rcu_read_unlock() after the get_task_struct() rather than before.  But I
> > don't claim to understand the locking design of this part of the kernel
> > well enough to say which is the best approach.
> > 
> > So, either way, will you be submitting the patches for this?
> > 
> > 							Thanx, Paul
> > 



  reply	other threads:[~2010-11-08 13:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-29 12:55 [PATCH] rcu_read_lock/unlock protect find_task_by_vpid call Sergey Senozhatsky
2010-10-29 20:16 ` Paul E. McKenney
2010-10-30  9:32   ` Sergey Senozhatsky
2010-10-30 13:14     ` Tetsuo Handa
2010-10-30 21:02       ` Paul E. McKenney
2010-10-30 23:33         ` Tetsuo Handa
2010-11-07 19:43           ` Paul E. McKenney
2010-11-07 22:04             ` Tetsuo Handa
2010-11-08  3:01               ` Paul E. McKenney
2010-11-08 10:28                 ` Sergey Senozhatsky
2010-11-08 13:19                   ` Paul E. McKenney [this message]
2010-11-08 16:01 ` Davidlohr Bueso
2010-11-08 16:18   ` Sergey Senozhatsky
2010-11-08 16:37     ` Davidlohr Bueso

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=20101108131958.GD2580@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).