[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 1/7] virtio-crypto: fix virtio_queue_set_notification
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 1/7] virtio-crypto: fix virtio_queue_set_notification() race |
Date: |
Fri, 18 Nov 2016 17:53:19 +0200 |
From: Stefan Hajnoczi <address@hidden>
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 <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Tested-by: Alexey Kardashevskiy <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
Reviewed-by: Gonglei <address@hidden>
---
hw/virtio/virtio-crypto.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 3293843..847dc9d 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -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
--
MST
- [Qemu-devel] [PULL 0/7] virtio, vhost, pc: fixes, Michael S. Tsirkin, 2016/11/18
- [Qemu-devel] [PULL 1/7] virtio-crypto: fix virtio_queue_set_notification() race,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 2/7] virtio: introduce grab/release_ioeventfd to fix vhost, Michael S. Tsirkin, 2016/11/18
- [Qemu-devel] [PULL 3/7] virtio: access ISR atomically, Michael S. Tsirkin, 2016/11/18
- [Qemu-devel] [PULL 4/7] virtio: set ISR on dataplane notifications, Michael S. Tsirkin, 2016/11/18
- [Qemu-devel] [PULL 5/7] ivshmem: Fix 64 bit memory bar configuration, Michael S. Tsirkin, 2016/11/18
- [Qemu-devel] [PULL 6/7] ipmi: fix qemu crash while migrating with ipmi, Michael S. Tsirkin, 2016/11/18
- [Qemu-devel] [PULL 7/7] acpi: Use apic_id_limit when calculating legacy ACPI table size, Michael S. Tsirkin, 2016/11/18
- Re: [Qemu-devel] [PULL 0/7] virtio, vhost, pc: fixes, Stefan Hajnoczi, 2016/11/21