All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Gonglei <arei.gonglei@huawei.com>,
	Alexey Kardashevskiy <aik@ozlabs.ru>
Subject: [Qemu-devel] [PULL 1/7] virtio-crypto: fix virtio_queue_set_notification() race
Date: Fri, 18 Nov 2016 17:53:19 +0200	[thread overview]
Message-ID: <1479484366-7977-2-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1479484366-7977-1-git-send-email-mst@redhat.com>

From: Stefan Hajnoczi <stefanha@redhat.com>

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>
---
 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

  reply	other threads:[~2016-11-18 15:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18 15:53 [Qemu-devel] [PULL 0/7] virtio, vhost, pc: fixes Michael S. Tsirkin
2016-11-18 15:53 ` Michael S. Tsirkin [this message]
2016-11-18 15:53 ` [Qemu-devel] [PULL 2/7] virtio: introduce grab/release_ioeventfd to fix vhost Michael S. Tsirkin
2016-11-18 15:53 ` [Qemu-devel] [PULL 3/7] virtio: access ISR atomically Michael S. Tsirkin
2016-11-18 15:53 ` [Qemu-devel] [PULL 4/7] virtio: set ISR on dataplane notifications Michael S. Tsirkin
2016-11-18 15:53 ` [Qemu-devel] [PULL 5/7] ivshmem: Fix 64 bit memory bar configuration Michael S. Tsirkin
2016-11-18 15:53 ` [Qemu-devel] [PULL 6/7] ipmi: fix qemu crash while migrating with ipmi Michael S. Tsirkin
2016-11-18 15:54 ` [Qemu-devel] [PULL 7/7] acpi: Use apic_id_limit when calculating legacy ACPI table size Michael S. Tsirkin
2016-11-21 11:10 ` [Qemu-devel] [PULL 0/7] virtio, vhost, pc: fixes Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479484366-7977-2-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=arei.gonglei@huawei.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.