Commit 05c05351 authored by Michael S. Tsirkin's avatar Michael S. Tsirkin Committed by David S. Miller

vhost: check owner before we overwrite ubuf_info

If device has an owner, we shouldn't touch ubuf_info
since it might be in use.
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c2020be3
...@@ -1054,6 +1054,10 @@ static long vhost_net_set_owner(struct vhost_net *n) ...@@ -1054,6 +1054,10 @@ static long vhost_net_set_owner(struct vhost_net *n)
int r; int r;
mutex_lock(&n->dev.mutex); mutex_lock(&n->dev.mutex);
if (vhost_dev_has_owner(&n->dev)) {
r = -EBUSY;
goto out;
}
r = vhost_net_set_ubuf_info(n); r = vhost_net_set_ubuf_info(n);
if (r) if (r)
goto out; goto out;
......
...@@ -343,6 +343,12 @@ static int vhost_attach_cgroups(struct vhost_dev *dev) ...@@ -343,6 +343,12 @@ static int vhost_attach_cgroups(struct vhost_dev *dev)
return attach.ret; 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 */ /* Caller should have device mutex */
long vhost_dev_set_owner(struct vhost_dev *dev) long vhost_dev_set_owner(struct vhost_dev *dev)
{ {
...@@ -350,7 +356,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev) ...@@ -350,7 +356,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
int err; int err;
/* Is there an owner already? */ /* Is there an owner already? */
if (dev->mm) { if (vhost_dev_has_owner(dev)) {
err = -EBUSY; err = -EBUSY;
goto err_mm; goto err_mm;
} }
......
...@@ -133,6 +133,7 @@ struct vhost_dev { ...@@ -133,6 +133,7 @@ struct vhost_dev {
long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, int nvqs); long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, int nvqs);
long vhost_dev_set_owner(struct vhost_dev *dev); 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 *); long vhost_dev_check_owner(struct vhost_dev *);
struct vhost_memory *vhost_dev_reset_owner_prepare(void); struct vhost_memory *vhost_dev_reset_owner_prepare(void);
void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_memory *); void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_memory *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment