From nobody Mon Apr 29 14:42:33 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=1558723126; cv=none; d=zoho.com; s=zohoarc; b=C3TJoibqNX5ZhnE9lrFQEkOeGeUjNu6LLL4Wu+2jqv6j5Rte/MQtMnWv7QHTLgddlrv07j259+wKKJ5aIKY4Bcl5WgNPkBfxeYNQOSb0Qzlqlq3jWRTCzXqNMCXR6TaICUMNs2k/xMDnNXYCYIBefsy07kQvfo2Y7D0qvX8hi6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558723126; 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=mI7vdkn8hq7RC7T4VcHa6tWaSlPdDigPamIkwz8yHEE=; b=EkaDL6MwGiTSavtqJxge2daLfdI08JmOX/CjSf5I85z7zxCmgM1McOPaOpDIvKAfwKidXY74RKmGdjvKecd3ppIAEziGIZtAEjC3E3ekFuSxOJy9CjP7wcQs/otZzmrnhTiy5ys5co42XAYk8AJhLKzZmtoLyPhIQMr4MzO2EWY= 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 1558723126902840.5778924635673; Fri, 24 May 2019 11:38:46 -0700 (PDT) Received: from localhost ([127.0.0.1]:58650 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF5O-00026o-PV for importer@patchew.org; Fri, 24 May 2019 14:38:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF3v-0001Em-3l for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUF3s-0008Tk-RH for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUF3r-0008QE-BL for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D5E33082B44; Fri, 24 May 2019 18:36:51 +0000 (UTC) Received: from localhost (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B2415B2F7; Fri, 24 May 2019 18:36:46 +0000 (UTC) From: Stefan Hajnoczi To: Date: Fri, 24 May 2019 19:36:36 +0100 Message-Id: <20190524183638.20745-2-stefanha@redhat.com> In-Reply-To: <20190524183638.20745-1-stefanha@redhat.com> References: <20190524183638.20745-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 24 May 2019 18:36:51 +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 v3 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: Fam Zheng , Kevin Wolf , Paolo Bonzini , 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 27c0efc3d0..5742efa1d7 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -158,6 +158,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 4805727b53..cdf869456b 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2291,6 +2291,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->started; vdev->vm_running =3D running; =20 @@ -2298,10 +2299,18 @@ static void virtio_vmstate_change(void *opaque, int= running, RunState state) virtio_set_status(vdev, vdev->status); } =20 + if (!backend_run && vdc->vmstate_change) { + vdc->vmstate_change(vdev, backend_run); + } + if (k->vmstate_change) { k->vmstate_change(qbus->parent, backend_run); } =20 + if (backend_run && vdc->vmstate_change) { + vdc->vmstate_change(vdev, backend_run); + } + if (!backend_run) { virtio_set_status(vdev, vdev->status); } --=20 2.21.0 From nobody Mon Apr 29 14:42:33 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=1558723208; cv=none; d=zoho.com; s=zohoarc; b=gtUpICIkbuOxrBSKivOQ94rhm0ut4zFRWAiN1P9ZM2ehDWHcsSSPxXE7h1d1SqPIZWpE58lqOItgBbNOHZnkzYlACTj+RJtO6jNO3DmaK4lYEj+j1hmIgdzOmlpGcFn2IXSUKP7UtvU7NHXhl2OdFaS95M5YpsZjdOK5E5tWTKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558723208; 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=GojUGvQ4pi9LrcYtG1dvCSTNMwkvlmGBI7Wi9qGGKUbOlpsDT/QETRPqp8EuRMZ2luz+wOSzDC48sBqczDk4suRjbPYLjS3pZhmwU0VqyXktfIr56eHfMAsWiAd+duidOcDzfq9TEykWVdvYputF1P9IlcXq0wISg2QvDrXlfvs= 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 1558723208159795.205324201711; Fri, 24 May 2019 11:40:08 -0700 (PDT) Received: from localhost ([127.0.0.1]:58680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF6k-00033c-4d for importer@patchew.org; Fri, 24 May 2019 14:39:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF3z-0001Hg-Pp for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUF3v-0008Uu-Bq for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUF3u-0008Tz-Ja for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:03 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A582F3092647; Fri, 24 May 2019 18:36:57 +0000 (UTC) Received: from localhost (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EAD984F7; Fri, 24 May 2019 18:36:52 +0000 (UTC) From: Stefan Hajnoczi To: Date: Fri, 24 May 2019 19:36:37 +0100 Message-Id: <20190524183638.20745-3-stefanha@redhat.com> In-Reply-To: <20190524183638.20745-1-stefanha@redhat.com> References: <20190524183638.20745-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 24 May 2019 18:36:57 +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 v3 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: Fam Zheng , Kevin Wolf , Paolo Bonzini , 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 Mon Apr 29 14:42:33 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=1558723406; cv=none; d=zoho.com; s=zohoarc; b=cz+r0x6w+yJVviwX7gFFRMvvWnf2q32FFK0jNm6kEcFRpXAaHAAJW6aSUxNo7wJGhjBfaxGlxl75T0Nj2EgkK2soq+Uas81DVLWKHBfwB9vLMNr5gQFmIlfukrnsE/4TbWvXYdd1z2lYsn3zgwd8WU/wQHCBqmCTnNo48VUuYZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558723406; 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=OXE+aF5RJabfJPAj7r7bOw1kaUC5QaZ22TmMtdVOpkMqhpG7qGsAm3qCWRYP3KlSI5LLwEfMhzYDVez+3GOPRMHG0zcAPCEg3a0V54baVhbm+c7zsA8tAXMmP+WMdl7oS1OaEUbpbXjN+d3KcRcLRZ1yKN4dNf/oK/LAejw53a8= 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 1558723406439522.7460271216936; Fri, 24 May 2019 11:43:26 -0700 (PDT) Received: from localhost ([127.0.0.1]:58724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF9L-0004yv-F5 for importer@patchew.org; Fri, 24 May 2019 14:42:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hUF4H-0001XZ-KJ for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hUF4C-0000CL-Ta for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39864) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hUF49-0008VJ-DP for qemu-devel@nongnu.org; Fri, 24 May 2019 14:37:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF8F1F74BC; Fri, 24 May 2019 18:37:03 +0000 (UTC) Received: from localhost (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 115AD12A73; Fri, 24 May 2019 18:36:58 +0000 (UTC) From: Stefan Hajnoczi To: Date: Fri, 24 May 2019 19:36:38 +0100 Message-Id: <20190524183638.20745-4-stefanha@redhat.com> In-Reply-To: <20190524183638.20745-1-stefanha@redhat.com> References: <20190524183638.20745-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 24 May 2019 18:37:04 +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 v3 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: Fam Zheng , Kevin Wolf , Paolo Bonzini , 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