]> Pileus Git - ~andy/linux/commitdiff
vhost_net: poll vhost queue after marking DMA is done
authorJason Wang <jasowang@redhat.com>
Mon, 2 Sep 2013 08:41:00 +0000 (16:41 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 Sep 2013 02:46:57 +0000 (22:46 -0400)
We used to poll vhost queue before making DMA is done, this is racy if vhost
thread were waked up before marking DMA is done which can result the signal to
be missed. Fix this by always polling the vhost thread before DMA is done.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/vhost/net.c

index 3f89dea297a3d7bdf39103ebea4b2810ac4a238e..8e9dc554b1ef3192335165896b5780d072beae07 100644 (file)
@@ -308,6 +308,11 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success)
        struct vhost_virtqueue *vq = ubufs->vq;
        int cnt = atomic_read(&ubufs->kref.refcount);
 
+       /* set len to mark this desc buffers done DMA */
+       vq->heads[ubuf->desc].len = success ?
+               VHOST_DMA_DONE_LEN : VHOST_DMA_FAILED_LEN;
+       vhost_net_ubuf_put(ubufs);
+
        /*
         * Trigger polling thread if guest stopped submitting new buffers:
         * in this case, the refcount after decrement will eventually reach 1
@@ -318,10 +323,6 @@ static void vhost_zerocopy_callback(struct ubuf_info *ubuf, bool success)
         */
        if (cnt <= 2 || !(cnt % 16))
                vhost_poll_queue(&vq->poll);
-       /* set len to mark this desc buffers done DMA */
-       vq->heads[ubuf->desc].len = success ?
-               VHOST_DMA_DONE_LEN : VHOST_DMA_FAILED_LEN;
-       vhost_net_ubuf_put(ubufs);
 }
 
 /* Expects to be always run from workqueue - which acts as