From patchwork Wed Sep 4 12:16:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 272586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7D10C2C00B7 for ; Wed, 4 Sep 2013 22:17:04 +1000 (EST) Received: from localhost ([::1]:52569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHC17-0007bV-S3 for incoming@patchwork.ozlabs.org; Wed, 04 Sep 2013 08:17:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHC0k-0007bF-Rs for qemu-devel@nongnu.org; Wed, 04 Sep 2013 08:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHC0V-0000zr-L6 for qemu-devel@nongnu.org; Wed, 04 Sep 2013 08:16:38 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:36197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHC0V-0000yB-CG for qemu-devel@nongnu.org; Wed, 04 Sep 2013 08:16:23 -0400 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Sep 2013 13:09:48 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Sep 2013 13:09:44 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 109FD219005F for ; Wed, 4 Sep 2013 13:16:17 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps4075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r84CG4Qr58589212 for ; Wed, 4 Sep 2013 12:16:04 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r84CGGcR004261 for ; Wed, 4 Sep 2013 06:16:16 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r84CGFlS004218 for ; Wed, 4 Sep 2013 06:16:15 -0600 From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 4 Sep 2013 14:16:15 +0200 Message-Id: <1378296975-17661-1-git-send-email-cornelia.huck@de.ibm.com> X-Mailer: git-send-email 1.8.3.4 X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13090412-8372-0000-0000-00000713CB38 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.108 Subject: [Qemu-devel] [PATCH RFC] dataplane: Fix startup race. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Avoid trying to setup dataplane again if dataplane setup is already in progress. This may happen if an eventfd is triggered during setup. I saw this occasionally with an experimental s390 irqfd implementation: virtio_blk_handle_output -> virtio_blk_data_plane_start -> virtio_ccw_set_host_notifier ... -> virtio_queue_set_host_notifier_fd_handler -> virtio_queue_host_notifier_read -> virtio_queue_notify_vq -> virtio_blk_handle_output -> virtio_blk_data_plane_start -> vring_setup -> hostmem_init -> memory_listener_register -> BOOM As virtio-ccw tries to follow what virtio-pci does, it might be triggerable for other platforms as well. Signed-off-by: Cornelia Huck --- hw/block/dataplane/virtio-blk.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 5a96ccd..f2d7350 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -42,6 +42,7 @@ typedef struct { struct VirtIOBlockDataPlane { bool started; + bool starting; bool stopping; QEMUBH *start_bh; QemuThread thread; @@ -451,8 +452,15 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) return; } + if (s->starting) { + return; + } + + s->starting = true; + vq = virtio_get_queue(s->vdev, 0); if (!vring_setup(&s->vring, s->vdev, 0)) { + s->starting = false; return; } @@ -482,6 +490,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) s->io_notifier = *ioq_get_notifier(&s->ioqueue); aio_set_event_notifier(s->ctx, &s->io_notifier, handle_io); + s->starting = false; s->started = true; trace_virtio_blk_data_plane_start(s);