login
Login
/
Register
Search
Search this site:
Forums
News
Blogs
Features
Site
Home
»
Mailing list archives
»
linux-kernel
»
2010
»
May
»
13
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annotations
view
thread
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
[view in full thread]
From: Michael S. Tsirkin
Subject:
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annotations
Date: Wednesday, May 12, 2010 - 8:53 pm
On Wed, May 12, 2010 at 04:00:57PM -0700, Paul E. McKenney wrote:
quoted text
> On Thu, May 13, 2010 at 12:48:47AM +0300, Michael S. Tsirkin wrote: > > On Wed, May 12, 2010 at 02:33:42PM -0700, Paul E. McKenney wrote: > > > From: Arnd Bergmann <arnd@relay.de.ibm.com> > > > > > > Also add rcu_dreference_protected() for code paths where locks are held. > > > > > > 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> > > > > Maybe long lines can be fixed? Otherwise looks ok. > > Done. I introduced locals to make it fit. > > One other thing... We need some API that says "we are running in the > context of a work queue." Otherwise, we will get false positives when > called in a work queue without locks held. > > Any thoughts? One approach would be to create a separate lockdep class > for vhost workqueue state, similar to the approach used in instrument > rcu_read_lock() and friends. > > Thanx, Paul
And we would want some way to tag the flushes ... not easy. Let's start with switching to raw to avoid the errors.
quoted text
> > > --- > > > drivers/vhost/net.c | 11 ++++++++--- > > > drivers/vhost/vhost.c | 14 ++++++++------ > > > drivers/vhost/vhost.h | 4 ++-- > > > 3 files changed, 18 insertions(+), 11 deletions(-) > > > > > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > > > index 9777583..945c5cb 100644 > > > --- a/drivers/vhost/net.c > > > +++ b/drivers/vhost/net.c > > > @@ -364,7 +364,10 @@ 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; > > > + > > > + sock = rcu_dereference_protected(vq->private_data, > > > + lockdep_is_held(&vq->mutex)); > > > if (!sock) > > > return; > > > if (vq == n->vqs + VHOST_NET_VQ_TX) { > > > @@ -380,7 +383,8 @@ 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_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 +522,8 @@ 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_protected(vq->private_data, > > > + lockdep_is_held(&vq->mutex)); > > > if (sock == oldsock) > > > goto done; > > > > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > > index e69d238..fc0c077 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_INIT_POINTER(dev->memory, memory); > > > return 0; > > > } > > > > > > @@ -212,8 +212,9 @@ 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_protected(dev->memory, > > > + lockdep_is_held(&dev->mutex))); > > > + RCU_INIT_POINTER(dev->memory, NULL); > > > if (dev->mm) > > > mmput(dev->mm); > > > dev->mm = NULL; > > > @@ -294,14 +295,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_protected(dev->memory, lockdep_is_held(&dev->mutex)), 1); > > > } > > > > > > /* 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_protected(vq->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 +343,8 @@ 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_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.6
--
unsubscribe notice
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to
majordomo@vger.kernel.org
More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at
http://www.tux.org/lkml/
Previous message: [
thread
] [
date
] [
author
]
Next message: [
thread
] [
date
] [
author
]
Messages in current thread:
[PATCH tip/core/rcu 0/23] infrastructure for sparse checks ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 01/23] rcu: add an rcu_dereference ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 02/23] rcu: add __rcu API for late ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 03/23] vfs: add fs.h to define str ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 04/23] net: Make accesses to ->br_ ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 05/23] mce: convert to rcu_derefer ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 06/23] rcu: define __rcu address s ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 07/23] rculist: avoid __rcu annota ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 08/23] cgroups: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 09/23] credentials: rcu annotation
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 10/23] keys: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 11/23] nfs: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 12/23] net: __rcu annotations for ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 13/23] perf_event: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 14/23] notifiers: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 15/23] radix-tree: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 16/23] idr: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 17/23] input: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 18/23] net/netfilter: __rcu annota ...
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 19/23] kvm: add __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 20/23] kernel: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 21/23] net: __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 22/23] kvm: more __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
[PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annotations
, Paul E. McKenney
, (Wed May 12, 2:33 pm)
Re: [PATCH RFC tip/core/rcu 04/23] net: Make accesses to - ...
, Stephen Hemminger
, (Wed May 12, 2:44 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Michael S. Tsirkin
, (Wed May 12, 2:48 pm)
Re: [PATCH RFC tip/core/rcu 04/23] net: Make accesses to - ...
, Paul E. McKenney
, (Wed May 12, 3:35 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Wed May 12, 4:00 pm)
Re: [PATCH RFC tip/core/rcu 04/23] net: Make accesses to - ...
, Stephen Hemminger
, (Wed May 12, 6:33 pm)
Re: [PATCH RFC tip/core/rcu 04/23] net: Make accesses to - ...
, Paul E. McKenney
, (Wed May 12, 7:00 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Michael S. Tsirkin
, (Wed May 12, 8:53 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Wed May 12, 9:49 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Michael S. Tsirkin
, (Wed May 12, 9:50 pm)
Re: [PATCH RFC tip/core/rcu 17/23] input: __rcu annotations
, Dmitry Torokhov
, (Thu May 13, 12:40 am)
Re: [PATCH RFC tip/core/rcu 09/23] credentials: rcu annotation
, David Howells
, (Thu May 13, 3:04 am)
Re: [PATCH RFC tip/core/rcu 10/23] keys: __rcu annotations
, David Howells
, (Thu May 13, 3:05 am)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Peter Zijlstra
, (Thu May 13, 6:07 am)
Re: [PATCH RFC tip/core/rcu 18/23] net/netfilter: __rcu an ...
, Patrick McHardy
, (Thu May 13, 6:21 am)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Thu May 13, 8:23 am)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Thu May 13, 12:55 pm)
Re: [PATCH RFC tip/core/rcu 02/23] rcu: add __rcu API for ...
, Matt Helsley
, (Thu May 13, 1:53 pm)
Re: [PATCH RFC tip/core/rcu 02/23] rcu: add __rcu API for ...
, Paul E. McKenney
, (Thu May 13, 2:48 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Michael S. Tsirkin
, (Mon May 17, 1:33 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Mon May 17, 2:06 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Mathieu Desnoyers
, (Mon May 17, 3:00 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Mon May 17, 4:05 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Michael S. Tsirkin
, (Mon May 17, 4:08 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Mathieu Desnoyers
, (Mon May 17, 4:40 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Mon May 17, 5:34 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Mathieu Desnoyers
, (Mon May 17, 6:35 pm)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Tue May 18, 7:20 am)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Michael S. Tsirkin
, (Tue May 18, 7:25 am)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Mathieu Desnoyers
, (Tue May 18, 7:47 am)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Tue May 18, 8:07 am)
Re: [PATCH RFC tip/core/rcu 23/23] vhost: add __rcu annota ...
, Paul E. McKenney
, (Tue May 18, 8:11 am)
Navigation
Mailing list archives
Recent posts
Popular discussions
linux-kernel
:
Greg KH
Og dreams of kernels
Jens Axboe
[PATCH 31/33] Fusion: sg chaining support
Arnd Bergmann
Re: finding your own dead "CONFIG_" variables
Mark Brown
[PATCH 2/2] Subject: natsemi: Allow users to disable workaround for DspCfg reset
Tony Breeds
[LGUEST] Look in object dir for .config