Skip to content

Commit

Permalink
vhost: check owner before we overwrite ubuf_info
Browse files Browse the repository at this point in the history
If device has an owner, we shouldn't touch ubuf_info
since it might be in use.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Michael S. Tsirkin authored and David S. Miller committed Jun 11, 2013
1 parent c2020be commit 05c0535
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions drivers/vhost/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,10 @@ static long vhost_net_set_owner(struct vhost_net *n)
int r;

mutex_lock(&n->dev.mutex);
if (vhost_dev_has_owner(&n->dev)) {
r = -EBUSY;
goto out;
}
r = vhost_net_set_ubuf_info(n);
if (r)
goto out;
Expand Down
8 changes: 7 additions & 1 deletion drivers/vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,20 @@ static int vhost_attach_cgroups(struct vhost_dev *dev)
return attach.ret;
}

/* Caller should have device mutex */
bool vhost_dev_has_owner(struct vhost_dev *dev)
{
return dev->mm;
}

/* Caller should have device mutex */
long vhost_dev_set_owner(struct vhost_dev *dev)
{
struct task_struct *worker;
int err;

/* Is there an owner already? */
if (dev->mm) {
if (vhost_dev_has_owner(dev)) {
err = -EBUSY;
goto err_mm;
}
Expand Down
1 change: 1 addition & 0 deletions drivers/vhost/vhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ struct vhost_dev {

long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, int nvqs);
long vhost_dev_set_owner(struct vhost_dev *dev);
bool vhost_dev_has_owner(struct vhost_dev *dev);
long vhost_dev_check_owner(struct vhost_dev *);
struct vhost_memory *vhost_dev_reset_owner_prepare(void);
void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_memory *);
Expand Down

0 comments on commit 05c0535

Please sign in to comment.