public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu,
	laijs@cn.fujitsu.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca,
	josh@joshtriplett.org, dvhltc@us.ibm.com, niv@us.ibm.com,
	tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org,
	Valdis.Kletnieks@vt.edu, dhowells@redhat.com,
	eric.dumazet@gmail.com, Arnd Bergmann <arnd@relay.de.ibm.com>,
	Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH tip/core/rcu 43/48] vhost: add __rcu annotations
Date: Wed, 5 May 2010 02:59:56 +0300	[thread overview]
Message-ID: <20100504235954.GA21573@redhat.com> (raw)
In-Reply-To: <20100504235750.GH2639@linux.vnet.ibm.com>

On Tue, May 04, 2010 at 04:57:50PM -0700, Paul E. McKenney wrote:
> On Wed, May 05, 2010 at 12:39:36AM +0300, Michael S. Tsirkin wrote:
> > On Tue, May 04, 2010 at 01:19:53PM -0700, Paul E. McKenney wrote:
> > > From: Arnd Bergmann <arnd@relay.de.ibm.com>
> > > 
> > > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > > Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> > > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > > ---
> > >  drivers/vhost/net.c   |    6 +++---
> > >  drivers/vhost/vhost.c |   12 ++++++------
> > >  drivers/vhost/vhost.h |    4 ++--
> > >  3 files changed, 11 insertions(+), 11 deletions(-)
> > > 
> > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> > > index 9777583..36e8dec 100644
> > > --- a/drivers/vhost/net.c
> > > +++ b/drivers/vhost/net.c
> > > @@ -364,7 +364,7 @@ static void vhost_net_disable_vq(struct vhost_net *n,
> > >  static void vhost_net_enable_vq(struct vhost_net *n,
> > >  				struct vhost_virtqueue *vq)
> > >  {
> > > -	struct socket *sock = vq->private_data;
> > > +	struct socket *sock = rcu_dereference(vq->private_data);
> > 
> > This should be rcu_dereference_const as well: it is called
> > with vq mutex held.
> 
> How about the following?
> 
> 	struct socket *sock;
> 	
> 	sock = rcu_dereference_protected(vq->private_data,
> 					 lockdep_is_held(&vq->mutex));
> 
> This could be used for some (though not all) of these situations.
> 
> And just so you know...  The fact that this is here in the first
> place is actually my mistake -- my intention was to include the __rcu
> annotations and nothing else, then follow up with bug fixes.  In fact,
> the alert reader will have noted that there is in fact no such thing
> as rcu_dereference_const().  And have concluded that none of my test
> machines use vhost.  :-/
> 
> But as long as we are here, might as well complete the annotation...
> 
> So I have inserted guesses for the lockdep_is_held() expressions below
> for your amusement.  Please let me know what I should be using instead.

I'll go over it. Could you point me to documentation to the API
I should use with this patch?

> > >  	if (!sock)
> > >  		return;
> > >  	if (vq == n->vqs + VHOST_NET_VQ_TX) {
> > > @@ -380,7 +380,7 @@ static struct socket *vhost_net_stop_vq(struct vhost_net *n,
> > >  	struct socket *sock;
> > >  
> > >  	mutex_lock(&vq->mutex);
> > > -	sock = vq->private_data;
> > > +	sock = rcu_dereference_const(vq->private_data);
> 
> 	sock = rcu_dereference_protected(vq->private_data,
> 					 lockdep_is_held(&vq->mutex));
> 
> > >  	vhost_net_disable_vq(n, vq);
> > >  	rcu_assign_pointer(vq->private_data, NULL);
> > >  	mutex_unlock(&vq->mutex);
> > > @@ -518,7 +518,7 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
> > >  	}
> > >  
> > >  	/* start polling new socket */
> > > -	oldsock = vq->private_data;
> > > +	oldsock = rcu_dereference_const(vq->private_data);
> 
> 	oldsock = rcu_dereference_protected(vq->private_data,
> 					    lockdep_is_held(&vq->mutex));
> 
> Though I can't say I see where this lock is actually acquired in this
> case...

Just above:

       mutex_lock(&vq->mutex);

        /* Verify that ring has been setup correctly. */
        if (!vhost_vq_access_ok(vq)) {
                r = -EFAULT;
                goto err_vq;
        }
        sock = get_socket(fd);
        if (IS_ERR(sock)) {
                r = PTR_ERR(sock);
                goto err_vq;
        }

        /* start polling new socket */



> > >  	if (sock == oldsock)
> > >  		goto done;
> > >  
> > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> > > index e69d238..fc9bde2 100644
> > > --- a/drivers/vhost/vhost.c
> > > +++ b/drivers/vhost/vhost.c
> > > @@ -180,7 +180,7 @@ long vhost_dev_reset_owner(struct vhost_dev *dev)
> > >  	vhost_dev_cleanup(dev);
> > >  
> > >  	memory->nregions = 0;
> > > -	dev->memory = memory;
> > > +	rcu_assign_pointer(dev->memory, memory);
> > 
> > This is called when there can be no active readers, so the smp_wmb
> > inside rcu_assign_pointer isn't really needed.
> > Use RCU_INIT_POINTER or something like this instead?
> 
> Good point!  Fixed.
> 
> > >  	return 0;
> > >  }
> > >  
> > > @@ -212,8 +212,8 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
> > >  		fput(dev->log_file);
> > >  	dev->log_file = NULL;
> > >  	/* No one will access memory at this point */
> > > -	kfree(dev->memory);
> > > -	dev->memory = NULL;
> > > +	kfree(rcu_dereference_const(dev->memory));
> 
> 	kfree(rcu_dereference_protected(dev->memory,
> 					lockdep_is_held(&dev->mutex));
> 
> > > +	rcu_assign_pointer(dev->memory, NULL);
> > 
> > Same here.
> 
> Fixed -- any in any case, we can always use RCU_INIT_POINTER() when
> assigning NULL.
> 
> > >  	if (dev->mm)
> > >  		mmput(dev->mm);
> > >  	dev->mm = NULL;
> > > @@ -294,14 +294,14 @@ static int vq_access_ok(unsigned int num,
> > >  /* Caller should have device mutex but not vq mutex */
> > >  int vhost_log_access_ok(struct vhost_dev *dev)
> > >  {
> > > -	return memory_access_ok(dev, dev->memory, 1);
> > > +	return memory_access_ok(dev, rcu_dereference_const(dev->memory), 1);
> 
> 	return memory_access_ok(dev, rcu_dereference_protected(dev->memory, lockdep_is_held(&dev->mutex)), 1);
> 
> And yes, we do need an rcu_dereference_vqdev() wrapper function, but just
> want to identify the mutexes for the moment.
> 
> Maybe a separate rcu_dereference_vq() as well -- but you tell me!
> 
> > >  }
> > >  
> > >  /* Verify access for write logging. */
> > >  /* Caller should have vq mutex and device mutex */
> > >  static int vq_log_access_ok(struct vhost_virtqueue *vq, void __user *log_base)
> > >  {
> > > -	return vq_memory_access_ok(log_base, vq->dev->memory,
> > > +	return vq_memory_access_ok(log_base, rcu_dereference(vq->dev->memory),
> > 
> > rcu_dereference_const. This is called under vq mutex and the comment
> > above it says as much.
> 
> 	return memory_access_ok(dev, rcu_dereference_protected(dev->memory, lockdep_is_held(&dev->mutex)),
> 
> > >  			    vhost_has_feature(vq->dev, VHOST_F_LOG_ALL)) &&
> > >  		(!vq->log_used || log_access_ok(log_base, vq->log_addr,
> > >  					sizeof *vq->used +
> > > @@ -342,7 +342,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
> > >  
> > >  	if (!memory_access_ok(d, newmem, vhost_has_feature(d, VHOST_F_LOG_ALL)))
> > >  		return -EFAULT;
> > > -	oldmem = d->memory;
> > > +	oldmem = rcu_dereference_const(d->memory);
> 
> 	oldmem = rcu_dereference_protected(d->memory,
> 					   lockdep_is_held(&d->mutex));
> 
> > >  	rcu_assign_pointer(d->memory, newmem);
> > >  	synchronize_rcu();
> > >  	kfree(oldmem);
> > > diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> > > index 44591ba..240396c 100644
> > > --- a/drivers/vhost/vhost.h
> > > +++ b/drivers/vhost/vhost.h
> > > @@ -92,7 +92,7 @@ struct vhost_virtqueue {
> > >  	 * work item execution acts instead of rcu_read_lock() and the end of
> > >  	 * work item execution acts instead of rcu_read_lock().
> > >  	 * Writers use virtqueue mutex. */
> > > -	void *private_data;
> > > +	void __rcu *private_data;
> > >  	/* Log write descriptors */
> > >  	void __user *log_base;
> > >  	struct vhost_log log[VHOST_NET_MAX_SG];
> > > @@ -102,7 +102,7 @@ struct vhost_dev {
> > >  	/* Readers use RCU to access memory table pointer
> > >  	 * log base pointer and features.
> > >  	 * Writers use mutex below.*/
> > > -	struct vhost_memory *memory;
> > > +	struct vhost_memory __rcu *memory;
> > >  	struct mm_struct *mm;
> > >  	struct mutex mutex;
> > >  	unsigned acked_features;
> > > -- 
> > > 1.7.0

  reply	other threads:[~2010-05-05  0:05 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-04 20:19 [PATCH tip/core/rcu 0/48] v4 patches queued for 2.6.35 Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 01/48] rcu: optionally leave lockdep enabled after RCU lockdep splat Paul E. McKenney
2010-05-05 22:46   ` Mathieu Desnoyers
2010-05-05 23:05     ` Paul E. McKenney
2010-05-05 23:24       ` Mathieu Desnoyers
2010-05-05 23:36         ` Paul E. McKenney
2010-05-06  2:05           ` Mathieu Desnoyers
2010-05-06 23:09             ` Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 02/48] rcu: substitute set_need_resched for sending resched IPIs Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 03/48] rcu: make dead code really dead Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 04/48] rcu: move some code from macro to function Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 05/48] rcu: ignore offline CPUs in last non-dyntick-idle CPU check Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 06/48] rcu: Fix bogus CONFIG_PROVE_LOCKING in comments to reflect reality Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 07/48] rcu: fix now-bogus rcu_scheduler_active comments Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 08/48] rcu: shrink rcutiny by making synchronize_rcu_bh() be inline Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 09/48] rcu: rename rcutiny rcu_ctrlblk to rcu_sched_ctrlblk Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 10/48] rcu: refactor RCU's context-switch handling Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 11/48] rcu: slim down rcutiny by removing rcu_scheduler_active and friends Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 12/48] rcu: enable CPU_STALL_VERBOSE by default Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 13/48] rcu: disable CPU stall warnings upon panic Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 14/48] rcu: print boot-time console messages if RCU configs out of ordinary Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 15/48] rcu: improve RCU CPU stall-warning messages Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 16/48] rcu: permit discontiguous cpu_possible_mask CPU numbering Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 17/48] rcu: v2: reduce the number of spurious RCU_SOFTIRQ invocations Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 18/48] rcu: improve the RCU CPU-stall warning documentation Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 19/48] Debugobjects transition check Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 20/48] rcu head introduce rcu head init on stack Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 21/48] remove all rcu head initializations, except on_stack initializations Paul E. McKenney
2010-05-04 20:27   ` Matt Mackall
2010-05-04 20:36     ` Paul E. McKenney
2010-05-04 23:44   ` James Morris
2010-05-05  0:03     ` Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 22/48] rcu head remove init Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 23/48] tree/tiny rcu: Add debug RCU head objects (v5) Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 24/48] rcu: make SRCU usable in modules Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 25/48] rcu: fix debugobjects rcu head init on stack in rcutree_plugin.h Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 26/48] rcu: RCU_FAST_NO_HZ must check RCU dyntick state Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 27/48] vfs: add fs.h to define struct file Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 28/48] net: Make accesses to ->br_port safe for sparse RCU Paul E. McKenney
2010-05-04 21:26   ` Stephen Hemminger
2010-05-04 21:41     ` Arnd Bergmann
2010-05-05 22:03       ` Paul E. McKenney
2010-05-06 14:09         ` Arnd Bergmann
2010-05-06 23:12           ` Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 29/48] rcu: add an rcu_dereference_index_check() Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 30/48] mce: convert to rcu_dereference_index_check() Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 31/48] rcu: define __rcu address space modifier for sparse Paul E. McKenney
2010-05-04 20:58   ` Arnd Bergmann
2010-05-04 23:07     ` Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 32/48] rculist: avoid __rcu annotations Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 33/48] cgroups: " Paul E. McKenney
2010-05-04 20:48   ` Paul Menage
2010-05-05  0:04     ` Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 34/48] credentials: rcu annotation Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 35/48] keys: __rcu annotations Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 36/48] nfs: " Paul E. McKenney
2010-05-05 10:14   ` David Howells
2010-05-05 12:44     ` Trond Myklebust
2010-05-05 21:01       ` Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 37/48] net: __rcu annotations for drivers Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 38/48] perf_event: __rcu annotations Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 39/48] notifiers: " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 40/48] radix-tree: " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 41/48] idr: " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 42/48] input: " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 43/48] vhost: add " Paul E. McKenney
2010-05-04 21:39   ` Michael S. Tsirkin
2010-05-04 23:57     ` Paul E. McKenney
2010-05-04 23:59       ` Michael S. Tsirkin [this message]
2010-05-05  0:39         ` Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 44/48] net/netfilter: " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 45/48] kvm: add " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 46/48] kernel: " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 47/48] net: " Paul E. McKenney
2010-05-04 20:19 ` [PATCH tip/core/rcu 48/48] kvm: more " Paul E. McKenney

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=20100504235954.GA21573@redhat.com \
    --to=mst@redhat.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=arnd@relay.de.ibm.com \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=dvhltc@us.ibm.com \
    --cc=eric.dumazet@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=mingo@elte.hu \
    --cc=niv@us.ibm.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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