From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7lTo-0006Pu-E4 for qemu-devel@nongnu.org; Fri, 18 Nov 2016 10:53:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7lTi-0006QA-H7 for qemu-devel@nongnu.org; Fri, 18 Nov 2016 10:53:32 -0500 Received: from mail.kernel.org ([198.145.29.136]:40696) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c7lTi-0006Pr-Ap for qemu-devel@nongnu.org; Fri, 18 Nov 2016 10:53:26 -0500 Date: Fri, 18 Nov 2016 17:53:19 +0200 From: "Michael S. Tsirkin" Message-ID: <1479484366-7977-2-git-send-email-mst@redhat.com> References: <1479484366-7977-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1479484366-7977-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 1/7] virtio-crypto: fix virtio_queue_set_notification() race List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi , Gonglei , Alexey Kardashevskiy From: Stefan Hajnoczi 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 Signed-off-by: Stefan Hajnoczi Tested-by: Alexey Kardashevskiy Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Gonglei --- 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