diff options
author | Arnd Bergmann <arnd@relay.de.ibm.com> | 2010-03-09 13:24:45 -0500 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2010-08-21 19:27:36 -0400 |
commit | 28457ee69c473a903e51e26c7bcd6f1e9eceb93e (patch) | |
tree | 7f872922577ec45ce655d68770c95082ad858a45 /drivers/vhost/vhost.c | |
parent | 65e6bf484c497f02d47a0faae69ee398cd59cfda (diff) |
vhost: add __rcu annotations
Also add rcu_dereference_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>
Diffstat (limited to 'drivers/vhost/vhost.c')
-rw-r--r-- | drivers/vhost/vhost.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index e05557d52999..b5c49478d203 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c | |||
@@ -284,7 +284,7 @@ long vhost_dev_reset_owner(struct vhost_dev *dev) | |||
284 | vhost_dev_cleanup(dev); | 284 | vhost_dev_cleanup(dev); |
285 | 285 | ||
286 | memory->nregions = 0; | 286 | memory->nregions = 0; |
287 | dev->memory = memory; | 287 | RCU_INIT_POINTER(dev->memory, memory); |
288 | return 0; | 288 | return 0; |
289 | } | 289 | } |
290 | 290 | ||
@@ -316,8 +316,9 @@ void vhost_dev_cleanup(struct vhost_dev *dev) | |||
316 | fput(dev->log_file); | 316 | fput(dev->log_file); |
317 | dev->log_file = NULL; | 317 | dev->log_file = NULL; |
318 | /* No one will access memory at this point */ | 318 | /* No one will access memory at this point */ |
319 | kfree(dev->memory); | 319 | kfree(rcu_dereference_protected(dev->memory, |
320 | dev->memory = NULL; | 320 | lockdep_is_held(&dev->mutex))); |
321 | RCU_INIT_POINTER(dev->memory, NULL); | ||
321 | if (dev->mm) | 322 | if (dev->mm) |
322 | mmput(dev->mm); | 323 | mmput(dev->mm); |
323 | dev->mm = NULL; | 324 | dev->mm = NULL; |
@@ -401,14 +402,22 @@ static int vq_access_ok(unsigned int num, | |||
401 | /* Caller should have device mutex but not vq mutex */ | 402 | /* Caller should have device mutex but not vq mutex */ |
402 | int vhost_log_access_ok(struct vhost_dev *dev) | 403 | int vhost_log_access_ok(struct vhost_dev *dev) |
403 | { | 404 | { |
404 | return memory_access_ok(dev, dev->memory, 1); | 405 | struct vhost_memory *mp; |
406 | |||
407 | mp = rcu_dereference_protected(dev->memory, | ||
408 | lockdep_is_held(&dev->mutex)); | ||
409 | return memory_access_ok(dev, mp, 1); | ||
405 | } | 410 | } |
406 | 411 | ||
407 | /* Verify access for write logging. */ | 412 | /* Verify access for write logging. */ |
408 | /* Caller should have vq mutex and device mutex */ | 413 | /* Caller should have vq mutex and device mutex */ |
409 | static int vq_log_access_ok(struct vhost_virtqueue *vq, void __user *log_base) | 414 | static int vq_log_access_ok(struct vhost_virtqueue *vq, void __user *log_base) |
410 | { | 415 | { |
411 | return vq_memory_access_ok(log_base, vq->dev->memory, | 416 | struct vhost_memory *mp; |
417 | |||
418 | mp = rcu_dereference_protected(vq->dev->memory, | ||
419 | lockdep_is_held(&vq->mutex)); | ||
420 | return vq_memory_access_ok(log_base, mp, | ||
412 | vhost_has_feature(vq->dev, VHOST_F_LOG_ALL)) && | 421 | vhost_has_feature(vq->dev, VHOST_F_LOG_ALL)) && |
413 | (!vq->log_used || log_access_ok(log_base, vq->log_addr, | 422 | (!vq->log_used || log_access_ok(log_base, vq->log_addr, |
414 | sizeof *vq->used + | 423 | sizeof *vq->used + |
@@ -448,7 +457,8 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) | |||
448 | kfree(newmem); | 457 | kfree(newmem); |
449 | return -EFAULT; | 458 | return -EFAULT; |
450 | } | 459 | } |
451 | oldmem = d->memory; | 460 | oldmem = rcu_dereference_protected(d->memory, |
461 | lockdep_is_held(&d->mutex)); | ||
452 | rcu_assign_pointer(d->memory, newmem); | 462 | rcu_assign_pointer(d->memory, newmem); |
453 | synchronize_rcu(); | 463 | synchronize_rcu(); |
454 | kfree(oldmem); | 464 | kfree(oldmem); |