Skip to content

Commit

Permalink
vhost-net: Always access vq->private_data under vq mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Asias He <asias@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Asias He authored and Michael S. Tsirkin committed Jul 11, 2013
1 parent 09a34c8 commit 2e26af7
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions drivers/vhost/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -461,7 +460,7 @@ static void handle_tx(struct vhost_net *net)
break;
}
}

out:
mutex_unlock(&vq->mutex);
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -652,7 +651,7 @@ static void handle_rx(struct vhost_net *net)
break;
}
}

out:
mutex_unlock(&vq->mutex);
}

Expand Down

0 comments on commit 2e26af7

Please sign in to comment.