Skip to content

Commit

Permalink
virtio-crypto: fix virtio_queue_set_notification() race
Browse files Browse the repository at this point in the history
We must check for new virtqueue buffers after re-enabling notifications.
This prevents the race condition where the guest added buffers just
after we stopped popping the virtqueue but before we re-enabled
notifications.

I think the virtio-crypto code was based on virtio-net but this crucial
detail was missed.  virtio-net does not have the race condition because
it processes the virtqueue one more time after re-enabling
notifications.

Cc: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gonglei <arei.gonglei@huawei.com>
  • Loading branch information
stefanhaRH authored and mstsirkin committed Nov 18, 2016
1 parent 453ac88 commit 600f5ce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hw/virtio/virtio-crypto.c
Expand Up @@ -692,8 +692,17 @@ static void virtio_crypto_dataq_bh(void *opaque)
return;
}

virtio_crypto_handle_dataq(vdev, q->dataq);
virtio_queue_set_notification(q->dataq, 1);
for (;;) {
virtio_crypto_handle_dataq(vdev, q->dataq);
virtio_queue_set_notification(q->dataq, 1);

/* Are we done or did the guest add more buffers? */
if (virtio_queue_empty(q->dataq)) {
break;
}

virtio_queue_set_notification(q->dataq, 0);
}
}

static void
Expand Down

0 comments on commit 600f5ce

Please sign in to comment.