summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsias He <asias@redhat.com>2013-05-07 08:54:33 +0200
committerMichael S. Tsirkin <mst@redhat.com>2013-07-11 14:36:45 +0200
commit2e26af79b7e24e9644a6c16ad4dca61501fb4b3f (patch)
tree82bef64341c45ba98f4dc1154afbbe65c64d51cd
parentvhost/test: update test after vhost cleanups (diff)
downloadlinux-2e26af79b7e24e9644a6c16ad4dca61501fb4b3f.tar.xz
linux-2e26af79b7e24e9644a6c16ad4dca61501fb4b3f.zip
vhost-net: Always access vq->private_data under vq mutex
Signed-off-by: Asias He <asias@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--drivers/vhost/net.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 027be91db139..99f8d63491aa 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -346,12 +346,11 @@ static void handle_tx(struct vhost_net *net)
struct vhost_net_ubuf_ref *uninitialized_var(ubufs);
bool zcopy, zcopy_used;
- /* TODO: check that we are running from vhost_worker? */
- sock = rcu_dereference_check(vq->private_data, 1);
+ mutex_lock(&vq->mutex);
+ sock = vq->private_data;
if (!sock)
- return;
+ goto out;
- mutex_lock(&vq->mutex);
vhost_disable_notify(&net->dev, vq);
hdr_size = nvq->vhost_hlen;
@@ -461,7 +460,7 @@ static void handle_tx(struct vhost_net *net)
break;
}
}
-
+out:
mutex_unlock(&vq->mutex);
}
@@ -570,14 +569,14 @@ static void handle_rx(struct vhost_net *net)
s16 headcount;
size_t vhost_hlen, sock_hlen;
size_t vhost_len, sock_len;
- /* TODO: check that we are running from vhost_worker? */
- struct socket *sock = rcu_dereference_check(vq->private_data, 1);
-
- if (!sock)
- return;
+ struct socket *sock;
mutex_lock(&vq->mutex);
+ sock = vq->private_data;
+ if (!sock)
+ goto out;
vhost_disable_notify(&net->dev, vq);
+
vhost_hlen = nvq->vhost_hlen;
sock_hlen = nvq->sock_hlen;
@@ -652,7 +651,7 @@ static void handle_rx(struct vhost_net *net)
break;
}
}
-
+out:
mutex_unlock(&vq->mutex);
}