From patchwork Sun Feb 14 17:17:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8302461 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4597CC02AA for ; Sun, 14 Feb 2016 17:22:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 737A3203A9 for ; Sun, 14 Feb 2016 17:22:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9D32B2039E for ; Sun, 14 Feb 2016 17:22:12 +0000 (UTC) Received: from localhost ([::1]:52239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aV0N9-0005mo-WA for patchwork-qemu-devel@patchwork.kernel.org; Sun, 14 Feb 2016 12:22:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aV0IZ-0006ph-JF for qemu-devel@nongnu.org; Sun, 14 Feb 2016 12:17:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aV0IY-00035T-DF for qemu-devel@nongnu.org; Sun, 14 Feb 2016 12:17:27 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aV0IY-00035I-2w for qemu-devel@nongnu.org; Sun, 14 Feb 2016 12:17:26 -0500 Received: by mail-wm0-x243.google.com with SMTP id g62so11958067wme.2 for ; Sun, 14 Feb 2016 09:17:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=t0rmW8SQZG0+OK1xeiRajQ4VBAeka5pG1oT73VNgO5E=; b=sncokvIGYUtXECe05bQbPDPXsS7YoyLMJGTWtkA4OJgUhmkxkYVFethc0ScRzN/csn mdevFE6rN/TOre3xLUC77Vy8goIKtc33+3tPUMtwzVy4uusAzT9ZdIXCw4Fueil/f6yr xR6wn3ue/z6wkyyaXgSjOcibPxgBe2f3xiqywKP5rnJAjrLq+OfifcqUnqiHAk5RdVSj 10tdzk8lZF3o/HELRNbjuWMWGh2QsYmB1xs9ki0cE2WQa3D5gq0pb24sIVEm0uYSLWk9 aqiuXLHWvP7Goo2cY64GaGJzks81i2i57aYiEsFWNvDHyNVFqsBe0NFVIEvOcLFDJScn j4Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=t0rmW8SQZG0+OK1xeiRajQ4VBAeka5pG1oT73VNgO5E=; b=g0axz2I3nej/wT1gkuuRoSye1oT+KZZ8Xq4lAX71FckbdZ5usS3sBtBcfN8gdyCgUE BlM+nAY8NFJnXibKaIzphicnSdoWL8Q3oFMh4ANJ/5jYYvlmVfRu1wUFtKOalf3uYYBY dMwj1Y807xkOdr9Q5+HJCMYPdWVrOstesE51lQW9qdiBygGlz2tGIXgbbcabaMEdzqK0 j2lMLxc4CVkTOBr9G4e88WYVz0D+rusR+avrWi09icDAJzNzy/FqITfs/fDLMyVKqys3 AtM5hjSs/7ySz5fPrQfr4bXSo0OlE/Sygp4p/1/Mp+/WYqdF0//bNzluLoBTBBV7AI3F 791Q== X-Gm-Message-State: AG10YOQI59Utkvlqg2icp9vGk7gWV2jU3gvASEoLs8Wi7MpwOuiE3Bzrk4qyMfS/8M8ZPg== X-Received: by 10.194.7.195 with SMTP id l3mr11721565wja.43.1455470245584; Sun, 14 Feb 2016 09:17:25 -0800 (PST) Received: from donizetti.lan (94-39-152-251.adsl-ull.clienti.tiscali.it. [94.39.152.251]) by smtp.gmail.com with ESMTPSA id ko2sm21426149wjc.9.2016.02.14.09.17.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Feb 2016 09:17:24 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 14 Feb 2016 18:17:08 +0100 Message-Id: <1455470231-5223-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455470231-5223-1-git-send-email-pbonzini@redhat.com> References: <1455470231-5223-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Cc: stefanha@redhat.com, mst@redhat.com Subject: [Qemu-devel] [PATCH 5/8] virtio-blk: fix "disabled data plane" mode 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In disabled mode, virtio-blk dataplane seems to be enabled, but flow actually goes through the normal virtio path. This patch simplifies a bit the handling of disabled mode. In disabled mode, virtio_blk_handle_output might be called even if s->dataplane is not NULL. This is a bit tricky, because the current check for s->dataplane will always trigger, causing a continuous stream of calls to virtio_blk_data_plane_start. Unfortunately, these calls will not do anything. To fix this, set the "started" flag even in disabled mode, and skip virtio_blk_data_plane_start if the started flag is true. The resulting changes also prepare the code for the next patch, were virtio-blk dataplane will reuse the same virtio_blk_handle_output function as "regular" virtio-blk. Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have to move s->dataplane->started inside struct VirtIOBlock. Signed-off-by: Paolo Bonzini Reviewed-by: Cornelia Huck Reviewed-by: Fam Zheng --- hw/block/dataplane/virtio-blk.c | 21 +++++++++------------ hw/block/virtio-blk.c | 2 +- include/hw/virtio/virtio-blk.h | 1 + 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 03b81bc..cc521c1 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -28,7 +28,6 @@ #include "qom/object_interfaces.h" struct VirtIOBlockDataPlane { - bool started; bool starting; bool stopping; bool disabled; @@ -264,11 +263,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) VirtQueue *vq; int r; - if (s->started || s->disabled) { - return; - } - - if (s->starting) { + if (vblk->dataplane_started || s->starting) { return; } @@ -300,7 +295,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) vblk->complete_request = complete_request_vring; s->starting = false; - s->started = true; + vblk->dataplane_started = true; trace_virtio_blk_data_plane_start(s); blk_set_aio_context(s->conf->conf.blk, s->ctx); @@ -319,9 +314,10 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) k->set_guest_notifiers(qbus->parent, 1, false); fail_guest_notifiers: vring_teardown(&s->vring, s->vdev, 0); - s->disabled = true; fail_vring: + s->disabled = true; s->starting = false; + vblk->dataplane_started = true; } /* Context: QEMU global mutex held */ @@ -331,13 +327,14 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); VirtIOBlock *vblk = VIRTIO_BLK(s->vdev); + if (!vblk->dataplane_started || s->stopping) { + return; + } /* Better luck next time. */ if (s->disabled) { s->disabled = false; - return; - } - if (!s->started || s->stopping) { + vblk->dataplane_started = false; return; } s->stopping = true; @@ -364,6 +361,6 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) /* Clean up guest notifier (irq) */ k->set_guest_notifiers(qbus->parent, 1, false); - s->started = false; + vblk->dataplane_started = false; s->stopping = false; } diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index c427698..e04c8f5 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -589,7 +589,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq) /* Some guests kick before setting VIRTIO_CONFIG_S_DRIVER_OK so start * dataplane here instead of waiting for .set_status(). */ - if (s->dataplane) { + if (s->dataplane && !s->dataplane_started) { virtio_blk_data_plane_start(s->dataplane); return; } diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 199bb0e..781969d 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -56,6 +56,7 @@ typedef struct VirtIOBlock { /* Function to push to vq and notify guest */ void (*complete_request)(struct VirtIOBlockReq *req, unsigned char status); Notifier migration_state_notifier; + bool dataplane_started; struct VirtIOBlockDataPlane *dataplane; } VirtIOBlock;