Skip to content

Commit 2ae7669

Browse files
committed
vhost: replace rcu with mutex
All memory accesses are done under some VQ mutex. So lock/unlock all VQs is a faster equivalent of synchronize_rcu() for memory access changes. Some guests cause a lot of these changes, so it's helpful to make them faster. Reported-by: "Gonglei (Arei)" <arei.gonglei@huawei.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent d89a274 commit 2ae7669

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/vhost/vhost.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
593593
{
594594
struct vhost_memory mem, *newmem, *oldmem;
595595
unsigned long size = offsetof(struct vhost_memory, regions);
596+
int i;
596597

597598
if (copy_from_user(&mem, m, size))
598599
return -EFAULT;
@@ -619,7 +620,14 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
619620
oldmem = rcu_dereference_protected(d->memory,
620621
lockdep_is_held(&d->mutex));
621622
rcu_assign_pointer(d->memory, newmem);
622-
synchronize_rcu();
623+
624+
/* All memory accesses are done under some VQ mutex.
625+
* So below is a faster equivalent of synchronize_rcu()
626+
*/
627+
for (i = 0; i < d->nvqs; ++i) {
628+
mutex_lock(&d->vqs[i]->mutex);
629+
mutex_unlock(&d->vqs[i]->mutex);
630+
}
623631
kfree(oldmem);
624632
return 0;
625633
}

0 commit comments

Comments
 (0)