From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: "Michael S. Tsirkin" <mst@redhat.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 RFC tip/core/rcu 23/23] vhost: add __rcu annotations
Date: Thu, 13 May 2010 12:55:47 -0700 [thread overview]
Message-ID: <20100513195547.GK2879@linux.vnet.ibm.com> (raw)
In-Reply-To: <20100513045048.GC7413@redhat.com>
On Thu, May 13, 2010 at 07:50:50AM +0300, Michael S. Tsirkin wrote:
> On Wed, May 12, 2010 at 04:00:57PM -0700, Paul E. McKenney wrote:
> > 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.
>
> Just pls check this does not lead to unused variable
> warnings when the whole lockdep is off.
Will do! It should not, because the assignment happens independently
of lockdep, but I will nevertheless build both ways.
I am also merging in Peter Zijlstra's suggestion of leveraging the
existing lockdep on workqueues.
Thanx, Paul
> > 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
> >
> > > > ---
> > > > 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
next prev parent reply other threads:[~2010-05-13 19:55 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-12 21:33 [PATCH tip/core/rcu 0/23] infrastructure for sparse checks for RCU usage Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 01/23] rcu: add an rcu_dereference_index_check() Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 02/23] rcu: add __rcu API for later sparse checking Paul E. McKenney
2010-05-13 20:53 ` Matt Helsley
2010-05-13 21:48 ` Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 03/23] vfs: add fs.h to define struct file Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 04/23] net: Make accesses to ->br_port safe for sparse RCU Paul E. McKenney
2010-05-12 21:44 ` Stephen Hemminger
2010-05-12 22:35 ` Paul E. McKenney
2010-05-13 1:33 ` Stephen Hemminger
2010-05-13 2:00 ` Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 05/23] mce: convert to rcu_dereference_index_check() Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 06/23] rcu: define __rcu address space modifier for sparse Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 07/23] rculist: avoid __rcu annotations Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 08/23] cgroups: " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 09/23] credentials: rcu annotation Paul E. McKenney
2010-05-13 10:04 ` David Howells
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 10/23] keys: __rcu annotations Paul E. McKenney
2010-05-13 10:05 ` David Howells
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 11/23] nfs: " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 12/23] net: __rcu annotations for drivers Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 13/23] perf_event: __rcu annotations Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 14/23] notifiers: " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 15/23] radix-tree: " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 16/23] idr: " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 17/23] input: " Paul E. McKenney
2010-05-13 7:40 ` Dmitry Torokhov
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 18/23] net/netfilter: " Paul E. McKenney
2010-05-13 13:21 ` Patrick McHardy
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 19/23] kvm: add " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 20/23] kernel: " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 21/23] net: " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 22/23] kvm: more " Paul E. McKenney
2010-05-12 21:33 ` [PATCH RFC tip/core/rcu 23/23] vhost: add " Paul E. McKenney
2010-05-12 21:48 ` Michael S. Tsirkin
2010-05-12 23:00 ` Paul E. McKenney
2010-05-13 3:53 ` Michael S. Tsirkin
2010-05-13 4:49 ` Paul E. McKenney
2010-05-13 4:50 ` Michael S. Tsirkin
2010-05-13 19:55 ` Paul E. McKenney [this message]
2010-05-13 13:07 ` Peter Zijlstra
2010-05-13 15:23 ` Paul E. McKenney
2010-05-17 20:33 ` Michael S. Tsirkin
2010-05-17 21:06 ` Paul E. McKenney
2010-05-17 22:00 ` Mathieu Desnoyers
2010-05-17 23:05 ` Paul E. McKenney
2010-05-17 23:08 ` Michael S. Tsirkin
2010-05-17 23:40 ` Mathieu Desnoyers
2010-05-18 0:34 ` Paul E. McKenney
2010-05-18 1:35 ` Mathieu Desnoyers
2010-05-18 14:20 ` Paul E. McKenney
2010-05-18 14:25 ` Michael S. Tsirkin
2010-05-18 15:07 ` Paul E. McKenney
2010-05-18 14:47 ` Mathieu Desnoyers
2010-05-18 15:11 ` 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=20100513195547.GK2879@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.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=mst@redhat.com \
--cc=niv@us.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.