diff options
author | Asias He <asias@redhat.com> | 2013-05-07 02:54:33 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2013-07-11 08:36:45 -0400 |
commit | 2e26af79b7e24e9644a6c16ad4dca61501fb4b3f (patch) | |
tree | 82bef64341c45ba98f4dc1154afbbe65c64d51cd /drivers/vhost | |
parent | 09a34c8404c1d4c5782de319c02e1d742c57875c (diff) |
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>
Diffstat (limited to 'drivers/vhost')
-rw-r--r-- | drivers/vhost/net.c | 21 |
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) | |||
346 | struct vhost_net_ubuf_ref *uninitialized_var(ubufs); | 346 | struct vhost_net_ubuf_ref *uninitialized_var(ubufs); |
347 | bool zcopy, zcopy_used; | 347 | bool zcopy, zcopy_used; |
348 | 348 | ||
349 | /* TODO: check that we are running from vhost_worker? */ | 349 | mutex_lock(&vq->mutex); |
350 | sock = rcu_dereference_check(vq->private_data, 1); | 350 | sock = vq->private_data; |
351 | if (!sock) | 351 | if (!sock) |
352 | return; | 352 | goto out; |
353 | 353 | ||
354 | mutex_lock(&vq->mutex); | ||
355 | vhost_disable_notify(&net->dev, vq); | 354 | vhost_disable_notify(&net->dev, vq); |
356 | 355 | ||
357 | hdr_size = nvq->vhost_hlen; | 356 | hdr_size = nvq->vhost_hlen; |
@@ -461,7 +460,7 @@ static void handle_tx(struct vhost_net *net) | |||
461 | break; | 460 | break; |
462 | } | 461 | } |
463 | } | 462 | } |
464 | 463 | out: | |
465 | mutex_unlock(&vq->mutex); | 464 | mutex_unlock(&vq->mutex); |
466 | } | 465 | } |
467 | 466 | ||
@@ -570,14 +569,14 @@ static void handle_rx(struct vhost_net *net) | |||
570 | s16 headcount; | 569 | s16 headcount; |
571 | size_t vhost_hlen, sock_hlen; | 570 | size_t vhost_hlen, sock_hlen; |
572 | size_t vhost_len, sock_len; | 571 | size_t vhost_len, sock_len; |
573 | /* TODO: check that we are running from vhost_worker? */ | 572 | struct socket *sock; |
574 | struct socket *sock = rcu_dereference_check(vq->private_data, 1); | ||
575 | |||
576 | if (!sock) | ||
577 | return; | ||
578 | 573 | ||
579 | mutex_lock(&vq->mutex); | 574 | mutex_lock(&vq->mutex); |
575 | sock = vq->private_data; | ||
576 | if (!sock) | ||
577 | goto out; | ||
580 | vhost_disable_notify(&net->dev, vq); | 578 | vhost_disable_notify(&net->dev, vq); |
579 | |||
581 | vhost_hlen = nvq->vhost_hlen; | 580 | vhost_hlen = nvq->vhost_hlen; |
582 | sock_hlen = nvq->sock_hlen; | 581 | sock_hlen = nvq->sock_hlen; |
583 | 582 | ||
@@ -652,7 +651,7 @@ static void handle_rx(struct vhost_net *net) | |||
652 | break; | 651 | break; |
653 | } | 652 | } |
654 | } | 653 | } |
655 | 654 | out: | |
656 | mutex_unlock(&vq->mutex); | 655 | mutex_unlock(&vq->mutex); |
657 | } | 656 | } |
658 | 657 | ||