From nobody Thu May 2 03:39:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558619790; cv=none; d=zoho.com; s=zohoarc; b=IMgWSpvWr7XQkn99SRzz4sF8ABER0kX/0h/oOvYSu4fqfJURmYIrdhbZBAbLXV11izMENX5t6i/9m/jAXCNdVCg6xuN8rER7tteRL3HfOe3UpuBhscTP5Yzv7AzzE3n0pUb3R8EVpQeXooFS8T5pBpE/Ce/ewZGepEhyGdYUDTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558619790; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=A4p3+E45G+31ptPOOKGGQsbe4ngnnI0wVZvVSAd2kL0=; b=czvDv4xeqnmQUGfxsZwt/u8duM5W2vLHhteIyUYELFm/FOdHJdXZGnbgJRhoGbzKCQb2qDGUbUCnH3gVTdFfvkPND+VzA5a1ot+owIhPxlQdrrwKwCVLSPmc3xQOBLm+zMQ+u7Zhp5qZ4PE0KMbgQhbalQpwWtRjF/VxKi6EGl8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558619790239669.5292518359893; Thu, 23 May 2019 06:56:30 -0700 (PDT) Received: from localhost ([127.0.0.1]:36869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToCU-0002Ww-34 for importer@patchew.org; Thu, 23 May 2019 09:56:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTo1f-0002rq-56 for qemu-devel@nongnu.org; Thu, 23 May 2019 09:44:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTo1c-00060X-Mb for qemu-devel@nongnu.org; Thu, 23 May 2019 09:44:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTo1c-0005Pc-Br for qemu-devel@nongnu.org; Thu, 23 May 2019 09:44:52 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 408413001749; Thu, 23 May 2019 13:44:32 +0000 (UTC) Received: from localhost (ovpn-116-196.ams2.redhat.com [10.36.116.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EF064385; Thu, 23 May 2019 13:44:26 +0000 (UTC) From: Stefan Hajnoczi To: Date: Thu, 23 May 2019 14:44:07 +0100 Message-Id: <20190523134409.18673-2-stefanha@redhat.com> In-Reply-To: <20190523134409.18673-1-stefanha@redhat.com> References: <20190523134409.18673-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 23 May 2019 13:44:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 1/3] virtio: add vdc->vmchange_state() callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Fam Zheng , Stefan Hajnoczi , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The core virtio code invokes ->set_status() followed by ->ioeventfd_start() when the guest resumes execution. Both of these functions are also called in other cases unrelated to vm change state. This patch introduces ->vmstate_change() so that devices can act on guest pause/resume. The existing qemu_add_vm_change_state_handler() API isn't usable by virtio devices since the ordering between vm change state handlers is undefined. The new ->vmstate_change() callback is always invoked after ->set_status() and ->ioeventfd_start() when resuming a guest. A later patch makes use of this new callback. Signed-off-by: Stefan Hajnoczi --- include/hw/virtio/virtio.h | 7 +++++++ hw/virtio/virtio.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 7140381e3a..46e54362dc 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -156,6 +156,13 @@ typedef struct VirtioDeviceClass { void (*save)(VirtIODevice *vdev, QEMUFile *f); int (*load)(VirtIODevice *vdev, QEMUFile *f, int version_id); const VMStateDescription *vmsd; + + /* Called when the device should start/stop running because the guest = was + * resumed/paused. Note that this takes VIRTIO_CONFIG_S_DRIVER_OK into + * account so running is true iff the guest is resumed and the guest d= river + * has already indicated it is ready. + */ + void (*vmstate_change)(VirtIODevice *vdev, bool running); } VirtioDeviceClass; =20 void virtio_instance_init_common(Object *proxy_obj, void *data, diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 28056a7ef7..f9f31b5325 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2246,6 +2246,7 @@ static void virtio_vmstate_change(void *opaque, int r= unning, RunState state) VirtIODevice *vdev =3D opaque; BusState *qbus =3D qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); bool backend_run =3D running && (vdev->status & VIRTIO_CONFIG_S_DRIVER= _OK); vdev->vm_running =3D running; =20 @@ -2253,10 +2254,18 @@ static void virtio_vmstate_change(void *opaque, int= running, RunState state) virtio_set_status(vdev, vdev->status); } =20 + if (!backend_run && k->vmstate_change) { + vdc->vmstate_change(vdev, backend_run); + } + if (k->vmstate_change) { k->vmstate_change(qbus->parent, backend_run); } =20 + if (backend_run && k->vmstate_change) { + vdc->vmstate_change(vdev, backend_run); + } + if (!backend_run) { virtio_set_status(vdev, vdev->status); } --=20 2.21.0 From nobody Thu May 2 03:39:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558619183; cv=none; d=zoho.com; s=zohoarc; b=LowhDsrSow/sS1kGsNF/679Yv3JEYF/N+UBUmPah1aU46S6cscejb/VWGuNDS2T/2E8OPNU3d+q0Wp/8Srku4WcDgLUPd223t9sg60ORDowPHnbNbAzk7pZ/2sW8U2Y27oS+uYbr75n2qD5lHF3+nVRzusHlq/dSj1ne1r8HNQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558619183; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5jNY4Hu0hBVtkl0ko21RXjOsw7KqYdpZDhwbRsZOkgQ=; b=JB7sYJOG4+i0yyEud9Cupn1vOxLDLhb4vBzzjdsNnAs6soNiFtoaTpKFAUrNghtC06eSUAh2AwxZMFF2fQ1Fp0K8KVRmPenzrFSCvJsKsIvVajTzXvQOXTxtVaa6mDqiYldogHFkFxy+su9o6/IQqyoqMpqshlxgLZp/SpobNW4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558619183022492.89971057795844; Thu, 23 May 2019 06:46:23 -0700 (PDT) Received: from localhost ([127.0.0.1]:36663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTo2z-0003Xj-1g for importer@patchew.org; Thu, 23 May 2019 09:46:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTo1a-0002op-Ie for qemu-devel@nongnu.org; Thu, 23 May 2019 09:44:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTo1Y-0005sN-RR for qemu-devel@nongnu.org; Thu, 23 May 2019 09:44:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTo1Y-0005ab-Fg for qemu-devel@nongnu.org; Thu, 23 May 2019 09:44:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14BF1300415C; Thu, 23 May 2019 13:44:34 +0000 (UTC) Received: from localhost (ovpn-116-196.ams2.redhat.com [10.36.116.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CFE41001E80; Thu, 23 May 2019 13:44:33 +0000 (UTC) From: Stefan Hajnoczi To: Date: Thu, 23 May 2019 14:44:08 +0100 Message-Id: <20190523134409.18673-3-stefanha@redhat.com> In-Reply-To: <20190523134409.18673-1-stefanha@redhat.com> References: <20190523134409.18673-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 23 May 2019 13:44:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 2/3] scsi: add scsi_bus_dma_restart() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Fam Zheng , Stefan Hajnoczi , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" By default scsi-bus.c registers vm change state handlers for SCSIDevice instances and restarts DMA when guest execution is resumed. Unfortunately virtio-scsi with iothreads has a special ordering requirement that the core virtio code's vm change state handler runs before scsi-bus.c's vm change state handler. This patch allows SCSI busses to disable the default vm change state handler for DMA restart. The new scsi_bus_dma_restart() API allows them to manually restart DMA at a time of their choice. Signed-off-by: Stefan Hajnoczi --- include/hw/scsi/scsi.h | 5 +++++ hw/scsi/scsi-bus.c | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index acef25faa4..e9cc563daa 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -120,6 +120,10 @@ struct SCSIReqOps { struct SCSIBusInfo { int tcq; int max_channel, max_target, max_lun; + + /* Will the bus call scsi_bus_dma_restart() itself? */ + bool custom_dma_restart; + int (*parse_cdb)(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf, void *hba_private); void (*transfer_data)(SCSIRequest *req, uint32_t arg); @@ -160,6 +164,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, Blo= ckBackend *blk, const char *serial, Error **errp); void scsi_bus_legacy_handle_cmdline(SCSIBus *bus); void scsi_legacy_handle_cmdline(void); +void scsi_bus_dma_restart(SCSIBus *bus); =20 SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag, uint32_t lun, void *hba_private); diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index c480553083..d2c5a1652b 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -134,6 +134,27 @@ void scsi_req_retry(SCSIRequest *req) req->retry =3D true; } =20 +static void scsi_device_dma_restart(SCSIDevice *dev) +{ + if (!dev->bh) { + AioContext *ctx =3D blk_get_aio_context(dev->conf.blk); + dev->bh =3D aio_bh_new(ctx, scsi_dma_restart_bh, dev); + qemu_bh_schedule(dev->bh); + } +} + +void scsi_bus_dma_restart(SCSIBus *bus) +{ + BusChild *kid; + + QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) { + DeviceState *qdev =3D kid->child; + SCSIDevice *dev =3D SCSI_DEVICE(qdev); + + scsi_device_dma_restart(dev); + } +} + static void scsi_dma_restart_cb(void *opaque, int running, RunState state) { SCSIDevice *s =3D opaque; @@ -141,11 +162,8 @@ static void scsi_dma_restart_cb(void *opaque, int runn= ing, RunState state) if (!running) { return; } - if (!s->bh) { - AioContext *ctx =3D blk_get_aio_context(s->conf.blk); - s->bh =3D aio_bh_new(ctx, scsi_dma_restart_bh, s); - qemu_bh_schedule(s->bh); - } + + scsi_device_dma_restart(s); } =20 static void scsi_qdev_realize(DeviceState *qdev, Error **errp) @@ -206,8 +224,13 @@ static void scsi_qdev_realize(DeviceState *qdev, Error= **errp) error_propagate(errp, local_err); return; } - dev->vmsentry =3D qemu_add_vm_change_state_handler(scsi_dma_restart_cb, - dev); + + if (bus->info->custom_dma_restart) { + dev->vmsentry =3D NULL; + } else { + dev->vmsentry =3D qemu_add_vm_change_state_handler(scsi_dma_restar= t_cb, + dev); + } } =20 static void scsi_qdev_unrealize(DeviceState *qdev, Error **errp) --=20 2.21.0 From nobody Thu May 2 03:39:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1558619896; cv=none; d=zoho.com; s=zohoarc; b=UGf5nUABFQJjRVBDhuyEXWGdvIqaBAMTsCJkoLSs3RKdL/nlvYBB8wgjRcwjjbtP61wjUDxJFn8VAXd/KoIueUkwKGBJBzNC1oCJKiD69AbOAkfoy10/dTSrGZXSzsDHacFyn5HQIIJ+UWeni1xaDT+7oWRX9bPn02Rvf4Dnrtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558619896; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=43tb5F2j/EbMgo5WzG56pm9DozAz2a3I28GGxOLs3AA=; b=HR7EMVfbvEbzrQTlX6bT8KI0WMoL4IJnzkt3COKQkLDEgeye4MVmvI30Q1V3UlXDi8Smb0KSRWS/842HroVHs2I4bXLAMmKrhHgcQMdbPBGUdTyK69c6do0j8vI+SmZ24zouRlthnjJY1Y660n5Dalyag0g7fnvOYuhWE4HiCLM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558619896597994.9795563651459; Thu, 23 May 2019 06:58:16 -0700 (PDT) Received: from localhost ([127.0.0.1]:36879 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToEQ-0003sd-E7 for importer@patchew.org; Thu, 23 May 2019 09:58:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTo1k-0002vl-KA for qemu-devel@nongnu.org; Thu, 23 May 2019 09:45:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTo1i-00068g-Ft for qemu-devel@nongnu.org; Thu, 23 May 2019 09:45:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTo1i-0005eL-8h for qemu-devel@nongnu.org; Thu, 23 May 2019 09:44:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6AB84C004BEB; Thu, 23 May 2019 13:44:40 +0000 (UTC) Received: from localhost (ovpn-116-196.ams2.redhat.com [10.36.116.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76E185D707; Thu, 23 May 2019 13:44:35 +0000 (UTC) From: Stefan Hajnoczi To: Date: Thu, 23 May 2019 14:44:09 +0100 Message-Id: <20190523134409.18673-4-stefanha@redhat.com> In-Reply-To: <20190523134409.18673-1-stefanha@redhat.com> References: <20190523134409.18673-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 23 May 2019 13:44:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v2 3/3] virtio-scsi: fix iothread deadlock on 'cont' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , Fam Zheng , Stefan Hajnoczi , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When the 'cont' command resumes guest execution the vm change state handlers are invoked. Unfortunately there is no explicit ordering between vm change state handlers. When two layers of code both use vm change state handlers, we don't control which handler runs first. virtio-scsi with iothreads hits a deadlock when a failed SCSI command is restarted and completes before the iothread is re-initialized. This patch makes sure that DMA restart happens after the iothread has been started again. Signed-off-by: Stefan Hajnoczi --- hw/scsi/virtio-scsi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 839f120256..236a0ee873 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -846,12 +846,28 @@ static void virtio_scsi_hotunplug(HotplugHandler *hot= plug_dev, DeviceState *dev, qdev_simple_device_unplug_cb(hotplug_dev, dev, errp); } =20 +static void virtio_scsi_vmstate_change(VirtIODevice *vdev, bool running) +{ + VirtIOSCSI *s =3D VIRTIO_SCSI(vdev); + + if (running) { + scsi_bus_dma_restart(&s->bus); + } +} + static struct SCSIBusInfo virtio_scsi_scsi_info =3D { .tcq =3D true, .max_channel =3D VIRTIO_SCSI_MAX_CHANNEL, .max_target =3D VIRTIO_SCSI_MAX_TARGET, .max_lun =3D VIRTIO_SCSI_MAX_LUN, =20 + /* We call scsi_bus_dma_restart() ourselves to control the ordering be= tween + * ->start_ioeventfd() and DMA restart. Do it in + * virtio_scsi_vmstate_change(), which is called by the core virtio co= de + * after ->start_ioeventfd(). + */ + .custom_dma_restart =3D true, + .complete =3D virtio_scsi_command_complete, .cancel =3D virtio_scsi_request_cancelled, .change =3D virtio_scsi_change, @@ -986,6 +1002,7 @@ static void virtio_scsi_class_init(ObjectClass *klass,= void *data) vdc->reset =3D virtio_scsi_reset; vdc->start_ioeventfd =3D virtio_scsi_dataplane_start; vdc->stop_ioeventfd =3D virtio_scsi_dataplane_stop; + vdc->vmstate_change =3D virtio_scsi_vmstate_change; hc->plug =3D virtio_scsi_hotplug; hc->unplug =3D virtio_scsi_hotunplug; } --=20 2.21.0