[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 2/3] scsi: add scsi_bus_dma_restart()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [RFC v2 2/3] scsi: add scsi_bus_dma_restart() |
Date: |
Thu, 23 May 2019 14:44:08 +0100 |
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 <address@hidden>
---
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,
BlockBackend *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);
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 = true;
}
+static void scsi_device_dma_restart(SCSIDevice *dev)
+{
+ if (!dev->bh) {
+ AioContext *ctx = blk_get_aio_context(dev->conf.blk);
+ dev->bh = 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 = kid->child;
+ SCSIDevice *dev = SCSI_DEVICE(qdev);
+
+ scsi_device_dma_restart(dev);
+ }
+}
+
static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
{
SCSIDevice *s = opaque;
@@ -141,11 +162,8 @@ static void scsi_dma_restart_cb(void *opaque, int running,
RunState state)
if (!running) {
return;
}
- if (!s->bh) {
- AioContext *ctx = blk_get_aio_context(s->conf.blk);
- s->bh = aio_bh_new(ctx, scsi_dma_restart_bh, s);
- qemu_bh_schedule(s->bh);
- }
+
+ scsi_device_dma_restart(s);
}
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 = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
- dev);
+
+ if (bus->info->custom_dma_restart) {
+ dev->vmsentry = NULL;
+ } else {
+ dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
+ dev);
+ }
}
static void scsi_qdev_unrealize(DeviceState *qdev, Error **errp)
--
2.21.0